Class: Stylesheet::CssStyleSheet
- Inherits:
-
Object
- Object
- Stylesheet::CssStyleSheet
- Defined in:
- lib/stylesheet/css_style_sheet.rb
Instance Attribute Summary collapse
-
#disabled ⇒ Object
writeonly
Sets the attribute disabled.
-
#href ⇒ Object
Returns the value of attribute href.
-
#media ⇒ Object
Returns the value of attribute media.
-
#owner_rule ⇒ Object
readonly
Returns the value of attribute owner_rule.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#title ⇒ Object
Returns the value of attribute title.
- #type ⇒ Object
Instance Method Summary collapse
- #content ⇒ Object
- #content=(content) ⇒ Object
- #css_rules ⇒ Object (also: #rules)
- #delete_rule(index) ⇒ Object
- #disabled? ⇒ Boolean
- #import_rules ⇒ Object
- #init_with_hash(args) ⇒ Object
- #init_with_url(url) ⇒ Object
-
#initialize(args) ⇒ CssStyleSheet
constructor
A new instance of CssStyleSheet.
- #insert_rule(rule, index) ⇒ Object
- #location ⇒ Object
- #location=(location) ⇒ Object
- #parent_style_sheet ⇒ Object
- #style_rules ⇒ Object
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
5 6 7 |
# File 'lib/stylesheet/css_style_sheet.rb', line 5 def disabled=(value) @disabled = value end |
#href ⇒ Object
Returns the value of attribute href.
4 5 6 |
# File 'lib/stylesheet/css_style_sheet.rb', line 4 def href @href end |
#media ⇒ Object
Returns the value of attribute media.
4 5 6 |
# File 'lib/stylesheet/css_style_sheet.rb', line 4 def media @media end |
#owner_rule ⇒ Object (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 |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/stylesheet/css_style_sheet.rb', line 3 def parent @parent end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/stylesheet/css_style_sheet.rb', line 3 def title @title end |
#type ⇒ Object
37 38 39 |
# File 'lib/stylesheet/css_style_sheet.rb', line 37 def type @type || "text/css" end |
Instance Method Details
#content ⇒ Object
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_rules ⇒ Object 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
33 34 35 |
# File 'lib/stylesheet/css_style_sheet.rb', line 33 def disabled? @disabled || false end |
#import_rules ⇒ Object
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 |
#location ⇒ Object
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_sheet ⇒ Object
73 74 75 |
# File 'lib/stylesheet/css_style_sheet.rb', line 73 def parent_style_sheet @parent if @owner_rule end |
#style_rules ⇒ Object
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 |