zevarito-uglify_html 0.11 → 0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/uglify_html.rb +6 -2
- data/test/test_uglify.rb +13 -2
- data/uglify_html.gemspec +1 -1
- metadata +1 -1
data/CHANGELOG
CHANGED
data/lib/uglify_html.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/hpricot_ext.rb")
|
2
2
|
|
3
3
|
class UglifyHtml
|
4
|
-
def initialize(html)
|
4
|
+
def initialize(html, options = {})
|
5
5
|
@doc = Hpricot html
|
6
|
+
options[:pass_through] ||= []
|
7
|
+
@options = options
|
6
8
|
end
|
7
9
|
|
8
10
|
def make_ugly
|
9
11
|
(@doc/"*").each do |e|
|
12
|
+
next if @options[:pass_through].include? e.name
|
13
|
+
|
10
14
|
case e.name
|
11
15
|
when 'b', 'strong' then process_with_style(e, "font-weight", "bold")
|
12
16
|
when 'i', 'em' then process_with_style(e, "font-style", "italic")
|
data/test/test_uglify.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
2
|
|
3
3
|
class UglifyHtmlTest < Test::Unit::TestCase
|
4
|
-
def assert_renders_uglify(uglify, html)
|
5
|
-
assert_equal uglify, UglifyHtml.new(html).make_ugly
|
4
|
+
def assert_renders_uglify(uglify, html, options ={})
|
5
|
+
assert_equal uglify, UglifyHtml.new(html, options).make_ugly
|
6
|
+
end
|
7
|
+
|
8
|
+
context "let pass through certain elements" do
|
9
|
+
test "pass strong tags, pass em tags" do
|
10
|
+
html = "<p>some <strong>bold</strong> text inside a paragraph</p>"
|
11
|
+
uglify = "<p>some <strong>bold</strong> text inside a paragraph</p>"
|
12
|
+
assert_renders_uglify uglify, html, {:pass_through => ['strong']}
|
13
|
+
html = "<p>some <em>bold</em> text inside a paragraph</p>"
|
14
|
+
uglify = "<p>some <em>bold</em> text inside a paragraph</p>"
|
15
|
+
assert_renders_uglify uglify, html, {:pass_through => ['em']}
|
16
|
+
end
|
6
17
|
end
|
7
18
|
|
8
19
|
context "convert common tags" do
|
data/uglify_html.gemspec
CHANGED