Class: StyleSheet::StyleSheetParser
- Inherits:
-
Object
- Object
- StyleSheet::StyleSheetParser
- Defined in:
- lib/csspress/style_sheet.rb
Overview
This class is responsible for processing a CSS file and allows iteration over the rules contained within the file to add to a StyleSheet object. – Due to the flexible nature of CSS syntax most of the work performed by the parser is envolved in normalizing the text into an array of style rules with the comments striped out.
This parser uses patern matching and string manupulation rather than analysing the file byte, by byte. This may or may not be proved to be a good thing.
At present all ‘@import’ statements with in the CSS file are ignored!
A file is processed as follows:
-
The file is read into an array (@raw_data)
-
White space is removed from the beginnig and end of each field in the @raw_data
-
Comments are sepatated into there own array fields as they could be mixed into style code
-
All fields with comments and empty fields are removed from @raw_data
-
All style rules are put in their own array field
-
Each field has any white space removed
Data clean!
Only the file in gerneral is parsed. Parsing of Rules and Declarations is handled by them internaly. ++
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#each ⇒ Object
Yield each rule in the parsed file.
-
#initialize(file_name) ⇒ StyleSheetParser
constructor
Creates new StyleSheetParser to parse the file file_name.
Constructor Details
#initialize(file_name) ⇒ StyleSheetParser
Creates new StyleSheetParser to parse the file file_name
133 134 135 136 137 |
# File 'lib/csspress/style_sheet.rb', line 133 def initialize( file_name ) @file = file_name @raw_data = [] parse end |
Instance Attribute Details
#lines ⇒ Object (readonly)
:nodoc:
128 129 130 |
# File 'lib/csspress/style_sheet.rb', line 128 def lines @lines end |
Instance Method Details
#each ⇒ Object
Yield each rule in the parsed file
141 142 143 144 145 |
# File 'lib/csspress/style_sheet.rb', line 141 def each @raw_data.each do |rule| yield rule end end |