Class: Kss::Parser
- Inherits:
-
Object
- Object
- Kss::Parser
- Defined in:
- lib/kss/parser.rb
Overview
Public: The main KSS parser. Takes a directory full of SASS / SCSS / CSS files and parses the KSS within them.
Instance Attribute Summary collapse
-
#sections ⇒ Object
Public: Returns a hash of Sections.
Class Method Summary collapse
-
.kss_block?(cleaned_comment) ⇒ Boolean
Public: Takes a cleaned (no comment syntax like // or /* */) comment block and determines whether it is a KSS documentation block.
Instance Method Summary collapse
- #add_section(comment_text, filename) ⇒ Object
-
#initialize(base_path) ⇒ Parser
constructor
Public: Initializes a new parser based on a directory of files.
-
#section(reference) ⇒ Object
Public: Finds the Section for a given styleguide reference.
Constructor Details
#initialize(base_path) ⇒ Parser
Public: Initializes a new parser based on a directory of files. Scans within the directory recursively for any comment blocks that look like KSS.
base_path - The path String where style files are located.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kss/parser.rb', line 14 def initialize(base_path) @sections = {} Dir["#{base_path}/**/*.*"].each do |filename| parser = CommentParser.new(filename) parser.blocks.each do |comment_block| add_section comment_block, filename if self.class.kss_block?(comment_block) end end end |
Instance Attribute Details
#sections ⇒ Object
Public: Returns a hash of Sections.
7 8 9 |
# File 'lib/kss/parser.rb', line 7 def sections @sections end |
Class Method Details
.kss_block?(cleaned_comment) ⇒ Boolean
Public: Takes a cleaned (no comment syntax like // or /* */) comment block and determines whether it is a KSS documentation block.
Returns a boolean indicating whether the block conforms to KSS.
35 36 37 38 39 40 |
# File 'lib/kss/parser.rb', line 35 def self.kss_block?(cleaned_comment) return false unless cleaned_comment.is_a? String possible_reference = cleaned_comment.split("\n\n").last possible_reference =~ /Styleguide \d/ end |
Instance Method Details
#add_section(comment_text, filename) ⇒ Object
25 26 27 28 29 |
# File 'lib/kss/parser.rb', line 25 def add_section comment_text, filename base_name = File.basename(filename) section = Section.new(comment_text, base_name) @sections[section.section] = section end |
#section(reference) ⇒ Object
Public: Finds the Section for a given styleguide reference.
Returns a Section for a reference, or a blank Section if none found.
45 46 47 |
# File 'lib/kss/parser.rb', line 45 def section(reference) @sections[reference] || Section.new end |