Class: DocContract::ContractTemplate
Constant Summary
collapse
- HANDLEBARS_REGEX =
/{{((#)?[a-z._ ]+)}}/
- RANSACKABLE_ATTRIBUTES =
%w[name].freeze
ApplicationRecord::RANSACKABLE_ASSOCIATIONS
Instance Method Summary
collapse
ransackable_associations, ransackable_attributes
Instance Method Details
#config ⇒ Object
15
16
17
|
# File 'app/models/doc_contract/contract_template.rb', line 15
def config
YAML.safe_load(config_yml.to_s, permitted_classes: [Symbol, Date]) || {}
end
|
#contract_template ⇒ Object
Do not fail when an instance trait tries to access fallback template properties
20
21
22
|
# File 'app/models/doc_contract/contract_template.rb', line 20
def contract_template
self
end
|
#present_handlebars_expressions ⇒ Object
44
45
46
|
# File 'app/models/doc_contract/contract_template.rb', line 44
def present_handlebars_expressions
markdown.to_s.scan(HANDLEBARS_REGEX).map(&:first).uniq
end
|
#processed_html ⇒ Object
38
39
40
41
42
|
# File 'app/models/doc_contract/contract_template.rb', line 38
def processed_html
result = processed_markdown.sub(/.*\n...\n\n/m, '')
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, tables: true)
markdown.render result
end
|
#processed_markdown(config_addittions = {}) ⇒ Object
24
25
26
27
28
|
# File 'app/models/doc_contract/contract_template.rb', line 24
def processed_markdown(config_addittions = {})
config = self.config
config.merge! config_addittions unless config_addittions.blank?
DocContract::Handlebars.compile(markdown, config)
end
|
#template_markdown(config_addittions = {}) ⇒ Object
30
31
32
33
34
35
36
|
# File 'app/models/doc_contract/contract_template.rb', line 30
def template_markdown(config_addittions = {})
config = self.config
config.merge! config_addittions unless config_addittions.blank?
result = DocContract::Handlebars.compile(markdown, config)
"#{config.to_yaml}...\n\n#{result}"
end
|