improve pdf
This commit is contained in:
parent
02e13871bb
commit
3f76aeeb3c
3 changed files with 65 additions and 23 deletions
|
|
@ -124,7 +124,7 @@ timeout = 3
|
||||||
|
|
||||||
[language-server.ruby-lsp]
|
[language-server.ruby-lsp]
|
||||||
command = "ruby-lsp"
|
command = "ruby-lsp"
|
||||||
args = ["--debug"]
|
# args = ["--debug"]
|
||||||
|
|
||||||
LANGS
|
LANGS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,12 +60,12 @@ module PdfDocuments
|
||||||
def markup_options
|
def markup_options
|
||||||
{
|
{
|
||||||
text: { size: 12, margin_bottom: 5 },
|
text: { size: 12, margin_bottom: 5 },
|
||||||
heading1: { style: :bold, size: 26, margin_bottom: 10, margin_top: 0 },
|
heading1: { style: :bold, size: 26, margin_bottom: 5, margin_top: 0 },
|
||||||
heading2: { style: :bold, size: 17, margin_bottom: 10, margin_top: 15 },
|
heading2: { style: :bold, size: 17, margin_bottom: 5, margin_top: 5 },
|
||||||
heading3: { style: :bold, size: 13, margin_bottom: 10, margin_top: 15 },
|
heading3: { style: :bold, size: 13, margin_bottom: 5, margin_top: 5 },
|
||||||
heading4: { style: :bold, size: 12, margin_bottom: 10, margin_top: 10 },
|
heading4: { style: :bold, size: 12, margin_bottom: 5, margin_top: 5 },
|
||||||
heading5: { style: :bold, size: 12, margin_bottom: 10, margin_top: 10 },
|
heading5: { style: :bold, size: 12, margin_bottom: 5, margin_top: 5 },
|
||||||
heading6: { style: :thin, size: 12, margin_bottom: 10, margin_top: 5 }
|
heading6: { style: :thin, size: 12, margin_bottom: 5, margin_top: 5 }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ module PdfDocuments
|
||||||
rich_text = rich_text.to_s.gsub("</#{tag}>", "</#{replacement}>")
|
rich_text = rich_text.to_s.gsub("</#{tag}>", "</#{replacement}>")
|
||||||
end
|
end
|
||||||
|
|
||||||
rich_text
|
rich_text.sub(/(<br>)+$/, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def font(...)
|
def font(...)
|
||||||
|
|
@ -108,7 +108,36 @@ module PdfDocuments
|
||||||
end
|
end
|
||||||
|
|
||||||
def image(attachable, **args)
|
def image(attachable, **args)
|
||||||
@prawn_document.image(ActiveStorage::Blob.service.path_for(attachable.key), **args) rescue StandardError
|
@prawn_document.image(ActiveStorage::Blob.service.path_for(attachable.key), **args) rescue StandardError do false end
|
||||||
|
end
|
||||||
|
|
||||||
|
def without_page_break(&block)
|
||||||
|
return yield
|
||||||
|
return @prawn_document.bounding_box([ 0, @prawn_document.cursor ], width: 300) do
|
||||||
|
yield
|
||||||
|
# @prawn_document.stroke_bounds if Rails.env.development?
|
||||||
|
# print_coordinates
|
||||||
|
end
|
||||||
|
@prawn_document.span(520) do
|
||||||
|
yield
|
||||||
|
# @prawn_document.stroke_bounds
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_coordinates
|
||||||
|
@prawn_document.text("top: #{@prawn_document.bounds.top}")
|
||||||
|
@prawn_document.text("bottom: #{@prawn_document.bounds.bottom}")
|
||||||
|
@prawn_document.text("left: #{@prawn_document.bounds.left}")
|
||||||
|
@prawn_document.text("right: #{@prawn_document.bounds.right}")
|
||||||
|
@prawn_document.move_down(10)
|
||||||
|
@prawn_document.text("absolute top: #{Float(@prawn_document.bounds.absolute_top).round(2)}")
|
||||||
|
@prawn_document.text("absolute bottom: #{Float(@prawn_document.bounds.absolute_bottom).round(2)}")
|
||||||
|
@prawn_document.text("absolute left: #{Float(@prawn_document.bounds.absolute_left).round(2)}")
|
||||||
|
@prawn_document.text("absolute right: #{Float(@prawn_document.bounds.absolute_right).round(2)}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_page
|
||||||
|
@prawn_document.start_new_page
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,14 @@ module PdfDocuments
|
||||||
rich_text params.report.comment
|
rich_text params.report.comment
|
||||||
|
|
||||||
params.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index|
|
params.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index|
|
||||||
|
new_page if element_index > 1
|
||||||
|
without_page_break do
|
||||||
heading2 "#{element_index} #{element.title}"
|
heading2 "#{element_index} #{element.title}"
|
||||||
move_down(5)
|
bold("#{element.page.path}")
|
||||||
bold("Pfad: #{element.page.path}")
|
safe_display(element.screenshot) { image(_1.variant(:thumbnail), height: 160) && move_down(5) }
|
||||||
move_down(5)
|
end
|
||||||
rich_text element.description
|
rich_text element.description
|
||||||
safe_display(element.screenshot) { image(_1, height: 160) }
|
move_down(10)
|
||||||
|
|
||||||
success_criteria.each.with_index(1) do |success_criterion, sc_index|
|
success_criteria.each.with_index(1) do |success_criterion, sc_index|
|
||||||
success_criterion_row(success_criterion, [ element_index, sc_index ])
|
success_criterion_row(success_criterion, [ element_index, sc_index ])
|
||||||
|
|
@ -32,21 +34,32 @@ module PdfDocuments
|
||||||
def success_criterion_row(success_criterion, index)
|
def success_criterion_row(success_criterion, index)
|
||||||
heading3 "#{index.join(".")} #{success_criterion.title}"
|
heading3 "#{index.join(".")} #{success_criterion.title}"
|
||||||
safe_display(success_criterion.test_comment) do
|
safe_display(success_criterion.test_comment) do
|
||||||
|
without_page_break do
|
||||||
heading4 "Kommentar"
|
heading4 "Kommentar"
|
||||||
rich_text success_criterion.test_comment
|
rich_text success_criterion.test_comment
|
||||||
end
|
end
|
||||||
|
end
|
||||||
safe_display(success_criterion.quick_criterion) do
|
safe_display(success_criterion.quick_criterion) do
|
||||||
|
without_page_break do
|
||||||
heading4 "Kriterium"
|
heading4 "Kriterium"
|
||||||
rich_text success_criterion.quick_criterion
|
rich_text success_criterion.quick_criterion
|
||||||
end
|
end
|
||||||
|
end
|
||||||
safe_display(success_criterion.quick_fail) do
|
safe_display(success_criterion.quick_fail) do
|
||||||
|
without_page_break do
|
||||||
heading4 "Fail"
|
heading4 "Fail"
|
||||||
rich_text success_criterion.quick_fail
|
rich_text success_criterion.quick_fail
|
||||||
end
|
end
|
||||||
|
end
|
||||||
safe_display(success_criterion.quick_fix) do
|
safe_display(success_criterion.quick_fix) do
|
||||||
|
without_page_break do
|
||||||
heading4 "Fix"
|
heading4 "Fix"
|
||||||
rich_text success_criterion.quick_fix
|
rich_text success_criterion.quick_fix
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
heading4("Protokollnummer")
|
||||||
|
text(success_criterion.number)
|
||||||
|
move_down(10)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue