Class: StyleSheet::StyleSheetParser

Inherits:
Object
  • Object
show all
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:

  1. The file is read into an array (@raw_data)

  2. White space is removed from the beginnig and end of each field in the @raw_data

  3. Comments are sepatated into there own array fields as they could be mixed into style code

  4. All fields with comments and empty fields are removed from @raw_data

  5. All style rules are put in their own array field

  6. 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

Instance Method Summary collapse

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

#linesObject (readonly)

:nodoc:



128
129
130
# File 'lib/csspress/style_sheet.rb', line 128

def lines
  @lines
end

Instance Method Details

#eachObject

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