module Middleman::Sculptor::Helpers::Outliner

Public Instance Methods

outline(&block) click to toggle source
# File lib/middleman-sculptor/helpers/outliner.rb, line 7
def outline(&block)
  html = capture_html(&block)
  doc = Nokogiri::HTML.fragment(html, encoding='utf-8')

  elements = parse_elements(doc.children)

  partial('glyptotheque/model-outline', locals: { elements: elements })
end

Private Instance Methods

parse_elements(elements) click to toggle source
# File lib/middleman-sculptor/helpers/outliner.rb, line 18
def parse_elements(elements)
  result = []

  elements.each do |e|
    text = e.xpath('text()').text

    next unless e.element?

    class_name = e.attributes['class'] && e.attributes['class'].value
    id = e.attributes['id'] && e.attributes['id'].value
    attributes = e.attributes.reject {|k| k == 'class' || k == 'id' }

    result << {
      el_name: e.name,
      class_name: class_name,
      id: id,
      attrs: attributes.values.map { |a| { name: a.name, value: a.value } },
      children: parse_elements(e.children),
      text: text
    }
  end

  return result
end