Class: Typstify::Generators::TemplateGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Typstify::Generators::TemplateGenerator
- Defined in:
- lib/generators/typstify/template/template_generator.rb
Overview
rails g typstify:template invoice
Copies a starter template and its sample data into app/views, so the preview task works immediately and you have something real to edit.
Constant Summary collapse
- AVAILABLE =
%w[invoice receipt report certificate].freeze
Instance Method Summary collapse
- #copy_sample_data ⇒ Object
- #copy_template ⇒ Object
- #ensure_branding ⇒ Object
- #report ⇒ Object
- #validate_name ⇒ Object
Instance Method Details
#copy_sample_data ⇒ Object
34 35 36 37 |
# File 'lib/generators/typstify/template/template_generator.rb', line 34 def copy_sample_data copy_file "#{name}/sample_data.json", "app/views/#{File.dirname(destination)}/sample_data.json" end |
#copy_template ⇒ Object
30 31 32 |
# File 'lib/generators/typstify/template/template_generator.rb', line 30 def copy_template copy_file "#{name}/#{name}.typ", "app/views/#{destination}.typ" end |
#ensure_branding ⇒ Object
39 40 41 42 43 |
# File 'lib/generators/typstify/template/template_generator.rb', line 39 def ensure_branding return if File.exist?(File.join(destination_root, "app/views/shared/branding.typ")) copy_file "shared/branding.typ", "app/views/shared/branding.typ" end |
#report ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/generators/typstify/template/template_generator.rb', line 45 def report say "" say "Preview it: rake typstify:preview[#{destination}]", :green say "" say "Render it from a controller:" say "" say " render pdf: #{destination.inspect}," say " data: { ... }," say " filename: #{"#{name}.pdf".inspect}" say "" end |