Class: TamTam

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

Overview

Takes CSS + HTML and converts it to inline styles. css <= ‘#foo { font-color: blue; }’ html <= ‘<div id=“foo”>woot</div>’

output => ‘<div id=“foo” style=“font-color: blue;”>woot</div>’

The class uses regular expressions to parse the CSS. The regular expressions are based on CPAN’s CSS::Parse::Lite.

Author: Dave Hoover of Obtiva Corp. Sponsor: Gary Levitt of MadMimi.com

Constant Summary collapse

UNSUPPORTED =
/(::first-letter|:link|:visited|:hover|:active)$/

Class Method Summary collapse

Class Method Details

.inline(args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tamtam.rb', line 18

def inline(args)
  css, doc = process(args)
  raw_styles(css).each do |raw_style|
    style, contents = parse(raw_style)        
    next if style.match(UNSUPPORTED)
    (doc/style).each do |element|
      apply_to(element, style, contents)
    end
  end
  doc.to_s
end