flurin-buttonize 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,13 +2,12 @@ Buttonize, your favourite button generator.
2
2
  ===========================================
3
3
 
4
4
  Buttonize is a little tool to generate sets of buttons by creating simple image templates (a left side, a repeatable middle
5
- and a right side). You can use buttonize do create sets of buttons and sets of button styles. See the examples directory
6
- for more information (examples/buttons.rb is a buttonset file and examples/default/styles.rb is a styleset file)
5
+ and a right side). You can use buttonize to create sets of buttons and sets of button styles. See the examples directory
6
+ for more information (examples/buttons.rb is a buttonset file and examples/default/styles.rb is a styleset file).
7
7
 
8
8
 
9
9
  Installing
10
10
  ============
11
-
12
11
  Buttonize has the following dependencies:
13
12
 
14
13
  * Ruby 1.8.x (not tested in 1.9.x)
@@ -23,17 +22,15 @@ sudo gem install flurin-buttonize --source=http://gems.github.com
23
22
 
24
23
  Quickstart
25
24
  ==========
25
+ For the impatient who just want to generate a blue button (and have all required stuff installed)
26
26
 
27
- For the impatient who just want to generate a blue button (and have all required stuff installed)!
28
-
29
- Run:
27
+ Run:
30
28
  buttonize button --style=big_blue "My first button"
31
29
 
32
- and open
30
+ Open:
33
31
  my_first_button.gif
34
32
 
35
33
 
36
34
  Copyright & license
37
35
  ===================
38
-
39
36
  Copyright (c) 2009 Flurin Egger, DigitPaint, MIT Style License. (see MIT-LICENSE)
@@ -0,0 +1,73 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "buttonize"
3
+ s.version = "0.1.1"
4
+ s.date = "2009-01-25"
5
+
6
+ s.authors = ["Flurin Egger"]
7
+ s.email = "f.p.egger@gmail.com"
8
+ s.summary = "A button generation tool for web applications."
9
+ s.homepage = "http://github.com/flurin/buttonize"
10
+
11
+ s.files = %w( bin/buttonize
12
+ buttonize.gemspec
13
+ examples/buttons.rb
14
+ examples/default/big_blue_left.gif
15
+ examples/default/big_blue_middle.gif
16
+ examples/default/big_blue_right.gif
17
+ examples/default/big_green_left.gif
18
+ examples/default/big_green_middle.gif
19
+ examples/default/big_green_right.gif
20
+ examples/default/big_orange_left.gif
21
+ examples/default/big_orange_middle.gif
22
+ examples/default/big_orange_right.gif
23
+ examples/default/big_red_left.gif
24
+ examples/default/big_red_middle.gif
25
+ examples/default/big_red_right.gif
26
+ examples/default/fonts/Bitstream Vera License.txt
27
+ examples/default/fonts/Vera-Bold-Italic.ttf
28
+ examples/default/fonts/Vera-Bold.ttf
29
+ examples/default/fonts/Vera-Italic.ttf
30
+ examples/default/fonts/Vera.ttf
31
+ examples/default/small_blue_left.gif
32
+ examples/default/small_blue_middle.gif
33
+ examples/default/small_blue_right.gif
34
+ examples/default/small_green_left.gif
35
+ examples/default/small_green_middle.gif
36
+ examples/default/small_green_right.gif
37
+ examples/default/small_orange_left.gif
38
+ examples/default/small_orange_middle.gif
39
+ examples/default/small_orange_right.gif
40
+ examples/default/small_red_left.gif
41
+ examples/default/small_red_middle.gif
42
+ examples/default/small_red_right.gif
43
+ examples/default/styles.rb
44
+ examples/default/table_blue_left.gif
45
+ examples/default/table_blue_middle.gif
46
+ examples/default/table_blue_right.gif
47
+ examples/default/table_green_left.gif
48
+ examples/default/table_green_middle.gif
49
+ examples/default/table_green_right.gif
50
+ examples/default/table_orange_left.gif
51
+ examples/default/table_orange_middle.gif
52
+ examples/default/table_orange_right.gif
53
+ examples/default/table_red_left.gif
54
+ examples/default/table_red_middle.gif
55
+ examples/default/table_red_right.gif
56
+ lib/buttonize/button.rb
57
+ lib/buttonize/button_set.rb
58
+ lib/buttonize/cli.rb
59
+ lib/buttonize/style_set.rb
60
+ lib/buttonize.rb
61
+ MIT-LICENSE
62
+ README
63
+ )
64
+
65
+ s.bindir = "bin"
66
+ s.executables << "buttonize"
67
+ s.require_paths = ["lib"]
68
+
69
+ s.has_rdoc = false
70
+
71
+ s.add_dependency "rmagick", [">= 2.5.1"]
72
+ s.add_dependency "wycats-thor", ["~> 0.9.8"]
73
+ end
@@ -1,18 +1,58 @@
1
1
  Buttonize::StyleSet.define(:template_path => File.dirname(__FILE__)) do |set|
2
+
3
+ # Style definition with a block
2
4
  set.style(:big_blue) do |s|
3
- s.font_size = 10
5
+ # The name of the template image files the images will be searched for
6
+ # in s.template_path and will be suffixed with "_left.gif", "_right.gif", "_middle.gif"
7
+ # (default = button)
4
8
  s.template_base = "big_blue"
5
- s.paddings = [20,20]
9
+
10
+ # Alternatively you can use template_images to specify the left/middle/right images
11
+ # with paths relative to the template_path.
12
+ # s.template_images = ["big_blue_left.gif","big_blue_middle.gif","big_blue_right.gif"]
13
+
14
+ # The font to use (can be all fonts RMagick can use), (default = Arial)
15
+ s.font = File.join(File.dirname(__FILE__),"fonts","Vera.ttf")
16
+ # Size of the font to use in pt (default = 9)
17
+ s.font_size = 10
18
+ # Antialias the font when rendering (default = true)
19
+ s.font_antialias = true
20
+
21
+ # The color of the textrendering, can be anything RMagick sees as
22
+ # a color. (default = #fff)
23
+ s.text_color = "#fff"
24
+ # The text alignment within the final button, can be any of
25
+ # :left, :right or :center (default = :center)
26
+ s.text_align = :center
27
+ # The x and y offset the text should be rendered with. This
28
+ # is in relation to the alignment set and can be used to finetune the optical
29
+ # text placement.
30
+ s.text_offset = {:x => 0, :y => 0}
31
+
32
+
33
+ # If width is set (not nil) Buttonize will try to create a button of
34
+ # the specified width, if the text will however not fit (including paddings)
35
+ # Buttonize falls back on rendering the text with the specified paddings (see below)
36
+ # (default = nil)
37
+ s.width = nil
38
+ # The padding to give the text to the left and right side of the button
39
+ # specified in an array of [left_padding,right_padding] in pixels. If width
40
+ # is set and the text width + padding fits into the width, these paddings
41
+ # will be ignored. (default = {:left => 10, :right => 10})
42
+ s.padding = {:left => 20, :right => 20}
43
+
6
44
  end
7
45
 
8
46
  set.style(:big_orange, :based_on => :big_blue, :template_base => "big_orange")
9
47
  set.style(:big_red, :based_on => :big_blue, :template_base => "big_red")
10
48
  set.style(:big_green, :based_on => :big_blue, :template_base => "big_green")
11
-
12
- set.style(:small_blue, :font_size => 9, :template_base => "small_blue", :width => 65)
49
+
50
+ # Inline style definition with a Hash
51
+ set.style(:small_blue, :font => File.join(File.dirname(__FILE__),"fonts","Vera.ttf"), :font_size => 9, :template_base => "small_blue", :width => 65)
13
52
  set.style(:small_orange, :based_on => :small_blue, :template_base => "small_orange")
14
53
  set.style(:small_red, :based_on => :small_blue, :template_base => "small_red")
15
54
  set.style(:small_green, :based_on => :small_blue, :template_base => "small_green")
55
+
16
56
  end
17
57
 
18
58
  # Styles = {
@@ -4,15 +4,17 @@ class Buttonize::Button
4
4
 
5
5
  def initialize(options)
6
6
  @options = {
7
- :font_size => 9,
8
- :paddings => [10,10],
9
7
  :width => nil,
10
8
  :template_base => "button",
11
9
  :template_path => File.dirname(__FILE__) + "/../../examples/default",
12
10
  :font => "Arial",#File.dirname(__FILE__) + "/fonts/verdanab.ttf",
11
+ :font_size => 9,
12
+ :font_antialias => true,
13
+ :text_color => "#fff",
13
14
  :text_offset => {:x => 0, :y => 0},
14
- :target_path => Dir.pwd,
15
- :antialias => true
15
+ :text_align => :center,
16
+ :padding => {:left => 10, :right => 10},
17
+ :target_path => Dir.pwd
16
18
  }.update(options)
17
19
  @options[:template_images] ||= ["_left","_middle","_right"].map{|p| options[:template_base] + p + ".gif" }
18
20
 
@@ -27,22 +29,22 @@ class Buttonize::Button
27
29
  def generate(text, filename = nil)
28
30
  filename ||= self.text_to_filename(text)
29
31
  filename = add_extension(filename,"gif")
30
- paddings = options[:paddings]
32
+ padding = options[:padding]
31
33
 
32
34
  # Load the images
33
35
  left,mid,right = options[:template_images].map{|p| Image.read(File.join(options[:template_path],p)).first }
34
36
 
35
37
  draw = Draw.new
36
38
  draw.pointsize = options[:font_size]
37
- draw.fill = "#fff"
38
- draw.gravity = Magick::CenterGravity
39
+ draw.fill = options[:text_color]
40
+ draw.gravity = self.gravity_from_alignment(options[:text_align])
39
41
  draw.font = options[:font]
40
- draw.font_weight = Magick::BoldWeight
41
- draw.text_antialias = options[:antialias] || false
42
+ draw.font_weight = Magick::AnyWeight
43
+ draw.text_antialias = options[:font_antialias] || false
42
44
 
43
45
  # Measure the text first
44
46
  metrics = draw.get_type_metrics(text)
45
- target_width = metrics.width + paddings[0] + paddings[1]
47
+ target_width = metrics.width + padding[:left] + padding[:right]
46
48
 
47
49
  target_width = options[:width] if options[:width] && options[:width] > target_width
48
50
 
@@ -68,7 +70,13 @@ class Buttonize::Button
68
70
 
69
71
  # Place right
70
72
  dst.composite!(right,pos,0,Magick::OverCompositeOp)
71
- draw.annotate(dst,0,0,options[:text_offset][:x],options[:text_offset][:y],text)
73
+
74
+ # Draw text
75
+ left = options[:text_offset][:x] || 0
76
+ left += padding[:left] unless options[:text_align] == :center
77
+ draw.annotate(dst,0,0,left,options[:text_offset][:y],text)
78
+
79
+ # Write file
72
80
  dst.write(File.join(options[:target_path],filename))
73
81
  dst.destroy!
74
82
 
@@ -87,4 +95,12 @@ class Buttonize::Button
87
95
  end
88
96
  end
89
97
 
98
+ def gravity_from_alignment(alignment)
99
+ case alignment
100
+ when :left then Magick::WestGravity
101
+ when :right then Magick::EastGravity
102
+ else Magick::CenterGravity
103
+ end
104
+ end
105
+
90
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flurin-buttonize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flurin Egger
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-23 00:00:00 -08:00
12
+ date: 2009-01-25 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -17,7 +17,7 @@ dependencies:
17
17
  version_requirement:
18
18
  version_requirements: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - ~>
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 2.5.1
23
23
  version:
@@ -40,8 +40,8 @@ extra_rdoc_files: []
40
40
 
41
41
  files:
42
42
  - bin/buttonize
43
+ - buttonize.gemspec
43
44
  - examples/buttons.rb
44
- - examples/default
45
45
  - examples/default/big_blue_left.gif
46
46
  - examples/default/big_blue_middle.gif
47
47
  - examples/default/big_blue_right.gif
@@ -54,6 +54,13 @@ files:
54
54
  - examples/default/big_red_left.gif
55
55
  - examples/default/big_red_middle.gif
56
56
  - examples/default/big_red_right.gif
57
+ - examples/default/fonts/Bitstream
58
+ - Vera
59
+ - License.txt
60
+ - examples/default/fonts/Vera-Bold-Italic.ttf
61
+ - examples/default/fonts/Vera-Bold.ttf
62
+ - examples/default/fonts/Vera-Italic.ttf
63
+ - examples/default/fonts/Vera.ttf
57
64
  - examples/default/small_blue_left.gif
58
65
  - examples/default/small_blue_middle.gif
59
66
  - examples/default/small_blue_right.gif
@@ -79,7 +86,6 @@ files:
79
86
  - examples/default/table_red_left.gif
80
87
  - examples/default/table_red_middle.gif
81
88
  - examples/default/table_red_right.gif
82
- - lib/buttonize
83
89
  - lib/buttonize/button.rb
84
90
  - lib/buttonize/button_set.rb
85
91
  - lib/buttonize/cli.rb