edit comment and pdf export
Some checks failed
/ Run tests (push) Successful in 2m6s
/ Run system tests (push) Failing after 2m29s
/ Build, push and deploy image (push) Successful in 1m46s

This commit is contained in:
david 2024-11-23 21:11:01 +01:00
parent 110d75f2b7
commit c36230b8ba
10 changed files with 90 additions and 19 deletions

View file

@ -2,7 +2,7 @@
module PdfDocuments
class Base
attr_reader :params
attr_reader :params, :font
def initialize(prawn_document, **params)
@prawn_document = prawn_document
@ -13,7 +13,8 @@ module PdfDocuments
# exta_bold: 'vendor/assets/fonts/Lexend-ExtraBold.ttf',
# italic: 'vendor/assets/fonts/Lexend-Regular.ttf'
# })
@prawn_document.font "Helvetica", size: 12
@font = "Helvetica"
@prawn_document.font @font, size: 12
@params = OpenStruct.new(params)
end
@ -40,6 +41,10 @@ module PdfDocuments
@prawn_document.markup "<h3>#{text}</h3>"
end
def heading4(text)
@prawn_document.markup "<h4>#{text}</h4>"
end
def text(text)
@prawn_document.text text, markup_options[:text]
end
@ -56,10 +61,10 @@ module PdfDocuments
{
text: { size: 12, margin_bottom: 5 },
heading1: { style: :bold, size: 26, margin_bottom: 10, margin_top: 0 },
heading2: { style: :bold, size: 17, margin_bottom: 10, margin_top: 5 },
heading3: { style: :bold, size: 13, margin_bottom: 10, margin_top: 5 },
heading4: { style: :bold, size: 12, margin_bottom: 10, margin_top: 5 },
heading5: { style: :bold, size: 12, margin_bottom: 10, margin_top: 5 },
heading2: { style: :bold, size: 17, margin_bottom: 10, margin_top: 15 },
heading3: { style: :bold, size: 13, margin_bottom: 10, margin_top: 15 },
heading4: { style: :bold, size: 12, margin_bottom: 10, margin_top: 10 },
heading5: { style: :bold, size: 12, margin_bottom: 10, margin_top: 10 },
heading6: { style: :thin, size: 12, margin_bottom: 10, margin_top: 5 }
}
end
@ -70,7 +75,7 @@ module PdfDocuments
end
def prepare_rich_text(rich_text)
{ h1: "h4" }.each do |tag, replacement|
{ h1: "h5" }.each do |tag, replacement|
rich_text = rich_text.to_s.gsub("<#{tag}", "<#{replacement}")
rich_text = rich_text.to_s.gsub("</#{tag}>", "</#{replacement}>")
end
@ -89,5 +94,17 @@ module PdfDocuments
def move_down(...)
@prawn_document.move_down(...)
end
def safe_display(value, &block)
return if value.blank?
yield
end
def bold(text)
@prawn_document.font(@font, style: :bold) do
@prawn_document.text text
end
end
end
end

View file

@ -13,18 +13,39 @@ module PdfDocuments
heading1 params.report.name
rich_text params.report.comment
params.report.elements.each.with_index(1) do |element, element_index|
params.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index|
heading2 "#{element_index} #{element.title}"
formatted_text [ { text: element.path, styles: %i[bold italic underline] } ]
move_down(5)
rich_text element.description_html
bold("Pfad: #{element.page.path}")
move_down(5)
rich_text element.description
element.success_criteria.each.with_index(1) do |success_criterion, sc_index|
heading3 "#{element_index}.#{sc_index} #{success_criterion.title}"
rich_text success_criterion.description_html
rich_text success_criterion.comment
success_criteria.each.with_index(1) do |success_criterion, sc_index|
success_criterion_row(success_criterion, [element_index, sc_index])
end
end
end
private
def success_criterion_row(success_criterion, index)
heading3 "#{index.join(".")} #{success_criterion.title}"
safe_display(success_criterion.test_comment) do
heading4 "Kommentar"
rich_text success_criterion.test_comment
end
safe_display(success_criterion.quick_criterion) do
heading4 "Kriterium"
rich_text success_criterion.quick_criterion
end
safe_display(success_criterion.quick_fail) do
heading4 "Fail"
rich_text success_criterion.quick_fail
end
safe_display(success_criterion.quick_fix) do
heading4 "Fix"
rich_text success_criterion.quick_fix
end
end
end
end