📃 Kamisaku
Build resume PDF from a YAML text file.
🚀 See it in action at https://kamisaku.sinaru.com/.
Templates
For a list of templates available for PDF generation, check the examples directory where each directory name is a template name.
The templates are simple ERB files. You can find the templates in /lib/templates.
Example YAML files
Each type of document (e.g., resume) has its own schema based of YAML. There are example YAML files for the schemas for
each document type in /lib/schema. For example, for resume, see /lib/schema/resume/example.yml.
You can use them to try the PDF generation.
Installation
This is a Ruby gem. So you can either install as a gem or clone the repo and use bin/console file run from terminal.
Dependency Requirement
- Ruby 3.4.3
- Ensure that Google Chrome is installed.
- Chrome must be accessible from the terminal as
google-chrome.- Kamisaku uses Chrome's headless mode to generate PDF files.
- Ensure
exiftoolis installed available in command line.- exiftool is used to soft-remove metadata added by chrome in the PDF file.
Add this line to your application's Gemfile:
gem 'kamisaku'And then execute:
$ bundle installOr install it yourself as:
$ gem install kamisakuUsage
First, we need to have a YAML file or a string with the correct schema data structure for the type of the PDF you are generating.
For the list of schemas, check lib/schema folder. E.g. For resume, it is lib/schema/resume/schema.yml.
Generating PDF
Using terminal
Once you have the YAML text file, feed it into the bin/console and specify the output location.
bin/console -c lib/schema/resume/example.yml -o ~/Downloads/test_resume.pdf -k resume -t paperBash options
-
-cthe YAML file -
-ooutput location for the PDF file including the name -
-kthe type of document you want to generate -
-ttemplate to use
Using PDF class
# Have a YAML string
yaml_str = "..."
# Create a hash
content_hash = Kamisaku::Helpers.yaml_str_to_content_hash(yaml_str)
# Validate the hash is correct. If there is any issue, it will raise a ` Kamisaku::Error ` exception.
Kamisaku::BaseContentValidator.new(content_hash:).validate!
# create a pdf instance
pdf = Kamisaku::PDF.new(content_hash:, category: "resume", template: "paper")
# create the PDF at given path
pdf.write_to('/path/to/generated_file.pdf')Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests.
You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
Create or Update a template
To a new template, create a folder with template name at lib/templates. Additionally add the template name
to Kamisaku::TemplateHelpers::TEMPLATES list.
Inside this folder, create template.html.erb.
The template will be exposed to a Ruby hash variable called data. This data represents the data in the YAML file as a hash.
So you can use the Ruby hash methods to access and render the values.
In addition, the template helper methods defined at lib/kamisaku/template_helpers.rb will also be available to use directly.
To test and build the template, you can run scripts/rebuild_examples.rb -t <name of new template>. This will
create the PDF using the lib/schema/example.yml
and place it in examples/ folder.
Releasing a new gem version
To release a new version;
- update the version number in
version.rb - run
bundle update - commit the changes
- then run
bundle exec rake releasewhich will create a git tag for the version, push git commits and the created tag, and push the.gemfile to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/sinaru/kamisaku. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Kamisaku project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
