wordcram 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ require 'java'
2
+
3
+ require 'ruby-processing'
4
+
5
+ # Wordcram dependencies
6
+ require_relative '../vendor/WordCram.jar'
7
+ require_relative '../vendor/jsoup-1.3.3.jar'
8
+ require_relative '../vendor/cue.language.jar'
9
+ require_relative '../vendor/processing/core.jar'
10
+ require_relative '../vendor/processing/itext.jar'
11
+ require_relative '../vendor/processing/pdf.jar'
12
+
13
+ require_relative 'wordcram/wordcram'
14
+ require_relative 'wordcram/styles/styles'
15
+ require_relative 'wordcram/placer'
16
+ require_relative 'wordcram/sketch'
17
+ require_relative 'wordcram/version'
18
+ Processing::App::SKETCH_PATH = '.'
19
+
20
+ # This is the main interface. The API that most users are going to use.
@@ -0,0 +1,25 @@
1
+ class Wordcram
2
+ class Placer
3
+ def initialize(&block)
4
+ @block = block
5
+ end
6
+
7
+ # This method is called from the java side, so I can't make the arguments
8
+ # a hash key. Blame Java T_T
9
+ def place(word, index, count, word_width, word_height, field_width, field_height)
10
+ data = {}
11
+ data[:word] = word
12
+ data[:index] = index
13
+ data[:count] = count
14
+ data[:word_width] = word_width
15
+ data[:word_height] = word_height
16
+ data[:field_width] = field_width
17
+ data[:field_height] = field_height
18
+
19
+ pos = @block.call(data)
20
+
21
+ Processing::PVector.new(pos[0], pos[1])
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ class Wordcram
2
+ class Sketch < Processing::App
3
+ include Style
4
+ attr_accessor :wordcram, :block
5
+
6
+ def initialize(&block)
7
+ @block = block
8
+ super()
9
+ end
10
+
11
+ def canvas(&block)
12
+ self.instance_eval(&block)
13
+ end
14
+
15
+ def setup
16
+ @wordcram = Java.wordcram.WordCram.new(self)
17
+
18
+ self.instance_eval(&@block)
19
+
20
+ @wordcram.draw_all()
21
+ end
22
+
23
+ def save_to(path)
24
+ saveFrame(path)
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,164 @@
1
+ class Wordcram
2
+ module Style
3
+
4
+ #######################
5
+ # Angler
6
+ #######################
7
+
8
+ def angled_at(angle)
9
+ wordcram.angled_at(angle)
10
+ end
11
+
12
+ def angled_between(from, to)
13
+ wordcram.angled_between(from, to)
14
+ end
15
+
16
+
17
+ #######################
18
+ # Case
19
+ #######################
20
+
21
+ def text_case(option)
22
+ wordcram.send :"#{option}_case"
23
+ rescue NoMethodError
24
+ wordcram.keep_case
25
+ end
26
+
27
+
28
+ #######################
29
+ # Color
30
+ #######################
31
+
32
+ def colors(*colors)
33
+ if colors.size == 1
34
+ wordcram.with_color(*colors)
35
+ else
36
+ wordcram.with_colors(*colors)
37
+ end
38
+ end
39
+
40
+ def blue
41
+ color(0, 0, 255)
42
+ end
43
+
44
+ def green
45
+ color(0, 255, 0)
46
+ end
47
+
48
+ def orange
49
+ color(255, 127, 0)
50
+ end
51
+
52
+ def black
53
+ color(0, 0, 0)
54
+ end
55
+
56
+ def white
57
+ color(255, 255, 255)
58
+ end
59
+
60
+ def yellow
61
+ color(255, 255, 0)
62
+ end
63
+
64
+ def red
65
+ color(255, 0, 0)
66
+ end
67
+
68
+
69
+ #######################
70
+ # Font
71
+ #######################
72
+
73
+ def fonts(*fonts)
74
+ if fonts.size == 1
75
+ wordcram.with_font(*fonts)
76
+ else
77
+ wordcram.with_fonts(*fonts)
78
+ end
79
+ end
80
+
81
+
82
+ #######################
83
+ # Padding
84
+ #######################
85
+
86
+ def word_padding(padding)
87
+ wordcram.with_word_padding(padding)
88
+ end
89
+
90
+
91
+ #######################
92
+ # Sizer
93
+ #######################
94
+
95
+ def sized_by_weight(options)
96
+ wordcram.sized_by_weight(options[:min], options[:max])
97
+ end
98
+
99
+ def sized_by_rank(options)
100
+ wordcram.sized_by_rank(options[:min], options[:max])
101
+ end
102
+
103
+
104
+ #######################
105
+ # Sources
106
+ #######################
107
+
108
+ def from(content, options = {})
109
+ wordcram.send(:"from_#{options[:as]}", content)
110
+ rescue NoMethodError
111
+ wordcram.send(:from_text_string, content)
112
+ end
113
+
114
+
115
+ #########################
116
+ # Placer
117
+ #########################
118
+
119
+ def create_placer(name)
120
+ placer = send(name)
121
+ rescue NoMethodError
122
+ placer = ''
123
+ end
124
+
125
+ def placer(placer=nil, &block)
126
+ if placer.nil?
127
+ placer = Placer.new &block
128
+ else
129
+ placer = create_placer(placer)
130
+ end
131
+ wordcram.with_placer(placer)
132
+ end
133
+
134
+
135
+ ##########################
136
+ # Bundled Placers
137
+ ##########################
138
+
139
+ def horizontal_line
140
+ Java.wordcram.Placers.horiz_line
141
+ end
142
+
143
+ def center_clump
144
+ Java.wordcram.Placers.center_clump
145
+ end
146
+
147
+ def horiz_band_anchored_left
148
+ Java.wordcram.Placers.horiz_band_anchored_left
149
+ end
150
+
151
+ def swirl
152
+ Java.wordcram.Placers.swirl
153
+ end
154
+
155
+ def upper_left
156
+ Java.wordcram.Placers.upper_left
157
+ end
158
+
159
+ def wave
160
+ Java.wordcram.Placers.wave
161
+ end
162
+
163
+ end
164
+ end
@@ -0,0 +1,3 @@
1
+ class Wordcram
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ class Wordcram
2
+ def self.draw(&block)
3
+ Sketch.new(&block)
4
+ end
5
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wordcram
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Gonzalo Rodriguez-Baltanas Diaz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-13 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby-processing
17
+ version_requirements: &2070 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ none: false
23
+ requirement: *2070
24
+ prerelease: false
25
+ type: :runtime
26
+ description: A wrapper for the WordCram java library
27
+ email: siotopo@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/wordcram.rb
33
+ - lib/wordcram/placer.rb
34
+ - lib/wordcram/sketch.rb
35
+ - lib/wordcram/version.rb
36
+ - lib/wordcram/wordcram.rb
37
+ - lib/wordcram/styles/styles.rb
38
+ - vendor/cue.language.jar
39
+ - vendor/jsoup-1.3.3.jar
40
+ - vendor/mockito-all-1.8.5.jar
41
+ - vendor/WordCram.jar
42
+ - vendor/ant-googlecode/ant-googlecode-0.0.2.jar
43
+ - vendor/junit/junit-4.8.2.jar
44
+ - vendor/junit/junit-dep-4.8.2.jar
45
+ - vendor/processing/core.jar
46
+ - vendor/processing/itext.jar
47
+ - vendor/processing/pdf.jar
48
+ - vendor/svnant/ganymed.jar
49
+ - vendor/svnant/svnant.jar
50
+ - vendor/svnant/svnClientAdapter.jar
51
+ - vendor/svnant/svnjavahl.jar
52
+ - vendor/svnant/svnkit.jar
53
+ has_rdoc: true
54
+ homepage: https://github.com/Nerian/s9-e1
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ none: false
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ none: false
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.5.1
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Create cool Word Clouds programatically
78
+ test_files: []
79
+ ...