magick_title 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.md +55 -27
  2. data/lib/magick_title.rb +14 -0
  3. data/lib/magick_title/hash.rb +8 -0
  4. data/lib/magick_title/image.rb +55 -25
  5. data/lib/magick_title/options.rb +20 -6
  6. data/lib/magick_title/version.rb +1 -1
  7. data/magick_title.gemspec +0 -1
  8. data/test/dummy/Gemfile +1 -1
  9. data/test/dummy/app.rb +20 -7
  10. data/test/dummy/public/favicon.ico +0 -0
  11. data/test/dummy/public/javascripts/jquery-1.5.1.min.js +16 -0
  12. data/test/dummy/public/javascripts/jquery-ui-1.8.10.custom.min.js +83 -0
  13. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  14. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_0_eeeeee_40x100.png +0 -0
  15. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_55_994d53_40x100.png +0 -0
  16. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_55_fafafa_40x100.png +0 -0
  17. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_gloss-wave_30_3d3644_500x100.png +0 -0
  18. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_100_dcd9de_1x100.png +0 -0
  19. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_100_eae6ea_1x100.png +0 -0
  20. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_25_30273a_1x100.png +0 -0
  21. data/test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_45_5f5964_1x100.png +0 -0
  22. data/test/dummy/public/stylesheets/eggplant/images/ui-icons_454545_256x240.png +0 -0
  23. data/test/dummy/public/stylesheets/eggplant/images/ui-icons_734d99_256x240.png +0 -0
  24. data/test/dummy/public/stylesheets/eggplant/images/ui-icons_8d78a5_256x240.png +0 -0
  25. data/test/dummy/public/stylesheets/eggplant/images/ui-icons_a8a3ae_256x240.png +0 -0
  26. data/test/dummy/public/stylesheets/eggplant/images/ui-icons_ebccce_256x240.png +0 -0
  27. data/test/dummy/public/stylesheets/eggplant/images/ui-icons_ffffff_256x240.png +0 -0
  28. data/test/dummy/public/stylesheets/eggplant/jquery-ui-1.8.10.custom.css +318 -0
  29. data/test/dummy/public/stylesheets/styles.css +83 -0
  30. data/test/dummy/views/index.erb +216 -39
  31. data/test/dummy/views/layout.erb +3 -1
  32. data/test/helper.rb +7 -4
  33. data/test/test_dsl.rb +36 -0
  34. data/test/test_image.rb +58 -75
  35. data/test/test_magick_title.rb +9 -0
  36. data/test/test_options.rb +17 -0
  37. data/test/test_to_html.rb +77 -0
  38. metadata +50 -17
  39. data/test/dummy/public/styles.css +0 -31
@@ -2,7 +2,9 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Magick Title Demo</title>
5
- <link rel="stylesheet" type="text/css" href="styles.css" />
5
+ <link rel="stylesheet" type="text/css" href="stylesheets/styles.css" />
6
+ <script type="text/javascript" src="javascripts/jquery-1.5.1.min.js"></script>
7
+ <script type="text/javascript" src="javascripts/jquery-ui-1.8.10.custom.min.js"></script>
6
8
  </head>
7
9
  <body>
8
10
 
data/test/helper.rb CHANGED
@@ -1,18 +1,21 @@
1
1
  ENV["environment"] = "test"
2
2
 
3
- require 'test/unit'
3
+ require 'bundler/setup'
4
+ Bundler.require(:default, :test)
4
5
  require 'shoulda'
5
- require 'magick_title'
6
6
 
7
- #require 'rack/test'
8
- #require 'fileutils'
9
7
 
10
8
  class Test::Unit::TestCase
11
9
 
12
10
  def setup
13
11
  super
14
12
  MagickTitle.options[:root] = File.expand_path("../dummy", __FILE__)
13
+ MagickTitle.options[:log_command] = false
15
14
  FileUtils.rm_r MagickTitle.options.destination if Dir.exists?(MagickTitle.options.destination)
16
15
  end
16
+
17
+ def teardown
18
+ # nada
19
+ end
17
20
 
18
21
  end
data/test/test_dsl.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ class TestDsl < Test::Unit::TestCase
4
+
5
+ should "set font" do
6
+
7
+ MagickTitle.style :h1 do
8
+ font "PermanentMarker.ttf"
9
+ font_size 50
10
+ width 200
11
+ end
12
+
13
+ assert MagickTitle.styles.include?(:h1)
14
+ assert_equal 50, MagickTitle.styles[:h1][:font_size]
15
+ assert_equal 200, MagickTitle.styles[:h1][:width]
16
+
17
+ end
18
+
19
+
20
+ should "set font style 2" do
21
+
22
+ MagickTitle.style :h2 do
23
+ font "Lobster.ttf"
24
+ font_size 30
25
+ color "#cc0000"
26
+ to_html :parent => { :tag => "h2" }
27
+ end
28
+
29
+ assert MagickTitle.styles.include?(:h2)
30
+ assert_equal 30, MagickTitle.styles[:h2][:font_size]
31
+ assert_equal "#cc0000", MagickTitle.styles[:h2][:color]
32
+ assert_equal Hash, MagickTitle.styles[:h2][:to_html].class
33
+ assert_equal "h2", MagickTitle.styles[:h2][:to_html][:parent][:tag]
34
+ end
35
+
36
+ end
data/test/test_image.rb CHANGED
@@ -1,23 +1,24 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
1
4
  require 'helper'
2
5
 
3
6
  class TestImage < Test::Unit::TestCase
4
-
5
- def assert_opening_tag(html, tag, inline=false)
6
- assert html.match(Regexp.new("#{'^' unless inline}<#{tag}\s?")), "#{tag} opening tag"
7
- end
8
-
9
- def assert_closing_tag(html, tag, inline=false)
10
- assert html.match(Regexp.new("</#{tag}>#{'$' unless inline}")), "#{tag} closing tag"
11
- end
12
-
13
- def assert_self_closing_tag(html)
14
- assert html.match(/\/>$/), "Has self closing tag"
15
- end
16
7
 
17
8
  should "create an instance of MagickTitle::Image" do
18
9
  @title = MagickTitle::Image.create("created using class method")
19
10
  end
20
11
 
12
+ should "set a title's line-height" do
13
+ @title = MagickTitle::Image.create("Default\nLine\nHeight")
14
+ assert_equal 183, @title.identify[:height]
15
+
16
+ @title2 = MagickTitle::Image.create("Default\nLine\nHeight", :line_height => -25)
17
+ assert_equal 133, @title2.identify[:height]
18
+ end
19
+
20
+
21
+
21
22
  context "an invalid title" do
22
23
 
23
24
  setup do
@@ -43,6 +44,7 @@ class TestImage < Test::Unit::TestCase
43
44
  end
44
45
 
45
46
  end
47
+
46
48
 
47
49
  context "a valid title" do
48
50
 
@@ -62,23 +64,29 @@ class TestImage < Test::Unit::TestCase
62
64
  assert !File.exists?(@title.fullpath)
63
65
  end
64
66
 
65
- should "downcase the image tag text" do
66
- html = @title.to_html(:id => "crazy-test-id", :class => "span-12 last", :alt => "Custom Alt Tags, Yo!", :parent => nil)
67
- assert_opening_tag html, 'img'
68
- assert html.match(/id="crazy-test-id"/)
69
- assert html.match(/class="span-12\slast"/)
70
- assert html.match(/alt="Custom\sAlt\sTags\,\sYo\!"/)
71
- assert_self_closing_tag html
72
- end
73
-
74
67
  end
75
68
 
69
+
76
70
  context "an existing title" do
77
71
 
78
72
  setup do
79
73
  @title = MagickTitle::Image.create("hello!")
80
74
  end
81
75
 
76
+ should "return convert_command" do
77
+ assert @title.convert_command.match('echo "hello!" | convert')
78
+ assert @title.convert_command.match(/\.png$/)
79
+ end
80
+
81
+ should "identify its dimensions and size" do
82
+ hash = @title.identify
83
+ assert_equal Hash, hash.class
84
+ assert_equal 3, hash.values.length
85
+ assert_equal 155, hash[:width]
86
+ assert_equal 40, hash[:height]
87
+ assert_equal 3858, hash[:size]
88
+ end
89
+
82
90
  should "cache when asked to" do
83
91
  # make sure cache is turned ON
84
92
  assert @title.options.cache
@@ -112,56 +120,9 @@ class TestImage < Test::Unit::TestCase
112
120
  assert mod != mod2
113
121
  end
114
122
 
115
- should "create an html img tag without a parent element" do
116
- html = @title.to_html(false)
117
- assert html.is_a?(String)
118
- assert_opening_tag html, 'img'
119
- assert html.match("src=#{@title.url.inspect}"), "Sets src to url"
120
- assert html.match("alt=#{@title.text.inspect}"), "Sets alt to text"
121
- assert_self_closing_tag html
122
- end
123
-
124
- should "set the parent html container with a string" do
125
- tag = "h3"
126
- html = @title.to_html(tag)
127
- assert_opening_tag html, tag
128
- assert_closing_tag html, tag
129
- end
130
-
131
- should "defaults the parent html container" do
132
- tag = "h1"
133
- html = @title.to_html(:parent => { :id => "custom_id" })
134
- assert_opening_tag html, tag
135
- assert_opening_tag html, 'img', true #inline img tag
136
- assert_closing_tag html, tag
137
- end
138
-
139
- should "use a different parent container" do
140
- tag = "div"
141
- html = @title.to_html(tag)
142
- assert html.match(/<div></)
143
- end
144
-
145
- should "customize the parent html container" do
146
- tag = "div"
147
- html = @title.to_html(:parent => { :tag => tag, :id => "custom_id", :class => "some-class" })
148
- assert_opening_tag html, tag
149
- assert html.match(/id="custom_id"/)
150
- assert html.match(/class="some-class"/)
151
- assert_closing_tag html, tag
152
- end
153
-
154
- should "customize the image tag" do
155
- html = @title.to_html(:id => "crazy-test-id", :class => "span-12 last", :alt => "Custom Alt Tags, Yo!", :parent => nil)
156
- assert_opening_tag html, 'img'
157
- assert html.match(/id="crazy-test-id"/)
158
- assert html.match(/class="span-12\slast"/)
159
- assert html.match(/alt="Custom\sAlt\sTags\,\sYo\!"/)
160
- assert_self_closing_tag html
161
- end
162
-
163
123
  end
164
124
 
125
+
165
126
  context "titles with the same text" do
166
127
 
167
128
  setup do
@@ -173,7 +134,7 @@ class TestImage < Test::Unit::TestCase
173
134
  end
174
135
 
175
136
  should "each have uniq filenames" do
176
- assert @title1.filename != @title2.filename
137
+ assert @title1.filename != @title2.filename
177
138
  assert @title2.filename != @title3.filename
178
139
  assert @title3.filename != @title4.filename
179
140
  assert @title4.filename != @title5.filename
@@ -182,14 +143,11 @@ class TestImage < Test::Unit::TestCase
182
143
 
183
144
  end
184
145
 
185
-
186
146
 
187
- context "a long or short title" do
147
+ context "an unusual title" do
188
148
 
189
149
  should "allow one letter titles" do
190
150
  @title = MagickTitle::Image.create("a")
191
- assert @title.valid?
192
- assert @title.save
193
151
  end
194
152
 
195
153
  should "truncate filename when long" do
@@ -197,6 +155,31 @@ class TestImage < Test::Unit::TestCase
197
155
  assert @title.filename.length < 100
198
156
  end
199
157
 
200
- end
158
+ should "allow utf8 characters" do
159
+ @title = MagickTitle::Image.create("J'aime Café Chèvre et Crêpes")
160
+ end
201
161
 
162
+ should "allow single quotes" do
163
+ @title = MagickTitle::Image.create("It's pretty nifty")
164
+ end
165
+
166
+ should "allow double quotes" do
167
+ @title = MagickTitle::Image.create('Then he said; "Ruby rocks"')
168
+ end
169
+
170
+ should "allow mixed quotes" do
171
+ @title = MagickTitle::Image.create(%("Ruby rocks" - it's what she said))
172
+ end
173
+
174
+ should "allow escaped quotes" do
175
+ @title = MagickTitle::Image.create(%(he said, "\"Ruby rocks\" - it\'s what she said"))
176
+ end
177
+
178
+ teardown do
179
+ assert @title.valid?
180
+ assert @title.save
181
+ end
182
+
183
+ end
184
+
202
185
  end
@@ -11,4 +11,13 @@ class TestMagickTitle < Test::Unit::TestCase
11
11
 
12
12
  end
13
13
 
14
+
15
+
16
+ should "not get cut off" do
17
+
18
+ @title = MagickTitle.say("HELLO MAGICK TITLE OF DOOM!", :font_path => "/Users/Spencer/Library/Fonts", :font => "HelveticaNeueLTStd-UltLt.otf", :color => "#000000")
19
+ assert File.exists?(@title.fullpath)
20
+
21
+ end
22
+
14
23
  end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class TestOptions < Test::Unit::TestCase
4
+
5
+ should "raise error on invalid option" do
6
+
7
+ assert_raise(NoMethodError) do
8
+ MagickTitle.options = { :size => 56 }
9
+ end
10
+
11
+ assert_raise(NoMethodError) do
12
+ MagickTitle.option[:size] = 56
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,77 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require 'helper'
5
+
6
+ class TestToHtml < Test::Unit::TestCase
7
+
8
+ def assert_opening_tag(html, tag, inline=false)
9
+ assert html.match(Regexp.new("#{'^' unless inline}<#{tag}\s?")), "#{tag} opening tag"
10
+ end
11
+
12
+ def assert_closing_tag(html, tag, inline=false)
13
+ assert html.match(Regexp.new("</#{tag}>#{'$' unless inline}")), "#{tag} closing tag"
14
+ end
15
+
16
+ def assert_self_closing_tag(html)
17
+ assert html.match(/\/>$/), "Has self closing tag"
18
+ end
19
+
20
+
21
+ context "an existing title" do
22
+
23
+ setup do
24
+ @title = MagickTitle::Image.create("hello mr. to_html!")
25
+ end
26
+
27
+ should "create an html img tag without a parent element" do
28
+ html = @title.to_html(false)
29
+ assert html.is_a?(String)
30
+ assert_opening_tag html, 'img'
31
+ assert html.match("src=#{@title.url.inspect}"), "Sets src to url"
32
+ assert html.match("alt=#{@title.text.inspect}"), "Sets alt to text"
33
+ assert_self_closing_tag html
34
+ end
35
+
36
+ should "set the parent html container with a string" do
37
+ tag = "h3"
38
+ html = @title.to_html(tag)
39
+ assert_opening_tag html, tag
40
+ assert_closing_tag html, tag
41
+ end
42
+
43
+ should "defaults the parent html container" do
44
+ tag = "h1"
45
+ html = @title.to_html(:parent => { :id => "custom_id" })
46
+ assert_opening_tag html, tag
47
+ assert_opening_tag html, 'img', true #inline img tag
48
+ assert_closing_tag html, tag
49
+ end
50
+
51
+ should "use a different parent container" do
52
+ tag = "div"
53
+ html = @title.to_html(tag)
54
+ assert html.match(/<div></)
55
+ end
56
+
57
+ should "customize the parent html container" do
58
+ tag = "div"
59
+ html = @title.to_html(:parent => { :tag => tag, :id => "custom_id", :class => "some-class" })
60
+ assert_opening_tag html, tag
61
+ assert html.match(/id="custom_id"/)
62
+ assert html.match(/class="some-class"/)
63
+ assert_closing_tag html, tag
64
+ end
65
+
66
+ should "customize the image tag" do
67
+ html = @title.to_html(:id => "crazy-test-id", :class => "span-12 last", :alt => "Custom Alt Tags, Yo!", :parent => nil)
68
+ assert_opening_tag html, 'img'
69
+ assert html.match(/id="crazy-test-id"/)
70
+ assert html.match(/class="span-12\slast"/)
71
+ assert html.match(/alt="Custom\sAlt\sTags\,\sYo\!"/)
72
+ assert_self_closing_tag html
73
+ end
74
+
75
+ end
76
+
77
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: magick_title
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.7
5
+ version: 0.1.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Spencer Steffen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-24 00:00:00 -07:00
13
+ date: 2011-04-05 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -24,28 +24,17 @@ dependencies:
24
24
  version: 2.11.3
25
25
  type: :development
26
26
  version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rack-test
29
- prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
33
- - - "="
34
- - !ruby/object:Gem::Version
35
- version: 0.5.7
36
- type: :development
37
- version_requirements: *id002
38
27
  - !ruby/object:Gem::Dependency
39
28
  name: sinatra
40
29
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
30
+ requirement: &id002 !ruby/object:Gem::Requirement
42
31
  none: false
43
32
  requirements:
44
33
  - - "="
45
34
  - !ruby/object:Gem::Version
46
35
  version: 1.1.0
47
36
  type: :development
48
- version_requirements: *id003
37
+ version_requirements: *id002
49
38
  description: Want beautiful copyright-protected browser-compatible custom-smoothed & kerned fonts? Magick Title delivers just that by using imagemagick to generate titles based on the options you provide.
50
39
  email:
51
40
  - spencer@citrusme.com
@@ -76,12 +65,34 @@ files:
76
65
  - test/dummy/fonts/PermanentMarker.ttf
77
66
  - test/dummy/fonts/Raleway-Thin.ttf
78
67
  - test/dummy/fonts/RockSalt.ttf
79
- - test/dummy/public/styles.css
68
+ - test/dummy/public/favicon.ico
69
+ - test/dummy/public/javascripts/jquery-1.5.1.min.js
70
+ - test/dummy/public/javascripts/jquery-ui-1.8.10.custom.min.js
71
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_0_aaaaaa_40x100.png
72
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_0_eeeeee_40x100.png
73
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_55_994d53_40x100.png
74
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_55_fafafa_40x100.png
75
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_gloss-wave_30_3d3644_500x100.png
76
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_100_dcd9de_1x100.png
77
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_100_eae6ea_1x100.png
78
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_25_30273a_1x100.png
79
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_45_5f5964_1x100.png
80
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_454545_256x240.png
81
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_734d99_256x240.png
82
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_8d78a5_256x240.png
83
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_a8a3ae_256x240.png
84
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_ebccce_256x240.png
85
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_ffffff_256x240.png
86
+ - test/dummy/public/stylesheets/eggplant/jquery-ui-1.8.10.custom.css
87
+ - test/dummy/public/stylesheets/styles.css
80
88
  - test/dummy/views/index.erb
81
89
  - test/dummy/views/layout.erb
82
90
  - test/helper.rb
91
+ - test/test_dsl.rb
83
92
  - test/test_image.rb
84
93
  - test/test_magick_title.rb
94
+ - test/test_options.rb
95
+ - test/test_to_html.rb
85
96
  has_rdoc: true
86
97
  homepage: https://github.com/citrus/magick_title
87
98
  licenses: []
@@ -121,9 +132,31 @@ test_files:
121
132
  - test/dummy/fonts/PermanentMarker.ttf
122
133
  - test/dummy/fonts/Raleway-Thin.ttf
123
134
  - test/dummy/fonts/RockSalt.ttf
124
- - test/dummy/public/styles.css
135
+ - test/dummy/public/favicon.ico
136
+ - test/dummy/public/javascripts/jquery-1.5.1.min.js
137
+ - test/dummy/public/javascripts/jquery-ui-1.8.10.custom.min.js
138
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_0_aaaaaa_40x100.png
139
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_0_eeeeee_40x100.png
140
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_55_994d53_40x100.png
141
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_flat_55_fafafa_40x100.png
142
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_gloss-wave_30_3d3644_500x100.png
143
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_100_dcd9de_1x100.png
144
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_100_eae6ea_1x100.png
145
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_25_30273a_1x100.png
146
+ - test/dummy/public/stylesheets/eggplant/images/ui-bg_highlight-soft_45_5f5964_1x100.png
147
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_454545_256x240.png
148
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_734d99_256x240.png
149
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_8d78a5_256x240.png
150
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_a8a3ae_256x240.png
151
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_ebccce_256x240.png
152
+ - test/dummy/public/stylesheets/eggplant/images/ui-icons_ffffff_256x240.png
153
+ - test/dummy/public/stylesheets/eggplant/jquery-ui-1.8.10.custom.css
154
+ - test/dummy/public/stylesheets/styles.css
125
155
  - test/dummy/views/index.erb
126
156
  - test/dummy/views/layout.erb
127
157
  - test/helper.rb
158
+ - test/test_dsl.rb
128
159
  - test/test_image.rb
129
160
  - test/test_magick_title.rb
161
+ - test/test_options.rb
162
+ - test/test_to_html.rb