premailer-plus 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +8 -0
- data/LICENSE +42 -0
- data/README.textile +43 -0
- data/Rakefile +62 -0
- data/VERSION.yml +4 -0
- data/bin/premailer_plus +107 -0
- data/lib/html_to_plain_text.rb +61 -0
- data/lib/premailer.rb +401 -0
- data/misc/client_support.yaml +185 -0
- data/premailer-plus.gemspec +88 -0
- data/test/fixtures/client_support.html +10 -0
- data/test/fixtures/test-import.css +4 -0
- data/test/fixtures/test-with-folding.html +77 -0
- data/test/fixtures/test.css +90 -0
- data/test/fixtures/test.html +66 -0
- data/test/fixtures/test2.css +81 -0
- data/test/fixtures/test2.html +75 -0
- data/test/fixtures/test3-import.css +4 -0
- data/test/fixtures/test3-noimport.css +1 -0
- data/test/fixtures/test3-out.html +82 -0
- data/test/fixtures/test3.css +83 -0
- data/test/fixtures/test3.html +85 -0
- data/test/images/content_bg.jpg +0 -0
- data/test/images/inset.jpg +0 -0
- data/test/speed.rb +34 -0
- data/test/test_convert_to_plain_text.rb +30 -0
- data/test/test_helper.rb +6 -0
- data/test/test_link_resolver.rb +32 -0
- data/test/test_premailer.rb +22 -0
- data/test/test_premailer_download.rb +77 -0
- metadata +130 -0
Binary file
|
Binary file
|
data/test/speed.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../css_parser/'))
|
2
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../'))
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
require "benchmark"
|
8
|
+
require 'css_parser'
|
9
|
+
|
10
|
+
include Benchmark
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
css_block = {:declarations=>"color: #fff; background: #1c2815 none;", :selector=>"body", :specificity=>1},
|
15
|
+
{:declarations=>"color: #fff; background: #1c2815 none;", :selector=>"#container", :specificity=>100}
|
16
|
+
|
17
|
+
n = 10000
|
18
|
+
|
19
|
+
|
20
|
+
bm(12) do |test|
|
21
|
+
test.report("creating ruleset:") do
|
22
|
+
@cp = CssParser.new
|
23
|
+
n.times do |x|
|
24
|
+
@cp.fold_declarations(css_block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
test.report("parsing in block:") do
|
28
|
+
@cp = CssParser.new
|
29
|
+
n.times do |x|
|
30
|
+
@cp.fold_declarations_old(css_block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'lib/html_to_plain_text'
|
3
|
+
|
4
|
+
class PlainTextTests < Test::Unit::TestCase
|
5
|
+
include HtmlToPlainText
|
6
|
+
|
7
|
+
def test_unordered_lists
|
8
|
+
html = %q{
|
9
|
+
<link rel="test" />
|
10
|
+
<ul>
|
11
|
+
<li class="123" id="456">Test 1</li>
|
12
|
+
<li>Test 2
|
13
|
+
<ul>
|
14
|
+
<li>Test 2a</li>
|
15
|
+
</ul>
|
16
|
+
</li>
|
17
|
+
<li>Test 3</li>
|
18
|
+
</ul>
|
19
|
+
}
|
20
|
+
text = %q{ * Test 1
|
21
|
+
* Test 2
|
22
|
+
* Test 2a
|
23
|
+
* Test 3}
|
24
|
+
|
25
|
+
assert_equal text, convert_to_text(html, 80)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class PremailerLinkResolverTests < Test::Unit::TestCase
|
5
|
+
def test_resolving_urls_from_string
|
6
|
+
['test.html', '/test.html', './test.html',
|
7
|
+
'test/../test.html', 'test/../test/../test.html'].each do |q|
|
8
|
+
assert_equal 'http://example.com/test.html', Premailer.resolve_link(q, 'http://example.com/'), q
|
9
|
+
end
|
10
|
+
|
11
|
+
assert_equal 'https://example.net:80/~basedir/test.html?var=1#anchor', Premailer.resolve_link('test/../test/../test.html?var=1#anchor', 'https://example.net:80/~basedir/')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_resolving_urls_from_uri
|
15
|
+
base_uri = URI.parse('http://example.com/')
|
16
|
+
['test.html', '/test.html', './test.html',
|
17
|
+
'test/../test.html', 'test/../test/../test.html'].each do |q|
|
18
|
+
assert_equal 'http://example.com/test.html', Premailer.resolve_link(q, base_uri), q
|
19
|
+
end
|
20
|
+
|
21
|
+
base_uri = URI.parse('https://example.net:80/~basedir/')
|
22
|
+
assert_equal 'https://example.net:80/~basedir/test.html?var=1#anchor', Premailer.resolve_link('test/../test/../test.html?var=1#anchor', base_uri)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_resolving_local_paths
|
26
|
+
base_dir = 'c:/root/'
|
27
|
+
['test.html', 'test/../test.html', './test.html',
|
28
|
+
'test/../test.html', 'test/../test/../test.html'].each do |q|
|
29
|
+
assert_equal 'c:/root/test.html', Premailer.resolve_link(q, base_dir), q
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class PremailerTests < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
#@premailer = Premailer.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_escaping_strings
|
11
|
+
str = %q{url("/images/test.png");}
|
12
|
+
assert "url(\'/images/test.png\');", Premailer.escape_string(str)
|
13
|
+
|
14
|
+
str = %q{url("/images/\"test.png");}
|
15
|
+
assert "url(\'/images/\'test.png\');", Premailer.escape_string(str)
|
16
|
+
|
17
|
+
str = %q{url('/images/\"test.png');}
|
18
|
+
assert "url(\'/images/\'test.png\');", Premailer.escape_string(str)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
# Test cases for the CssParser's downloading functions.
|
4
|
+
class PremailerDownloadTest < Test::Unit::TestCase
|
5
|
+
include WEBrick
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@uri_base = 'http://localhost:12000'
|
9
|
+
|
10
|
+
www_root = File.dirname(__FILE__) + '/fixtures/'
|
11
|
+
|
12
|
+
@server_thread = Thread.new do
|
13
|
+
s = WEBrick::HTTPServer.new(:Port => 12000, :DocumentRoot => www_root, :Logger => Log.new(nil, BasicLog::ERROR), :AccessLog => [])
|
14
|
+
@port = s.config[:Port]
|
15
|
+
begin
|
16
|
+
s.start
|
17
|
+
ensure
|
18
|
+
s.shutdown
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
sleep 1 # ensure the server has time to load
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
@server_thread.kill
|
27
|
+
@server_thread.join(5)
|
28
|
+
@server_thread = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_loading_a_remote_file
|
32
|
+
@cp.load_uri!("#{@uri_base}/simple.css")
|
33
|
+
assert_equal 'margin: 0px;', @cp.find_by_selector('p').join(' ')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_following_at_import_rules
|
37
|
+
@cp.load_uri!("#{@uri_base}/import1.css")
|
38
|
+
|
39
|
+
# from '/import1.css'
|
40
|
+
assert_equal 'color: lime;', @cp.find_by_selector('div').join(' ')
|
41
|
+
|
42
|
+
# from '/subdir/import2.css'
|
43
|
+
assert_equal 'text-decoration: none;', @cp.find_by_selector('a').join(' ')
|
44
|
+
|
45
|
+
# from '/subdir/../simple.css'
|
46
|
+
assert_equal 'margin: 0px;', @cp.find_by_selector('p').join(' ')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_importing_with_media_types
|
50
|
+
@cp.load_uri!("#{@uri_base}/import-with-media-types.css")
|
51
|
+
|
52
|
+
# from simple.css with :screen media type
|
53
|
+
assert_equal 'margin: 0px;', @cp.find_by_selector('p', :screen).join(' ')
|
54
|
+
assert_equal '', @cp.find_by_selector('p', :tty).join(' ')
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_throwing_circular_reference_exception
|
58
|
+
assert_raise CircularReferenceError do
|
59
|
+
@cp.load_uri!("#{@uri_base}/import-circular-reference.css")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_toggling_not_found_exceptions
|
64
|
+
cp_with_exceptions = Parser.new(:io_exceptions => true)
|
65
|
+
|
66
|
+
assert_raise RemoteFileError do
|
67
|
+
cp_with_exceptions.load_uri!("#{@uri_base}/no-exist.xyz")
|
68
|
+
end
|
69
|
+
|
70
|
+
cp_without_exceptions = Parser.new(:io_exceptions => false)
|
71
|
+
|
72
|
+
assert_nothing_raised RemoteFileError do
|
73
|
+
cp_without_exceptions.load_uri!("#{@uri_base}/no-exist.xyz")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: premailer-plus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Green
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-11 00:00:00 -05:00
|
13
|
+
default_executable: premailer_plus
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.8.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: htmlentities
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.1.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: css_parser
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.9.0
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: text-reform
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.2.0
|
54
|
+
version:
|
55
|
+
description:
|
56
|
+
email: mike.is.green@gmail.com
|
57
|
+
executables:
|
58
|
+
- premailer_plus
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- LICENSE
|
63
|
+
- README.textile
|
64
|
+
files:
|
65
|
+
- .document
|
66
|
+
- .gitignore
|
67
|
+
- LICENSE
|
68
|
+
- README.textile
|
69
|
+
- Rakefile
|
70
|
+
- VERSION.yml
|
71
|
+
- bin/premailer_plus
|
72
|
+
- lib/html_to_plain_text.rb
|
73
|
+
- lib/premailer.rb
|
74
|
+
- misc/client_support.yaml
|
75
|
+
- premailer-plus.gemspec
|
76
|
+
- test/fixtures/client_support.html
|
77
|
+
- test/fixtures/test-import.css
|
78
|
+
- test/fixtures/test-with-folding.html
|
79
|
+
- test/fixtures/test.css
|
80
|
+
- test/fixtures/test.html
|
81
|
+
- test/fixtures/test2.css
|
82
|
+
- test/fixtures/test2.html
|
83
|
+
- test/fixtures/test3-import.css
|
84
|
+
- test/fixtures/test3-noimport.css
|
85
|
+
- test/fixtures/test3-out.html
|
86
|
+
- test/fixtures/test3.css
|
87
|
+
- test/fixtures/test3.html
|
88
|
+
- test/images/content_bg.jpg
|
89
|
+
- test/images/inset.jpg
|
90
|
+
- test/speed.rb
|
91
|
+
- test/test_convert_to_plain_text.rb
|
92
|
+
- test/test_helper.rb
|
93
|
+
- test/test_link_resolver.rb
|
94
|
+
- test/test_premailer.rb
|
95
|
+
- test/test_premailer_download.rb
|
96
|
+
has_rdoc: true
|
97
|
+
homepage: http://github.com/mikedamage/premailer-plus
|
98
|
+
licenses: []
|
99
|
+
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options:
|
102
|
+
- --charset=UTF-8
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: "0"
|
110
|
+
version:
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: "0"
|
116
|
+
version:
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.3.5
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Miscellaneous improvements and fixes to Alex Dunae's Premailer gem
|
124
|
+
test_files:
|
125
|
+
- test/speed.rb
|
126
|
+
- test/test_convert_to_plain_text.rb
|
127
|
+
- test/test_helper.rb
|
128
|
+
- test/test_link_resolver.rb
|
129
|
+
- test/test_premailer.rb
|
130
|
+
- test/test_premailer_download.rb
|