Class: Styles::Stylesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/styles/stylesheet.rb

Defined Under Namespace

Classes: EvalContext

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stylesheet_file_path = nil) ⇒ Stylesheet

Returns a new instance of Stylesheet.



15
16
17
18
19
20
# File 'lib/styles/stylesheet.rb', line 15

def initialize(stylesheet_file_path=nil)
  @file_path = stylesheet_file_path
  @rules = []
  @last_updated = nil
  load_rules_from_file if @file_path
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



4
5
6
# File 'lib/styles/stylesheet.rb', line 4

def file_path
  @file_path
end

#last_updatedObject

Returns the value of attribute last_updated.



5
6
7
# File 'lib/styles/stylesheet.rb', line 5

def last_updated
  @last_updated
end

#rulesObject

Returns the value of attribute rules.



4
5
6
# File 'lib/styles/stylesheet.rb', line 4

def rules
  @rules
end

Class Method Details

.from_string(string) ⇒ Object

For creating a one off, temporary Stylesheet without an associated file. Mostly useful for testing.



9
10
11
12
13
# File 'lib/styles/stylesheet.rb', line 9

def self.from_string(string)
  stylesheet = new
  stylesheet.rules = eval_rules string
  stylesheet
end

Instance Method Details

#outdated?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/styles/stylesheet.rb', line 30

def outdated?
  !last_updated || file_mtime > last_updated
end

#reloadObject



26
27
28
# File 'lib/styles/stylesheet.rb', line 26

def reload
  load_rules_from_file
end

#reload_if_outdatedObject



34
35
36
# File 'lib/styles/stylesheet.rb', line 34

def reload_if_outdated
  reload if outdated?
end

#unrecognized_property_namesObject



22
23
24
# File 'lib/styles/stylesheet.rb', line 22

def unrecognized_property_names
  rules.map { |rule| rule.unrecognized_properties.keys }.flatten
end