decoration_mail 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ # coding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ ENV['BUNDLER_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
7
+ Bundler.setup
8
+ Bundler.require
9
+
10
+ require File.expand_path('../../lib/decoration_mail', __FILE__)
@@ -0,0 +1,72 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../../spec_helper', __FILE__)
3
+
4
+ describe DecorationMail::Base do
5
+ before {
6
+ @mail = Mail.read(File.expand_path('../../resources/docomo_decoration_with_attachment.eml', __FILE__))
7
+ @deco = @mail.decoration
8
+ }
9
+
10
+ subject { @deco }
11
+
12
+ it { should have(7).images }
13
+
14
+ context "using save method" do
15
+ it "ブロック付きで呼び出すべき" do
16
+ lambda { subject.save }.should raise_error(ArgumentError)
17
+ end
18
+
19
+ it "ブロック変数はDecorationMail::Imageのインスタンスであるべき" do
20
+ images = []
21
+ subject.save do |image|
22
+ images << image
23
+ end
24
+ images.first.should be_instance_of DecorationMail::Image
25
+ end
26
+
27
+ it "HTMLが返るべき" do
28
+ html = subject.save do |image|
29
+ end
30
+ Hpricot.parse(html).search("div").should_not be_empty
31
+ end
32
+
33
+ it "HTMLにはHTMLタグが含まれない" do
34
+ html = subject.save do |image|
35
+ end
36
+ Hpricot.parse(html).search("html").should be_empty
37
+ end
38
+
39
+ it "HTMLにはHEADタグが含まれない" do
40
+ html = subject.save do |image|
41
+ end
42
+ Hpricot.parse(html).search("head").should be_empty
43
+ end
44
+
45
+ it "HTMLにはBODYタグが含まれない" do
46
+ html = subject.save do |image|
47
+ end
48
+ Hpricot.parse(html).search("body").should be_empty
49
+ end
50
+
51
+ it "ブロック変数にパスを渡すとIMGタグのSRCが書き換わるべき" do
52
+ html = subject.save do |image|
53
+ image.path = "http://exmaple.com"
54
+ end
55
+ html.should match /http:\/\/exmaple\.com/
56
+ end
57
+
58
+ it "other_imagesオプションで:topを指定すると添付画像をデコメ上部に貼り付ける" do
59
+ html = subject.save(:other_images => :top) do |image|
60
+ image.path = "other_image.jpg" unless image.content_id
61
+ end
62
+ html.should match /other_image\.jpg/
63
+ end
64
+
65
+ it "other_imagesオプションで:bottomを指定すると添付画像をデコメ上部に貼り付ける" do
66
+ html = subject.save(:other_images => :bottom) do |image|
67
+ image.path = "other_image.jpg" unless image.content_id
68
+ end
69
+ html.should match /other_image\.jpg/
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,155 @@
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
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decoration_mail
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Dai Akatsuka
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-08 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mail
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 2
30
+ - 9
31
+ version: 2.2.9
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: hpricot
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 8
45
+ - 3
46
+ version: 0.8.3
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 2
59
+ - 0
60
+ version: "2.0"
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: jeweler
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: *id004
77
+ description: Decoration Mail Parser
78
+ email: d.akatsuka@gmail.com
79
+ executables: []
80
+
81
+ extensions: []
82
+
83
+ extra_rdoc_files:
84
+ - README.rdoc
85
+ files:
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - MIT-LICENSE
89
+ - README.rdoc
90
+ - Rakefile
91
+ - VERSION
92
+ - decoration_mail.gemspec
93
+ - init.rb
94
+ - lib/decoration_mail.rb
95
+ - lib/decoration_mail/base.rb
96
+ - lib/decoration_mail/converter.rb
97
+ - lib/decoration_mail/image.rb
98
+ - lib/decoration_mail/message.rb
99
+ - spec/resources/au_decoration.eml
100
+ - spec/resources/au_decoration_with_attachment.eml
101
+ - spec/resources/docomo_decoration.eml
102
+ - spec/resources/docomo_decoration_with_attachment.eml
103
+ - spec/resources/softbank_decoration.eml
104
+ - spec/resources/softbank_decoration_with_attachment.eml
105
+ - spec/spec_helper.rb
106
+ - spec/unit/base_spec.rb
107
+ - spec/unit/converter_spec.rb
108
+ has_rdoc: true
109
+ homepage: https://github.com/dakatsuka/decoration_mail
110
+ licenses: []
111
+
112
+ post_install_message:
113
+ rdoc_options: []
114
+
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ requirements: []
134
+
135
+ rubyforge_project:
136
+ rubygems_version: 1.3.7
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Decoration Mail Parser
140
+ test_files:
141
+ - spec/spec_helper.rb
142
+ - spec/unit/base_spec.rb
143
+ - spec/unit/converter_spec.rb