Make rich_text searchable and renderable in pdf
This commit is contained in:
parent
6d3a269231
commit
879670983d
6 changed files with 26 additions and 5 deletions
8
app/helpers/pdf_helper.rb
Normal file
8
app/helpers/pdf_helper.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
module PdfHelper
|
||||
def prepare_rich_text(rich_text)
|
||||
%w[div p del blockquote pre code].each do |tag|
|
||||
rich_text = rich_text.to_s.gsub(%r{<#{tag}.*?>|</#{tag}>}, '')
|
||||
end
|
||||
rich_text
|
||||
end
|
||||
end
|
||||
7
app/models/action_text/rich_text.rb
Normal file
7
app/models/action_text/rich_text.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module ActionText
|
||||
class RichText < Record
|
||||
before_save do
|
||||
self.body_text = body.to_plain_text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -6,6 +6,6 @@ class Check < ApplicationRecord
|
|||
has_rich_text :success_criterion_html
|
||||
|
||||
scope :search, lambda { |term|
|
||||
joins("INNER JOIN action_text_rich_texts ON action_text_rich_texts.record_id = checks.id AND record_type = 'Check'").where('checks.name LIKE :term OR action_text_rich_texts.body LIKE :term', term: "%#{term}%")
|
||||
joins("INNER JOIN action_text_rich_texts ON action_text_rich_texts.record_id = checks.id AND record_type = 'Check'").where('checks.name LIKE :term OR action_text_rich_texts.body_text LIKE :term', term: "%#{term}%")
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ prawn_document do |pdf|
|
|||
@report.elements.each do |element|
|
||||
pdf.text element.title
|
||||
pdf.text element.path
|
||||
pdf.text element.description_html, inline_format: true
|
||||
pdf.text prepare_rich_text(element.description_html), inline_format: true
|
||||
|
||||
element.success_criteria.each do |success_criterion|
|
||||
pdf.text success_criterion.title
|
||||
pdf.text success_criterion.description_html, inline_format: true
|
||||
pdf.text success_criterion.comment_html, inline_format: true
|
||||
pdf.text prepare_rich_text(success_criterion.description_html), inline_format: true
|
||||
pdf.text prepare_rich_text(success_criterion.comment_html), inline_format: true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue