magick_title 0.1.8 → 0.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -5
- data/lib/magick_title/image.rb +1 -19
- data/lib/magick_title/renderer.rb +36 -0
- data/lib/magick_title/version.rb +1 -1
- data/lib/magick_title.rb +1 -0
- data/test/dummy/fonts/custom/nested/Lobster.ttf +0 -0
- data/test/test_dsl.rb +1 -1
- data/test/test_image.rb +1 -1
- data/test/test_magick_title.rb +2 -2
- data/test/test_options.rb +18 -3
- data/test/{test_to_html.rb → test_renderer.rb} +21 -3
- metadata +10 -9
- data/test/bench/hash_to_attributes.rb +0 -34
data/README.md
CHANGED
@@ -3,8 +3,8 @@ Magick Title
|
|
3
3
|
|
4
4
|
Want beautiful copyright-protected browser-compatible custom-smoothed & kerned fonts? MagickTitle delivers just that by using [imagemagick](http://www.imagemagick.org/script/index.php) to generate titles based on the options you provide.
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
Want your titles to be automagically created for your Rails apps' models? Check out [has_magick_title](https://github.com/citrus/has_magick_title).
|
7
|
+
|
8
8
|
|
9
9
|
Requirements
|
10
10
|
------------
|
@@ -21,7 +21,7 @@ As usual, just use the `gem install` command:
|
|
21
21
|
|
22
22
|
Or add magick_title as a gem in your Gemfile:
|
23
23
|
|
24
|
-
gem 'magick_title', '>= 0.1.
|
24
|
+
gem 'magick_title', '>= 0.1.8'
|
25
25
|
|
26
26
|
Then run `bundle install`
|
27
27
|
|
@@ -163,9 +163,8 @@ To Do
|
|
163
163
|
* Write more tests
|
164
164
|
* Smart option validation (:color => 'fff' converts to :color => '#fff' and :color => 'pink' fails)
|
165
165
|
* More documentation
|
166
|
-
* Auto ActiveRecord integration (`has_magick_title` class method)
|
167
166
|
* Heroku support / tempfiles / base64
|
168
|
-
* Clean up and publish demo app
|
167
|
+
* Clean up and publish demo app (/test/dummy)
|
169
168
|
|
170
169
|
|
171
170
|
License
|
data/lib/magick_title/image.rb
CHANGED
@@ -137,15 +137,7 @@ module MagickTitle
|
|
137
137
|
def to_html(opts={})
|
138
138
|
opts = { :parent => nil } if opts === false
|
139
139
|
opts = { :parent => opts } if opts.is_a?(String)
|
140
|
-
|
141
|
-
parent = opts.delete(:parent)
|
142
|
-
tag = %(<img#{hash_to_attributes(opts)}/>)
|
143
|
-
if parent
|
144
|
-
ptag = parent.is_a?(String) ? parent : parent.is_a?(Hash) ? parent.delete(:tag) : nil
|
145
|
-
ptag ||= "h1"
|
146
|
-
tag = %(<#{ptag}#{hash_to_attributes(parent)}>#{tag}</#{ptag}>)
|
147
|
-
end
|
148
|
-
tag
|
140
|
+
Renderer.to_html(text, url, options[:to_html].merge(opts))
|
149
141
|
end
|
150
142
|
|
151
143
|
|
@@ -222,16 +214,6 @@ module MagickTitle
|
|
222
214
|
end
|
223
215
|
dupe || file
|
224
216
|
end
|
225
|
-
|
226
|
-
|
227
|
-
# Converts a hash to a string of html style key="value" pairs
|
228
|
-
def hash_to_attributes(hash)
|
229
|
-
attributes = []
|
230
|
-
return "" unless hash.is_a?(Hash)
|
231
|
-
hash.each { |key, value| attributes << %(#{key}="#{value}") if value and 0 < value.length }
|
232
|
-
return "" if attributes.length == 0
|
233
|
-
" " + attributes.join(" ").strip
|
234
|
-
end
|
235
217
|
|
236
218
|
end # Image
|
237
219
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module MagickTitle
|
2
|
+
|
3
|
+
module Renderer
|
4
|
+
|
5
|
+
extend self
|
6
|
+
|
7
|
+
# Creates and HTML image tag with the options provided
|
8
|
+
def to_html(text, url, opts={})
|
9
|
+
opts = { :parent => nil } if opts === false
|
10
|
+
opts = { :parent => opts } if opts.is_a?(String)
|
11
|
+
opts[:alt] ||= text
|
12
|
+
opts.merge!(:src => url)
|
13
|
+
parent = opts.delete(:parent)
|
14
|
+
tag = %(<img#{hash_to_attributes(opts)}/>)
|
15
|
+
if parent
|
16
|
+
ptag = parent.is_a?(String) ? parent : parent.is_a?(Hash) ? parent.delete(:tag) : nil
|
17
|
+
ptag ||= "h1"
|
18
|
+
tag = %(<#{ptag}#{hash_to_attributes(parent)}>#{tag}</#{ptag}>)
|
19
|
+
end
|
20
|
+
tag
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Converts a hash to a string of html style key="value" pairs
|
26
|
+
def hash_to_attributes(hash)
|
27
|
+
attributes = []
|
28
|
+
return "" unless hash.is_a?(Hash)
|
29
|
+
hash.each { |key, value| attributes << %(#{key}="#{value}") if value and 0 < value.length }
|
30
|
+
return "" if attributes.length == 0
|
31
|
+
" " + attributes.join(" ").strip
|
32
|
+
end
|
33
|
+
|
34
|
+
end # Renderer
|
35
|
+
|
36
|
+
end # MagickTitle
|
data/lib/magick_title/version.rb
CHANGED
data/lib/magick_title.rb
CHANGED
Binary file
|
data/test/test_dsl.rb
CHANGED
data/test/test_image.rb
CHANGED
data/test/test_magick_title.rb
CHANGED
@@ -15,9 +15,9 @@ class TestMagickTitle < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
should "not get cut off" do
|
17
17
|
|
18
|
-
@title = MagickTitle.say("HELLO MAGICK TITLE OF DOOM!", :
|
18
|
+
@title = MagickTitle.say("HELLO MAGICK TITLE OF DOOM!", :color => "#000000")
|
19
19
|
assert File.exists?(@title.fullpath)
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
end
|
23
|
+
end
|
data/test/test_options.rb
CHANGED
@@ -2,6 +2,14 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestOptions < Test::Unit::TestCase
|
4
4
|
|
5
|
+
def setup
|
6
|
+
@font_path = MagickTitle.options[:font_path]
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
MagickTitle.options[:font_path] = @font_path
|
11
|
+
end
|
12
|
+
|
5
13
|
should "raise error on invalid option" do
|
6
14
|
|
7
15
|
assert_raise(NoMethodError) do
|
@@ -9,9 +17,16 @@ class TestOptions < Test::Unit::TestCase
|
|
9
17
|
end
|
10
18
|
|
11
19
|
assert_raise(NoMethodError) do
|
12
|
-
MagickTitle.
|
20
|
+
MagickTitle.options[:size] = 56
|
13
21
|
end
|
14
22
|
|
15
23
|
end
|
16
|
-
|
17
|
-
|
24
|
+
|
25
|
+
should "use custom font path" do
|
26
|
+
MagickTitle.options[:font_path] = File.expand_path("../dummy/fonts/custom/nested", __FILE__)
|
27
|
+
assert File.exists?(File.join(MagickTitle.options[:font_path], "Lobster.ttf"))
|
28
|
+
@title = MagickTitle.say("Hello Magick Title with Custom font path!", :font => "Lobster.ttf")
|
29
|
+
assert File.exists?(@title.fullpath)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'helper'
|
5
5
|
|
6
|
-
class
|
6
|
+
class TestRenderer < Test::Unit::TestCase
|
7
7
|
|
8
8
|
def assert_opening_tag(html, tag, inline=false)
|
9
9
|
assert html.match(Regexp.new("#{'^' unless inline}<#{tag}\s?")), "#{tag} opening tag"
|
@@ -17,8 +17,25 @@ class TestToHtml < Test::Unit::TestCase
|
|
17
17
|
assert html.match(/\/>$/), "Has self closing tag"
|
18
18
|
end
|
19
19
|
|
20
|
+
context "the renderer by itself" do
|
20
21
|
|
21
|
-
|
22
|
+
should "create the most basic tag" do
|
23
|
+
tag = %(<img alt="Hello" src="test.jpg"/>)
|
24
|
+
html = MagickTitle::Renderer.to_html("Hello", "test.jpg", false)
|
25
|
+
assert_equal tag, html
|
26
|
+
end
|
27
|
+
|
28
|
+
should "create the most basic tag inside a parent" do
|
29
|
+
tag = %(<p><img alt="Hello" src="test.jpg"/></p>)
|
30
|
+
html = MagickTitle::Renderer.to_html("Hello", "test.jpg", "p")
|
31
|
+
assert_equal tag, html
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with an existing title" do
|
22
39
|
|
23
40
|
setup do
|
24
41
|
@title = MagickTitle::Image.create("hello mr. to_html!")
|
@@ -74,4 +91,5 @@ class TestToHtml < Test::Unit::TestCase
|
|
74
91
|
|
75
92
|
end
|
76
93
|
|
77
|
-
|
94
|
+
|
95
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magick_title
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.
|
4
|
+
prerelease: 6
|
5
|
+
version: 0.2.0.rc1
|
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-
|
13
|
+
date: 2011-05-24 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -53,9 +53,9 @@ files:
|
|
53
53
|
- lib/magick_title/hash.rb
|
54
54
|
- lib/magick_title/image.rb
|
55
55
|
- lib/magick_title/options.rb
|
56
|
+
- lib/magick_title/renderer.rb
|
56
57
|
- lib/magick_title/version.rb
|
57
58
|
- magick_title.gemspec
|
58
|
-
- test/bench/hash_to_attributes.rb
|
59
59
|
- test/dummy/.gitignore
|
60
60
|
- test/dummy/Gemfile
|
61
61
|
- test/dummy/app.rb
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- test/dummy/fonts/PermanentMarker.ttf
|
66
66
|
- test/dummy/fonts/Raleway-Thin.ttf
|
67
67
|
- test/dummy/fonts/RockSalt.ttf
|
68
|
+
- test/dummy/fonts/custom/nested/Lobster.ttf
|
68
69
|
- test/dummy/public/favicon.ico
|
69
70
|
- test/dummy/public/javascripts/jquery-1.5.1.min.js
|
70
71
|
- test/dummy/public/javascripts/jquery-ui-1.8.10.custom.min.js
|
@@ -92,7 +93,7 @@ files:
|
|
92
93
|
- test/test_image.rb
|
93
94
|
- test/test_magick_title.rb
|
94
95
|
- test/test_options.rb
|
95
|
-
- test/
|
96
|
+
- test/test_renderer.rb
|
96
97
|
has_rdoc: true
|
97
98
|
homepage: https://github.com/citrus/magick_title
|
98
99
|
licenses: []
|
@@ -111,9 +112,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
113
|
none: false
|
113
114
|
requirements:
|
114
|
-
- - "
|
115
|
+
- - ">"
|
115
116
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
117
|
+
version: 1.3.1
|
117
118
|
requirements: []
|
118
119
|
|
119
120
|
rubyforge_project: magick_title
|
@@ -122,7 +123,6 @@ signing_key:
|
|
122
123
|
specification_version: 3
|
123
124
|
summary: Converts text to an image using imagemagick.
|
124
125
|
test_files:
|
125
|
-
- test/bench/hash_to_attributes.rb
|
126
126
|
- test/dummy/.gitignore
|
127
127
|
- test/dummy/Gemfile
|
128
128
|
- test/dummy/app.rb
|
@@ -132,6 +132,7 @@ test_files:
|
|
132
132
|
- test/dummy/fonts/PermanentMarker.ttf
|
133
133
|
- test/dummy/fonts/Raleway-Thin.ttf
|
134
134
|
- test/dummy/fonts/RockSalt.ttf
|
135
|
+
- test/dummy/fonts/custom/nested/Lobster.ttf
|
135
136
|
- test/dummy/public/favicon.ico
|
136
137
|
- test/dummy/public/javascripts/jquery-1.5.1.min.js
|
137
138
|
- test/dummy/public/javascripts/jquery-ui-1.8.10.custom.min.js
|
@@ -159,4 +160,4 @@ test_files:
|
|
159
160
|
- test/test_image.rb
|
160
161
|
- test/test_magick_title.rb
|
161
162
|
- test/test_options.rb
|
162
|
-
- test/
|
163
|
+
- test/test_renderer.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
|
3
|
-
puts "Benchmark Hash to Attribtes"
|
4
|
-
puts " string vs array"
|
5
|
-
puts "-" * 50
|
6
|
-
|
7
|
-
# Converts a hash to a string of html style key="value" pairs
|
8
|
-
def hash_to_attributes_using_string(hash)
|
9
|
-
attributes = ""
|
10
|
-
return attributes unless hash.is_a?(Hash)
|
11
|
-
hash.each { |key, value| attributes << key.to_s << "=\"" << value.strip << "\" " if value and 0 < value.length }
|
12
|
-
attributes.strip
|
13
|
-
end
|
14
|
-
|
15
|
-
def hash_to_attributes_using_array(hash)
|
16
|
-
attributes = []
|
17
|
-
return attributes unless hash.is_a?(Hash)
|
18
|
-
hash.each { |key, value| attributes << %(#{key}="#{value.strip}") if value and 0 < value.length }
|
19
|
-
attributes.join(" ")
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
@hash = { :id => "some-html-id", :class => "a-css-class-that-is-long ", :href => "http://google.com ", :title => "Visit Google!", :rel => "that-related-thing" }
|
24
|
-
|
25
|
-
using_string = hash_to_attributes_using_string(@hash)
|
26
|
-
using_array = hash_to_attributes_using_array(@hash)
|
27
|
-
|
28
|
-
raise "Strings don't match!" unless using_string == using_array
|
29
|
-
|
30
|
-
n = 999999999999999999999
|
31
|
-
Benchmark.bm do |x|
|
32
|
-
x.report { hash_to_attributes_using_string(@hash) }
|
33
|
-
x.report { hash_to_attributes_using_array(@hash) }
|
34
|
-
end
|