Class: StyleGuide::Partial
- Inherits:
-
Object
- Object
- StyleGuide::Partial
- Defined in:
- lib/style_guide/partial.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
Instance Method Summary collapse
- #classes ⇒ Object
- #description ⇒ Object
- #id ⇒ Object
- #identifiers ⇒ Object
- #ids ⇒ Object
-
#initialize(path, section) ⇒ Partial
constructor
A new instance of Partial.
- #render ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(path, section) ⇒ Partial
Returns a new instance of Partial.
8 9 10 11 |
# File 'lib/style_guide/partial.rb', line 8 def initialize(path, section) @path = path @section = section end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/style_guide/partial.rb', line 6 def path @path end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
6 7 8 |
# File 'lib/style_guide/partial.rb', line 6 def section @section end |
Instance Method Details
#classes ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/style_guide/partial.rb', line 25 def classes @classes ||= begin parsed.css("[class]").reduce({}) do |output, tag| output.tap do || tag["class"].split.each do |class_name| [".#{class_name}"] = true end end end.keys end end |
#description ⇒ Object
21 22 23 |
# File 'lib/style_guide/partial.rb', line 21 def description @description ||= GitHub::Markdown.render_gfm(translated_description) end |
#id ⇒ Object
13 14 15 |
# File 'lib/style_guide/partial.rb', line 13 def id @id ||= title.downcase.gsub(/[^a-zA-Z0-9]+/, "_") end |
#identifiers ⇒ Object
41 42 43 |
# File 'lib/style_guide/partial.rb', line 41 def identifiers ids + classes end |
#ids ⇒ Object
37 38 39 |
# File 'lib/style_guide/partial.rb', line 37 def ids @ids ||= parsed.css("[id]").map { |tag| %(##{tag["id"]}) } end |
#render ⇒ Object
45 46 47 |
# File 'lib/style_guide/partial.rb', line 45 def render @render ||= action_view.render(:file => path) end |
#title ⇒ Object
17 18 19 |
# File 'lib/style_guide/partial.rb', line 17 def title @title ||= File.basename(path, File.extname(path)).titleize.strip end |