decoration_mail 0.2.4 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +1 -7
- data/{MIT-LICENSE → LICENSE.txt} +3 -1
- data/Rakefile +7 -23
- data/decoration_mail.gemspec +23 -73
- data/lib/decoration_mail/base.rb +36 -56
- data/lib/decoration_mail/{converter.rb → html.rb} +51 -35
- data/lib/decoration_mail/image.rb +4 -0
- data/lib/decoration_mail/version.rb +3 -0
- data/lib/decoration_mail.rb +3 -3
- data/spec/{unit → decoration_mail}/base_spec.rb +16 -16
- data/spec/decoration_mail/html_spec.rb +171 -0
- data/spec/{unit → decoration_mail}/image_spec.rb +8 -1
- data/spec/spec_helper.rb +17 -0
- metadata +120 -102
- data/Gemfile.lock +0 -39
- data/VERSION +0 -1
- data/init.rb +0 -3
- data/spec/unit/converter_spec.rb +0 -155
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d0a474271ee1e5cd289bdba16b7130a1969f81b
|
4
|
+
data.tar.gz: 44cf247349b4ae24f86816a85499d8bb5988bd74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4be509f5787e387a62e312a953a4903fef87ae247115154518be97354d439f7badc038dff2104e144022eae3ee5e6903a48fdcf36af4f04a593fb775c1ae5d07
|
7
|
+
data.tar.gz: 02f983ed779354de25dbc2f4b03e503e27fcabbf12e2c5fd089f101332134e3e689fd20bd1dc621a24e71604c5cab31b590e8965a44f1cc1590b231d8718d556
|
data/.gitignore
ADDED
data/Gemfile
CHANGED
data/{MIT-LICENSE → LICENSE.txt}
RENAMED
data/Rakefile
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
require '
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rdoc/task'
|
4
4
|
|
5
5
|
desc 'Default: run unit tests.'
|
6
|
-
task :default => :
|
6
|
+
task :default => :spec
|
7
7
|
|
8
8
|
desc 'Test the decoration_mail plugin.'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
t.pattern = 'test/**/*_test.rb'
|
13
|
-
t.verbose = true
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
10
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
11
|
+
spec.rspec_opts = ['-c --backtrace']
|
14
12
|
end
|
15
13
|
|
16
14
|
desc 'Generate documentation for the decoration_mail plugin.'
|
@@ -21,17 +19,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
21
19
|
rdoc.rdoc_files.include('README')
|
22
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
21
|
end
|
24
|
-
|
25
|
-
begin
|
26
|
-
require 'jeweler'
|
27
|
-
Jeweler::Tasks.new do |gemspec|
|
28
|
-
gemspec.name = "decoration_mail"
|
29
|
-
gemspec.summary = "Decoration Mail Parser"
|
30
|
-
gemspec.email = "d.akatsuka@gmail.com"
|
31
|
-
gemspec.homepage = "https://github.com/dakatsuka/decoration_mail"
|
32
|
-
gemspec.description = "Decoration Mail Parser"
|
33
|
-
gemspec.authors = ["Dai Akatsuka"]
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
37
|
-
end
|
data/decoration_mail.gemspec
CHANGED
@@ -1,77 +1,27 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'decoration_mail/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "decoration_mail"
|
8
|
+
spec.version = DecorationMail::VERSION
|
9
|
+
spec.authors = ["Dai Akatsuka", "M.Shibuya"]
|
10
|
+
spec.email = ["d.akatsuka@gmail.com", "mit.shibuya@gmail.com"]
|
11
|
+
spec.description = %q{Decoration Mail Parser}
|
12
|
+
spec.summary = %q{Decoration Mail Parser}
|
13
|
+
spec.homepage = "https://github.com/dakatsuka/decoration_mail"
|
14
|
+
spec.license = "MIT"
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
s.email = %q{d.akatsuka@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.rdoc"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
"Gemfile",
|
20
|
-
"Gemfile.lock",
|
21
|
-
"MIT-LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"decoration_mail.gemspec",
|
26
|
-
"init.rb",
|
27
|
-
"lib/decoration_mail.rb",
|
28
|
-
"lib/decoration_mail/base.rb",
|
29
|
-
"lib/decoration_mail/converter.rb",
|
30
|
-
"lib/decoration_mail/image.rb",
|
31
|
-
"lib/decoration_mail/message.rb",
|
32
|
-
"spec/resources/au_decoration.eml",
|
33
|
-
"spec/resources/au_decoration_with_attachment.eml",
|
34
|
-
"spec/resources/docomo_decoration.eml",
|
35
|
-
"spec/resources/docomo_decoration_with_attachment.eml",
|
36
|
-
"spec/resources/other_decoration.eml",
|
37
|
-
"spec/resources/softbank_decoration.eml",
|
38
|
-
"spec/resources/softbank_decoration_with_attachment.eml",
|
39
|
-
"spec/spec_helper.rb",
|
40
|
-
"spec/unit/base_spec.rb",
|
41
|
-
"spec/unit/converter_spec.rb",
|
42
|
-
"spec/unit/image_spec.rb"
|
43
|
-
]
|
44
|
-
s.homepage = %q{https://github.com/dakatsuka/decoration_mail}
|
45
|
-
s.require_paths = ["lib"]
|
46
|
-
s.rubygems_version = %q{1.3.7}
|
47
|
-
s.summary = %q{Decoration Mail Parser}
|
48
|
-
s.test_files = [
|
49
|
-
"spec/spec_helper.rb",
|
50
|
-
"spec/unit/base_spec.rb",
|
51
|
-
"spec/unit/converter_spec.rb",
|
52
|
-
"spec/unit/image_spec.rb"
|
53
|
-
]
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
54
20
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
s.add_runtime_dependency(%q<hpricot>, [">= 0.8.3"])
|
62
|
-
s.add_development_dependency(%q<rspec>, [">= 2.0"])
|
63
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
64
|
-
else
|
65
|
-
s.add_dependency(%q<mail>, [">= 2.2.9"])
|
66
|
-
s.add_dependency(%q<hpricot>, [">= 0.8.3"])
|
67
|
-
s.add_dependency(%q<rspec>, [">= 2.0"])
|
68
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
69
|
-
end
|
70
|
-
else
|
71
|
-
s.add_dependency(%q<mail>, [">= 2.2.9"])
|
72
|
-
s.add_dependency(%q<hpricot>, [">= 0.8.3"])
|
73
|
-
s.add_dependency(%q<rspec>, [">= 2.0"])
|
74
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
75
|
-
end
|
21
|
+
spec.add_dependency "mail", "~> 2.2"
|
22
|
+
spec.add_dependency "nokogiri"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "debugger"
|
76
27
|
end
|
77
|
-
|
data/lib/decoration_mail/base.rb
CHANGED
@@ -6,86 +6,66 @@ module DecorationMail
|
|
6
6
|
attr_reader :images, :subject
|
7
7
|
|
8
8
|
def initialize(mail)
|
9
|
-
|
9
|
+
extract_attachments(mail)
|
10
10
|
@subject = mail.subject.blank? ? nil : mail.subject.toutf8
|
11
|
-
@
|
12
|
-
@
|
11
|
+
@text_body = mail.text_part.to_s.toutf8
|
12
|
+
@html_body = DecorationMail::HTML.new(mail.html_part.body.to_s.toutf8)
|
13
13
|
end
|
14
14
|
|
15
15
|
def save(options = {}, &block)
|
16
16
|
@images.each do |image|
|
17
17
|
image.instance_eval(&block)
|
18
18
|
|
19
|
-
if @
|
20
|
-
@
|
21
|
-
if element[:src] == image.content_id
|
22
|
-
element[:src] = (image.path ? image.path : image.filename.to_s)
|
23
|
-
end
|
24
|
-
end
|
19
|
+
if @html_body.match /#{image.content_id}/
|
20
|
+
@html_body.update_img_src(image.content_id, image.src)
|
25
21
|
else
|
26
22
|
case options[:other_images]
|
27
23
|
when :top
|
28
|
-
@
|
24
|
+
@html_body.prepend_img(image.src)
|
29
25
|
when :bottom
|
30
|
-
@
|
26
|
+
@html_body.append_img(image.src)
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
34
30
|
|
35
|
-
@
|
31
|
+
@html_body.to_s
|
36
32
|
end
|
37
33
|
|
38
|
-
|
39
|
-
def parse_text(text)
|
40
|
-
text.to_s.toutf8
|
41
|
-
end
|
42
|
-
|
43
|
-
def parse_html(html)
|
44
|
-
html = html.body.to_s.toutf8
|
45
|
-
html = Hpricot.parse(html)
|
46
|
-
|
47
|
-
if html.search("body").empty?
|
48
|
-
raise ArgumentError, 'invalid HTML'
|
49
|
-
else
|
50
|
-
html = DecorationMail::Converter.convert_to_xhtml(html).at('div')
|
51
|
-
end
|
52
|
-
|
53
|
-
html
|
54
|
-
end
|
34
|
+
private
|
55
35
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
36
|
+
def check_content_type(content_type)
|
37
|
+
case content_type
|
38
|
+
when /^image\/gif/
|
39
|
+
true
|
40
|
+
when /^image\/jpg/
|
41
|
+
true
|
42
|
+
when /^image\/jpeg/
|
43
|
+
true
|
44
|
+
when /^image\/png/
|
45
|
+
true
|
46
|
+
else
|
47
|
+
false
|
69
48
|
end
|
49
|
+
end
|
70
50
|
|
71
|
-
|
72
|
-
|
51
|
+
def extract_attachments(part)
|
52
|
+
@images = [] unless defined?(@images)
|
73
53
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
54
|
+
if part.multipart?
|
55
|
+
part.parts.each do |part|
|
56
|
+
if part.multipart?
|
57
|
+
extract_attachments(part)
|
58
|
+
else
|
59
|
+
content_type = part.header['content-type'].to_s
|
60
|
+
next unless check_content_type(content_type)
|
81
61
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
62
|
+
content_id = part.header['content-id'].to_s.sub(/^</, '').sub(/>$/, '')
|
63
|
+
content_id = part.filename if content_id.blank?
|
64
|
+
filename = part.filename
|
65
|
+
@images << DecorationMail::Image.new(content_id, content_type, filename, part)
|
87
66
|
end
|
88
67
|
end
|
89
68
|
end
|
69
|
+
end
|
90
70
|
end
|
91
71
|
end
|
@@ -1,45 +1,65 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
module DecorationMail
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
class HTML
|
5
|
+
def initialize(str)
|
6
|
+
@tree = Nokogiri.HTML(str)
|
7
|
+
raise ArgumentError, 'invalid HTML' if @tree.search("body").empty?
|
8
|
+
|
9
|
+
convert_font_color_to_css
|
10
|
+
convert_font_size_to_css
|
11
|
+
convert_align_to_css
|
12
|
+
convert_blink_to_css
|
13
|
+
convert_marquee_to_css
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def match(regexp)
|
17
|
+
@tree.css('body').to_html =~ regexp
|
18
|
+
end
|
19
|
+
|
20
|
+
def append_img(src)
|
21
|
+
@tree.css('body').children.after(%(<br /><div style="text-align:center;"><img src="#{src}" /></div>))
|
22
|
+
end
|
23
|
+
|
24
|
+
def prepend_img(src)
|
25
|
+
@tree.css('body').children.before(%(<div style="text-align:center;"><img src="#{src}" /></div><br />))
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_img_src(from, to)
|
29
|
+
@tree.css("img[src=\"#{from}\"]").each{|e| e['src'] = to }
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
to_div.to_html
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def to_div
|
39
|
+
@tree.search('body').first.dup.tap do |body|
|
40
|
+
body.name = 'div'
|
41
|
+
bgcolor = body[:bgcolor]
|
42
|
+
body.attributes.each{|k, v| body.remove_attribute k}
|
43
|
+
body[:style] = "background-color:#{bgcolor};" if bgcolor
|
22
44
|
end
|
23
|
-
html
|
24
45
|
end
|
25
46
|
|
26
|
-
def
|
27
|
-
|
47
|
+
def convert_font_color_to_css
|
48
|
+
@tree.search("font").each do |element|
|
28
49
|
if element[:color]
|
29
50
|
str = "<span>#{element.inner_html}</span>"
|
30
|
-
tmp =
|
51
|
+
tmp = Nokogiri::HTML.fragment(str).search("span")
|
31
52
|
tmp.first[:style] = "color:#{element[:color].downcase};"
|
32
53
|
element.swap(tmp.to_html)
|
33
54
|
end
|
34
55
|
end
|
35
|
-
html
|
36
56
|
end
|
37
57
|
|
38
|
-
def
|
39
|
-
|
58
|
+
def convert_font_size_to_css
|
59
|
+
@tree.search("font").each do |element|
|
40
60
|
if element[:size]
|
41
61
|
str = "<span>#{element.inner_html}</span>"
|
42
|
-
tmp =
|
62
|
+
tmp = Nokogiri::HTML.fragment(str).search("span")
|
43
63
|
|
44
64
|
case element[:size]
|
45
65
|
when "1"
|
@@ -62,31 +82,28 @@ module DecorationMail
|
|
62
82
|
element.swap(tmp.to_html)
|
63
83
|
end
|
64
84
|
end
|
65
|
-
html
|
66
85
|
end
|
67
86
|
|
68
|
-
def
|
69
|
-
|
87
|
+
def convert_align_to_css
|
88
|
+
@tree.search("div").each do |element|
|
70
89
|
if element[:align]
|
71
90
|
str = "<div>#{element.inner_html}</div>"
|
72
|
-
tmp =
|
91
|
+
tmp = Nokogiri::HTML.fragment(str).search "div"
|
73
92
|
|
74
93
|
tmp.first[:style] = "text-align:#{element[:align]};"
|
75
94
|
element.swap(tmp.to_html)
|
76
95
|
end
|
77
96
|
end
|
78
|
-
html
|
79
97
|
end
|
80
98
|
|
81
|
-
def
|
82
|
-
|
99
|
+
def convert_blink_to_css
|
100
|
+
@tree.search("blink").each do |element|
|
83
101
|
element.swap('<span style="text-decoration:blink;">' + element.inner_html + '</span>')
|
84
102
|
end
|
85
|
-
html
|
86
103
|
end
|
87
104
|
|
88
|
-
def
|
89
|
-
|
105
|
+
def convert_marquee_to_css
|
106
|
+
@tree.search("marquee").each do |element|
|
90
107
|
if element[:behavior] == "scroll"
|
91
108
|
element.swap('<div style="display:-wap-marquee;-wap-marquee-loop:infinite;">' + element.inner_html + '</div>')
|
92
109
|
elsif element[:behavior] == "alternate"
|
@@ -95,7 +112,6 @@ module DecorationMail
|
|
95
112
|
element.swap('<div style="display:-wap-marquee;-wap-marquee-loop:infinite;">' + element.inner_html + '</div>')
|
96
113
|
end
|
97
114
|
end
|
98
|
-
html
|
99
115
|
end
|
100
116
|
end
|
101
117
|
end
|
data/lib/decoration_mail.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
$:.unshift(File.dirname(__FILE__))
|
3
3
|
|
4
4
|
require 'mail'
|
5
|
-
require '
|
5
|
+
require 'nokogiri'
|
6
6
|
|
7
|
-
require 'decoration_mail/converter'
|
8
|
-
require 'decoration_mail/image'
|
9
7
|
require 'decoration_mail/base'
|
8
|
+
require 'decoration_mail/html'
|
9
|
+
require 'decoration_mail/image'
|
10
10
|
require 'decoration_mail/message'
|
11
11
|
|
12
12
|
Mail::Message.send :include, DecorationMail::Message
|
@@ -38,25 +38,25 @@ describe DecorationMail::Base do
|
|
38
38
|
it "HTMLが返るべき" do
|
39
39
|
html = subject.save do |image|
|
40
40
|
end
|
41
|
-
|
41
|
+
Nokogiri.parse(html).search("div").should_not be_empty
|
42
42
|
end
|
43
43
|
|
44
44
|
it "HTMLにはHTMLタグが含まれない" do
|
45
45
|
html = subject.save do |image|
|
46
46
|
end
|
47
|
-
|
47
|
+
Nokogiri.parse(html).search("html").should be_empty
|
48
48
|
end
|
49
49
|
|
50
50
|
it "HTMLにはHEADタグが含まれない" do
|
51
51
|
html = subject.save do |image|
|
52
52
|
end
|
53
|
-
|
53
|
+
Nokogiri.parse(html).search("head").should be_empty
|
54
54
|
end
|
55
55
|
|
56
56
|
it "HTMLにはBODYタグが含まれない" do
|
57
57
|
html = subject.save do |image|
|
58
58
|
end
|
59
|
-
|
59
|
+
Nokogiri.parse(html).search("body").should be_empty
|
60
60
|
end
|
61
61
|
|
62
62
|
it "ブロック変数にパスを渡すとIMGタグのSRCが書き換わるべき" do
|
@@ -105,25 +105,25 @@ describe DecorationMail::Base do
|
|
105
105
|
it "HTMLが返るべき" do
|
106
106
|
html = subject.save do |image|
|
107
107
|
end
|
108
|
-
|
108
|
+
Nokogiri.parse(html).search("div").should_not be_empty
|
109
109
|
end
|
110
110
|
|
111
111
|
it "HTMLにはHTMLタグが含まれない" do
|
112
112
|
html = subject.save do |image|
|
113
113
|
end
|
114
|
-
|
114
|
+
Nokogiri.parse(html).search("html").should be_empty
|
115
115
|
end
|
116
116
|
|
117
117
|
it "HTMLにはHEADタグが含まれない" do
|
118
118
|
html = subject.save do |image|
|
119
119
|
end
|
120
|
-
|
120
|
+
Nokogiri.parse(html).search("head").should be_empty
|
121
121
|
end
|
122
122
|
|
123
123
|
it "HTMLにはBODYタグが含まれない" do
|
124
124
|
html = subject.save do |image|
|
125
125
|
end
|
126
|
-
|
126
|
+
Nokogiri.parse(html).search("body").should be_empty
|
127
127
|
end
|
128
128
|
|
129
129
|
it "ブロック変数にパスを渡すとIMGタグのSRCが書き換わるべき" do
|
@@ -172,25 +172,25 @@ describe DecorationMail::Base do
|
|
172
172
|
it "HTMLが返るべき" do
|
173
173
|
html = subject.save do |image|
|
174
174
|
end
|
175
|
-
|
175
|
+
Nokogiri.parse(html).search("div").should_not be_empty
|
176
176
|
end
|
177
177
|
|
178
178
|
it "HTMLにはHTMLタグが含まれない" do
|
179
179
|
html = subject.save do |image|
|
180
180
|
end
|
181
|
-
|
181
|
+
Nokogiri.parse(html).search("html").should be_empty
|
182
182
|
end
|
183
183
|
|
184
184
|
it "HTMLにはHEADタグが含まれない" do
|
185
185
|
html = subject.save do |image|
|
186
186
|
end
|
187
|
-
|
187
|
+
Nokogiri.parse(html).search("head").should be_empty
|
188
188
|
end
|
189
189
|
|
190
190
|
it "HTMLにはBODYタグが含まれない" do
|
191
191
|
html = subject.save do |image|
|
192
192
|
end
|
193
|
-
|
193
|
+
Nokogiri.parse(html).search("body").should be_empty
|
194
194
|
end
|
195
195
|
|
196
196
|
it "ブロック変数にパスを渡すとIMGタグのSRCが書き換わるべき" do
|
@@ -237,25 +237,25 @@ describe DecorationMail::Base do
|
|
237
237
|
it "HTMLが返るべき" do
|
238
238
|
html = subject.save do |image|
|
239
239
|
end
|
240
|
-
|
240
|
+
Nokogiri.parse(html).search("div").should_not be_empty
|
241
241
|
end
|
242
242
|
|
243
243
|
it "HTMLにはHTMLタグが含まれない" do
|
244
244
|
html = subject.save do |image|
|
245
245
|
end
|
246
|
-
|
246
|
+
Nokogiri.parse(html).search("html").should be_empty
|
247
247
|
end
|
248
248
|
|
249
249
|
it "HTMLにはHEADタグが含まれない" do
|
250
250
|
html = subject.save do |image|
|
251
251
|
end
|
252
|
-
|
252
|
+
Nokogiri.parse(html).search("head").should be_empty
|
253
253
|
end
|
254
254
|
|
255
255
|
it "HTMLにはBODYタグが含まれない" do
|
256
256
|
html = subject.save do |image|
|
257
257
|
end
|
258
|
-
|
258
|
+
Nokogiri.parse(html).search("body").should be_empty
|
259
259
|
end
|
260
260
|
|
261
261
|
it "ブロック変数にパスを渡すとIMGタグのSRCが書き換わるべき" do
|
@@ -0,0 +1,171 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
3
|
+
|
4
|
+
|
5
|
+
describe DecorationMail::HTML do
|
6
|
+
context "with invalid HTML" do
|
7
|
+
it "raises ArgumentError" do
|
8
|
+
lambda{ DecorationMail::HTML.new('') }.should raise_error ArgumentError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#match" do
|
13
|
+
subject{ DecorationMail::HTML.new('<body bgcolor="#ffffff">ほげほげ</body>') }
|
14
|
+
|
15
|
+
it "performs regexp matching within body" do
|
16
|
+
subject.match(/ほげ/).should be_true
|
17
|
+
subject.match(/#ffffff/).should be_true
|
18
|
+
subject.match(/もげ/).should be_false
|
19
|
+
subject.match(/html/).should be_false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#append_img" do
|
24
|
+
subject{ DecorationMail::HTML.new('<body>ほげほげ</body>') }
|
25
|
+
|
26
|
+
it "inserts img tag after the content" do
|
27
|
+
subject.append_img('http://example.com/img.gif')
|
28
|
+
subject.to_s.should == %(<div>ほげほげ<br><div style="text-align:center;"><img src="http://example.com/img.gif"></div>\n</div>)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#prepend_img" do
|
33
|
+
subject{ DecorationMail::HTML.new('<body>ほげほげ</body>') }
|
34
|
+
|
35
|
+
it "inserts img tag ahead of the content" do
|
36
|
+
subject.prepend_img('http://example.com/img.gif')
|
37
|
+
subject.to_s.should == %(<div>\n<div style="text-align:center;"><img src="http://example.com/img.gif"></div>\n<br>ほげほげ</div>)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#update_img_src" do
|
42
|
+
subject{ DecorationMail::HTML.new('<body>ほげほげ<img src="cid:hoge"><img src="fuga.gif"></body>') }
|
43
|
+
|
44
|
+
it "changes img's src to new one" do
|
45
|
+
subject.update_img_src('cid:hoge', 'http://example.com/img.gif')
|
46
|
+
subject.to_s.should == %(<div>ほげほげ<img src="http://example.com/img.gif"><img src="fuga.gif">\n</div>)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#to_s" do
|
51
|
+
it "should convert body to div" do
|
52
|
+
'<body>ほげほげ</body>'.should be_converted_to '<div>ほげほげ</div>'
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with 'bgcolor' attribute" do
|
56
|
+
it "should convert body to div and inline css" do
|
57
|
+
'<body bgcolor="#ffffff">ほげほげ</body>'.
|
58
|
+
should be_converted_to '<div style="background-color:#ffffff;">ほげほげ</div>'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "with 'onclick' attribute" do
|
63
|
+
it "should not contain it" do
|
64
|
+
'<body onclick="alert(\'a\')">ほげほげ</body>'.
|
65
|
+
should be_converted_to '<div>ほげほげ</div>'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#convert_font_color_to_css" do
|
71
|
+
it "should convert font to span and inline css" do
|
72
|
+
'<body><font color="#ffffff">ほげほげ</font></body>'.
|
73
|
+
should be_converted_to '<div><span style="color:#ffffff;">ほげほげ</span></div>'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#convert_font_size_to_css" do
|
78
|
+
it "should convert font(size=1) to span and inline css(xx-small)" do
|
79
|
+
'<body><font size="1">ほげほげ</font></body>'.
|
80
|
+
should be_converted_to '<div><span style="font-size:xx-small;">ほげほげ</span></div>'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should convert font(size=2) to span and inline css(x-small)" do
|
84
|
+
'<body><font size="2">ほげほげ</font></body>'.
|
85
|
+
should be_converted_to '<div><span style="font-size:x-small;">ほげほげ</span></div>'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should convert font(size=3) to span and inline css(small)" do
|
89
|
+
'<body><font size="3">ほげほげ</font></body>'.
|
90
|
+
should be_converted_to '<div><span style="font-size:small;">ほげほげ</span></div>'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should convert font(size=4) to span and inline css(medium)" do
|
94
|
+
'<body><font size="4">ほげほげ</font></body>'.
|
95
|
+
should be_converted_to '<div><span style="font-size:medium;">ほげほげ</span></div>'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should convert font(size=5) to span and inline css(large)" do
|
99
|
+
'<body><font size="5">ほげほげ</font></body>'.
|
100
|
+
should be_converted_to '<div><span style="font-size:large;">ほげほげ</span></div>'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should convert font(size=6) to span and inline css(x-large)" do
|
104
|
+
'<body><font size="6">ほげほげ</font></body>'.
|
105
|
+
should be_converted_to '<div><span style="font-size:x-large;">ほげほげ</span></div>'
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should convert font(size=7) to span and inline css(xx-large)" do
|
109
|
+
'<body><font size="7">ほげほげ</font></body>'.
|
110
|
+
should be_converted_to '<div><span style="font-size:xx-large;">ほげほげ</span></div>'
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should convert font of invalid size to span and inline css(x-small)" do
|
114
|
+
'<body><font size="10">ほげほげ</font></body>'.
|
115
|
+
should be_converted_to '<div><span style="font-size:x-small;">ほげほげ</span></div>'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#convert_align_to_css" do
|
120
|
+
context "when align is left" do
|
121
|
+
it "should convert legacy attribute to inline css" do
|
122
|
+
'<body><div align="left">ほげほげ</div></body>'.
|
123
|
+
should be_converted_to '<div><div style="text-align:left;">ほげほげ</div></div>'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when align is right" do
|
128
|
+
it "should convert legacy attribute to inline css" do
|
129
|
+
'<body><div align="right">ほげほげ</div></body>'.
|
130
|
+
should be_converted_to '<div><div style="text-align:right;">ほげほげ</div></div>'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "when align is center" do
|
135
|
+
it "should convert legacy attribute to inline css" do
|
136
|
+
'<body><div align="center">ほげほげ</div></body>'.
|
137
|
+
should be_converted_to '<div><div style="text-align:center;">ほげほげ</div></div>'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#convert_blink_to_css" do
|
143
|
+
it "should convert blink to span and inline css" do
|
144
|
+
'<body><blink>ほげほげ</blink></body>'.
|
145
|
+
should be_converted_to '<div><span style="text-decoration:blink;">ほげほげ</span></div>'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "#convert_marquee_to_css" do
|
150
|
+
context "when behavior is scroll" do
|
151
|
+
it "should convert marquee to div and inline css" do
|
152
|
+
'<body><marquee behavior="scroll">ほげほげ</marquee></body>'.
|
153
|
+
should be_converted_to '<div><div style="display:-wap-marquee;-wap-marquee-loop:infinite;">ほげほげ</div></div>'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when behavior is alternate" do
|
158
|
+
it "should convert marquee to div and inline css" do
|
159
|
+
'<body><marquee behavior="alternate">ほげほげ</marquee></body>'.
|
160
|
+
should be_converted_to '<div><div style="display:-wap-marquee;-wap-marquee-style:alternate;-wap-marquee-loop:infinite;">ほげほげ</div></div>'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "without attribute" do
|
165
|
+
it "should convert marquee to div and inline css" do
|
166
|
+
'<body><marquee>ほげほげ</marquee></body>'.
|
167
|
+
should be_converted_to '<div><div style="display:-wap-marquee;-wap-marquee-loop:infinite;">ほげほげ</div></div>'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -14,8 +14,15 @@ describe DecorationMail::Image do
|
|
14
14
|
subject { @image }
|
15
15
|
|
16
16
|
it { should respond_to :path }
|
17
|
-
|
17
|
+
it("have the same content with attached file"){ subject.read.should eql @mail.attachments.first.decoded }
|
18
18
|
its(:content_id) { should eql "cid:01@110207.142735@______F03B@docomo.ne.jp" }
|
19
19
|
its(:filename) { should eql "06_gochisou_header.gif" }
|
20
20
|
its(:extension) { should eql "gif" }
|
21
|
+
its(:src) { should eql "06_gochisou_header.gif" }
|
22
|
+
|
23
|
+
context "when path is given" do
|
24
|
+
before { @image.path = 'http://example.com/image.gif' }
|
25
|
+
|
26
|
+
its(:src) { should eql 'http://example.com/image.gif' }
|
27
|
+
end
|
21
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,3 +8,20 @@ Bundler.setup
|
|
8
8
|
Bundler.require
|
9
9
|
|
10
10
|
require File.expand_path('../../lib/decoration_mail', __FILE__)
|
11
|
+
|
12
|
+
RSpec::Matchers.define :be_converted_to do |expected|
|
13
|
+
match do |actual|
|
14
|
+
convert(actual) == expected
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_for_should do
|
18
|
+
<<-MESSAGE
|
19
|
+
expected #{expected}
|
20
|
+
got #{convert(actual)}
|
21
|
+
MESSAGE
|
22
|
+
end
|
23
|
+
|
24
|
+
def convert(str)
|
25
|
+
DecorationMail::HTML.new(str).to_s
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,101 +1,123 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: decoration_mail
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 4
|
9
|
-
version: 0.2.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Dai Akatsuka
|
8
|
+
- M.Shibuya
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: mail
|
22
|
-
requirement:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
segments:
|
28
|
-
- 2
|
29
|
-
- 2
|
30
|
-
- 9
|
31
|
-
version: 2.2.9
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.2'
|
32
21
|
type: :runtime
|
33
22
|
prerelease: false
|
34
|
-
version_requirements:
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
version: 0.8.3
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: nokogiri
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
47
35
|
type: :runtime
|
48
36
|
prerelease: false
|
49
|
-
version_requirements:
|
50
|
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.3'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.3'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
51
71
|
name: rspec
|
52
|
-
requirement:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 2
|
59
|
-
- 0
|
60
|
-
version: "2.0"
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
61
77
|
type: :development
|
62
78
|
prerelease: false
|
63
|
-
version_requirements:
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: debugger
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
74
91
|
type: :development
|
75
92
|
prerelease: false
|
76
|
-
version_requirements:
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
77
98
|
description: Decoration Mail Parser
|
78
|
-
email:
|
99
|
+
email:
|
100
|
+
- d.akatsuka@gmail.com
|
101
|
+
- mit.shibuya@gmail.com
|
79
102
|
executables: []
|
80
|
-
|
81
103
|
extensions: []
|
82
|
-
|
83
|
-
|
84
|
-
-
|
85
|
-
files:
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- .gitignore
|
86
107
|
- Gemfile
|
87
|
-
-
|
88
|
-
- MIT-LICENSE
|
108
|
+
- LICENSE.txt
|
89
109
|
- README.rdoc
|
90
110
|
- Rakefile
|
91
|
-
- VERSION
|
92
111
|
- decoration_mail.gemspec
|
93
|
-
- init.rb
|
94
112
|
- lib/decoration_mail.rb
|
95
113
|
- lib/decoration_mail/base.rb
|
96
|
-
- lib/decoration_mail/
|
114
|
+
- lib/decoration_mail/html.rb
|
97
115
|
- lib/decoration_mail/image.rb
|
98
116
|
- lib/decoration_mail/message.rb
|
117
|
+
- lib/decoration_mail/version.rb
|
118
|
+
- spec/decoration_mail/base_spec.rb
|
119
|
+
- spec/decoration_mail/html_spec.rb
|
120
|
+
- spec/decoration_mail/image_spec.rb
|
99
121
|
- spec/resources/au_decoration.eml
|
100
122
|
- spec/resources/au_decoration_with_attachment.eml
|
101
123
|
- spec/resources/docomo_decoration.eml
|
@@ -104,43 +126,39 @@ files:
|
|
104
126
|
- spec/resources/softbank_decoration.eml
|
105
127
|
- spec/resources/softbank_decoration_with_attachment.eml
|
106
128
|
- spec/spec_helper.rb
|
107
|
-
- spec/unit/base_spec.rb
|
108
|
-
- spec/unit/converter_spec.rb
|
109
|
-
- spec/unit/image_spec.rb
|
110
|
-
has_rdoc: true
|
111
129
|
homepage: https://github.com/dakatsuka/decoration_mail
|
112
|
-
licenses:
|
113
|
-
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
114
133
|
post_install_message:
|
115
134
|
rdoc_options: []
|
116
|
-
|
117
|
-
require_paths:
|
135
|
+
require_paths:
|
118
136
|
- lib
|
119
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
requirements:
|
130
|
-
- - ">="
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
segments:
|
133
|
-
- 0
|
134
|
-
version: "0"
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
135
147
|
requirements: []
|
136
|
-
|
137
148
|
rubyforge_project:
|
138
|
-
rubygems_version:
|
149
|
+
rubygems_version: 2.2.2
|
139
150
|
signing_key:
|
140
|
-
specification_version:
|
151
|
+
specification_version: 4
|
141
152
|
summary: Decoration Mail Parser
|
142
|
-
test_files:
|
153
|
+
test_files:
|
154
|
+
- spec/decoration_mail/base_spec.rb
|
155
|
+
- spec/decoration_mail/html_spec.rb
|
156
|
+
- spec/decoration_mail/image_spec.rb
|
157
|
+
- spec/resources/au_decoration.eml
|
158
|
+
- spec/resources/au_decoration_with_attachment.eml
|
159
|
+
- spec/resources/docomo_decoration.eml
|
160
|
+
- spec/resources/docomo_decoration_with_attachment.eml
|
161
|
+
- spec/resources/other_decoration.eml
|
162
|
+
- spec/resources/softbank_decoration.eml
|
163
|
+
- spec/resources/softbank_decoration_with_attachment.eml
|
143
164
|
- spec/spec_helper.rb
|
144
|
-
- spec/unit/base_spec.rb
|
145
|
-
- spec/unit/converter_spec.rb
|
146
|
-
- spec/unit/image_spec.rb
|
data/Gemfile.lock
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (3.0.3)
|
5
|
-
diff-lcs (1.1.2)
|
6
|
-
git (1.2.5)
|
7
|
-
hpricot (0.8.3)
|
8
|
-
i18n (0.5.0)
|
9
|
-
jeweler (1.5.2)
|
10
|
-
bundler (~> 1.0.0)
|
11
|
-
git (>= 1.2.5)
|
12
|
-
rake
|
13
|
-
mail (2.2.15)
|
14
|
-
activesupport (>= 2.3.6)
|
15
|
-
i18n (>= 0.4.0)
|
16
|
-
mime-types (~> 1.16)
|
17
|
-
treetop (~> 1.4.8)
|
18
|
-
mime-types (1.16)
|
19
|
-
polyglot (0.3.1)
|
20
|
-
rake (0.8.7)
|
21
|
-
rspec (2.5.0)
|
22
|
-
rspec-core (~> 2.5.0)
|
23
|
-
rspec-expectations (~> 2.5.0)
|
24
|
-
rspec-mocks (~> 2.5.0)
|
25
|
-
rspec-core (2.5.0)
|
26
|
-
rspec-expectations (2.5.0)
|
27
|
-
diff-lcs (~> 1.1.2)
|
28
|
-
rspec-mocks (2.5.0)
|
29
|
-
treetop (1.4.9)
|
30
|
-
polyglot (>= 0.3.1)
|
31
|
-
|
32
|
-
PLATFORMS
|
33
|
-
ruby
|
34
|
-
|
35
|
-
DEPENDENCIES
|
36
|
-
hpricot (>= 0.8.3)
|
37
|
-
jeweler
|
38
|
-
mail (>= 2.2.9)
|
39
|
-
rspec (>= 2.0)
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.4
|
data/init.rb
DELETED
data/spec/unit/converter_spec.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
3
|
-
|
4
|
-
|
5
|
-
describe DecorationMail::Converter do
|
6
|
-
describe "body tag" do
|
7
|
-
it "should convert body to div" do
|
8
|
-
html = Hpricot.parse('<body>ほげほげ</body>')
|
9
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
10
|
-
result.should eql '<div>ほげほげ</div>'
|
11
|
-
end
|
12
|
-
|
13
|
-
context "with bgcolor" do
|
14
|
-
it "should convert body to div and inline css" do
|
15
|
-
html = Hpricot.parse('<body bgcolor="#ffffff">ほげほげ</body>')
|
16
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
17
|
-
result.should eql '<div style="background-color:#ffffff;">ほげほげ</div>'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "font tag" do
|
23
|
-
context "color" do
|
24
|
-
it "should convert font to span and inline css" do
|
25
|
-
html = Hpricot.parse('<font color="#ffffff">ほげほげ</font>')
|
26
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
27
|
-
result.should eql '<span style="color:#ffffff;">ほげほげ</span>'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "size = 1" do
|
32
|
-
it "should convert font to span and inline css (xx-small)" do
|
33
|
-
html = Hpricot.parse('<font size="1">ほげほげ</font>')
|
34
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
35
|
-
result.should eql '<span style="font-size:xx-small;">ほげほげ</span>'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "size = 2" do
|
40
|
-
it "should convert font to span and inline css (x-small)" do
|
41
|
-
html = Hpricot.parse('<font size="2">ほげほげ</font>')
|
42
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
43
|
-
result.should eql '<span style="font-size:x-small;">ほげほげ</span>'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "size = 3" do
|
48
|
-
it "should convert font to span and inline css (small)" do
|
49
|
-
html = Hpricot.parse('<font size="3">ほげほげ</font>')
|
50
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
51
|
-
result.should eql '<span style="font-size:small;">ほげほげ</span>'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "size = 4" do
|
56
|
-
it "should convert font to span and inline css (medium)" do
|
57
|
-
html = Hpricot.parse('<font size="4">ほげほげ</font>')
|
58
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
59
|
-
result.should eql '<span style="font-size:medium;">ほげほげ</span>'
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "size = 5" do
|
64
|
-
it "should convert font to span and inline css (large)" do
|
65
|
-
html = Hpricot.parse('<font size="5">ほげほげ</font>')
|
66
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
67
|
-
result.should eql '<span style="font-size:large;">ほげほげ</span>'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "size = 6" do
|
72
|
-
it "should convert font to span and inline css (x-large)" do
|
73
|
-
html = Hpricot.parse('<font size="6">ほげほげ</font>')
|
74
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
75
|
-
result.should eql '<span style="font-size:x-large;">ほげほげ</span>'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "size = 7" do
|
80
|
-
it "should convert font to span and inline css (xx-large)" do
|
81
|
-
html = Hpricot.parse('<font size="7">ほげほげ</font>')
|
82
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
83
|
-
result.should eql '<span style="font-size:xx-large;">ほげほげ</span>'
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "size = 10 (invalid value)" do
|
88
|
-
it "should convert font to span and inline css (x-small)" do
|
89
|
-
html = Hpricot.parse('<font size="10">ほげほげ</font>')
|
90
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
91
|
-
result.should eql '<span style="font-size:x-small;">ほげほげ</span>'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "div tag" do
|
97
|
-
context "align = left" do
|
98
|
-
it "should convert legacy attribute to inline css" do
|
99
|
-
html = Hpricot.parse('<div align="left">ほげほげ</div>')
|
100
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
101
|
-
result.should eql '<div style="text-align:left;">ほげほげ</div>'
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "align = right" do
|
106
|
-
it "should convert legacy attribute to inline css" do
|
107
|
-
html = Hpricot.parse('<div align="right">ほげほげ</div>')
|
108
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
109
|
-
result.should eql '<div style="text-align:right;">ほげほげ</div>'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "align = center" do
|
114
|
-
it "should convert legacy attribute to inline css" do
|
115
|
-
html = Hpricot.parse('<div align="center">ほげほげ</div>')
|
116
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
117
|
-
result.should eql '<div style="text-align:center;">ほげほげ</div>'
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "blink tag" do
|
123
|
-
it "should convert blink to span and inline css" do
|
124
|
-
html = Hpricot.parse('<blink>ほげほげ</blink>')
|
125
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
126
|
-
result.should eql '<span style="text-decoration:blink;">ほげほげ</span>'
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "marquee tag" do
|
131
|
-
context "behavior = scroll" do
|
132
|
-
it "should convert marquee to div and inline css" do
|
133
|
-
html = Hpricot.parse('<marquee behavior="scroll">ほげほげ</marquee>')
|
134
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
135
|
-
result.should eql '<div style="display:-wap-marquee;-wap-marquee-loop:infinite;">ほげほげ</div>'
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context "behavior = alternate" do
|
140
|
-
it "should convert marquee to div and inline css" do
|
141
|
-
html = Hpricot.parse('<marquee behavior="alternate">ほげほげ</marquee>')
|
142
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
143
|
-
result.should eql '<div style="display:-wap-marquee;-wap-marquee-style:alternate;-wap-marquee-loop:infinite;">ほげほげ</div>'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context "without attribute" do
|
148
|
-
it "should convert marquee to div and inline css" do
|
149
|
-
html = Hpricot.parse('<marquee>ほげほげ</marquee>')
|
150
|
-
result = DecorationMail::Converter.convert_to_xhtml(html).to_html
|
151
|
-
result.should eql '<div style="display:-wap-marquee;-wap-marquee-loop:infinite;">ほげほげ</div>'
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|