class DocTemplate::Tags::StandardTag
Constants
- STANDARD_RE
- TAG_NAME
- TAG_RE
- TAG_SEPARATOR
- TEMPLATES
Public Instance Methods
parse(node, opts)
click to toggle source
# File lib/doc_template/tags/standard_tag.rb, line 15 def parse(node, opts) @content = render_template node, opts loop do break unless STANDARD_RE =~ @content @content = render_template Nokogiri::HTML.fragment(@content), opts end # preserve `li` element if node.name == 'li' @result = node.replace "<li class='#{node['class']}'>#{placeholder}</li>" else replace_tag node end self end
Private Instance Methods
fetch_data(source)
click to toggle source
Extracting content outside the tag TODO: Extract to the parent class
# File lib/doc_template/tags/standard_tag.rb, line 37 def fetch_data(source) @preserved_style = %r{<span (style=[^.>]*)>[^<]+</span>$}.match(source).try(:[], 1) {}.tap do |result| data = source.squish .sub(TAG_RE, TAG_SEPARATOR) .split(TAG_SEPARATOR, 2) .reject(&:blank?) break unless data result[:prepend] = data[0] result[:append] = data[1] end end
fetch_description(text)
click to toggle source
# File lib/doc_template/tags/standard_tag.rb, line 51 def fetch_description(text) return unless (matches = STANDARD_RE.match text) name = matches[2].downcase.to_sym Lcms::Engine::Standard.search_by_name(name).first.try(:description) end
render_template(node, opts)
click to toggle source
# File lib/doc_template/tags/standard_tag.rb, line 58 def render_template(node, opts) @data = fetch_data node.inner_html @standard_shortcut = TAG_RE.match(node.content).try(:[], 0).try(:gsub, /[\[\]]/, '') @description = fetch_description node.content template = File.read template_path(template_name(opts)) ERB.new(template).result(binding).gsub(/\s{2,}</, '<') end