class StyleGuide::Partial

Attributes

path[R]
section[R]

Public Class Methods

new(path, section) click to toggle source
# File lib/style_guide/partial.rb, line 8
def initialize(path, section)
  @path = path
  @section = section
end

Public Instance Methods

classes() click to toggle source
# File lib/style_guide/partial.rb, line 25
def classes
  @classes ||= begin
    parsed.css("[class]").reduce({}) do |output, tag|
      output.tap do |tags|
        tag["class"].split.each do |class_name|
          tags[".#{class_name}"] = true
        end
      end
    end.keys
  end
end
description() click to toggle source
# File lib/style_guide/partial.rb, line 21
def description
  @description ||= GitHub::Markdown.render_gfm(translated_description)
end
id() click to toggle source
# File lib/style_guide/partial.rb, line 13
def id
  @id ||= title.downcase.gsub(/[^a-zA-Z0-9]+/, "_")
end
identifiers() click to toggle source
# File lib/style_guide/partial.rb, line 41
def identifiers
  ids + classes
end
ids() click to toggle source
# File lib/style_guide/partial.rb, line 37
def ids
  @ids ||= parsed.css("[id]").map { |tag| %(##{tag["id"]}) }
end
render() click to toggle source
# File lib/style_guide/partial.rb, line 45
def render
  @render ||= action_view.render(:file => path)
end
title() click to toggle source
# File lib/style_guide/partial.rb, line 17
def title
  @title ||= File.basename(path, File.extname(path)).titleize.strip
end

Private Instance Methods

action_view() click to toggle source
# File lib/style_guide/partial.rb, line 51
def action_view
  ActionView::Base.new(Rails.root.join("app", "views"))
end
parsed() click to toggle source
# File lib/style_guide/partial.rb, line 65
def parsed
  @parsed ||= Nokogiri::HTML.parse(render)
end
style_guide_scope() click to toggle source
# File lib/style_guide/partial.rb, line 55
def style_guide_scope
  [:style_guide, section.id.to_sym]
end
translated_description() click to toggle source
# File lib/style_guide/partial.rb, line 59
def translated_description
  I18n.translate!(id, :scope => style_guide_scope)
rescue I18n::MissingTranslationData
  nil
end