diff --git a/lib/generators/snail_mail_template/snail_mail_template_generator.rb b/lib/generators/snail_mail_template/snail_mail_template_generator.rb new file mode 100644 index 0000000..717e4da --- /dev/null +++ b/lib/generators/snail_mail_template/snail_mail_template_generator.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class SnailMailTemplateGenerator < Rails::Generators::NamedBase + source_root File.expand_path('templates', __dir__) + + desc "Generates a new snail mail template" + + class_option :description, type: :string, default: "A mail template", desc: "Template description" + class_option :base_class, type: :string, default: "TemplateBase", desc: "Base class to inherit from (TemplateBase or HalfLetterComponent)" + class_option :size, type: :string, default: "full", desc: "Template size (full or half_letter)" + + def create_template_file + @class_name = file_name.camelize + "Template" + @template_name = file_name.humanize.downcase + @description = options[:description] + @base_class = options[:base_class] + @size = options[:size] + + template( + "template.rb.erb", + "app/lib/snail_mail/components/templates/#{file_name}_template.rb" + ) + end + + private + + def file_name + name.underscore + end +end diff --git a/lib/generators/snail_mail_template/templates/template.rb.erb b/lib/generators/snail_mail_template/templates/template.rb.erb new file mode 100644 index 0000000..53edf8e --- /dev/null +++ b/lib/generators/snail_mail_template/templates/template.rb.erb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +module SnailMail + module Components + module Templates + class <%= @class_name %> < <%= @base_class %> + def self.template_name + "<%= @template_name %>" + end + + def self.template_description + "<%= @description %>" + end + + def self.show_on_single? + true + end + +<% if @base_class == "HalfLetterComponent" %> + def self.template_size + :<%= @size %> + end + + def render_front + # Add your front side template content here + font "arial" do + text_box "Hello from <%= @template_name %>!", + size: 24, + at: [0, bounds.top - 50], + valign: :center, + align: :center + end + end + + def render_back + # Add your back side template content here (optional) + end +<% else %> + def view_template + # Add your template content here + + # Example: Add an image + # image( + # image_path("your-image.png"), + # at: [x, y], + # width: width, + # ) + + # Render return address + render_return_address(10, 278, 260, 70, size: 10) + + # Render destination address + render_destination_address( + 88, + 166, + 236, + 71, + size: 16, + valign: :bottom, + align: :left + ) + + # Render postal elements + render_imb(240, 24, 183) + render_qr_code(5, 65, 60) + render_letter_id(10, 19, 10) + render_postage + end +<% end %> + end + end + end +end