class Stylesheet::CssStyleSheet
Attributes
disabled[W]
href[R]
media[R]
owner_rule[R]
parent[RW]
title[RW]
type[W]
Public Class Methods
new(args)
click to toggle source
# 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
Public Instance Methods
content()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 55 def content @content ||= request_content end
content=(content)
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 51 def content=(content) @content = content if content end
css_rules()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 59 def css_rules @css_rules ||= CssRuleList.new(content, self) end
Also aliased as: rules
delete_rule(index)
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 77 def delete_rule(index) @css_rules.delete_at(index) end
disabled?()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 33 def disabled? @disabled || false end
href=(url)
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 41 def href=(url) return unless url @url = url @href = location.to_s end
import_rules()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 81 def insert_rule(rule, index) @css_rules.insert(index, rule) end
location()
click to toggle source
# 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)
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 90 def location=(location) return unless location @location = location @url = location.href @href = location.href end
media=(media)
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 47 def media=(media) @media ||= MediaList.new(media) end
parent_style_sheet()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 73 def parent_style_sheet @parent if @owner_rule end
style_rules()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 69 def style_rules css_rules.select {|r| r.type == CssRule::STYLE_RULE } end
type()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 37 def type @type || "text/css" end
Private Instance Methods
inline_css?()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 104 def inline_css? !@url || @url == "" end
request()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 114 def request @request ||= Stylesheet.request end
request_content()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 108 def request_content return "" if inline_css? raise InvalidLocationError unless location && location.valid? request.get(location.href) end
standalone_css?()
click to toggle source
# File lib/stylesheet/css_style_sheet.rb, line 100 def standalone_css? !parent end