Class: Stylesheet::CssStyleSheet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CssStyleSheet

Returns a new instance of CssStyleSheet.



7
8
9
10
11
12
13
# File 'lib/stylesheet/css_style_sheet.rb', line 7

def initialize(args)
  if args.kind_of?(String)
    init_with_url(args)
  else
    init_with_hash(args)
  end
end

Instance Attribute Details

#disabled=(value) ⇒ Object (writeonly)

Sets the attribute disabled

Parameters:

  • value

    the value to set the attribute disabled to.



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

def disabled=(value)
  @disabled = value
end

#hrefObject

Returns the value of attribute href.



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

def href
  @href
end

#mediaObject

Returns the value of attribute media.



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

def media
  @media
end

#owner_ruleObject (readonly)

Returns the value of attribute owner_rule.



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

def owner_rule
  @owner_rule
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/stylesheet/css_style_sheet.rb', line 3

def parent
  @parent
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/stylesheet/css_style_sheet.rb', line 3

def title
  @title
end

#typeObject



37
38
39
# File 'lib/stylesheet/css_style_sheet.rb', line 37

def type
  @type || "text/css"
end

Instance Method Details

#contentObject



55
56
57
# File 'lib/stylesheet/css_style_sheet.rb', line 55

def content
  @content ||= request_content
end

#content=(content) ⇒ Object



51
52
53
# File 'lib/stylesheet/css_style_sheet.rb', line 51

def content=(content)
  @content = content if content
end

#css_rulesObject Also known as: rules



59
60
61
# File 'lib/stylesheet/css_style_sheet.rb', line 59

def css_rules
  @css_rules ||= CssRuleList.new(content, self)
end

#delete_rule(index) ⇒ Object



77
78
79
# File 'lib/stylesheet/css_style_sheet.rb', line 77

def delete_rule(index)
  @css_rules.delete_at(index)
end

#disabled?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/stylesheet/css_style_sheet.rb', line 33

def disabled?
  @disabled || false
end

#import_rulesObject



65
66
67
# File 'lib/stylesheet/css_style_sheet.rb', line 65

def import_rules
  css_rules.select {|r| r.type == CssRule::IMPORT_RULE }
end

#init_with_hash(args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stylesheet/css_style_sheet.rb', line 21

def init_with_hash(args)
  @parent     = args[:parent]
  @title      = args[:title]
  @type       = args[:type]
  @owner_rule = args[:owner_rule]

  self.href     = args[:href]
  self.location = args[:location]
  self.media    = args[:media]
  self.content  = args[:content]
end

#init_with_url(url) ⇒ Object



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

def init_with_url(url)
  self.href    = url
  self.media   = ""
  self.content = nil
end

#insert_rule(rule, index) ⇒ Object



81
82
83
# File 'lib/stylesheet/css_style_sheet.rb', line 81

def insert_rule(rule, index)
  @css_rules.insert(index, rule)
end

#locationObject



85
86
87
88
# File 'lib/stylesheet/css_style_sheet.rb', line 85

def location
  return if inline_css?
  @location ||= Location.new(@url, parent && parent.location)
end

#location=(location) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/stylesheet/css_style_sheet.rb', line 90

def location=(location)
  return unless location

  @location = location
  @url      = location.href
  @href     = location.href
end

#parent_style_sheetObject



73
74
75
# File 'lib/stylesheet/css_style_sheet.rb', line 73

def parent_style_sheet
  @parent if @owner_rule
end

#style_rulesObject



69
70
71
# File 'lib/stylesheet/css_style_sheet.rb', line 69

def style_rules
  css_rules.select {|r| r.type == CssRule::STYLE_RULE }
end