Class: CssDomCompiler

Inherits:
DOMCompiler show all
Defined in:
lib/compilers/cssDomCompiler.rb

Overview

Turn link to extenrnal stylesheets into inline style elements..

Constant Summary

Constants included from SqweezeUtils

SqweezeUtils::EMBED_MIME_TYPES

Instance Attribute Summary

Attributes inherited from DOMCompiler

#dom_documents

Instance Method Summary collapse

Methods inherited from DOMCompiler

#css_cdata, #get_resource, #initialize, #iterate_over, #js_cdata

Methods included from SqweezeUtils

#ansi_bold, #ansi_green, #ansi_nocolour, #ansi_red, #ansi_yellow, #byteweight, #compression_percentage, #encoded_contents, #find_file_in_targetdir, #mime_type, #notify, #remap_filepath, #write_file

Constructor Details

This class inherits a constructor from DOMCompiler

Instance Method Details

#compileObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/compilers/cssDomCompiler.rb', line 4

def compile
  iterate_over('link[@rel="stylesheet"]') do |elm, doc|
    next unless elm.has_attribute?('href') and not elm.get_attribute('href').empty?
    
    fbody=get_resource(elm.get_attribute('href'))
    
    # this is a bit convoluted, but it seems to be the right way of doing it
    elm.parent.children.delete(elm)
    
    style_html = "<style type=\"text/css\">\n" + css_cdata(fbody,:compress) + '</style>'
    doc.search('head').append(style_html)
  end
end

#compress(fbody) ⇒ Object



19
20
21
# File 'lib/compilers/cssDomCompiler.rb', line 19

def compress(fbody)
  YUI::CssCompressor.new.compress(fbody)
end