pimento 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/{spec/spec.opts → .rspec} +0 -0
- data/Gemfile +4 -0
- data/README.rdoc +6 -5
- data/Rakefile +6 -41
- data/examples/banner.rb +74 -0
- data/lib/pimento.rb +4 -2
- data/lib/pimento/canvas.rb +55 -13
- data/lib/pimento/component.rb +69 -0
- data/lib/pimento/component/bevel_button.rb +5 -0
- data/lib/pimento/component/check_box.rb +5 -0
- data/lib/pimento/component/circular_progress_indicator.rb +7 -0
- data/lib/pimento/component/disclosure_button.rb +5 -0
- data/lib/pimento/component/disclosure_triangle.rb +5 -0
- data/lib/pimento/component/help_button.rb +5 -0
- data/lib/pimento/component/horizontal_slider.rb +5 -0
- data/lib/pimento/component/popup_button.rb +5 -0
- data/lib/pimento/component/progress_indicator.rb +7 -0
- data/lib/pimento/component/round_button.rb +5 -0
- data/lib/pimento/component/rounded_rect_button.rb +5 -0
- data/lib/pimento/component/search_field.rb +5 -0
- data/lib/pimento/component/vertical_slider.rb +5 -0
- data/lib/pimento/renderable.rb +8 -0
- data/lib/pimento/util.rb +11 -0
- data/pimento.gemspec +17 -59
- data/spec/fixtures/1dot.xib +207 -222
- data/spec/fixtures/empty.xib +164 -174
- data/spec/pimento_spec.rb +2 -0
- data/spec/spec_helper.rb +7 -4
- data/template/bevel_button_ro.xml.erb +24 -0
- data/template/{canvas.xib.erb → canvas.xml.erb} +15 -52
- data/template/check_box_ro.xml.erb +31 -0
- data/template/circular_progress_indicator_ro.xml.erb +10 -0
- data/template/disclosure_button_ro.xml.erb +44 -0
- data/template/disclosure_triangle_ro.xml.erb +24 -0
- data/template/help_button_ro.xml.erb +24 -0
- data/template/horizontal_slider_ro.xml.erb +27 -0
- data/template/or_1.xml.erb +5 -0
- data/template/or_2.xml.erb +14 -0
- data/template/popup_button_ro.xml.erb +23 -0
- data/template/progress_indicator_ro.xml.erb +10 -0
- data/template/round_button_ro.xml.erb +24 -0
- data/template/rounded_rect_button_ro.xml.erb +24 -0
- data/template/search_field_ro.xml.erb +39 -0
- data/template/vertical_slider_ro.xml.erb +26 -0
- metadata +98 -69
- data/.document +0 -5
- data/examples/hello.rb +0 -32
- data/lib/pimento/dot.rb +0 -12
data/.gitignore
CHANGED
data/{spec/spec.opts → .rspec}
RENAMED
File without changes
|
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -2,17 +2,18 @@
|
|
2
2
|
|
3
3
|
Draw graphics using Mac OS X GUI Components
|
4
4
|
|
5
|
-
http://buycheapviagraonlinenow.com/files/
|
5
|
+
http://buycheapviagraonlinenow.com/files/pimento.png
|
6
6
|
|
7
|
-
==
|
7
|
+
== Synopsis
|
8
8
|
|
9
9
|
require 'ubygems'
|
10
10
|
require 'pimento'
|
11
11
|
|
12
|
-
c = Pimento::Canvas.new(0, 0,
|
12
|
+
c = Pimento::Canvas.new(0, 0, 620, 200)
|
13
13
|
|
14
|
-
c.point(20, 20)
|
15
|
-
c.line(
|
14
|
+
c.point(20, 20, 20, 180)
|
15
|
+
c.line(20, 100, 100, 100)
|
16
|
+
c.line_with_dots(100, 20, 100, 180)
|
16
17
|
|
17
18
|
c.to_xml.save('foo.xib')
|
18
19
|
|
data/Rakefile
CHANGED
@@ -1,46 +1,11 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
2
|
require 'rake'
|
3
|
+
require "bundler/gem_tasks"
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
gem.summary = %Q{Draw graphics using Mac OS X GUI Components}
|
9
|
-
gem.description = %Q{Draw graphics using Mac OS X GUI Components}
|
10
|
-
gem.email = "youpy@buycheapviagraonlinenow.com"
|
11
|
-
gem.homepage = "http://github.com/youpy/pimento"
|
12
|
-
gem.authors = ["youpy"]
|
13
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
-
gem.add_dependency "libxml-ruby"
|
15
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
5
|
+
require 'rspec/core'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
20
9
|
end
|
21
10
|
|
22
|
-
require 'spec/rake/spectask'
|
23
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
-
spec.libs << 'lib' << 'spec'
|
25
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
-
end
|
27
|
-
|
28
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
-
spec.libs << 'lib' << 'spec'
|
30
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
-
spec.rcov = true
|
32
|
-
end
|
33
|
-
|
34
|
-
task :spec => :check_dependencies
|
35
|
-
|
36
11
|
task :default => :spec
|
37
|
-
|
38
|
-
require 'rake/rdoctask'
|
39
|
-
Rake::RDocTask.new do |rdoc|
|
40
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
-
|
42
|
-
rdoc.rdoc_dir = 'rdoc'
|
43
|
-
rdoc.title = "pimento #{version}"
|
44
|
-
rdoc.rdoc_files.include('README*')
|
45
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
-
end
|
data/examples/banner.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# based on http://gist.github.com/411787
|
2
|
+
|
3
|
+
require 'ubygems'
|
4
|
+
require 'pimento'
|
5
|
+
|
6
|
+
str = ARGV.shift
|
7
|
+
exit unless str =~ /^[\d\w ]+$/
|
8
|
+
x = 50
|
9
|
+
c = Pimento::Canvas.new 0,0,x+str.size*x*2,x*4
|
10
|
+
d = [
|
11
|
+
lambda {|i| c.line x+i*2*x,x,2*x+i*2*x,x },
|
12
|
+
lambda {|i| c.line x+i*2*x,2*x,2*x+i*2*x,2*x },
|
13
|
+
lambda {|i| c.line x+i*2*x,3*x,2*x+i*2*x,3*x },
|
14
|
+
lambda {|i| c.line x+i*2*x,x,x+i*2*x,2*x },
|
15
|
+
lambda {|i| c.line x+i*2*x,2*x,x+i*2*x,3*x },
|
16
|
+
lambda {|i| c.line 2*x+i*2*x,x,2*x+i*2*x,2*x },
|
17
|
+
lambda {|i| c.line 2*x+i*2*x,2*x,2*x+i*2*x,3*x },
|
18
|
+
lambda {|i| c.line x+i*2*x,x,1.5*x+i*2*x,2*x },
|
19
|
+
lambda {|i| c.line 1.5*x+i*2*x,2*x,2*x+i*2*x,x },
|
20
|
+
lambda {|i| c.line x+i*2*x,3*x,1.5*x+i*2*x,2*x },
|
21
|
+
lambda {|i| c.line 1.5*x+i*2*x,2*x,2*x+i*2*x,3*x },
|
22
|
+
lambda {|i| c.line 1.5*x+i*2*x,2*x,2*x+i*2*x,2*x },
|
23
|
+
lambda {|i| c.line x+i*2*x,2*x,1.5*x+i*2*x,2*x },
|
24
|
+
lambda {|i| c.line 1.5*x+i*2*x,x,1.5*x+i*2*x,2*x },
|
25
|
+
lambda {|i| c.line 1.5*x+i*2*x,2*x,1.5*x+i*2*x,3*x },
|
26
|
+
lambda {|i| c.line x+i*2*x,x,2*x+i*2*x,3*x },
|
27
|
+
]
|
28
|
+
n = {
|
29
|
+
' ' => [],
|
30
|
+
'0' => [0,2,3,4,5,6],
|
31
|
+
'1' => [5,6],
|
32
|
+
'2' => [0,1,2,5,4],
|
33
|
+
'3' => [0,1,2,5,6],
|
34
|
+
'4' => [1,3,5,6],
|
35
|
+
'5' => [0,1,2,3,6],
|
36
|
+
'6' => [0,1,2,3,4,6],
|
37
|
+
'7' => [0,5,6],
|
38
|
+
'8' => [0,1,2,3,4,5,6],
|
39
|
+
'9' => [0,1,2,3,5,6],
|
40
|
+
'A' => [0,1,3,4,5,6],
|
41
|
+
'B' => [1,2,3,4,6],
|
42
|
+
'C' => [0,2,3,4],
|
43
|
+
'D' => [1,2,4,5,6],
|
44
|
+
'E' => [0,1,2,3,4],
|
45
|
+
'F' => [0,1,3,4],
|
46
|
+
'G' => [0,2,3,4,6,11],
|
47
|
+
'H' => [1,3,4,5,6],
|
48
|
+
'I' => [13,14],
|
49
|
+
'J' => [2,5,6],
|
50
|
+
'K' => [3,4,8,10,12],
|
51
|
+
'L' => [2,3,4],
|
52
|
+
'M' => [0,3,4,5,6,13],
|
53
|
+
'N' => [3,4,5,6,15],
|
54
|
+
'O' => [0,2,3,4,5,6],
|
55
|
+
'P' => [0,1,3,4,5],
|
56
|
+
'Q' => [0,2,3,4,5,6,10],
|
57
|
+
'R' => [0,1,3,4,5,10],
|
58
|
+
'S' => [0,1,2,3,6],
|
59
|
+
'T' => [0,13,14],
|
60
|
+
'U' => [2,3,4,5,6],
|
61
|
+
'V' => [3,4,8,9],
|
62
|
+
'W' => [2,3,4,5,6,14],
|
63
|
+
'X' => [7,8,9,10],
|
64
|
+
'Y' => [1,2,3,5,6],
|
65
|
+
'Z' => [0,2,8,9],
|
66
|
+
}
|
67
|
+
str.to_s.split(//).each_with_index do |ch, i|
|
68
|
+
n[ch.upcase].reverse.each do |r|
|
69
|
+
d[r].call i
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
c.to_xml.save 'a.xib'
|
74
|
+
#`open a.xib`
|
data/lib/pimento.rb
CHANGED
data/lib/pimento/canvas.rb
CHANGED
@@ -4,24 +4,23 @@ require 'xml'
|
|
4
4
|
|
5
5
|
module Pimento
|
6
6
|
class Canvas
|
7
|
-
|
7
|
+
include Renderable
|
8
|
+
|
9
|
+
attr_reader :width, :height
|
10
|
+
|
11
|
+
FIRST_ID = 741820390
|
12
|
+
FIRST_OBJ = 3
|
8
13
|
|
9
14
|
def initialize(top, left, width, height)
|
10
|
-
@step = 5
|
11
15
|
@top = top
|
12
16
|
@left = left
|
13
17
|
@width = width
|
14
18
|
@height = height
|
15
|
-
@
|
16
|
-
@obj_count = 2
|
17
|
-
@id = 741820390
|
18
|
-
@cell_id = 799499906
|
19
|
+
@components = []
|
19
20
|
end
|
20
21
|
|
21
22
|
def point(x, y)
|
22
|
-
@
|
23
|
-
@id += 1
|
24
|
-
@cell_id += 1
|
23
|
+
@components << Component.for(:dot).new(self, x, y)
|
25
24
|
end
|
26
25
|
|
27
26
|
def line(x1, y1, x2, y2)
|
@@ -30,16 +29,59 @@ module Pimento
|
|
30
29
|
w = (x2 - x1).abs
|
31
30
|
h = (y2 - y1).abs
|
32
31
|
|
33
|
-
|
32
|
+
case
|
33
|
+
when y1 == y2
|
34
|
+
@components << Component.for(:horizontal_line).new(self, x, y, w)
|
35
|
+
when x1 == x2
|
36
|
+
@components << Component.for(:vertical_line).new(self, x, y, h)
|
37
|
+
else
|
38
|
+
line_with_dots(x1, y1, x2, y2)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def line_with_dots(x1, y1, x2, y2, step = 20)
|
43
|
+
x = x1
|
44
|
+
y = y1
|
45
|
+
w = (x2 - x1).abs
|
46
|
+
h = (y2 - y1).abs
|
34
47
|
|
35
|
-
num_dots
|
48
|
+
num_dots = ((w > h) ? w : h) / step
|
49
|
+
(num_dots + 1).times do |i|
|
36
50
|
point(x1 + ((x2 - x1) / num_dots * i).to_i, y1 + ((y2 - y1) / num_dots * i).to_i)
|
37
51
|
end
|
38
52
|
end
|
39
53
|
|
40
54
|
def to_xml
|
41
|
-
|
42
|
-
|
55
|
+
XML::Document.string(render('canvas'), :options =>
|
56
|
+
XML::Parser::Options::NOENT | XML::Parser::Options::NOBLANKS)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def render_objects
|
62
|
+
id_offset = FIRST_ID
|
63
|
+
result = ''
|
64
|
+
|
65
|
+
@components.each do |component|
|
66
|
+
result += component.render_object(id_offset)
|
67
|
+
id_offset += component.num_objects
|
68
|
+
end
|
69
|
+
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
def render_object_records
|
74
|
+
obj_offset = FIRST_OBJ
|
75
|
+
id_offset = FIRST_ID
|
76
|
+
result = ''
|
77
|
+
|
78
|
+
@components.each do |component|
|
79
|
+
result += component.render_object_record(id_offset, obj_offset)
|
80
|
+
obj_offset += component.num_objects
|
81
|
+
id_offset += component.num_objects
|
82
|
+
end
|
83
|
+
|
84
|
+
result
|
43
85
|
end
|
44
86
|
end
|
45
87
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Pimento
|
2
|
+
class Component
|
3
|
+
include Renderable
|
4
|
+
|
5
|
+
attr_reader :x, :y
|
6
|
+
|
7
|
+
@@klasses = {}
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def handles(*types)
|
11
|
+
types.each do |type|
|
12
|
+
@@klasses[type] ||= []
|
13
|
+
@@klasses[type] << self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def for(type)
|
18
|
+
@@klasses[type][rand(@@klasses[type].length)]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(canvas, x, y)
|
23
|
+
@x = x
|
24
|
+
@y = y
|
25
|
+
@canvas = canvas
|
26
|
+
end
|
27
|
+
|
28
|
+
def num_objects
|
29
|
+
2
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_object(id_offset)
|
33
|
+
render(template_name('ro'), :id_offset => id_offset).to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def render_object_record(id_offset, obj_offset)
|
37
|
+
render('or_%i' % num_objects, :id_offset => id_offset, :obj_offset => obj_offset).to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def template_name(suffix)
|
41
|
+
basename = Util.underscore(self.class.to_s.split(/::/).last)
|
42
|
+
[basename, suffix].join('_')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class DotComponent < Component; end
|
47
|
+
|
48
|
+
class HorizontalLineComponent < Component
|
49
|
+
attr_accessor :width
|
50
|
+
|
51
|
+
def initialize(canvas, x, y, width)
|
52
|
+
super(canvas, x, y)
|
53
|
+
@width = width
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class VerticalLineComponent < Component
|
58
|
+
attr_accessor :height
|
59
|
+
|
60
|
+
def initialize(canvas, x, y, height)
|
61
|
+
super(canvas, x, y)
|
62
|
+
@height = height
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Dir[File.expand_path(File.dirname(__FILE__) + '/component/*.rb')].each do |file|
|
68
|
+
require file
|
69
|
+
end
|