jitterbug 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +113 -12
- data/VERSION +1 -1
- data/jitterbug.gemspec +3 -2
- data/lib/jitterbug/config.rb +1 -1
- data/lib/jitterbug/css.rb +15 -0
- data/lib/jitterbug/fonts.rb +1 -1
- data/lib/jitterbug.rb +9 -2
- metadata +3 -2
data/README.markdown
CHANGED
@@ -1,46 +1,147 @@
|
|
1
1
|
# Jitterbug: A just-in-time image creator for pretty text headers
|
2
2
|
|
3
|
-
Jitterbug provides on-demand text
|
3
|
+
Jitterbug provides on-demand graphical text headers using the font of your choice. On the first request, Jitterbug creates the requested header graphic and returns its image tag. On subsequent requests it returns the image tag of the already-created graphic.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
+
jitterbug(label, options = {})
|
8
|
+
|
7
9
|
Pass the `jitterbug` helper a string to convert into a header graphic. Optionally pass in any other parameters that differ from the defaults.
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
<%= jitterbug(t('whole_enchilada'), :background => '#fff', :color => 'green', :font => 'Yummy.otf', :font_dir => '/fonts/', :format => 'gif', :img_path => '/images/headers/', :size => 64, :width => 240) %>
|
11
|
+
jitterbug 'Hello World'
|
12
|
+
=> <img alt="Hello World" class="jitterbug" src="/content/jitterbug/72a65768cdccea18870b0cb2bdff4703.png?1258050948" />
|
12
13
|
|
13
|
-
|
14
|
+
![Hello World](http://a51.flying-saucer.net/jitterbug/72a65768cdccea18870b0cb2bdff4703.png)
|
14
15
|
|
15
|
-
|
16
|
+
jitterbug t('hello_world')
|
17
|
+
=> <img alt="¡Hola, mundo!" class="jitterbug" src="/content/jitterbug/3a395edcea566b56ed20f6c7b96aeec9.png?1258050948" />
|
16
18
|
|
17
|
-
|
19
|
+
![¡Hola, mundo!](http://a51.flying-saucer.net/jitterbug/3a395edcea566b56ed20f6c7b96aeec9.png)
|
20
|
+
|
21
|
+
jitterbug 'Hello Big World', :size => 72
|
22
|
+
=> <img alt="Hello Big World" class="jitterbug" src="/content/jitterbug/2dd5f6f98139fcdf3e671eca84671baf.png?1258050948" />
|
23
|
+
|
24
|
+
![Hello Big World](http://a51.flying-saucer.net/jitterbug/2dd5f6f98139fcdf3e671eca84671baf.png)
|
25
|
+
|
26
|
+
jitterbug 'Well hello, World, how do you do?', :tag => :h1, :width => 240, :style => 'height: 110px;'
|
27
|
+
=> <h1 class="jitterbug" style="background-image:url(/content/jitterbug/e0eb0490fcf15de125eaca6cbdffee12.png);height: 110px;">Well hello, World, how do you do?</h1>
|
18
28
|
|
19
|
-
|
20
|
-
|
29
|
+
|
30
|
+
![Well hello, World, how do you do?](http://a51.flying-saucer.net/jitterbug/e0eb0490fcf15de125eaca6cbdffee12.png)
|
31
|
+
|
32
|
+
jitterbug 'Hello_World.gif', :fat => :h2, :format => :gif, :color => '#FFCC00', :background => 'black'
|
33
|
+
=> <h2 class="jitterbug" style="display:block;text-indent:-9999px;margin:0;padding:0;background:url(/content/jitterbug/11686362655ca2fb3235b23a6d6c2621.gif)no-repeat;height:36px;">Hello_World.gif</h2>
|
34
|
+
|
35
|
+
![Hello_World.gif](http://a51.flying-saucer.net/jitterbug/11686362655ca2fb3235b23a6d6c2621.gif)
|
21
36
|
|
22
37
|
## Installation
|
23
38
|
|
39
|
+
Install the gem:
|
40
|
+
|
24
41
|
sudo gem install jitterbug
|
25
42
|
|
26
43
|
In your `config/environment.rb` file:
|
27
44
|
|
28
45
|
Rails::Initializer.run do |config|
|
46
|
+
...
|
29
47
|
config.gem "jitterbug", :source => 'http://gemcutter.org/'
|
48
|
+
...
|
30
49
|
end
|
31
50
|
|
32
|
-
|
51
|
+
In your `app\controllers\application_controller.rb` file:
|
52
|
+
|
53
|
+
class ApplicationController < ActionController::Base
|
54
|
+
...
|
55
|
+
helper Jitterbug
|
56
|
+
...
|
57
|
+
end
|
58
|
+
|
59
|
+
Drop any fonts into your project's font directory (by default `/lib/fonts`).
|
60
|
+
|
61
|
+
## Available Options
|
62
|
+
|
63
|
+
`:background` Background color for the generated header image (default `transparent`)
|
64
|
+
|
65
|
+
`:class` Any additional classes to include in the generated tag (default `jitterbug`)
|
66
|
+
|
67
|
+
`:color` Font color for the generated header image (default `black`)
|
68
|
+
|
69
|
+
`:fat` Return the specified tag (eg. `:fat => :h1`) with full inline styles to hide a text label and show the graphic instead (see the next section)
|
70
|
+
|
71
|
+
`:font_dir` Directory where fonts reside (default `/lib/fonts/`)
|
72
|
+
|
73
|
+
`:font` Font to use in the generated header image (default `*`, ie. first font found in the font directory)
|
74
|
+
|
75
|
+
`:format` Format to output the generated header image (default `png`)
|
76
|
+
|
77
|
+
`:img_path` Image path for generated header images (default `/content/jitterbug/`)
|
78
|
+
|
79
|
+
`:size` Font size for the generated header image (default `16`)
|
80
|
+
|
81
|
+
`:style` Any additional inline styles to include in the generated tag
|
82
|
+
|
83
|
+
`:tag` Return the specified tag (eg. `:tag => :h1`) with only the `background-image` declared inline (see the next section)
|
84
|
+
|
85
|
+
`:width` Maximum width for the generated header image (text will wrap to a new line to stay within the specified width)
|
86
|
+
|
87
|
+
## Using the `:fat` and `:tag` Options
|
88
|
+
|
89
|
+
Jitterbug provides two easy ways to display a header graphic within HTML header tags. The first and simplest is by passing `:fat => :h1` in with the options (replacing `:h1` with whatever tag you need). For example:
|
90
|
+
|
91
|
+
<%= jitterbug 'Hello World', :size => 64, :fat => :h2 %>
|
92
|
+
|
93
|
+
generates the following HTML with all the necessary styles defined inline:
|
94
|
+
|
95
|
+
<h2 class="jitterbug" style="display:block;text-indent:-9999px;margin:0;padding:0;background:url(/content/jitterbug/a034939a8aaccd59354207b4fdff120b.png)no-repeat;height:64px;">Hello World</h2>
|
96
|
+
|
97
|
+
The alternative option is `:tag => :h1`:
|
98
|
+
|
99
|
+
<%= jitterbug 'Hello World', :tag => :h1, :width => 240 %>
|
100
|
+
|
101
|
+
Which generates a leaner tag:
|
102
|
+
|
103
|
+
<h1 class="jitterbug" style="background-image:url(/content/jitterbug/37cf820f2f6b018f6f4d486517ac8d20.png);">Hello World</h1>
|
104
|
+
|
105
|
+
And relies on an external stylesheet like the following:
|
106
|
+
|
107
|
+
h1.jitterbug {
|
108
|
+
background-repeat: no-repeat;
|
109
|
+
display: block;
|
110
|
+
height: 64px;
|
111
|
+
margin: 0;
|
112
|
+
padding: 0;
|
113
|
+
text-indent: -9999px;
|
114
|
+
}
|
115
|
+
|
116
|
+
## Dependencies
|
117
|
+
|
118
|
+
Jitterbug uses `Imagemagick` to build the header images. It needs to be installed on your development and production machines, as do any fonts that you're using. The default location for fonts is `/lib/fonts` in your project.
|
119
|
+
|
120
|
+
Jitterbug's currently Rails-centric, with these Rails dependencies: `RAILS_ROOT`, `content_tag`, `image_tag`. These aren't completely necessary, but we haven't had a need to remove them yet.
|
121
|
+
|
122
|
+
## Compatibility and Font Types
|
123
|
+
|
124
|
+
Jitterbug has been tested on OSX and Linux.
|
125
|
+
|
126
|
+
The following font formats have successfully passed through the Jitterbug: OpenType (PostScript flavored), OpenType (TrueType flavored), PostScript (Type1), TrueType (Mac), and TrueType (PC). When processing Postscript fonts, Jitterbug (or rather Imagemagick) only uses the font outline file. Please rename any fonts with spaces in their filename.
|
127
|
+
|
128
|
+
## Quick Links
|
129
|
+
|
130
|
+
* [github.com/flyingsaucer/jitterbug](http://github.com/flyingsaucer/jitterbug)
|
131
|
+
* [imagemagick.org](http://www.imagemagick.org/script/index.php)
|
132
|
+
|
133
|
+
## Global Configuration
|
33
134
|
|
34
135
|
Define your global configuration in `config/jitterbug.yml`. The following sample contains Jitterbug's built in defaults. Note that the asterisk default for the font causes Jitterbug to use the first font that it finds in the font_dir folder.
|
35
136
|
|
36
137
|
development: &defaults
|
37
138
|
background: transparent
|
38
|
-
color:
|
139
|
+
color: black
|
39
140
|
font: *
|
40
141
|
font_dir: /lib/fonts/
|
41
142
|
format: png
|
42
143
|
img_path: /content/jitterbug/
|
43
|
-
size:
|
144
|
+
size: 16
|
44
145
|
|
45
146
|
test:
|
46
147
|
<<: *defaults
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/jitterbug.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jitterbug}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris Sessions", "Seth Engelhard"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-12}
|
13
13
|
s.description = %q{Jitterbug provides on-demand text header images using the font of your choice. On its first request, Jitterbug creates the requested header graphic. Then, and on subsequent requests, it returns an html image tag pointing to the header graphic file.}
|
14
14
|
s.email = %q{contact@flying-saucer.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"jitterbug.gemspec",
|
27
27
|
"lib/jitterbug.rb",
|
28
28
|
"lib/jitterbug/config.rb",
|
29
|
+
"lib/jitterbug/css.rb",
|
29
30
|
"lib/jitterbug/fonts.rb",
|
30
31
|
"spec/jitterbug_spec.rb",
|
31
32
|
"spec/spec.opts",
|
data/lib/jitterbug/config.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Jitterbug
|
2
|
+
module Css
|
3
|
+
|
4
|
+
def self.fat(src, opts)
|
5
|
+
css = "display:block;text-indent:-9999px;margin:0;padding:0;background:url(#{src})no-repeat;"
|
6
|
+
css += "height:#{opts[:size]}px;" if opts[:width].nil?
|
7
|
+
"#{css}#{opts[:style].to_s}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tag(src, opts)
|
11
|
+
"background-image:url(#{src});#{opts[:style].to_s}"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/jitterbug/fonts.rb
CHANGED
data/lib/jitterbug.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'jitterbug/config'
|
2
|
+
require 'jitterbug/css'
|
2
3
|
require 'jitterbug/fonts'
|
3
4
|
require 'md5'
|
4
5
|
|
@@ -8,7 +9,7 @@ module Jitterbug
|
|
8
9
|
Jitterbug::Config.read
|
9
10
|
end
|
10
11
|
|
11
|
-
def jitterbug(label = '<
|
12
|
+
def jitterbug(label = '<jitterbug>', options = {})
|
12
13
|
options = Jitterbug::Config.settings.merge(options)
|
13
14
|
hash = MD5.new("#{label}#{options.sort {|a, b| a[0].to_s <=> b[0].to_s}.to_s}")
|
14
15
|
path = "#{RAILS_ROOT}/public/#{options[:img_path]}/#{hash}.#{options[:format]}".gsub('//', '/')
|
@@ -21,7 +22,13 @@ module Jitterbug
|
|
21
22
|
end
|
22
23
|
img_src = "/#{options[:img_path]}/#{hash}.#{options[:format]}".gsub('//', '/')
|
23
24
|
img_class = (['jitterbug'] << options[:class]).compact.join(' ')
|
24
|
-
|
25
|
+
if options[:tag]
|
26
|
+
content_tag(options[:tag], label, :class => img_class, :style => Jitterbug::Css.tag(img_src, options))
|
27
|
+
elsif options[:fat]
|
28
|
+
content_tag(options[:fat], label, :class => img_class, :style => Jitterbug::Css.fat(img_src, options))
|
29
|
+
else
|
30
|
+
image_tag(img_src, :alt => label, :class => img_class)
|
31
|
+
end
|
25
32
|
end
|
26
33
|
|
27
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jitterbug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Sessions
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-11-
|
13
|
+
date: 2009-11-12 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- jitterbug.gemspec
|
43
43
|
- lib/jitterbug.rb
|
44
44
|
- lib/jitterbug/config.rb
|
45
|
+
- lib/jitterbug/css.rb
|
45
46
|
- lib/jitterbug/fonts.rb
|
46
47
|
- spec/jitterbug_spec.rb
|
47
48
|
- spec/spec.opts
|