This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Templates::Templates::Contexts::PdfGeneration::Strategies | |
# The HexaPdf class is responsible for generating HTML content from a template | |
# using the HexaPDF library. It processes the template instructions and converts | |
# them into an HTML representation suitable for PDF generation. | |
class HexaPdf < BaseService | |
# Generates HTML content from a template using HexaPDF. | |
# | |
# @param [Object] template The template object containing instructions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# The Base class serves as a foundational class for key type applicators. | |
# It defines the common interface and behavior for specific key type implementations. | |
class Templates::Components::KeyTypeApplicators::Base | |
attr_reader :current_value | |
# Applies the key type applicator to the provided arguments. | |
# | |
# @param [Templates::Component] template_component The component to be applied. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# PdfMailer is responsible for sending emails that contain PDF attachments. | |
# It formats the email using the user's details and attaches the generated PDF. | |
class PdfMailer < ApplicationMailer | |
# Sends an email with the generated PDF attachment. | |
# | |
# @param input [Hash] A hash containing input data including: | |
# - :user [User] The user receiving the email. | |
# - :template [Templates::Template] The template associated with the PDF. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# The EmailDispatch class is responsible for dispatching emails containing generated PDFs. | |
# It uses a specified PDF generation strategy and the associated template to create the PDF, | |
# then sends it to the user via email. | |
class Templates::Templates::Contexts::EmailDispatch < BaseService | |
MailerInput = Struct.new(:user, :tmpfile, :template, keyword_init: true) | |
performs_checks | |
# Initializes a new instance of the EmailDispatch class. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class Templates::TemplatesController < ApplicationController | |
before_action :ensure_current_user! | |
def dispatch_mail | |
context = ::Templates::Templates::Contexts::EmailDispatch.call(input: email_dispatch_input) | |
return error_response(context.message) unless context.success? | |
render json: ::Templates::TemplateBlueprint.render(context.payload), status: :created |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Templates | |
module Components | |
module KeyTypeApplicators | |
class TotalApplicator < ::Templates::Components::KeyTypeApplicators::Base | |
def apply! | |
selector.content = computed_value if apply_changes? | |
document | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# The Engine class is responsible for generating PDFs based on a specified strategy | |
# and a given template ID. It modifies the original HTML document by applying | |
# components from the template before generating the final PDF file. | |
# | |
# Supported strategies for PDF generation include :pdfkit and :hexapdf. | |
class Templates::Templates::Contexts::PdfGeneration::Service < BaseService | |
HTML_GENERATION_STRATEGIES = %i[pdfkit hexapdf].freeze |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# DEPRECATED | |
module PDF | |
module Pages | |
module HexaDefinitions | |
module GraphicDefinitions | |
def close_fill_stroke(instruction, page) | |
page.canvas.close_fill_stroke(*instruction[:args]) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{:name=>:set_graphics_state_parameters, :args=>[:GSa]}, | |
{:name=>:set_nonstroke_color_space, :args=>[:CSp]}, | |
{:name=>:set_stroke_color_space, :args=>[:CSp]}, | |
{:name=>:concatenate_matrix, :args=>[0.24, 0, 0, -0.24, 28.32, 707.039999]}, | |
{:name=>:save_graphics_state, :args=>[]}, | |
{:name=>:save_graphics_state, :args=>[]}, | |
{:name=>:restore_graphics_state, :args=>[]}, | |
{:name=>:restore_graphics_state, :args=>[]}, | |
{:name=>:save_graphics_state, :args=>[]}, | |
{:name=>:save_graphics_state, :args=>[]}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class Templates::ComponentsController < ApplicationController | |
before_action :ensure_current_user! | |
def create | |
ctx = ::Templates::Components::Contexts::Creation.call(input: component_create_input) | |
return error_response(ctx.message) unless ctx.success? | |
render json: ::Templates::ComponentBlueprint.render(ctx.payload), status: :created |
NewerOlder