Class: Decidim::Budgets::OrderPDF
Instance Attribute Summary collapse
Instance Method Summary
collapse
#linked_classes_filter_values_for, #linked_classes_for, #resource_locator
#attachment?, #default_locale?
Constructor Details
#initialize(order) ⇒ OrderPDF
Returns a new instance of OrderPDF.
15
16
17
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 15
def initialize(order)
@order = order
end
|
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order.
13
14
15
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 13
def order
@order
end
|
Instance Method Details
#add_content ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 38
def add_content
composer.text(I18n.t("decidim.budgets.order_pdf.title"), style: :h1, position: [30, 700])
composer.text(I18n.t("decidim.budgets.order_pdf.text", space_name:), style: :text, position: [30, 670])
order.projects.each_with_index do |project, index|
composer.text("- #{translated_attribute(project.title)}", style: :text, position: [30, 650 - (index * 20)])
end
composer.text(component_url, style: :text, position: [30, 650 - (order.projects.count * 20) - 10])
end
|
#bold_font ⇒ Object
64
65
66
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 64
def bold_font
@bold_font ||= load_font("source-sans-pro-v21-cyrillic_cyrillic-ext_greek_greek-ext_latin_latin-ext_vietnamese-700.ttf")
end
|
#budget ⇒ Object
56
57
58
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 56
def budget
@budget ||= order.budget
end
|
#component_url ⇒ Object
52
53
54
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 52
def component_url
Decidim::ResourceLocatorPresenter.new(budget).url
end
|
#composer ⇒ Object
27
28
29
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 27
def composer
@composer ||= ::HexaPDF::Composer.new(page_orientation: :portrait, page_size: :A4)
end
|
#font ⇒ Object
60
61
62
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 60
def font
@font ||= load_font("source-sans-pro-v21-cyrillic_cyrillic-ext_greek_greek-ext_latin_latin-ext_vietnamese-regular.ttf")
end
|
#load_font(path) ⇒ Object
68
69
70
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 68
def load_font(path)
document.fonts.add(Decidim::Core::Engine.root.join("app/packs/fonts/decidim/").join(path))
end
|
#render ⇒ Object
19
20
21
22
23
24
25
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 19
def render
composer.styles(**styles)
add_content
::Decidim::Exporters::ExportData.new(composer.write_to_string, "pdf")
end
|
#space_name ⇒ Object
48
49
50
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 48
def space_name
translated_attribute(budget.participatory_space.title)
end
|
#styles ⇒ Object
31
32
33
34
35
36
|
# File 'decidim-budgets/lib/decidim/budgets/budget_order_pdf.rb', line 31
def styles
{
h1: { font: bold_font, text_align: :left, font_size: 15 },
text: { font:, text_align: :left, font_size: 10 }
}
end
|