class Stylesheet::Document

Public Class Methods

new(url=nil) click to toggle source
# File lib/stylesheet/document.rb, line 4
def initialize(url=nil)
  @url = url
end

Public Instance Methods

location() click to toggle source
# File lib/stylesheet/document.rb, line 8
def location
  @location ||= Location.new(@url)
end
location=(location) click to toggle source
# File lib/stylesheet/document.rb, line 12
def location=(location)
  @location = location
end
style_sheets() click to toggle source
# File lib/stylesheet/document.rb, line 20
def style_sheets
  @style_sheets ||= StyleSheetList.new(styles)
end
text() click to toggle source
# File lib/stylesheet/document.rb, line 16
def text 
  @text ||= request_content
end
to_s() click to toggle source
# File lib/stylesheet/document.rb, line 24
def to_s
  "#<Document location:#{location.href}>"
end

Private Instance Methods

external_styles() click to toggle source
# File lib/stylesheet/document.rb, line 46
def external_styles
  parser.css("link[rel='stylesheet']").to_a
end
inline_styles() click to toggle source

find all inline styles and build new stylesheet from them

# File lib/stylesheet/document.rb, line 42
def inline_styles
  parser.css("style").to_a
end
parser() click to toggle source
# File lib/stylesheet/document.rb, line 56
def parser
  @parser ||= Nokogiri::HTML(text)
end
request() click to toggle source
# File lib/stylesheet/document.rb, line 60
def request
  @request ||= Stylesheet.request
end
request_content() click to toggle source
# File lib/stylesheet/document.rb, line 50
def request_content
  raise InvalidLocationError unless location.valid?

  request.get(location.href)
end
styles() click to toggle source
# File lib/stylesheet/document.rb, line 30
def styles
  (inline_styles + external_styles).map do |style|
    html = style.inner_html
    { parent:  self,
      content: html != "" ? html : nil,
      href:    style["href"],
      media:   style["media"],
      title:   style["title"] }
  end
end