Browse Source

Agregado trestle admin panel y ahora renderizando pdf con info desde BD

main
rodley82 3 years ago
parent
commit
39fe1cbf98
  1. 2
      Dockerfile
  2. 4
      Gemfile
  3. 33
      Gemfile.lock
  4. 35
      app/admin/education_entries_admin.rb
  5. 35
      app/admin/skills_admin.rb
  6. 35
      app/admin/users_admin.rb
  7. 35
      app/admin/work_experiences_admin.rb
  8. 7
      app/assets/javascripts/trestle/custom.js
  9. 8
      app/assets/stylesheets/trestle/_custom.scss
  10. 13
      app/assets/stylesheets/trestle/_theme.scss
  11. 8
      app/controllers/work_experiences_controller.rb
  12. 3
      app/models/education_entry.rb
  13. 3
      app/models/skill.rb
  14. 5
      app/models/user.rb
  15. 1
      app/models/work_experience.rb
  16. 63
      app/views/work_experiences/cv.html.erb
  17. 133
      config/initializers/trestle.rb
  18. 18
      db/migrate/20220901022243_create_users.rb
  19. 13
      db/migrate/20220901023425_create_education_entries.rb
  20. 11
      db/migrate/20220901023521_create_skills.rb
  21. 39
      db/schema.rb
  22. 13
      test/fixtures/education_entries.yml
  23. 11
      test/fixtures/skills.yml
  24. 21
      test/fixtures/users.yml
  25. 7
      test/models/education_entry_test.rb
  26. 7
      test/models/skill_test.rb
  27. 7
      test/models/user_test.rb

2
Dockerfile

@ -19,7 +19,7 @@ USER ${REGULAR_USER}
WORKDIR ${REGULAR_USER_APP_HOME}
# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
# RUN bundle config --global frozen 1
# ENV RAILS_ENV=production
COPY --chown=${REGULAR_USER}:${REGULAR_USER} Gemfile Gemfile.lock ./

4
Gemfile

@ -67,3 +67,7 @@ group :test do
gem "selenium-webdriver"
gem "webdrivers"
end
gem 'sass-rails'
gem 'trestle'

33
Gemfile.lock

@ -89,6 +89,7 @@ GEM
reline (>= 0.3.1)
digest (3.1.0)
erubi (1.11.0)
ffi (1.15.5)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.12.0)
@ -102,6 +103,18 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
loofah (2.18.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
@ -169,6 +182,16 @@ GEM
io-console (~> 0.5)
rexml (3.2.5)
rubyzip (2.3.2)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.4.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
@ -186,7 +209,13 @@ GEM
railties (>= 6.0.0)
strscan (3.0.4)
thor (1.2.1)
tilt (2.0.11)
timeout (0.3.0)
trestle (0.9.6)
activemodel (>= 4.2.0)
kaminari (>= 1.1.0)
railties (>= 4.2.0)
sprockets-rails (>= 2.0.0)
turbo-rails (1.1.1)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
@ -221,17 +250,19 @@ DEPENDENCIES
jbuilder
puma (~> 5.0)
rails (~> 7.0.2, >= 7.0.2.2)
sass-rails
selenium-webdriver
sprockets-rails
sqlite3 (~> 1.4)
stimulus-rails
trestle
turbo-rails
tzinfo-data
web-console
webdrivers
RUBY VERSION
ruby 3.1.1p18
ruby 3.1.2p20
BUNDLED WITH
2.3.8

35
app/admin/education_entries_admin.rb

@ -0,0 +1,35 @@
Trestle.resource(:education_entries) do
menu do
item :education_entries, icon: "fa fa-star"
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
end

35
app/admin/skills_admin.rb

@ -0,0 +1,35 @@
Trestle.resource(:skills) do
menu do
item :skills, icon: "fa fa-star"
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
end

35
app/admin/users_admin.rb

@ -0,0 +1,35 @@
Trestle.resource(:users) do
menu do
item :users, icon: "fa fa-star"
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 |user|
# 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(:user).permit(:name, ...)
# end
end

35
app/admin/work_experiences_admin.rb

@ -0,0 +1,35 @@
Trestle.resource(:work_experiences) do
menu do
item :work_experiences, icon: "fa fa-star"
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

7
app/assets/javascripts/trestle/custom.js

@ -0,0 +1,7 @@
// This file may be used for providing additional customizations to the Trestle
// admin. It will be automatically included within all admin pages.
//
// For organizational purposes, you may wish to define your customizations
// within individual partials and `require` them here.
//
// e.g. //= require "trestle/custom/my_custom_js"

8
app/assets/stylesheets/trestle/_custom.scss

@ -0,0 +1,8 @@
// This file may be used for providing additional customizations to the Trestle
// admin. It will be automatically included within all admin pages.
//
// For organizational purposes, you may wish to define your customizations
// within individual partials and `import` them here, e.g.
//
// @import "trestle/custom/my_custom_css";
//

13
app/assets/stylesheets/trestle/_theme.scss

@ -0,0 +1,13 @@
// This file may be used to override the Sass variables used within the Trestle
// admin. It will be automatically included within all admin pages.
//
// A subset of Bootstrap and Trestle defaults can be set here.
// For a detailed overview of the customizable variables, see the file
// `frontend/theme/trestle/theme/_defaults.scss` within the Trestle source.
// Customize admin theme colors:
//
// $theme-colors: (
// "primary": #337ab7,
// "secondary": #719dc3
// );

8
app/controllers/work_experiences_controller.rb

@ -2,13 +2,15 @@ class WorkExperiencesController < ApplicationController
before_action :set_work_experience, only: %i[ show edit update destroy ]
def cv
@full_name = "Rodolfo Leyes"
@user = User.last
# render layout: false, content_type: "application/octet-stream"
tex_content = render_to_string(layout: false)
File.open("./temp.tex", "w") do |f|
`rm -Rf #{Rails.root}/temp.tex #{Rails.root}/temp.pdf`
File.open("#{Rails.root}/temp.tex", "w") do |f|
f << tex_content
end
`pdflatex -interaction=batchmode temp.tex`
`pdflatex -interaction=batchmode -output-directory=#{Rails.root} #{Rails.root}/temp.tex`
render file: "#{Rails.root}/temp.pdf", layout: false
end

3
app/models/education_entry.rb

@ -0,0 +1,3 @@
class EducationEntry < ApplicationRecord
belongs_to :user
end

3
app/models/skill.rb

@ -0,0 +1,3 @@
class Skill < ApplicationRecord
belongs_to :user
end

5
app/models/user.rb

@ -0,0 +1,5 @@
class User < ApplicationRecord
has_many :work_experiences
has_many :skills
has_many :education_entries
end

1
app/models/work_experience.rb

@ -1,2 +1,3 @@
class WorkExperience < ApplicationRecord
belongs_to :user
end

63
app/views/work_experiences/cv.html.erb

@ -21,8 +21,8 @@
\usepackage{titlesec} % Allows creating custom \section's
\usepackage{marvosym} % Allows the use of symbols
\usepackage{tabularx,colortbl} % Advanced table configurations
\usepackage{ebgaramond} % Use the EB Garamond font
\usepackage{microtype} % To enable letterspacing
\usepackage[a4paper, total={7.2in, 8in}]{geometry}
\titleformat{\section}{\large\scshape\raggedright}{}{0em}{}[\titlerule] % Section formatting
@ -31,7 +31,10 @@
\addtolength{\voffset}{-0.5in} % Adjust the vertical offset - less whitespace at the top of the page
\addtolength{\textheight}{3cm} % Adjust the text height - less whitespace at the bottom of the page
\newcommand{\gray}{\rowcolor[gray]{.90}} % Custom highlighting for the work experience and education sections
% \addtolength{\hoffset}{-0.5in} % Adjust the horizontal offset - less whitespace at the top of the page
\newcommand{\gray}{\rowcolor[gray]{.95}} % Custom highlighting for the work experience and education sections
%----------------------------------------------------------------------------------------
% FOOTER SECTION
@ -42,8 +45,8 @@
\cofoot{
\fontsize{12.5}{17}\selectfont % Letter spacing and font size
\textls[150]{123 Broadway {\large\textperiodcentered} City {\large\textperiodcentered} Country 12345}\\ % Your mailing address
{\Large\Letter} \textls[150]{john@smith.com \ {\Large\Telefon} (000) 111-1111} % Your email address and phone number
\textls[150]{<%= @user.address %> {\large\textperiodcentered} Jujuy {\large\textperiodcentered} Argentina }\\ % Your mailing address
{\Large\Letter} \textls[150]{<%= @user.email %> \ {\Large\Telefon} <%= @user.phone %>} % Your email address and phone number
}
%----------------------------------------------------------------------------------------
@ -56,9 +59,9 @@
% HEADER SECTION
%----------------------------------------------------------------------------------------
{\fontsize{36}{36}\selectfont\scshape\textls[200]{<%= @full_name %>}} % Your name at the top
{\fontsize{36}{36}\selectfont\scshape\textls[200]{<%= @user.name %>}} % Your name at the top
\vspace{1.5cm} % Extra whitespace after the large name at the top
\vspace{1.0cm} % Extra whitespace after the large name at the top
%----------------------------------------------------------------------------------------
% OBJECTIVE
@ -66,7 +69,8 @@
\section{Objective}
A position in the field of computers with special interests in business applications \\ programming, information processing, and management systems.
% A position in the field of computers with special interests in business applications \\ programming, information processing, and management systems.
<%= @user.objective %>
%----------------------------------------------------------------------------------------
% WORK EXPERIENCE
@ -74,22 +78,17 @@ A position in the field of computers with special interests in business applicat
\section{Work Experience}
\begin{tabularx}{0.97\linewidth}{>{\raggedleft\scshape}p{2cm}X}
\gray Period & \textbf{March 2012 --- Present}\\
\gray Employer & \textbf{Layer BV} \hfill Amsterdam, The Netherlands\\
\gray Job Title & \textbf{J2EE Analyst programmer}\\
\gray Languages & \textbf{J2EE}\\
       & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec et auctor neque. Nullam ultricies sem sit amet magna tristique imperdiet. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus eget mollis nunc.
<% @user.work_experiences.each do |w| %>
\begin{tabularx}{0.97\linewidth}{>{\raggedleft\scshape}p{2.5cm}X}
\gray Period & \textbf{<%= w.period %>}\\
\gray Employer & \textbf{<%= w.employer %>} \hfill \\
\gray Job Title & \textbf{<%= w.title %>}\\
\gray Technologies & \textbf{<%= w.technologies %>}\\
       & <%= w.achivements %>
\end{tabularx}
\vspace{12pt}
\begin{tabularx}{0.97\linewidth}{>{\raggedleft\scshape}p{2cm}X}
\gray Period & \textbf{March 2009 --- August 2010 (Part Time)}\\
\gray Employer & \textbf{Buy More} \hfill New York, USA\\
\gray Job Title & \textbf{Supermarket Clerk}\\
       & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec et auctor neque. Nullam ultricies sem sit amet magna tristique imperdiet.
\end{tabularx}
<% end %>
%----------------------------------------------------------------------------------------
% EDUCATION
@ -97,23 +96,16 @@ A position in the field of computers with special interests in business applicat
\section{Education}
<% @user.education_entries.each do |e| %>
\begin{tabularx}{0.97\linewidth}{>{\raggedleft\scshape}p{2cm}X}
\gray Period & \textbf{January 2011 --- February 2012}\\
\gray Degree & \textbf{Master of Science in Computer Science}\\
\gray Rank & \textbf{First Class Honours}\\
\gray University & \textbf{The University of California} \hfill Los Angeles, USA\\
\gray Period & \textbf{<%= e.period %>}\\
\gray Title & \textbf{<%= e.title %>}\\
\gray Institution & \textbf{<%= e.institution %>} \hfill <%= e.location %>\\
%& Extra information about degree
\end{tabularx}
\vspace{12pt}
\begin{tabularx}{0.97\linewidth}{>{\raggedleft\scshape}p{2cm}X}
\gray Period & \textbf{August 2008 --- September 2010}\\
\gray Degree & \textbf{Bachelor of Science in Computer Science}\\
\gray Rank & \textbf{With Distinction}\\
\gray University & \textbf{New York University} \hfill New York, USA\\
%& Extra information about degree
\end{tabularx}
<% end %>
%----------------------------------------------------------------------------------------
% SKILLS
@ -122,10 +114,9 @@ A position in the field of computers with special interests in business applicat
\section{Skills}
\begin{tabular}{ @{} >{\bfseries}l @{\hspace{6ex}} l }
Computer Languages & Prolog, Haskell, AWK, Erlang, Scheme, ML \\
Protocols \& APIs & XML, JSON, SOAP, REST \\
Databases & MySQL, PostgreSQL, Microsoft SQL \\
Tools & SVN, Vim, Emacs
<% @user.skills.order(order: :asc).each do |s| %>
<%= s.title %> & <%= s.detail %>\\
<% end %>
\end{tabular}
%----------------------------------------------------------------------------------------

133
config/initializers/trestle.rb

@ -0,0 +1,133 @@
Trestle.configure do |config|
# == Customization Options
#
# Set the page title shown in the main header within the admin.
#
config.site_title = "Latex Resumes"
# Specify a custom image to be used in place of the site title for mobile and
# expanded/desktop navigation. These images should be placed within your
# asset paths, e.g. app/assets/images.
#
# config.site_logo = "logo.png"
# Specify a custom image to be used for the collapsed/tablet navigation.
#
# config.site_logo_small = "logo-small.png"
# Specify a favicon to be used within the admin.
#
# config.favicon = "favicon.ico"
# Set the text shown in the page footer within the admin.
# Defaults to 'Powered by Trestle'.
#
# config.footer = "Powered by Trestle"
# Sets the default precision for timestamps (either :minutes or :seconds).
# Defaults to :minutes.
#
# config.timestamp_precision = :minutes
# == Mounting Options
#
# Set the path at which to mount the Trestle admin. Defaults to /admin.
#
# config.path = "/admin"
# Toggle whether Trestle should automatically mount the admin within your
# Rails application's routes. Defaults to true.
#
# config.automount = false
# == Navigation Options
#
# Set the path to consider the application root (for title links and breadcrumbs).
# Defaults to the same value as `config.path`.
#
# config.root = "/"
# Set the initial breadcrumbs to display in the breadcrumb trail.
# Defaults to a breadcrumb labeled 'Home' linking to to the application root.
#
# config.root_breadcrumbs = -> { [Trestle::Breadcrumb.new("Home", Trestle.config.root)] }
# Set the default icon class to use when it is not explicitly provided.
# Defaults to "fa fa-arrow-circle-o-right".
#
# config.default_navigation_icon = "fa fa-arrow-circle-o-right"
# Add an explicit menu block to be added to the admin navigation.
#
# config.menu do
# group "Custom Group" do
# item "Custom Link", "/admin/custom", icon: "fa fa-car", badge: { text: "NEW!", class: "label-success" }, priority: :first
# end
# end
# == Extension Options
#
# Specify helper modules to expose to the admin.
#
# config.helper :all
# Register callbacks to run before, after or around all Trestle actions.
#
# config.before_action do |controller|
# Rails.logger.debug("Before action")
# end
#
# config.after_action do |controller|
# Rails.logger.debug("After action")
# end
#
# config.around_action do |controller, block|
# Rails.logger.debug("Around action (before)")
# block.call
# Rails.logger.debug("Around action (after)")
# end
# Specify a custom hook to be injected into the admin.
#
# config.hook(:stylesheets) do
# stylesheet_link_tag "custom"
# end
# Toggle whether Turbolinks is enabled within the admin.
# Defaults to true if Turbolinks is available.
#
# config.turbolinks = false
# Specify the parameters that should persist across requests when
# paginating or reordering. Defaults to [:sort, :order, :scope].
#
# config.persistent_params << :query
# List of methods to try calling on an instance when displayed by the `display` helper.
# Defaults to [:display_name, :full_name, :name, :title, :username, :login, :email].
#
# config.display_methods.unshift(:admin_label)
# Customize the default adapter class used by all admin resources.
# See the documentation on Trestle::Adapters::Adapter for details on
# the adapter methods that can be customized.
#
# config.default_adapter = Trestle::Adapters.compose(Trestle::Adapters::SequelAdapter)
# config.default_adapter.include MyAdapterExtensions
# Register a form field type to be made available to the Trestle form builder.
# Field types should conform to the following method definition:
#
# class CustomFormField
# def initialize(builder, template, name, options={}, &block); end
# def render; end
# end
#
# config.form_field :custom, CustomFormField
# == Debugging Options
#
# Enable debugging of form errors. Defaults to true in development mode.
#
# config.debug_form_errors = true
end

18
db/migrate/20220901022243_create_users.rb

@ -0,0 +1,18 @@
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :name
t.string :objective
t.string :address
t.string :email
t.string :phone
t.string :linkedin
t.string :github
t.string :other_page_url
t.timestamps
end
add_reference :work_experiences, :user, index: true
end
end

13
db/migrate/20220901023425_create_education_entries.rb

@ -0,0 +1,13 @@
class CreateEducationEntries < ActiveRecord::Migration[7.0]
def change
create_table :education_entries do |t|
t.string :title
t.string :institution
t.string :period
t.string :location
t.references :user
t.timestamps
end
add_column :work_experiences, :reference_date, :date
end
end

11
db/migrate/20220901023521_create_skills.rb

@ -0,0 +1,11 @@
class CreateSkills < ActiveRecord::Migration[7.0]
def change
create_table :skills do |t|
t.string :title
t.string :detail
t.integer :order
t.references :user
t.timestamps
end
end
end

39
db/schema.rb

@ -10,7 +10,41 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_08_30_202251) do
ActiveRecord::Schema[7.0].define(version: 2022_09_01_023521) do
create_table "education_entries", force: :cascade do |t|
t.string "title"
t.string "institution"
t.string "period"
t.string "location"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_education_entries_on_user_id"
end
create_table "skills", force: :cascade do |t|
t.string "title"
t.string "detail"
t.integer "order"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_skills_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "objective"
t.string "address"
t.string "email"
t.string "phone"
t.string "linkedin"
t.string "github"
t.string "other_page_url"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "work_experiences", force: :cascade do |t|
t.string "period"
t.string "employer"
@ -19,6 +53,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_08_30_202251) do
t.string "achivements"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.date "reference_date"
t.index ["user_id"], name: "index_work_experiences_on_user_id"
end
end

13
test/fixtures/education_entries.yml

@ -0,0 +1,13 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
institution: MyString
period: MyString
location: MyString
two:
title: MyString
institution: MyString
period: MyString
location: MyString

11
test/fixtures/skills.yml

@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
detail: MyString
order: 1
two:
title: MyString
detail: MyString
order: 1

21
test/fixtures/users.yml

@ -0,0 +1,21 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
objective: MyString
address: MyString
email: MyString
phone: MyString
linkedin: MyString
github: MyString
other_page_url: MyString
two:
name: MyString
objective: MyString
address: MyString
email: MyString
phone: MyString
linkedin: MyString
github: MyString
other_page_url: MyString

7
test/models/education_entry_test.rb

@ -0,0 +1,7 @@
require "test_helper"
class EducationEntryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

7
test/models/skill_test.rb

@ -0,0 +1,7 @@
require "test_helper"
class SkillTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

7
test/models/user_test.rb

@ -0,0 +1,7 @@
require "test_helper"
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Loading…
Cancel
Save