class DocumentRenderer::Part

Constants

PART_RE

Public Class Methods

call(content, options) click to toggle source
# File lib/document_renderer/part.rb, line 8
def call(content, options)
  @excludes = options[:excludes] || []
  content.gsub(PART_RE) do |placeholder|
    next unless placeholder
    next unless (part = options[:parts_index][placeholder])
    next unless (subpart = part[:content])
    next unless should_render?(part, omit_optional: !options[:with_optional])

    call subpart.to_s, options
  end
end

Private Class Methods

should_render?(part, omit_optional: true) click to toggle source

If part is optional:

  • do not render it if optional have not been requested (not web-view)

  • do not render it if optional part was not turned ON (is not inside excludes list)

If part is not optional:

  • just ignore it if it has been turned OFF

# File lib/document_renderer/part.rb, line 29
def should_render?(part, omit_optional: true)
  if part[:optional] && omit_optional
    false unless @excludes.include?(part[:anchor])
  elsif @excludes.include?(part[:anchor])
    false
  else
    true
  end
end