Browse Source

Added cover letters generation

main
rodley82 3 years ago
parent
commit
938564052b
  1. 42
      app/admin/cover_letters_admin.rb
  2. 34
      app/admin/education_entries_admin.rb
  3. 34
      app/admin/skills_admin.rb
  4. 14
      app/admin/users_admin.rb
  5. 32
      app/admin/work_experiences_admin.rb
  6. 11
      app/models/cover_letter.rb
  7. 5
      app/views/templates/awesome/Makefile
  8. 131
      app/views/templates/awesome/coverletter.html.erb
  9. 3
      app/views/templates/awesome/resume.html.erb
  10. 14
      db/migrate/20221221141217_add_cover_letters.rb
  11. 15
      db/schema.rb

42
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

34
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

34
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

14
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

32
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

11
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

5
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:

131
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 <posquit0.bj@gmail.com>
% Lars Richter <mail@ayeks.de>
%
% 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(<left>, <center>, <right>)
% 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}

3
app/views/templates/awesome/resume.html.erb

@ -25,9 +25,6 @@
\renewcommand{\labelenumi}{A}
%-------------------------------------------------------------------------------
% CONFIGURATIONS
%-------------------------------------------------------------------------------

14
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

15
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"

Loading…
Cancel
Save