Browse Source

Endpoint basico /cv funcionando renderizando el tex y mostrando un PDF

main
rodley82 3 years ago
parent
commit
a0e1c0a3de
  1. 6
      .gitignore
  2. 11
      app/controllers/work_experiences_controller.rb
  3. 2
      app/views/work_experiences/cv.html.erb
  4. 2
      config/routes.rb

6
.gitignore

@ -33,3 +33,9 @@
# Ignore master key for decrypting credentials and more. # Ignore master key for decrypting credentials and more.
/config/master.key /config/master.key
*.tex
*.log
*.pdf
*.aux

11
app/controllers/work_experiences_controller.rb

@ -1,6 +1,17 @@
class WorkExperiencesController < ApplicationController class WorkExperiencesController < ApplicationController
before_action :set_work_experience, only: %i[ show edit update destroy ] before_action :set_work_experience, only: %i[ show edit update destroy ]
def cv
@full_name = "Rodolfo Leyes"
# render layout: false, content_type: "application/octet-stream"
tex_content = render_to_string(layout: false)
File.open("./temp.tex", "w") do |f|
f << tex_content
end
`pdflatex -interaction=batchmode temp.tex`
render file: "#{Rails.root}/temp.pdf", layout: false
end
# GET /work_experiences or /work_experiences.json # GET /work_experiences or /work_experiences.json
def index def index
@work_experiences = WorkExperience.all @work_experiences = WorkExperience.all

2
template.tex → app/views/work_experiences/cv.html.erb

@ -56,7 +56,7 @@
% HEADER SECTION % HEADER SECTION
%---------------------------------------------------------------------------------------- %----------------------------------------------------------------------------------------
{\fontsize{36}{36}\selectfont\scshape\textls[200]{John Smith}} % Your name at the top {\fontsize{36}{36}\selectfont\scshape\textls[200]{<%= @full_name %>}} % Your name at the top
\vspace{1.5cm} % Extra whitespace after the large name at the top \vspace{1.5cm} % Extra whitespace after the large name at the top

2
config/routes.rb

@ -4,4 +4,6 @@ Rails.application.routes.draw do
# Defines the root path route ("/") # Defines the root path route ("/")
# root "articles#index" # root "articles#index"
get "cv", to: "work_experiences#cv"
end end

Loading…
Cancel
Save