Sha256: fab78dc9d11a34b5ddbd5df0c82e6a1b6394683a06881d0218e87ec0a3d8343c
Contents?: true
Size: 1.08 KB
Versions: 9
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module DocumentRenderer class Part PART_RE = /{{[^}]+}}/.freeze class << self 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 # # 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 # def should_render?(part, omit_optional: true) if part[:optional] && omit_optional false unless @excludes.include?(part[:anchor]) else !@excludes.include?(part[:anchor]) end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems