clamsy 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.txt +10 -0
  3. data/README.rdoc +7 -63
  4. data/Rakefile +27 -2
  5. data/VERSION +1 -1
  6. data/clamsy.gemspec +77 -8
  7. data/examples/create_many.rb +15 -0
  8. data/examples/create_one.rb +15 -0
  9. data/examples/data/context.rb +41 -0
  10. data/examples/data/contexts.rb +2 -0
  11. data/examples/data/school_logo.jpg +0 -0
  12. data/examples/data/staff_signature.gif +0 -0
  13. data/examples/data/student_offer_letter.odt +0 -0
  14. data/lib/clamsy.rb +7 -2
  15. data/lib/clamsy.yml +32 -6
  16. data/lib/clamsy/base_printer.rb +10 -1
  17. data/lib/clamsy/configuration.rb +57 -10
  18. data/lib/clamsy/cups_pdf_printer.rb +3 -5
  19. data/lib/clamsy/file_system_support.rb +3 -3
  20. data/lib/clamsy/jod_converter_printer.rb +60 -0
  21. data/lib/clamsy/template_open_doc.rb +7 -1
  22. data/lib/jodconverter/CREDIT +1 -0
  23. data/lib/jodconverter/LICENSE.txt +504 -0
  24. data/lib/jodconverter/README.txt +58 -0
  25. data/lib/jodconverter/commons-cli-1.2.jar +0 -0
  26. data/lib/jodconverter/commons-io-1.4.jar +0 -0
  27. data/lib/jodconverter/jodconverter-2.2.2.jar +0 -0
  28. data/lib/jodconverter/jodconverter-cli-2.2.2.jar +0 -0
  29. data/lib/jodconverter/juh-3.0.1.jar +0 -0
  30. data/lib/jodconverter/jurt-3.0.1.jar +0 -0
  31. data/lib/jodconverter/ridl-3.0.1.jar +0 -0
  32. data/lib/jodconverter/slf4j-api-1.5.6.jar +0 -0
  33. data/lib/jodconverter/slf4j-jdk14-1.5.6.jar +0 -0
  34. data/lib/jodconverter/unoil-3.0.1.jar +0 -0
  35. data/lib/jodconverter/xstream-1.3.1.jar +0 -0
  36. data/spec/clamsy/configuration_spec.rb +323 -163
  37. data/spec/clamsy/cups_pdf_printer_spec.rb +1 -1
  38. data/spec/clamsy/invalid_printer_spec.rb +0 -4
  39. data/spec/clamsy/jod_converter_printer_spec.rb +58 -0
  40. data/spec/fake_ooffice_server.rb +18 -0
  41. data/spec/integration/cups_pdf_printer_spec.rb +4 -59
  42. data/spec/integration/has_integration_support_shared_spec.rb +85 -0
  43. data/spec/integration/jod_converter_printer_spec.rb +12 -0
  44. data/spec/pdfc/CCLib.jar +0 -0
  45. data/spec/pdfc/CREDIT +2 -0
  46. data/spec/pdfc/PDFC.bat +1 -0
  47. data/spec/pdfc/PDFC.jar +0 -0
  48. data/spec/pdfc/PDFC.sh +3 -0
  49. data/spec/pdfc/PDFParser.jar +0 -0
  50. data/spec/pdfc/config.xml +24 -0
  51. data/spec/pdfc/license/LICENSE.log4j +48 -0
  52. data/spec/pdfc/license/lgpl-3.0.txt +165 -0
  53. data/spec/pdfc/license/overview.txt +9 -0
  54. data/spec/pdfc/log4j-1.2.15.jar +0 -0
  55. data/spec/pdfc/readme.txt +89 -0
  56. data/spec/spec_helper.rb +28 -11
  57. metadata +87 -8
  58. data/spec/integration/has_stardand_integration_support_shared_spec.rb +0 -27
@@ -0,0 +1,58 @@
1
+ JODConverter
2
+ ============
3
+
4
+ This is JODConverter version 2.2.2, released on 2009-04-11.
5
+
6
+ JODConverter is a Java library for converting office documents into different
7
+ formats, using OpenOffice.org 2.x or 3.x.
8
+
9
+ See http://www.artofsolving.com/opensource/jodconverter for the latest documentation.
10
+
11
+ Before you can perform any conversions you need to start OpenOffice.org
12
+ in listening mode on port 8100 as described in the JODConverter Guide.
13
+
14
+ As a quick start you can type from a command line
15
+
16
+ soffice -headless -accept="socket,port=8100;urp;"
17
+
18
+ JODConverter is both a Java library and a set of ready-to-use tools:
19
+
20
+ * a web application that you can deploy into any servlet container (e.g. Apache Tomcat)
21
+ * a command line tool (java -jar jodconverter-cli-2.2.2.jar <input-document> <output-document>)
22
+
23
+ Requirements
24
+ ============
25
+
26
+ The JAR library requires
27
+
28
+ * Java 1.4 or higher
29
+ * OpenOffice.org 2.x or 3.x; the latest stable version (currenty 3.0.1) is generally recommended
30
+
31
+ The webapp additionally requires
32
+
33
+ * A Servlet 2.3 container such as Apache Tomcat v4.x or higher
34
+
35
+ Licenses
36
+ ========
37
+
38
+ JODConverter is distributed under the terms of the LGPL.
39
+
40
+ This basically means that you are free to use it in both open source
41
+ and commercial projects.
42
+
43
+ If you modify the library itself you are required to contribute
44
+ your changes back, so JODConverter can be improved.
45
+
46
+ (You are free to modify the sample webapp as a starting point for your
47
+ own webapp without restrictions.)
48
+
49
+ JODConverter includes various third-party libraries so you must
50
+ agree to their respective licenses - included in docs/third-party-licenses.
51
+
52
+ That may include software developed by
53
+
54
+ * the Apache Software Foundation (http://www.apache.org)
55
+ * the Spring Framework project (http://www.springframework.org)
56
+
57
+ --
58
+ Mirko Nasato <mirko@artofsolving.com>
@@ -1,195 +1,313 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- def Clamsy.unconfigure
4
- @config = nil
5
- end
6
-
7
3
  describe "Clamsy configuration" do
8
4
 
9
5
  before do
10
6
  Clamsy.unconfigure
11
- $bundled_config_file = File.join(File.dirname(__FILE__),'..','..','lib','clamsy.yml')
12
- $user_config_file = Tempfile.new('clamsy.yml').path
13
- @write_config = lambda do |data|
14
- File.open($user_config_file,'w') {|io| YAML.dump(data, io) }
15
- end
7
+ $bundled_config_file = tmp_file('bundled-clamsy.ym;').path
8
+ $user_config_file = tmp_file('user-clamsy.yml').path
9
+ @write_config = lambda {|file, data| File.open(file,'w') {|io| YAML.dump(data, io) } }
10
+ @write_bundled_config = lambda {|data| @write_config[$bundled_config_file, data] }
11
+ @write_user_config = lambda {|data| @write_config[$user_config_file, data] }
12
+
13
+ # NOTE: Essentially, we are just doing some stubbing ...
14
+ class << Clamsy::Configuration ; backup_methods %w{new ruby_platform} ; end
15
+ class << Clamsy ; backup_methods %w{bundled_config_file} ; end
16
16
  end
17
17
 
18
18
  after do
19
- class << Clamsy::Configuration
20
- alias_method :new, :orig_new
19
+ # NOTE: Essentially, we are just doing some unstubbing ...
20
+ class << Clamsy::Configuration ; recover_methods %w{new ruby_platform} ; end
21
+ class << Clamsy ; recover_methods %w{bundled_config_file} ; end
22
+ end
23
+
24
+ {
25
+ :linux => {
26
+ :printer => 'jod_converter',
27
+ :config_file => '~/.clamsy.yml',
28
+ :java_bin => 'java',
29
+ :ooffice_bin => 'ooffice',
30
+ :cups_pdf => {
31
+ :ooffice_print_args => '-norestore -nofirststartwizard -nologo -headless -pt Cups-PDF',
32
+ :cups_output_dir => "/var/spool/cups-pdf/#{ENV['USER']}",
33
+ :cups_output_file => nil,
34
+ },
35
+ :jod_converter => {
36
+ :ooffice_server_args =>
37
+ '-headless -nofirststartwizard -accept="socket,host=localhost,port=8100;urp;StarOffice.Service"'
38
+ }
39
+ },
40
+ :darwin => {
41
+ :printer => 'jod_converter',
42
+ :config_file => '~/.clamsy.yml',
43
+ :java_bin => 'java',
44
+ :ooffice_bin => '/Applications/OpenOffice.org.app/Contents/MacOS/soffice.bin',
45
+ :cups_pdf => {
46
+ :ooffice_print_args => '-norestore -nofirststartwizard -nologo -headless -pt Cups-PDF',
47
+ :cups_output_dir => "/opt/local/var/spool/cups-pdf/#{ENV['USER']}",
48
+ :cups_output_file => nil,
49
+ },
50
+ :jod_converter => {
51
+ :ooffice_server_args =>
52
+ '-headless -nofirststartwizard -accept="socket,host=localhost,port=8100;urp;StarOffice.Service" &'
53
+ }
54
+ },
55
+ :windows => {},
56
+ :java => {} # jruby
57
+ }.each do |$platform, configs|
58
+ describe "> default bundled config (#{$platform})" do
59
+ before do
60
+ class << Clamsy::Configuration
61
+ def ruby_platform ; "#{$platform}" ; end
62
+ def new(file, is_base_config, default_configs={})
63
+ file == '~/.clamsy.yml' ? nil : _orig_new(CLAMSY_BUNDLED_CONFIG, true)
64
+ end
65
+ end
66
+ end
67
+ if configs.empty?
68
+ # Platform is not yet supported !!
69
+ should 'raise Clamsy::PlatformNotSupportedError' do
70
+ lambda { Clamsy.configure {|config| 'watever' } }.
71
+ should.raise(Clamsy::PlatformNotSupportedError).
72
+ message.should.equal("Platform '#{$platform}' is not supported (yet).")
73
+ end
74
+ else
75
+ configs.each do |name, value|
76
+ if value.is_a?(Hash)
77
+ # Printer-specific settings
78
+ value.each do |_name, _value|
79
+ should "have :#{_name} as '#{_value}' (when printer is '#{name}')" do
80
+ Clamsy.configure do |config|
81
+ config.printer = "#{name}"
82
+ config.send(_name).should.equal _value
83
+ end
84
+ end
85
+ end
86
+ else
87
+ # Printer-independent settings
88
+ should "have :#{name} as '#{value}'" do
89
+ Clamsy.configure do |config|
90
+ config.send(name).should.equal value
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
21
96
  end
22
97
  end
23
98
 
24
- describe '> default (w missing default user config file)' do
99
+ describe '> configuring (using default user config file)' do
25
100
 
26
101
  before do
27
102
  class << Clamsy::Configuration
28
- alias_method :orig_new, :new
29
- def new(file, is_base_config=false)
30
- file == '~/.clamsy.yml' ? nil : orig_new($bundled_config_file, true)
103
+ def ruby_platform ; 'linux' ; end
104
+ def new(file, is_base_config, default_configs={})
105
+ is_base_config ? _orig_new($bundled_config_file, true) :
106
+ _orig_new(file, is_base_config, default_configs)
31
107
  end
32
108
  end
33
- end
34
-
35
- should "have :printer as 'cups_pdf'" do
36
- Clamsy.configure do |config|
37
- config.printer.should.equal 'cups_pdf'
38
- end
39
- end
40
-
41
- should "have :config_file as '~/.clamsy.yml'" do
42
- Clamsy.configure do |config|
43
- config.config_file.should.equal '~/.clamsy.yml'
109
+ @bundled_config = {
110
+ 'printer' => 'super',
111
+ 'ooffice_bin' => '/super/ooffice_bin',
112
+ 'java_bin' => '/super/java',
113
+ 'config_file' => $user_config_file,
114
+ 'super' => {'super_setting1' => 'super_setting'}
115
+ }
116
+ @write_bundled_config[{'linux' => @bundled_config}]
117
+ end
118
+
119
+ %w{printer ooffice_bin java_bin}.each do |setting|
120
+ should "use specified :#{setting} if it has been specified" do
121
+ other_val = @bundled_config[setting].sub('super','duper')
122
+ @write_user_config[{setting => other_val}]
123
+ Clamsy.configure do |config|
124
+ config.send(setting).should.equal other_val
125
+ end
44
126
  end
45
- end
46
-
47
- should "have :cups_output_dir (cups_pdf) as '/var/spool/cups-pdf/#{ENV['USER']}'" do
48
- Clamsy.configure do |config|
49
- config.cups_output_dir.should.equal "/var/spool/cups-pdf/#{ENV['USER']}"
127
+ should "use default :#{setting} if it has not been specified" do
128
+ @write_user_config[{}]
129
+ Clamsy.configure do |config|
130
+ config.send(setting).should.equal @bundled_config[setting]
131
+ end
50
132
  end
51
133
  end
52
134
 
53
- should "have :cups_output_file (cups_pdf) be nil (unspecified)" do
135
+ should "use specified printer-specific setting if it has been specified" do
136
+ other_val = @bundled_config['super']['super_setting1'].sub('super','duper')
137
+ @write_user_config[{'super' => {'super_setting1' => other_val}}]
54
138
  Clamsy.configure do |config|
55
- config.cups_output_file.should.equal nil
139
+ config.super_setting1.should.equal other_val
56
140
  end
57
141
  end
58
142
 
59
- should "have :ooffice_cmd (cups_pdf) as " +
60
- "'ooffice -norestore -nofirststartwizard -nologo -headless -pt Cups-PDF'" do
143
+ should "use default printer-specific setting if it has not been specified" do
144
+ @write_user_config[{}]
61
145
  Clamsy.configure do |config|
62
- config.ooffice_cmd.should.equal \
63
- 'ooffice -norestore -nofirststartwizard -nologo -headless -pt Cups-PDF'
146
+ config.super_setting1.should.equal @bundled_config['super']['super_setting1']
64
147
  end
65
148
  end
66
149
 
67
150
  end
68
151
 
69
- describe '> configuring (using default user config file)' do
152
+ shared 'configurable using config proc' do
70
153
 
71
154
  before do
72
155
  class << Clamsy::Configuration
73
- alias_method :orig_new, :new
74
- def new(file, is_base_config=false)
75
- file != '~/.clamsy.yml' ?
76
- orig_new($bundled_config_file, true) : orig_new($user_config_file)
156
+ def ruby_platform ; 'linux' ; end
157
+ def new(file, is_base_config, default_configs={})
158
+ is_base_config ? _orig_new($bundled_config_file, true) :
159
+ _orig_new(file, is_base_config, default_configs)
77
160
  end
78
161
  end
79
- end
80
-
81
- should "use specified :printer if it has been specified" do
82
- @write_config[{'printer' => 'dummy'}]
83
- Clamsy.configure {|config| config.printer.should.equal 'dummy' }
84
- end
85
-
86
- should "use default :printer if it has not been specified" do
87
- @write_config[{}]
88
- Clamsy.configure {|config| config.printer.should.equal 'cups_pdf' }
89
- end
90
-
91
- should "raise Clamsy::ConfigFileSettingNotSupportedError if :config_file has been specified" do
92
- @write_config[{'config_file' => 'ddd'}]
93
- lambda { Clamsy.configure {|config| 'do nothing here' } }.
94
- should.raise(Clamsy::ConfigFileSettingNotSupportedError).
95
- message.should.equal(
96
- "Specifying of 'config_file' setting in user config '#{$user_config_file}' is not supported."
97
- )
98
- end
99
-
100
- should 'use specified printer-specific settings if they have been specified' do
101
- @write_config[{'printer' => 'cups_pdf', 'cups_pdf' => {'cups_output_dir' => '/x/y/z'}}]
102
- Clamsy.configure {|config| config.cups_output_dir.should.equal '/x/y/z' }
103
- end
104
-
105
- should 'use default printer-specific settings if they have not been specified' do
106
- Clamsy.configure do |config|
107
- config.cups_output_dir.should.equal "/var/spool/cups-pdf/#{ENV['USER']}"
162
+ @bundled_config = {
163
+ 'printer' => 'super',
164
+ 'ooffice_bin' => '/super/ooffice_bin',
165
+ 'java_bin' => '/super/java',
166
+ 'config_file' => $user_config_file,
167
+ 'super' => {'super_setting1' => 'super_setting1_val'},
168
+ 'duper' => {'duper_setting1' => 'duper_setting1_val'}
169
+ }
170
+ @write_bundled_config[{'linux' => @bundled_config}]
171
+ end
172
+
173
+ %w{printer ooffice_bin java_bin}.each do |setting|
174
+ should "use specified :#{setting} if it has been specified" do
175
+ other_val = @bundled_config[setting].sub('super','duper')
176
+ clamsy_configure do |config|
177
+ config.send(:"#{setting}=", other_val)
178
+ config.send(setting).should.equal other_val
179
+ end
108
180
  end
109
- end
110
-
111
- end
112
-
113
- describe '> configuring (using only config proc)' do
114
-
115
- behaves_like 'has standard files support'
116
-
117
- before do
118
- class << Clamsy::Configuration
119
- alias_method :orig_new, :new
120
- def new(file, is_base_config=false)
121
- file == '~/.clamsy.yml' ? nil : orig_new($bundled_config_file, true)
181
+ should "use default :#{setting} if it has not been specified" do
182
+ clamsy_configure do |config|
183
+ config.send(setting).should.equal @bundled_config[setting]
122
184
  end
123
185
  end
124
186
  end
125
187
 
126
- should 'use specified :printer if it has been specified' do
127
- Clamsy.configure do |config|
128
- config.printer = 'dummy'
129
- config.printer.should.equal 'dummy'
188
+ should "use specified printer-specific setting if it has been specified" do
189
+ clamsy_configure do |config|
190
+ config.super_setting1 = 'duper_setting'
191
+ config.super_setting1.should.equal 'duper_setting'
130
192
  end
131
193
  end
132
194
 
133
- should "use default :printer if it has not been specified" do
134
- Clamsy.configure do |config|
135
- config.printer.should.equal 'cups_pdf'
136
- [nil, ''].each do |val|
137
- config.printer = val
138
- config.printer.should.equal 'cups_pdf'
139
- end
195
+ should "use default printer-specific setting if it has not been specified" do
196
+ clamsy_configure do |config|
197
+ config.super_setting1.should.equal @bundled_config['super']['super_setting1']
140
198
  end
141
199
  end
142
200
 
143
201
  should "use specified :config_file if it has been specified" do
144
- Clamsy.configure do |config|
145
- config.config_file = $user_config_file
146
- config.config_file.should.equal $user_config_file
202
+ other_user_config_file = tmp_file('yet_another_user_config_file').path
203
+ clamsy_configure do |config|
204
+ config.config_file = other_user_config_file
205
+ config.config_file.should.equal other_user_config_file
147
206
  end
148
207
  end
149
208
 
150
- should "use raise Clamsy::FileNotFoundError if the specified config file does not exist" do
209
+ should "raise Clamsy::FileNotFoundError if the specified config file does not exist" do
151
210
  lambda {
152
- Clamsy.configure {|config| config.config_file = "#{__FILE__}.clamsy.yml" }
211
+ clamsy_configure {|config| config.config_file = "#{__FILE__}.clamsy.yml" }
153
212
  }.should.raise(Clamsy::FileNotFoundError).message.should.equal(
154
213
  "File '#{__FILE__}.clamsy.yml' not found."
155
214
  )
156
215
  end
157
216
 
158
- should 'use specified printer-specific settings if they have been specified' do
159
- Clamsy.configure do |config|
160
- config.cups_output_dir = '/x/y/z'
161
- config.cups_output_dir.should.equal '/x/y/z'
217
+ should 'raise Clamsy::PrinterNotFoundError if the specified printer does not exist' do
218
+ other_printer = 'awesome'
219
+ lambda { clamsy_configure {|config| config.printer = other_printer } }.
220
+ should.raise(Clamsy::PrinterNotFoundError).
221
+ message.should.equal("Printer '#{other_printer}' cannot be found.")
222
+ end
223
+
224
+ should 'reload printer-specific config (in bundled config file) when another printer is specified' do
225
+ other_printer = 'duper'
226
+ other_val = @bundled_config[other_printer]['duper_setting1']
227
+ clamsy_configure do |config|
228
+ config.duper_setting1.should.be.nil
229
+ config.printer = other_printer
230
+ config.duper_setting1.should.equal other_val
162
231
  end
163
232
  end
164
233
 
165
- should 'use default printer-specific settings if they have not been specified' do
166
- Clamsy.configure do |config|
167
- config.cups_output_dir.should.equal "/var/spool/cups-pdf/#{ENV['USER']}"
234
+ should 'reload printer-specific config (in user config file) when another printer is specified' do
235
+ other_printer, other_val = 'duper', 'duper_setting2_val'
236
+ @write_user_config[{other_printer => {'duper_setting2' => other_val}}]
237
+ clamsy_configure do |config|
238
+ config.duper_setting2.should.be.nil
239
+ config.printer = other_printer
240
+ config.duper_setting2.should.equal other_val
168
241
  end
169
242
  end
170
243
 
171
244
  end
172
245
 
173
- describe '> configuring (using only specified user config file in config proc)' do
246
+ describe '> configuring (using config proc)' do
247
+ class << self
248
+ def clamsy_configure(&blk) ; Clamsy.configure(&blk) ; end
249
+ end
250
+ behaves_like 'configurable using config proc'
251
+ end
252
+
253
+ describe '> configuring (using user-specified config file)' do
174
254
 
175
- should 'use specified :printer if it has been specified' do
176
- @write_config[{'printer' => 'dummy'}]
255
+ before do
256
+ class << Clamsy::Configuration
257
+ def ruby_platform ; 'linux' ; end
258
+ def new(file, is_base_config, default_configs={})
259
+ is_base_config ? _orig_new($bundled_config_file, true) :
260
+ _orig_new(file, is_base_config, default_configs)
261
+ end
262
+ end
263
+ @bundled_config = {
264
+ 'printer' => 'super',
265
+ 'ooffice_bin' => '/super/ooffice_bin',
266
+ 'java_bin' => '/super/java',
267
+ 'config_file' => '/default/user/config/file',
268
+ 'super' => {'super_setting1' => 'super_setting'},
269
+ 'duper' => {'duper_setting1' => 'duper_setting'}
270
+ }
271
+ @write_bundled_config[{'linux' => @bundled_config}]
272
+ end
273
+
274
+ %w{printer ooffice_bin java_bin}.each do |setting|
275
+ should "use specified :#{setting} if it has been specified" do
276
+ other_val = @bundled_config[setting].sub('super','duper')
277
+ @write_user_config[{setting => other_val}]
278
+ Clamsy.configure do |config|
279
+ config.config_file = $user_config_file
280
+ config.send(setting).should.equal other_val
281
+ end
282
+ end
283
+ should "use default :#{setting} if it has not been specified" do
284
+ @write_user_config[{}]
285
+ Clamsy.configure do |config|
286
+ config.send(setting).should.equal @bundled_config[setting]
287
+ config.config_file = $user_config_file
288
+ config.send(setting).should.equal @bundled_config[setting]
289
+ end
290
+ end
291
+ end
292
+
293
+ should "use specified printer-specific setting if it has been specified" do
294
+ other_val = @bundled_config['super']['super_setting1'].sub('super','duper')
295
+ @write_user_config[{'super' => {'super_setting1' => other_val}}]
177
296
  Clamsy.configure do |config|
178
297
  config.config_file = $user_config_file
179
- config.printer.should.equal 'dummy'
298
+ config.super_setting1.should.equal other_val
180
299
  end
181
300
  end
182
301
 
183
- should 'use default :printer if it has not been specified' do
184
- @write_config[{}]
302
+ should "use default printer-specific setting if it has not been specified" do
303
+ @write_user_config[{}]
185
304
  Clamsy.configure do |config|
186
- config.config_file = $user_config_file
187
- config.printer.should.equal 'cups_pdf'
305
+ config.super_setting1.should.equal @bundled_config['super']['super_setting1']
188
306
  end
189
307
  end
190
308
 
191
309
  should "raise Clamsy::ConfigFileSettingNotSupportedError if :config_file has been specified" do
192
- @write_config[{'config_file' => 'ddd'}]
310
+ @write_user_config[{'config_file' => '/yet/another/config/file'}]
193
311
  lambda {
194
312
  Clamsy.configure {|config| config.config_file = $user_config_file }
195
313
  }.should.raise(Clamsy::ConfigFileSettingNotSupportedError).
@@ -198,89 +316,131 @@ describe "Clamsy configuration" do
198
316
  )
199
317
  end
200
318
 
201
- should 'use specified printer-specific settings if they have been specified' do
202
- @write_config[{'printer' => 'cups_pdf', 'cups_pdf' => {'cups_output_dir' => '/x/y/z'}}]
203
- Clamsy.configure do |config|
204
- config.config_file = $user_config_file
205
- config.cups_output_dir.should.equal '/x/y/z'
206
- end
207
- end
319
+ end
208
320
 
209
- should 'use default printer-specific settings if they have not been specified' do
210
- @write_config[{}]
211
- Clamsy.configure do |config|
212
- config.config_file = $user_config_file
213
- config.cups_output_dir.should.equal "/var/spool/cups-pdf/#{ENV['USER']}"
321
+ describe '> configuring (with clashes in user config file & config proc)' do
322
+
323
+ before do
324
+ class << Clamsy::Configuration
325
+ def ruby_platform ; 'linux' ; end
326
+ def new(file, is_base_config, default_configs={})
327
+ is_base_config ? _orig_new($bundled_config_file, true) :
328
+ _orig_new(file, is_base_config, default_configs)
329
+ end
330
+ end
331
+ @bundled_config = {
332
+ 'printer' => 'super',
333
+ 'ooffice_bin' => '/super/ooffice_bin',
334
+ 'java_bin' => '/super/java',
335
+ 'config_file' => $user_config_file,
336
+ 'super' => {'super_setting1' => 'super_setting'},
337
+ 'duper' => {'duper_setting1' => 'duper_setting'},
338
+ 'guper' => {'guper_setting1' => 'guper_setting'},
339
+ }
340
+ @write_bundled_config[{'linux' => @bundled_config}]
341
+ end
342
+
343
+ %w{printer ooffice_bin java_bin}.each do |setting|
344
+ should "use proc specified :#{setting} if it has been specified in both config proc & file" do
345
+ config_file_val = @bundled_config[setting].sub('super','duper')
346
+ config_proc_val = @bundled_config[setting].sub('super','guper')
347
+ @write_user_config[{setting => config_file_val}]
348
+ Clamsy.configure do |config|
349
+ config.send(:"#{setting}=", config_proc_val)
350
+ config.send(setting).should.equal config_proc_val
351
+ end
352
+ end
353
+ should "use file specified :#{setting} if it has not been specified in config proc" do
354
+ config_file_val = @bundled_config[setting].sub('super','duper')
355
+ @write_user_config[{setting => config_file_val}]
356
+ Clamsy.configure do |config|
357
+ config.send(setting).should.equal config_file_val
358
+ end
214
359
  end
215
360
  end
216
361
 
217
- end
218
-
219
- describe '> configuring (with clashes in specified user config file & config proc)' do
220
-
221
- should 'use proc specified :printer if it is specified in both config proc & file' do
222
- @write_config[{'printer' => 'dummy'}]
362
+ should "use proc specified printer-specific setting if it has been specified in both config proc & file" do
363
+ config_file_val = @bundled_config['super']['super_setting1'].sub('super','duper')
364
+ config_proc_val = @bundled_config['super']['super_setting1'].sub('super','guper')
365
+ @write_user_config[{'super' => {'super_setting1' => config_file_val}}]
223
366
  Clamsy.configure do |config|
224
- # NOTE: it doesn't matter how we order the declaration !!
225
- config.config_file = $user_config_file
226
- config.printer = 'mummy'
227
- config.printer.should.equal 'mummy'
228
- config.config_file = $user_config_file
229
- config.printer.should.equal 'mummy'
367
+ config.super_setting1 = config_proc_val
368
+ config.super_setting1.should.equal config_proc_val
230
369
  end
231
370
  end
232
371
 
233
- should 'use proc specified printer-specific settings if they are specified in both config proc & file' do
234
- @write_config[{'printer' => 'cups_pdf', 'cups_pdf' => {'cups_output_dir' => '/x/y/x'}}]
372
+ should "use file specified printer-specific setting if it has not been specified in config proc" do
373
+ config_file_val = @bundled_config['super']['super_setting1'].sub('super','duper')
374
+ @write_user_config[{'printer' => 'super', 'super' => {'super_setting1' => config_file_val}}]
235
375
  Clamsy.configure do |config|
236
- # NOTE: it doesn't matter how we order the declaration !!
237
- config.config_file = $user_config_file
238
- config.cups_output_dir = '/a/b/c'
239
- config.cups_output_dir.should.equal '/a/b/c'
240
- config.config_file = $user_config_file
241
- config.cups_output_dir.should.equal '/a/b/c'
376
+ config.super_setting1.should.equal config_file_val
242
377
  end
243
378
  end
244
379
 
245
380
  end
246
381
 
247
- describe '> configuring can also be done while doing processing' do
382
+ describe '> configuring can also be done while doing Clamsy.process(...)' do
383
+
384
+ class << self
385
+ def clamsy_configure(&blk)
386
+ Clamsy.process([], '/dummy/template/doc', '/dummy/final/pdf', &blk)
387
+ end
388
+ end
248
389
 
249
390
  before do
250
391
  class << Clamsy
392
+ alias_method :orig_generate_pdf, :generate_pdf
251
393
  def generate_pdf(*args) ; end
252
394
  end
253
395
  end
254
396
 
255
- should 'use specified :printer if it has been specified' do
256
- Clamsy.process([], '/dummy/template/doc', '/dummy/final/pdf') do |config|
257
- config.printer = 'dummy'
397
+ after do
398
+ class << Clamsy
399
+ alias_method :generate_pdf, :orig_generate_pdf
258
400
  end
259
- Clamsy.configure {|config| config.printer.should.equal 'dummy' }
260
401
  end
261
402
 
262
- should 'use default :printer if it has not been specified' do
263
- Clamsy.process([], '/dummy/template/doc', '/dummy/final/pdf')
264
- Clamsy.configure {|config| config.printer.should.equal 'cups_pdf' }
265
- end
403
+ behaves_like 'configurable using config proc'
266
404
 
267
405
  end
268
406
 
269
407
  describe '> retrieving of config values' do
270
408
 
409
+ before do
410
+ class << Clamsy::Configuration
411
+ def ruby_platform ; 'linux' ; end
412
+ def new(file, is_base_config, default_configs={})
413
+ is_base_config ? _orig_new($bundled_config_file, true) :
414
+ _orig_new(file, is_base_config, default_configs)
415
+ end
416
+ end
417
+ end
418
+
271
419
  should 'replace any ${...} with matching environment variable value' do
272
- @write_config[{'printer' => 'dummy', 'dummy' => {'output_dir' => '/home/${USER}'}}]
420
+ @write_bundled_config[{
421
+ 'linux' => {
422
+ 'printer' => 'super',
423
+ 'ooffice_bin' => '/super/ooffice_bin',
424
+ 'java_bin' => '/super/java',
425
+ 'config_file' => '/${USER}/${HOME}/clamsy.yml',
426
+ 'super' => {},
427
+ }}]
273
428
  Clamsy.configure do |config|
274
- config.config_file = $user_config_file
275
- config.output_dir.should.equal "/home/#{ENV['USER']}"
429
+ config.config_file.should.equal "/#{ENV['USER']}/#{ENV['HOME']}/clamsy.yml"
276
430
  end
277
431
  end
278
432
 
279
433
  should "replace any ${...} wo matching environment variable with blank string" do
280
- @write_config[{'printer' => 'dummy', 'dummy' => {'output_dir' => '/home/${WHATEVER}'}}]
434
+ @write_bundled_config[{
435
+ 'linux' => {
436
+ 'printer' => 'super',
437
+ 'ooffice_bin' => '/super/ooffice_bin',
438
+ 'java_bin' => '/super/java',
439
+ 'config_file' => '/${WATEVER}/clamsy.yml',
440
+ 'super' => {},
441
+ }}]
281
442
  Clamsy.configure do |config|
282
- config.config_file = $user_config_file
283
- config.output_dir.should.equal "/home/"
443
+ config.config_file.should.equal "//clamsy.yml"
284
444
  end
285
445
  end
286
446