magick_title 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +79 -12
- data/lib/magick_title/image.rb +38 -37
- data/lib/magick_title/options.rb +21 -6
- data/lib/magick_title/version.rb +1 -1
- data/test/bench/hash_to_attributes.rb +34 -0
- data/test/dummy/app.rb +1 -1
- data/test/dummy/fonts/Arvo-Regular.ttf +0 -0
- data/test/dummy/fonts/Lobster.ttf +0 -0
- data/test/dummy/fonts/Raleway-Thin.ttf +0 -0
- data/test/dummy/fonts/RockSalt.ttf +0 -0
- data/test/dummy/views/index.erb +31 -7
- data/test/test_image_title.rb +91 -5
- metadata +12 -6
- data/test/dummy/fonts/Cuprum.ttf +0 -0
- data/test/dummy/fonts/HelveticaNeueLTStd-UltLt.otf +0 -0
data/README.md
CHANGED
@@ -1,26 +1,67 @@
|
|
1
1
|
Magick Title
|
2
2
|
============
|
3
3
|
|
4
|
-
Want beautiful browser-compatible custom-smoothed & kerned fonts?
|
4
|
+
Want beautiful copyright-protected browser-compatible custom-smoothed & kerned fonts? MagickTitle delivers just that by using imagemagick to generate titles based on the options you provide.
|
5
5
|
|
6
|
-
** ----- under construction! ----- **
|
6
|
+
** ----- under construction, but getting closer! ----- **
|
7
7
|
|
8
|
+
|
8
9
|
Usage
|
9
10
|
-----
|
10
11
|
|
11
|
-
Using MagickTitle is easy
|
12
|
+
Using MagickTitle is easy. First, customize your global title styles by setting MagickTitle's default options while loading your app. If your using rails, it's best to do this in `config/initializers/magick_title.rb`.
|
13
|
+
|
14
|
+
# Here's the defaults
|
15
|
+
MagickTitle.options = {
|
16
|
+
:root => "./",
|
17
|
+
:font => "PermanentMarker.otf",
|
18
|
+
:font_path => Proc.new{ File.join MagickTitle.root, "fonts" },
|
19
|
+
:font_size => 50,
|
20
|
+
:destination => Proc.new{ File.join MagickTitle.root, "public/system/titles" },
|
21
|
+
:extension => "png",
|
22
|
+
:width => 800,
|
23
|
+
:height => nil,
|
24
|
+
:background_color => '#ffffff',
|
25
|
+
:background_alpha => '00',
|
26
|
+
:color => '#68962c',
|
27
|
+
:weight => 400,
|
28
|
+
:kerning => 0,
|
29
|
+
:command_path => nil,
|
30
|
+
:log_command => false,
|
31
|
+
:cache => true,
|
32
|
+
:to_html => {
|
33
|
+
:parent => {
|
34
|
+
:tag => "h1",
|
35
|
+
:class => "image-title"
|
36
|
+
},
|
37
|
+
:class => "magick-title"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
Set as few or as many options as you'd like. Your custom options will get merged into the defaults... You can also set individual options like this:
|
42
|
+
|
43
|
+
MagickTitle.options[:font] = 'Lobster.ttf'
|
44
|
+
|
45
|
+
|
46
|
+
Once you've set your options to your liking, just create a title like so:
|
12
47
|
|
13
48
|
MagickTitle.say("Hello!").to_html
|
14
49
|
|
15
|
-
|
16
|
-
|
50
|
+
#=> <h1 class="image-title"><img class="magick-title" alt="Hello!" src="/system/titles/hello_8e05f22657a3573d8fc6fa8115fecfc0812d82be.png"/></h1>
|
51
|
+
|
52
|
+
|
53
|
+
Place the image title in a div rather than an h1:
|
54
|
+
|
55
|
+
MagickTitle.say("Hello!").to_html("div")
|
56
|
+
|
57
|
+
#=> <div><img class="magick-title" alt="Hello!" src="/system/titles/hello_f76179c852bb2fa264b8ad2c0c9ceeb9f99dfc0b.png"/></div>
|
17
58
|
|
18
|
-
|
59
|
+
|
60
|
+
Or without the h1 tag:
|
19
61
|
|
20
62
|
MagickTitle.say("Hello!").to_html(false)
|
21
63
|
|
22
|
-
|
23
|
-
# <img src="/system/titles/hello.png" alt="Bienvenida al mundo de 28 Buenos Días " class="magick-title">
|
64
|
+
#=> <img class="magick-title" alt="Hello!" src="/system/titles/hello_f76179c852bb2fa264b8ad2c0c9ceeb9f99dfc0b.png"/>
|
24
65
|
|
25
66
|
|
26
67
|
To just get an instance of MagickTitle::Image:
|
@@ -31,15 +72,41 @@ To just get an instance of MagickTitle::Image:
|
|
31
72
|
puts title.url #=> "/system/titles/hello.png"
|
32
73
|
|
33
74
|
|
34
|
-
|
75
|
+
Or set some options on the fly:
|
76
|
+
|
77
|
+
MagickTitle.say("Hello!", :font_size => 24, :color => '#ff0000').to_html
|
78
|
+
|
79
|
+
#=> <h1 class="image-title"><img class="magick-title" alt="Hello!" src="/system/titles/hello_080fb04470589c55cd0e22c3229d2006baa05f7d.png"/></h1>
|
80
|
+
|
81
|
+
Note how the token is different than the previous 'Hello!' titles since we've set custom options.
|
82
|
+
|
83
|
+
|
84
|
+
The html helper can also be customized:
|
85
|
+
|
86
|
+
MagickTitle.say("Hello!").to_html(:class => "custom-title", :parent => { :tag => "h3", :id => "maaaagick" })
|
87
|
+
|
88
|
+
#=> <h3 id="maaaagick"><img class="custom-title" alt="Hello!" src="/system/titles/hello_f76179c852bb2fa264b8ad2c0c9ceeb9f99dfc0b.png"/></h3>
|
89
|
+
|
90
|
+
Combine no-parent with custom attributes:
|
91
|
+
|
92
|
+
MagickTitle.say("Hello!").to_html(:class => "custom-title", :parent => nil)
|
93
|
+
|
94
|
+
#=> <img class="custom-title" alt="Hello!" src="/system/titles/hello_f76179c852bb2fa264b8ad2c0c9ceeb9f99dfc0b.png"/>
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
## More to come!
|
100
|
+
|
35
101
|
|
36
102
|
|
37
103
|
To Do
|
38
104
|
-----
|
39
105
|
|
40
|
-
* Write tests
|
41
|
-
*
|
42
|
-
*
|
106
|
+
* Write more tests
|
107
|
+
* Smart option validation (:color => 'fff' converts to :color => '#fff' and :color => 'pink' fails)
|
108
|
+
* More documentation
|
109
|
+
* Auto ActiveRecord integration (`has_magick_title` class method)
|
43
110
|
* Clean up and publish demo app
|
44
111
|
|
45
112
|
|
data/lib/magick_title/image.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'digest/sha1'
|
1
2
|
require 'fileutils' unless defined?(FileUtils)
|
2
3
|
|
3
4
|
module MagickTitle
|
@@ -33,7 +34,7 @@ module MagickTitle
|
|
33
34
|
@text = text
|
34
35
|
return false unless valid?
|
35
36
|
@options = (@options || MagickTitle.options).merge(opts.symbolize_keys)
|
36
|
-
@filename = unique_filename(@text)
|
37
|
+
@filename = filename_from_options #unique_filename(@text)
|
37
38
|
@path = options.destination
|
38
39
|
@url = File.join((@path.match(/public(\/.*)/) || ['', './'])[1].to_s, @filename)
|
39
40
|
end
|
@@ -44,7 +45,7 @@ module MagickTitle
|
|
44
45
|
def save
|
45
46
|
return false unless valid?
|
46
47
|
FileUtils.mkdir_p(path)
|
47
|
-
run('convert', title_command_string)
|
48
|
+
run('convert', title_command_string(fullpath))
|
48
49
|
File.exists?(fullpath)
|
49
50
|
end
|
50
51
|
|
@@ -61,36 +62,28 @@ module MagickTitle
|
|
61
62
|
end
|
62
63
|
|
63
64
|
|
64
|
-
|
65
|
+
# Creates and HTML image tag with the options provided
|
65
66
|
def to_html(opts={})
|
66
67
|
opts = { :parent => nil } if opts === false
|
67
|
-
opts = {
|
68
|
-
|
69
|
-
:tag => "h1",
|
70
|
-
:class => "image-title"
|
71
|
-
},
|
72
|
-
:class => "magick-title",
|
73
|
-
:alt => text,
|
74
|
-
:src => url
|
75
|
-
}.merge(opts)
|
68
|
+
opts = { :parent => opts } if opts.is_a?(String)
|
69
|
+
opts = MagickTitle.options[:to_html].merge(:alt => text, :src => url).merge(opts)
|
76
70
|
parent = opts.delete(:parent)
|
77
|
-
|
78
|
-
tag = %(<img #{hash_to_attributes(opts)}/>)
|
71
|
+
tag = %(<img#{hash_to_attributes(opts)}/>)
|
79
72
|
if parent
|
80
|
-
ptag = parent.delete(:tag)
|
81
|
-
|
82
|
-
|
73
|
+
ptag = parent.is_a?(String) ? parent : parent.is_a?(Hash) ? parent.delete(:tag) : nil
|
74
|
+
ptag ||= "h1"
|
75
|
+
tag = %(<#{ptag}#{hash_to_attributes(parent)}>#{tag}</#{ptag}>)
|
76
|
+
end
|
83
77
|
tag
|
84
78
|
end
|
85
79
|
|
80
|
+
|
81
|
+
# Converts a hash to a string of html style key="value" pairs
|
86
82
|
def hash_to_attributes(hash)
|
87
|
-
attributes =
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
puts attributes.inspect
|
92
|
-
|
93
|
-
attributes
|
83
|
+
attributes = []
|
84
|
+
return "" unless hash.is_a?(Hash)
|
85
|
+
hash.each { |key, value| attributes << %(#{key}="#{value}") if value and 0 < value.length }
|
86
|
+
" " + attributes.join(" ").strip
|
94
87
|
end
|
95
88
|
|
96
89
|
|
@@ -103,7 +96,7 @@ module MagickTitle
|
|
103
96
|
end
|
104
97
|
|
105
98
|
# builds an imagemagick command based on the supplied options
|
106
|
-
def title_command_string
|
99
|
+
def title_command_string(file="")
|
107
100
|
%(
|
108
101
|
-trim
|
109
102
|
-antialias
|
@@ -115,10 +108,11 @@ module MagickTitle
|
|
115
108
|
-weight #{options.weight}
|
116
109
|
-kerning #{options.kerning}
|
117
110
|
caption:'#{@text}'
|
118
|
-
#{
|
111
|
+
#{file}
|
119
112
|
).gsub(/[\n\r\s]+/, ' ')
|
120
113
|
end
|
121
114
|
|
115
|
+
|
122
116
|
# Cleans and runs the supplied command
|
123
117
|
# (stolen from paperclip)
|
124
118
|
def run(cmd, params)
|
@@ -127,27 +121,33 @@ module MagickTitle
|
|
127
121
|
`#{command}`
|
128
122
|
end
|
129
123
|
|
124
|
+
|
130
125
|
# returns the `bin` path to the command
|
131
126
|
def path_for_command(command)
|
132
127
|
path = [options.command_path, command].compact
|
133
128
|
File.join(*path)
|
134
129
|
end
|
135
130
|
|
136
|
-
|
137
|
-
#
|
131
|
+
|
132
|
+
# Creates a filename token based on the title's options
|
133
|
+
def filename_from_options
|
134
|
+
digest = Digest::SHA1.hexdigest(title_command_string)
|
135
|
+
"#{unique_filename}_#{digest}.#{options.extension}"
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
# Truncates if necessary and converts the text to a useable filename
|
138
140
|
def fileize_text(text)
|
141
|
+
text = text[0..31] if 32 < text.length
|
139
142
|
file = text.to_s.downcase.gsub(/[^a-z0-9\s\-\_]/, '').strip.gsub(/[\s\-\_]+/, '_')
|
140
|
-
unless 0 < file.length
|
141
|
-
o = [('a'..'z'),('0'..'9')].map{|i| i.to_a}.flatten
|
142
|
-
file = (0..31).map{ o[rand(o.length)] }.join
|
143
|
-
end
|
144
143
|
file
|
145
144
|
end
|
146
145
|
|
147
146
|
|
148
|
-
|
149
|
-
|
150
|
-
|
147
|
+
|
148
|
+
# creates a unique filename for the title's text
|
149
|
+
def unique_filename
|
150
|
+
file = fileize_text(@text)
|
151
151
|
exists = exists_in_destination? file
|
152
152
|
dupe, count = nil, 0
|
153
153
|
while exists do
|
@@ -155,12 +155,13 @@ module MagickTitle
|
|
155
155
|
dupe = "#{file}_#{count}"
|
156
156
|
exists = exists_in_destination? dupe
|
157
157
|
end
|
158
|
-
|
158
|
+
dupe || file
|
159
159
|
end
|
160
160
|
|
161
|
+
|
161
162
|
# Checks if file exists in the destination option
|
162
163
|
def exists_in_destination?(file)
|
163
|
-
file
|
164
|
+
file = [file, options.extension].join(".") unless file.match(/\.[a-z]{3,4}$/)
|
164
165
|
File.exists?(File.join(options.destination, file))
|
165
166
|
end
|
166
167
|
|
data/lib/magick_title/options.rb
CHANGED
@@ -2,12 +2,14 @@ module MagickTitle
|
|
2
2
|
|
3
3
|
class Options < Hash
|
4
4
|
|
5
|
+
|
5
6
|
# Initializes the options hash with the defaults
|
6
7
|
def initialize
|
7
8
|
super
|
8
9
|
default!
|
9
10
|
end
|
10
11
|
|
12
|
+
|
11
13
|
# Clears current options and resets to the defaults
|
12
14
|
def default!
|
13
15
|
clear
|
@@ -15,17 +17,18 @@ module MagickTitle
|
|
15
17
|
merge! defaults
|
16
18
|
end
|
17
19
|
|
20
|
+
|
18
21
|
# A shortcut to [:root]
|
19
22
|
def root
|
20
23
|
@root ||= fetch(:root)
|
21
24
|
end
|
22
25
|
|
26
|
+
|
23
27
|
# The default options hash
|
24
28
|
def defaults
|
25
29
|
{
|
26
30
|
:root => "./",
|
27
|
-
:
|
28
|
-
:font => "HelveticaNeueLTStd-UltLt.otf",
|
31
|
+
:font => "PermanentMarker.ttf",
|
29
32
|
:font_path => Proc.new{ File.join MagickTitle.root, "fonts" },
|
30
33
|
:font_size => 50,
|
31
34
|
:destination => Proc.new{ File.join MagickTitle.root, "public/system/titles" },
|
@@ -39,10 +42,18 @@ module MagickTitle
|
|
39
42
|
:kerning => 0,
|
40
43
|
:command_path => nil,
|
41
44
|
:log_command => false,
|
42
|
-
:cache => true
|
45
|
+
:cache => true,
|
46
|
+
:to_html => {
|
47
|
+
:parent => {
|
48
|
+
:tag => "h1",
|
49
|
+
:class => "image-title"
|
50
|
+
},
|
51
|
+
:class => "magick-title"
|
52
|
+
}
|
43
53
|
}
|
44
54
|
end
|
45
55
|
|
56
|
+
|
46
57
|
# Sets and option and converts its key to a symbol
|
47
58
|
def []=(key, value)
|
48
59
|
key = key.to_sym
|
@@ -50,14 +61,18 @@ module MagickTitle
|
|
50
61
|
super(key, value)
|
51
62
|
end
|
52
63
|
|
64
|
+
|
53
65
|
# Turns the key into a symbol and returns the requested value
|
54
66
|
def [](key)
|
55
67
|
val = fetch key.to_sym
|
56
68
|
val.is_a?(Proc) ? val.call : val
|
57
69
|
end
|
58
|
-
|
59
|
-
|
60
|
-
#
|
70
|
+
|
71
|
+
|
72
|
+
# Retrieve a saved setting by dynamically looking up its value in the hash.
|
73
|
+
# Call the value if it's a Proc and return nil if the key's value doesn't exist.
|
74
|
+
#
|
75
|
+
# Options[:foo] = "bar"
|
61
76
|
# Options.foo #=> "bar"
|
62
77
|
# Options.fuz #=> method missing error
|
63
78
|
#
|
data/lib/magick_title/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
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
|
data/test/dummy/app.rb
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/dummy/views/index.erb
CHANGED
@@ -13,16 +13,15 @@
|
|
13
13
|
|
14
14
|
<form action="/" method="post">
|
15
15
|
<p>
|
16
|
-
<label for="text">Text:</label
|
17
|
-
<
|
16
|
+
<label for="text">Text:</label><br/>
|
17
|
+
<textarea name="text" id="name" rows="5" cols="50"><%= params[:text] %></textarea>
|
18
18
|
</p>
|
19
19
|
<p>
|
20
20
|
<label for="options_font">Font:</label>
|
21
21
|
<select name="options[font]" id="options_font">
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
<% Dir.entries(MagickTitle.options.font_path).reject!{|f| f.match(/\.+$/) }.each do |font| %>
|
23
|
+
<option value="<%= font %>"><%= font.gsub(/\.[a-z]{3}/, '') %></option>
|
24
|
+
<% end %>
|
26
25
|
</select>
|
27
26
|
</p>
|
28
27
|
|
@@ -31,8 +30,33 @@
|
|
31
30
|
<select name="options[color]" id="options_color">
|
32
31
|
<option value="#ff0000">Red</option>
|
33
32
|
<option value="#0000ff">Blue</option>
|
34
|
-
<option value="#000000">Black</option>
|
35
33
|
<option value="#00ff00">Green</option>
|
34
|
+
<option value="#000000">Black</option>
|
35
|
+
<option value="#aaaaaa">Gray</option>
|
36
|
+
</select>
|
37
|
+
</p>
|
38
|
+
|
39
|
+
<p>
|
40
|
+
<label for="options_font_size">Font Size:</label>
|
41
|
+
<select name="options[font_size]" id="options_font_size">
|
42
|
+
<option value="15">15</option>
|
43
|
+
<option value="25">25</option>
|
44
|
+
<option value="40" selected="selected">40</option>
|
45
|
+
<option value="100">100</option>
|
46
|
+
<option value="200">200</option>
|
47
|
+
</select>
|
48
|
+
</p>
|
49
|
+
|
50
|
+
<p>
|
51
|
+
<label for="options_kerning">Kerning:</label>
|
52
|
+
<select name="options[kerning]" id="options_kerning">
|
53
|
+
<option value="-10">-10</option>
|
54
|
+
<option value="-5">-5</option>
|
55
|
+
<option value="-2">-2</option>
|
56
|
+
<option value="0" selected="selected">0</option>
|
57
|
+
<option value="2">2</option>
|
58
|
+
<option value="5">5</option>
|
59
|
+
<option value="10">10</option>
|
36
60
|
</select>
|
37
61
|
</p>
|
38
62
|
|
data/test/test_image_title.rb
CHANGED
@@ -6,6 +6,18 @@ class TestImage < Test::Unit::TestCase
|
|
6
6
|
MagickTitle.options[:root] = File.expand_path("../dummy", __FILE__)
|
7
7
|
end
|
8
8
|
|
9
|
+
def assert_opening_tag(html, tag, inline=false)
|
10
|
+
assert html.match(Regexp.new("#{'^' unless inline}<#{tag}\s?")), "#{tag} opening tag"
|
11
|
+
end
|
12
|
+
|
13
|
+
def assert_closing_tag(html, tag, inline=false)
|
14
|
+
assert html.match(Regexp.new("</#{tag}>#{'$' unless inline}")), "#{tag} closing tag"
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_self_closing_tag(html)
|
18
|
+
assert html.match(/\/>$/), "Has self closing tag"
|
19
|
+
end
|
20
|
+
|
9
21
|
context "a valid title" do
|
10
22
|
|
11
23
|
setup do
|
@@ -14,15 +26,89 @@ class TestImage < Test::Unit::TestCase
|
|
14
26
|
|
15
27
|
should "return an image title" do
|
16
28
|
assert @title.is_a?(MagickTitle::Image)
|
29
|
+
assert @title.fullpath.match(/\.png$/)
|
17
30
|
assert File.exists?(@title.fullpath)
|
18
31
|
end
|
19
32
|
|
20
|
-
should "create an html img tag" do
|
21
|
-
|
22
|
-
assert
|
23
|
-
|
24
|
-
assert
|
33
|
+
should "create an html img tag without a parent element" do
|
34
|
+
html = @title.to_html(false)
|
35
|
+
assert html.is_a?(String)
|
36
|
+
assert_opening_tag html, 'img'
|
37
|
+
assert html.match("src=#{@title.url.inspect}"), "Sets src to url"
|
38
|
+
assert html.match("alt=#{@title.text.inspect}"), "Sets alt to text"
|
39
|
+
assert_self_closing_tag html
|
40
|
+
end
|
41
|
+
|
42
|
+
should "set the parent html container with a string" do
|
43
|
+
tag = "h3"
|
44
|
+
html = @title.to_html(tag)
|
45
|
+
assert_opening_tag html, tag
|
46
|
+
assert_closing_tag html, tag
|
47
|
+
end
|
48
|
+
|
49
|
+
should "defaults the parent html container" do
|
50
|
+
tag = "h1"
|
51
|
+
html = @title.to_html(:parent => { :id => "custom_id" })
|
52
|
+
assert_opening_tag html, tag
|
53
|
+
assert_opening_tag html, 'img', true #inline img tag
|
54
|
+
assert_closing_tag html, tag
|
55
|
+
end
|
56
|
+
|
57
|
+
should "use a different parent container" do
|
58
|
+
tag = "div"
|
59
|
+
html = @title.to_html(tag)
|
60
|
+
assert html.match(/<div></)
|
61
|
+
end
|
62
|
+
|
63
|
+
should "customize the parent html container" do
|
64
|
+
tag = "div"
|
65
|
+
html = @title.to_html(:parent => { :tag => tag, :id => "custom_id", :class => "some-class" })
|
66
|
+
assert_opening_tag html, tag
|
67
|
+
assert html.match(/id="custom_id"/)
|
68
|
+
assert html.match(/class="some-class"/)
|
69
|
+
assert_closing_tag html, tag
|
70
|
+
end
|
71
|
+
|
72
|
+
should "customize the image tag" do
|
73
|
+
html = @title.to_html(:id => "crazy-test-id", :class => "span-12 last", :alt => "Custom Alt Tags, Yo!", :parent => nil)
|
74
|
+
assert_opening_tag html, 'img'
|
75
|
+
assert html.match(/id="crazy-test-id"/)
|
76
|
+
assert html.match(/class="span-12\slast"/)
|
77
|
+
assert html.match(/alt="Custom\sAlt\sTags\,\sYo\!"/)
|
78
|
+
assert_self_closing_tag html
|
25
79
|
end
|
26
80
|
|
27
81
|
end
|
82
|
+
|
83
|
+
context "titles with the same text" do
|
84
|
+
|
85
|
+
setup do
|
86
|
+
@title1 = MagickTitle.say("hello!")
|
87
|
+
@title2 = MagickTitle.say("hello!", :color => '#000')
|
88
|
+
@title3 = MagickTitle.say("hello!", :color => '#000', :font_size => 16)
|
89
|
+
@title4 = MagickTitle.say("hello!", :size => 16)
|
90
|
+
@title5 = MagickTitle.say("HELLO!")
|
91
|
+
end
|
92
|
+
|
93
|
+
should "each have uniq filenames" do
|
94
|
+
assert @title1.filename != @title2.filename
|
95
|
+
assert @title2.filename != @title3.filename
|
96
|
+
assert @title3.filename != @title4.filename
|
97
|
+
assert @title4.filename != @title5.filename
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
context "a title with long text" do
|
103
|
+
|
104
|
+
setup do
|
105
|
+
@title = MagickTitle.say("Quisque commodo hendrerit lorem quis egestas. Maecenas quis tortor arcu. Vivamus rutrum nunc non neque consectetur quis placerat neque lobortis. Nam vestibulum, arcu sodales feugiat consectetur, nisl orci bibendum elit, eu euismod magna sapien ut nibh. Donec semper quam scelerisque tortor dictum gravida. In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien. Phasellus quis est sed turpis sollicitudin venenatis sed eu odio. Praesent eget neque eu eros interdum malesuada non vel leo. Sed fringilla porta ligula egestas tincidunt. Nullam risus magna, ornare vitae varius eget, scelerisque a libero. Morbi eu porttitor ipsum. Nullam lorem nisi, posuere quis volutpat eget, luctus nec massa. Pellentesque aliquam lacinia tellus sit amet bibendum. Ut posuere justo in enim pretium scelerisque. Etiam ornare vehicula euismod. Vestibulum at.")
|
106
|
+
end
|
107
|
+
|
108
|
+
should "truncate filename" do
|
109
|
+
assert @title.filename.length < 100
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
28
114
|
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.
|
5
|
+
version: 0.1.2
|
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-02-
|
13
|
+
date: 2011-02-25 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -66,11 +66,14 @@ files:
|
|
66
66
|
- lib/magick_title/options.rb
|
67
67
|
- lib/magick_title/version.rb
|
68
68
|
- magick_title.gemspec
|
69
|
+
- test/bench/hash_to_attributes.rb
|
69
70
|
- test/dummy/Gemfile
|
70
71
|
- test/dummy/app.rb
|
71
|
-
- test/dummy/fonts/
|
72
|
-
- test/dummy/fonts/
|
72
|
+
- test/dummy/fonts/Arvo-Regular.ttf
|
73
|
+
- test/dummy/fonts/Lobster.ttf
|
73
74
|
- test/dummy/fonts/PermanentMarker.ttf
|
75
|
+
- test/dummy/fonts/Raleway-Thin.ttf
|
76
|
+
- test/dummy/fonts/RockSalt.ttf
|
74
77
|
- test/dummy/public/styles.css
|
75
78
|
- test/dummy/views/index.erb
|
76
79
|
- test/dummy/views/layout.erb
|
@@ -106,11 +109,14 @@ signing_key:
|
|
106
109
|
specification_version: 3
|
107
110
|
summary: Converts text to an image using imagemagick.
|
108
111
|
test_files:
|
112
|
+
- test/bench/hash_to_attributes.rb
|
109
113
|
- test/dummy/Gemfile
|
110
114
|
- test/dummy/app.rb
|
111
|
-
- test/dummy/fonts/
|
112
|
-
- test/dummy/fonts/
|
115
|
+
- test/dummy/fonts/Arvo-Regular.ttf
|
116
|
+
- test/dummy/fonts/Lobster.ttf
|
113
117
|
- test/dummy/fonts/PermanentMarker.ttf
|
118
|
+
- test/dummy/fonts/Raleway-Thin.ttf
|
119
|
+
- test/dummy/fonts/RockSalt.ttf
|
114
120
|
- test/dummy/public/styles.css
|
115
121
|
- test/dummy/views/index.erb
|
116
122
|
- test/dummy/views/layout.erb
|
data/test/dummy/fonts/Cuprum.ttf
DELETED
Binary file
|
Binary file
|