From 938564052b52a2eef35f92b28f493bdf5a2cd3fa Mon Sep 17 00:00:00 2001 From: rodley82 Date: Wed, 21 Dec 2022 11:45:49 -0300 Subject: [PATCH] Added cover letters generation --- app/admin/cover_letters_admin.rb | 42 ++++++ app/admin/education_entries_admin.rb | 34 +---- app/admin/skills_admin.rb | 34 +---- app/admin/users_admin.rb | 14 +- app/admin/work_experiences_admin.rb | 32 +---- app/models/cover_letter.rb | 11 ++ app/views/templates/awesome/Makefile | 5 +- .../templates/awesome/coverletter.html.erb | 131 ++++++++++++++++++ app/views/templates/awesome/resume.html.erb | 3 - .../20221221141217_add_cover_letters.rb | 14 ++ db/schema.rb | 15 +- 11 files changed, 234 insertions(+), 101 deletions(-) create mode 100644 app/admin/cover_letters_admin.rb create mode 100644 app/models/cover_letter.rb create mode 100644 app/views/templates/awesome/coverletter.html.erb create mode 100644 db/migrate/20221221141217_add_cover_letters.rb diff --git a/app/admin/cover_letters_admin.rb b/app/admin/cover_letters_admin.rb new file mode 100644 index 0000000..7888b31 --- /dev/null +++ b/app/admin/cover_letters_admin.rb @@ -0,0 +1,42 @@ +Trestle.resource(:cover_letters) do + menu do + item :cover_letters, icon: "fa fa-envelope", priority: 2 + end + + form do |item| + concat Trestle::Form::Automatic.new(admin).render(self, item) + # text_area :objective + end + + # Customize the table columns shown on the index view. + table do + column :company_name + column :title + column :user + column :created_at, align: :center + actions do |toolbar, instance, admin| + toolbar.edit if admin && admin.actions.include?(:edit) + toolbar.delete if admin && admin.actions.include?(:destroy) + toolbar.link 'Coverletter', instance, action: :generate_coverletter, method: :get, style: :primary, icon: "fa fa-file-pdf", target: "_blank" + end + end + + controller do + def generate_coverletter + cover_letter = admin.find_instance(params) + ac = ActionController::Base.new() + tex_content = ac.render_to_string(layout: false, template: 'templates/awesome/coverletter', locals: { "@cover_letter": cover_letter } ) + destination_dir = "#{Rails.root}/app/views/templates/awesome" + `cd #{destination_dir} && make clean` + File.open("#{destination_dir}/coverletter.tex", "w") do |f| + f << tex_content + end + `cd #{destination_dir} && make coverletter.pdf` + render file: "#{destination_dir}/coverletter.pdf", layout: false + end + end + + routes do + get :generate_coverletter, on: :member + end +end diff --git a/app/admin/education_entries_admin.rb b/app/admin/education_entries_admin.rb index 2a85112..b33bdda 100644 --- a/app/admin/education_entries_admin.rb +++ b/app/admin/education_entries_admin.rb @@ -1,35 +1,9 @@ Trestle.resource(:education_entries) do menu do - item :education_entries, icon: "fa fa-star" + item :education_entries, icon: "fa fa-graduation-cap", priority: 4 end - # Customize the table columns shown on the index view. - # - # table do - # column :name - # column :created_at, align: :center - # actions - # end - - # Customize the form fields shown on the new/edit views. - # - # form do |education_entry| - # text_field :name - # - # row do - # col { datetime_field :updated_at } - # col { datetime_field :created_at } - # end - # end - - # By default, all parameters passed to the update and create actions will be - # permitted. If you do not have full trust in your users, you should explicitly - # define the list of permitted parameters. - # - # For further information, see the Rails documentation on Strong Parameters: - # http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters - # - # params do |params| - # params.require(:education_entry).permit(:name, ...) - # end + form do |item| + concat Trestle::Form::Automatic.new(admin).render(self, item) + end end diff --git a/app/admin/skills_admin.rb b/app/admin/skills_admin.rb index b0a735a..213a79f 100644 --- a/app/admin/skills_admin.rb +++ b/app/admin/skills_admin.rb @@ -1,35 +1,9 @@ Trestle.resource(:skills) do menu do - item :skills, icon: "fa fa-star" + item :skills, icon: "fa fa-toolbox", priority: 5 end - # Customize the table columns shown on the index view. - # - # table do - # column :name - # column :created_at, align: :center - # actions - # end - - # Customize the form fields shown on the new/edit views. - # - # form do |skill| - # text_field :name - # - # row do - # col { datetime_field :updated_at } - # col { datetime_field :created_at } - # end - # end - - # By default, all parameters passed to the update and create actions will be - # permitted. If you do not have full trust in your users, you should explicitly - # define the list of permitted parameters. - # - # For further information, see the Rails documentation on Strong Parameters: - # http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters - # - # params do |params| - # params.require(:skill).permit(:name, ...) - # end + form do |item| + concat Trestle::Form::Automatic.new(admin).render(self, item) + end end diff --git a/app/admin/users_admin.rb b/app/admin/users_admin.rb index 7cc1fe2..c4f1ddf 100644 --- a/app/admin/users_admin.rb +++ b/app/admin/users_admin.rb @@ -1,17 +1,22 @@ Trestle.resource(:users) do menu do - item :users, icon: "fa fa-star" + item :users, icon: "fa fa-user", priority: 1 + end + + form do |item| + concat Trestle::Form::Automatic.new(admin).render(self, item) + + text_area :objective end # Customize the table columns shown on the index view. - # table do column :name column :created_at, align: :center actions do |toolbar, instance, admin| toolbar.edit if admin && admin.actions.include?(:edit) toolbar.delete if admin && admin.actions.include?(:destroy) - toolbar.link 'Template 1', instance, action: :generate, method: :get, style: :primary, icon: "fa fa-file-pdf" + toolbar.link 'CV', instance, action: :generate, method: :get, style: :primary, icon: "fa fa-file-pdf", target: "_blank" end end @@ -19,14 +24,13 @@ Trestle.resource(:users) do def generate user = admin.find_instance(params) ac = ActionController::Base.new() - # debugger tex_content = ac.render_to_string(layout: false, template: 'templates/awesome/resume', locals: { "@user": user } ) destination_dir = "#{Rails.root}/app/views/templates/awesome" `cd #{destination_dir} && make clean` File.open("#{destination_dir}/resume.tex", "w") do |f| f << tex_content end - `cd #{destination_dir} && make` + `cd #{destination_dir} && make resume.pdf` render file: "#{destination_dir}/resume.pdf", layout: false end end diff --git a/app/admin/work_experiences_admin.rb b/app/admin/work_experiences_admin.rb index 49b766a..0a21592 100644 --- a/app/admin/work_experiences_admin.rb +++ b/app/admin/work_experiences_admin.rb @@ -1,35 +1,5 @@ Trestle.resource(:work_experiences) do menu do - item :work_experiences, icon: "fa fa-star" + item :work_experiences, icon: "fa fa-user-nurse", priority: 3 end - - # Customize the table columns shown on the index view. - # - # table do - # column :name - # column :created_at, align: :center - # actions - # end - - # Customize the form fields shown on the new/edit views. - # - # form do |work_experience| - # text_field :name - # - # row do - # col { datetime_field :updated_at } - # col { datetime_field :created_at } - # end - # end - - # By default, all parameters passed to the update and create actions will be - # permitted. If you do not have full trust in your users, you should explicitly - # define the list of permitted parameters. - # - # For further information, see the Rails documentation on Strong Parameters: - # http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters - # - # params do |params| - # params.require(:work_experience).permit(:name, ...) - # end end diff --git a/app/models/cover_letter.rb b/app/models/cover_letter.rb new file mode 100644 index 0000000..3e6ba8b --- /dev/null +++ b/app/models/cover_letter.rb @@ -0,0 +1,11 @@ +class CoverLetter < ApplicationRecord + belongs_to :user + + default_scope -> { order(order: :asc) } + scope :active, -> { where.not(order: nil) } + + + def tex_paragraph + csv_paragraphs.split(";").join("\n").tex_safe + end +end diff --git a/app/views/templates/awesome/Makefile b/app/views/templates/awesome/Makefile index 2232637..924eeef 100644 --- a/app/views/templates/awesome/Makefile +++ b/app/views/templates/awesome/Makefile @@ -4,7 +4,10 @@ CC = xelatex RESUME_DIR = . RESUME_SRCS = $(shell find $(RESUME_DIR) -name '*.tex') -resume.pdf: resume.tex $(RESUME_SRCS) +resume.pdf: $(RESUME_SRCS) + $(CC) -interaction=batchmode -output-directory=. $< + +coverletter.pdf: $(RESUME_SRCS) $(CC) -interaction=batchmode -output-directory=. $< clean: diff --git a/app/views/templates/awesome/coverletter.html.erb b/app/views/templates/awesome/coverletter.html.erb new file mode 100644 index 0000000..44ddbeb --- /dev/null +++ b/app/views/templates/awesome/coverletter.html.erb @@ -0,0 +1,131 @@ +<% + user = @cover_letter.user +%> +%!TEX TS-program = xelatex +%!TEX encoding = UTF-8 Unicode +% Awesome CV LaTeX Template for Cover Letter +% +% This template has been downloaded from: +% https://github.com/posquit0/Awesome-CV +% +% Authors: +% Claud D. Park +% Lars Richter +% +% Template license: +% CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/) +% + +%------------------------------------------------------------------------------- +% CONFIGURATIONS +%------------------------------------------------------------------------------- +% A4 paper size by default, use 'letterpaper' for US letter +\documentclass[11pt, a4paper]{awesome-cv} + +% Configure page margins with geometry +\geometry{left=1.4cm, top=.8cm, right=1.4cm, bottom=1.8cm, footskip=.5cm} + +% Color for highlights +% Awesome Colors: awesome-emerald, awesome-skyblue, awesome-red, awesome-pink, awesome-orange +% awesome-nephritis, awesome-concrete, awesome-darknight +\colorlet{awesome}{awesome-red} +% Uncomment if you would like to specify your own color +% \definecolor{awesome}{HTML}{CA63A8} + +% Colors for text +% Uncomment if you would like to specify your own color +% \definecolor{darktext}{HTML}{414141} +% \definecolor{text}{HTML}{333333} +% \definecolor{graytext}{HTML}{5D5D5D} +% \definecolor{lighttext}{HTML}{999999} +% \definecolor{sectiondivider}{HTML}{5D5D5D} + +% Set false if you don't want to highlight section with awesome color +\setbool{acvSectionColorHighlight}{true} + +% If you would like to change the social information separator from a pipe (|) to something else +\renewcommand{\acvHeaderSocialSep}{\quad\textbar\quad} + + +%------------------------------------------------------------------------------- +% PERSONAL INFORMATION +% Comment any of the lines below if they are not required +%------------------------------------------------------------------------------- +% Available options: circle|rectangle,edge/noedge,left/right +\name{<%= user.name.tex_safe %>}{} +\position{<%= user.title.tex_safe %>} +\address{<%= user.address.tex_safe %>} + +\mobile{<%= user.phone.tex_safe %>} +\email{<%= user.email.tex_safe %>} +%\dateofbirth{January 1st, 1970} +\homepage{<%= user.other_page_url.tex_safe %>} +\github{<%= user.github.tex_safe %>} +\linkedin{<%= user.linkedin.tex_safe %>} +% \gitlab{gitlab-id} +% \stackoverflow{SO-id}{SO-name} +% \twitter{@twit} +% \skype{skype-id} +% \reddit{reddit-id} +% \medium{madium-id} +% \kaggle{kaggle-id} +% \googlescholar{googlescholar-id}{name-to-display} +%% \firstname and \lastname will be used +% \googlescholar{googlescholar-id}{} +% \extrainfo{extra information} + +% \quote{``Be the change that you want to see in the world."} + + +%------------------------------------------------------------------------------- +% LETTER INFORMATION +% All of the below lines must be filled out +%------------------------------------------------------------------------------- +% The company being applied to +\recipient + {<%= @cover_letter.company_name.tex_safe %>} + { Company Recruitment Team } +% The date on the letter, default is the date of compilation +\letterdate{\today} +% The title of the letter +\lettertitle{<%= @cover_letter.title.tex_safe %>} +% How the letter is opened +\letteropening{Dear Mr./Ms./Dr. LastName,} +% How the letter is closed +\letterclosing{Sincerely,} +% Any enclosures with the letter +\letterenclosure[Attached]{Curriculum Vitae} + + +%------------------------------------------------------------------------------- +\begin{document} + +% Print the header with above personal information +% Give optional argument to change alignment(C: center, L: left, R: right) +\makecvheader[R] + +% Print the footer with 3 arguments(,
, ) +% Leave any of these blank if they are not needed +\makecvfooter + {\today} + {<%= user.name.tex_safe %>~~~ยท~~~Cover Letter} + {} + +% Print the title with above letter information +\makelettertitle + +%------------------------------------------------------------------------------- +% LETTER CONTENT +%------------------------------------------------------------------------------- +\begin{cvletter} + +<%= @cover_letter.tex_paragraph %> + +\end{cvletter} + + +%------------------------------------------------------------------------------- +% Print the signature and enclosures with above letter information +\makeletterclosing + +\end{document} diff --git a/app/views/templates/awesome/resume.html.erb b/app/views/templates/awesome/resume.html.erb index 9abc357..f8aba17 100644 --- a/app/views/templates/awesome/resume.html.erb +++ b/app/views/templates/awesome/resume.html.erb @@ -25,9 +25,6 @@ \renewcommand{\labelenumi}{A} - - - %------------------------------------------------------------------------------- % CONFIGURATIONS %------------------------------------------------------------------------------- diff --git a/db/migrate/20221221141217_add_cover_letters.rb b/db/migrate/20221221141217_add_cover_letters.rb new file mode 100644 index 0000000..a9225e4 --- /dev/null +++ b/db/migrate/20221221141217_add_cover_letters.rb @@ -0,0 +1,14 @@ +class AddCoverLetters < ActiveRecord::Migration[7.0] + def change + create_table :cover_letters do |t| + t.string :title + t.string :company_name + t.string :job_application + t.date :date_override + t.integer :order, default: 0 + t.references :user + t.text :csv_paragraphs + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fabbed5..61d2427 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,20 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_09_03_211620) do +ActiveRecord::Schema[7.0].define(version: 2022_12_21_141217) do + create_table "cover_letters", force: :cascade do |t| + t.string "title" + t.string "company_name" + t.string "job_application" + t.date "date_override" + t.integer "order", default: 0 + t.integer "user_id" + t.text "csv_paragraphs" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_cover_letters_on_user_id" + end + create_table "education_entries", force: :cascade do |t| t.string "title" t.string "institution"