Class: Kss::Section
- Inherits:
-
Object
- Object
- Kss::Section
- Defined in:
- lib/kss/section.rb
Overview
Public: Represents a styleguide section. Each section describes one UI element. A Section can be thought of as the collection of the description, modifiers, and styleguide reference.
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Public: Returns the filename where this section is found.
-
#raw ⇒ Object
readonly
Returns the raw comment text for the section, not including comment syntax (such as // or /* */).
Instance Method Summary collapse
-
#comment_sections ⇒ Object
Splits up the raw comment text into comment sections that represent description, modifiers, etc.
-
#description ⇒ Object
Public: The description section of a styleguide comment block.
-
#initialize(comment_text = nil, filename = nil) ⇒ Section
constructor
Public: Initialize a new Section.
-
#modifiers ⇒ Object
Public: The modifiers section of a styleguide comment block.
-
#section ⇒ Object
Public: The styleguide section for which this comment block references.
Constructor Details
#initialize(comment_text = nil, filename = nil) ⇒ Section
Public: Initialize a new Section
comment_text - The raw comment String, minus any comment syntax. filename - The filename as a String.
18 19 20 21 |
# File 'lib/kss/section.rb', line 18 def initialize(comment_text=nil, filename=nil) @raw = comment_text @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Public: Returns the filename where this section is found.
12 13 14 |
# File 'lib/kss/section.rb', line 12 def filename @filename end |
#raw ⇒ Object (readonly)
Returns the raw comment text for the section, not including comment syntax (such as // or /* */).
9 10 11 |
# File 'lib/kss/section.rb', line 9 def raw @raw end |
Instance Method Details
#comment_sections ⇒ Object
Splits up the raw comment text into comment sections that represent description, modifiers, etc.
Returns an Array of comment Strings.
27 28 29 |
# File 'lib/kss/section.rb', line 27 def comment_sections @comment_sections ||= raw ? raw.split("\n\n") : [] end |
#description ⇒ Object
Public: The description section of a styleguide comment block.
Returns the description String.
46 47 48 49 50 51 |
# File 'lib/kss/section.rb', line 46 def description comment_sections.reject do |section| section == section_comment || section == modifiers_comment end.join("\n\n") end |
#modifiers ⇒ Object
Public: The modifiers section of a styleguide comment block.
Returns an Array of Modifiers.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/kss/section.rb', line 56 def modifiers last_indent = nil modifiers = [] return modifiers unless modifiers_comment modifiers_comment.split("\n").each do |line| next if line.strip.empty? indent = line.scan(/^\s*/)[0].to_s.size if last_indent && indent > last_indent modifiers.last.description += line.squeeze(" ") else modifier, desc = line.split(" - ") modifiers << Modifier.new(modifier.strip, desc.strip) if modifier && desc end last_indent = indent end modifiers end |
#section ⇒ Object
Public: The styleguide section for which this comment block references.
Returns the section reference String (ex: “2.1.8”).
34 35 36 37 38 39 40 41 |
# File 'lib/kss/section.rb', line 34 def section return @section unless @section.nil? cleaned = section_comment.strip.sub(/\.$/, '') # Kill trailing period @section = cleaned.match(/Styleguide (.+)/i)[1] @section end |