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.
Constant Summary collapse
- STYLEGUIDE_PATTERN =
(/(?<!No )Styleguide [[:alnum:]]/i).freeze
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(*paths_or_strings) ⇒ Parser
constructor
Public: Initializes a new parser based on a directory of files or kss strings.
-
#section(reference) ⇒ Object
Public: Finds the Section for a given styleguide reference.
Constructor Details
#initialize(*paths_or_strings) ⇒ Parser
Public: Initializes a new parser based on a directory of files or kss strings. Scans within the directory recursively or the strings for any comment blocks that look like KSS.
paths_or_strings - Each path String where style files are located, or each String containing KSS.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kss/parser.rb', line 15 def initialize(*paths_or_strings) @sections = {} paths_or_strings.each do |path_or_string| if Dir.exists?(path_or_string) # argument is a path path = path_or_string Dir["#{path}/**/*.{css,less,sass,scss}"].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 else # argument is a KSS string kss_string = path_or_string parser = CommentParser.new(kss_string) parser.blocks.each do |comment_block| add_section comment_block if self.class.kss_block?(comment_block) end end end end |
Instance Attribute Details
#sections ⇒ Object
Public: Returns a hash of Sections.
8 9 10 |
# File 'lib/kss/parser.rb', line 8 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.
49 50 51 52 53 54 |
# File 'lib/kss/parser.rb', line 49 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_PATTERN end |