jitterbug 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,8 @@
1
1
  # Jitterbug: A just-in-time image creator for pretty text headers
2
2
 
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.
3
+ [Jitterbug](http://github.com/flyingsaucer/jitterbug) is a gem that provides on-demand graphical text headers using the font of your choice. Use wherever large collections of rich text headers are necessary especially useful in i18n projects.
4
+
5
+ On the initial request, Jitterbug creates the specified header graphic and returns its image or header tag. On subsequent requests it references the already-created graphic and returns the requested valid xhtml tag.
4
6
 
5
7
  ## Usage
6
8
 
@@ -40,6 +42,10 @@ Install the gem:
40
42
 
41
43
  sudo gem install jitterbug
42
44
 
45
+ Drop any fonts into your project's font directory (by default `/lib/fonts`).
46
+
47
+ ### Rails:
48
+
43
49
  In your `config/environment.rb` file:
44
50
 
45
51
  Rails::Initializer.run do |config|
@@ -56,8 +62,28 @@ In your `app\controllers\application_controller.rb` file:
56
62
  ...
57
63
  end
58
64
 
59
- Drop any fonts into your project's font directory (by default `/lib/fonts`).
65
+ ### Sinatra:
66
+
67
+ Thanks to [audionerd](http://github.com/audionerd) for making Jitterbug work with Sinatra.
68
+
69
+ require 'sinatra'
70
+ require 'jitterbug'
60
71
 
72
+ Jitterbug::Config.root = File.dirname(__FILE__)
73
+ Jitterbug::Config.env = Sinatra::Application::environment.to_s
74
+
75
+ helpers do
76
+ include Jitterbug
77
+ end
78
+
79
+ `Jitterbug::Config.root` is the root path, which should include folders like `public/`, `lib/` and `config/`.
80
+
81
+ `Jitterbug::Config.env` is the a string representing the current environment (e.g.: `"development"` or `"production"`).
82
+
83
+ ### Merb, Ramaze, others...
84
+
85
+ Any takers?
86
+
61
87
  ## Available Options
62
88
 
63
89
  `:background` Background color for the generated header image (default `transparent`)
@@ -76,6 +102,8 @@ Drop any fonts into your project's font directory (by default `/lib/fonts`).
76
102
 
77
103
  `:img_path` Image path for generated header images (default `/content/jitterbug/`)
78
104
 
105
+ `:kerning` Kerning value to apply to the generated header's text (default `0`)
106
+
79
107
  `:size` Font size for the generated header image (default `16`)
80
108
 
81
109
  `:style` Any additional inline styles to include in the generated tag
@@ -113,26 +141,9 @@ And relies on an external stylesheet like the following:
113
141
  text-indent: -9999px;
114
142
  }
115
143
 
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
144
  ## Global Configuration
134
145
 
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.
146
+ You can optionally define a 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.
136
147
 
137
148
  development: &defaults
138
149
  background: transparent
@@ -141,11 +152,21 @@ Define your global configuration in `config/jitterbug.yml`. The following sample
141
152
  font_dir: /lib/fonts/
142
153
  format: png
143
154
  img_path: /content/jitterbug/
144
- size: 16
155
+ size: 24
145
156
 
146
157
  test:
147
158
  <<: *defaults
148
159
  img_path: /tmp/jitterbug/
149
160
 
150
161
  production:
151
- <<: *defaults
162
+ <<: *defaults
163
+
164
+ ## Dependencies
165
+
166
+ Jitterbug uses [Imagemagick](http://www.imagemagick.org/script/index.php) 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.
167
+
168
+ ## Compatibility and Font Types
169
+
170
+ Jitterbug has been tested on OSX and Linux.
171
+
172
+ 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. Note that you should remove any spaces from your font filenames.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.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.4.0"
8
+ s.version = "0.5.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}
12
+ s.date = %q{2009-11-17}
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 = [
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/jitterbug/config.rb",
29
29
  "lib/jitterbug/css.rb",
30
30
  "lib/jitterbug/fonts.rb",
31
+ "lib/jitterbug/html.rb",
31
32
  "spec/jitterbug_spec.rb",
32
33
  "spec/spec.opts",
33
34
  "spec/spec_helper.rb"
@@ -1,18 +1,20 @@
1
1
  module Jitterbug
2
2
  module Config
3
-
3
+
4
4
  @@settings = { :background => 'transparent',
5
5
  :color => 'black',
6
6
  :font => '*',
7
7
  :font_dir => '/lib/fonts/',
8
8
  :format => 'png',
9
+ :kerning => 0,
9
10
  :img_path => '/content/jitterbug/',
10
- :size => 16 }
11
+ :size => 24 }
11
12
 
12
- def self.read
13
- config = "#{RAILS_ROOT}/config/jitterbug.yml"
13
+ def self.read
14
+ # TODO add :leading setting which requires >ImageMagick 6.5.5-8 to use -interline-spacing option
15
+ config = "#{Jitterbug::Config.root}/config/jitterbug.yml"
14
16
  if File.exist?(config)
15
- YAML.load_file(config)[RAILS_ENV].each {|key, value| @@settings[key.to_sym] = value}
17
+ YAML.load_file(config)[Jitterbug::Config.env].each {|key, value| @@settings[key.to_sym] = value}
16
18
  end
17
19
  end
18
20
 
@@ -20,5 +22,22 @@ module Jitterbug
20
22
  @@settings
21
23
  end
22
24
 
25
+ # accessor methods, with defaults for Rails
26
+ def self.root
27
+ @@root ||= RAILS_ROOT
28
+ end
29
+
30
+ def self.root=(value)
31
+ @@root = value
32
+ end
33
+
34
+ def self.env
35
+ @@environment ||= RAILS_ENV
36
+ end
37
+
38
+ def self.env=(value)
39
+ @@environment = value
40
+ end
41
+
23
42
  end
24
43
  end
@@ -2,7 +2,7 @@ module Jitterbug
2
2
  module Fonts
3
3
 
4
4
  def self.find(_path, _font)
5
- path = "#{RAILS_ROOT}/#{_path}/*#{_font}*".gsub('//', '/')
5
+ path = "#{Jitterbug::Config.root}/#{_path}/*#{_font}*".gsub('//', '/')
6
6
  font = Dir.glob(path)
7
7
  case font.size
8
8
  when 0: raise "*** Jitterbug Error: Font '#{_font}' could not be found in #{_path}"
@@ -0,0 +1,15 @@
1
+ module Jitterbug
2
+ module Html
3
+
4
+ def self.img(src, opts = {})
5
+ tag(:img, nil, opts.merge(:src => src))
6
+ end
7
+
8
+ def self.tag(type, content, opts = {})
9
+ attrs = opts.collect { |key, val| val.blank? ? nil : "#{key}=\"#{val}\"" }.compact.join(' ')
10
+ base = (attrs.present? ? "<#{type} #{attrs}" : "<#{type}")
11
+ base << (content ? ">#{content}</#{type}>" : " />")
12
+ end
13
+
14
+ end
15
+ end
data/lib/jitterbug.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'jitterbug/config'
2
- require 'jitterbug/css'
3
- require 'jitterbug/fonts'
4
1
  require 'md5'
2
+ %w(config css fonts html).each do |conf|
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'jitterbug', conf))
4
+ end
5
5
 
6
6
  module Jitterbug
7
7
 
@@ -11,23 +11,26 @@ module Jitterbug
11
11
 
12
12
  def jitterbug(label = '<jitterbug>', options = {})
13
13
  options = Jitterbug::Config.settings.merge(options)
14
+ root = Jitterbug::Config.root
14
15
  hash = MD5.new("#{label}#{options.sort {|a, b| a[0].to_s <=> b[0].to_s}.to_s}")
15
- path = "#{RAILS_ROOT}/public/#{options[:img_path]}/#{hash}.#{options[:format]}".gsub('//', '/')
16
+ path = "#{root}/public/#{options[:img_path]}/#{hash}.#{options[:format]}".gsub('//', '/')
16
17
  unless File.exist?(path)
17
18
  caption = options[:width] ? "-size #{options[:width]}x caption:'#{label}'" : "label:'#{label}'"
18
- `mkdir -p #{"#{RAILS_ROOT}/public/#{options[:img_path]}".gsub('//', '/')}`
19
+ `mkdir -p #{"#{root}/public/#{options[:img_path]}".gsub('//', '/')}`
19
20
  `convert -background #{options[:background]} -fill "#{options[:color]}" \
20
21
  -font #{Jitterbug::Fonts.find(options[:font_dir], options[:font])} \
21
- -pointsize #{options[:size]} -blur 0x.3 #{caption} #{path}`
22
+ -kerning #{options[:kerning]} -pointsize #{options[:size]} -blur 0x.3 \
23
+ #{caption} #{path}`
22
24
  end
23
25
  img_src = "/#{options[:img_path]}/#{hash}.#{options[:format]}".gsub('//', '/')
24
26
  img_class = (['jitterbug'] << options[:class]).compact.join(' ')
27
+
25
28
  if options[:tag]
26
- content_tag(options[:tag], label, :class => img_class, :style => Jitterbug::Css.tag(img_src, options))
29
+ Jitterbug::Html.tag(options[:tag], label, :class => img_class, :style => Jitterbug::Css.tag(img_src, options))
27
30
  elsif options[:fat]
28
- content_tag(options[:fat], label, :class => img_class, :style => Jitterbug::Css.fat(img_src, options))
31
+ Jitterbug::Html.tag(options[:fat], label, :class => img_class, :style => Jitterbug::Css.fat(img_src, options))
29
32
  else
30
- image_tag(img_src, :alt => label, :class => img_class)
33
+ Jitterbug::Html.img(img_src, :alt => label, :class => img_class, :style => options[:style])
31
34
  end
32
35
  end
33
36
 
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.0
4
+ version: 0.5.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-12 00:00:00 -08:00
13
+ date: 2009-11-17 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -44,6 +44,7 @@ files:
44
44
  - lib/jitterbug/config.rb
45
45
  - lib/jitterbug/css.rb
46
46
  - lib/jitterbug/fonts.rb
47
+ - lib/jitterbug/html.rb
47
48
  - spec/jitterbug_spec.rb
48
49
  - spec/spec.opts
49
50
  - spec/spec_helper.rb