dokkit 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -16,8 +16,10 @@ lib/dokkit/factory.rb
16
16
  lib/dokkit/factory/factory.rb
17
17
  lib/dokkit/filters.rb
18
18
  lib/dokkit/filters/deplate.rb
19
+ lib/dokkit/filters/erb.rb
19
20
  lib/dokkit/filters/maruku.rb
20
21
  lib/dokkit/filters/nil.rb
22
+ lib/dokkit/filters/tidy.rb
21
23
  lib/dokkit/hash.rb
22
24
  lib/dokkit/logging.rb
23
25
  lib/dokkit/logging/logger.rb
@@ -59,8 +61,10 @@ spec/dokkit/environment/test_data/doc/pages/document_2
59
61
  spec/dokkit/environment/test_data/doc/pages/subdir/document_1
60
62
  spec/dokkit/factory/factory_spec.rb
61
63
  spec/dokkit/filters/deplate_spec.rb
64
+ spec/dokkit/filters/erb_spec.rb
62
65
  spec/dokkit/filters/maruku_spec.rb
63
66
  spec/dokkit/filters/nil_spec.rb
67
+ spec/dokkit/filters/tidy_spec.rb
64
68
  spec/dokkit/hash_spec.rb
65
69
  spec/dokkit/logging/logger_spec.rb
66
70
  spec/dokkit/logging/observers/console_spec.rb
@@ -87,6 +91,7 @@ spec/dokkit/resource/test_data/doc/pages/document_with_nested_layout.ext
87
91
  spec/dokkit/resource/test_data/doc/pages/document_with_nil_target.ext
88
92
  spec/dokkit/resource/test_data/doc/pages/document_with_not_defined_target.ext
89
93
  spec/dokkit/resource/test_data/doc/pages/document_with_one_target.ext
94
+ spec/dokkit/resource/test_data/doc/pages/document_with_postfilter.ext
90
95
  spec/dokkit/resource/test_data/doc/pages/subdir/COMMON.yaml
91
96
  spec/dokkit/resource/test_data/doc/pages/subdir/document.ext
92
97
  spec/dokkit/resource/test_data/doc/pages/subdir/document.yaml
@@ -7,7 +7,6 @@
7
7
  #
8
8
 
9
9
  require 'ostruct'
10
- require 'rake'
11
10
  require 'dokkit'
12
11
  require 'dokkit/environment'
13
12
  require 'dokkit/logging'
@@ -98,6 +97,8 @@ module Dokkit
98
97
  # Construct a filter factory and register filters.
99
98
  def filter_factory
100
99
  @filter_factory ||= Dokkit::Factory.new do |factory|
100
+ factory.add('erb' => lambda { |binding| Dokkit::Filter::ERB.new(binding) } )
101
+ factory.add('tidy' => lambda { Dokkit::Filter::Tidy.new } )
101
102
  factory.add('maruku-html' => lambda { Dokkit::Filter::MarukuHTML.new } )
102
103
  factory.add('deplate-latex' => lambda { Dokkit::Filter::DeplateLatex.new } )
103
104
  factory.add('deplate-html' => lambda { Dokkit::Filter::DeplateHTML.new } )
@@ -114,6 +115,7 @@ module Dokkit
114
115
  factory.add(:data => data_factory_block)
115
116
  end
116
117
  end
118
+
117
119
  # Return a block that is able to construct a Document instance.
118
120
  def document_factory_block
119
121
  lambda do |source_fn|
@@ -126,20 +128,24 @@ module Dokkit
126
128
  &extmap[source_fn])
127
129
  end
128
130
  end
131
+
129
132
  # Return a block that is able to construct a Data instance.
130
133
  def data_factory_block
131
134
  lambda do |source_fn|
132
135
  Resource::Data.new(source_fn, configuration.marshal_dump)
133
136
  end
134
137
  end
138
+
135
139
  # Define render tasklib.
136
140
  def render
137
141
  TaskLib::Render.new(logger, resource_factory, documents.files, data.files)
138
142
  end
143
+
139
144
  # Define clean tasklib.
140
145
  def clean
141
146
  TaskLib::Clean.new(logger, configuration.marshal_dump)
142
147
  end
148
+
143
149
  end
144
150
  end
145
151
  end
@@ -147,10 +153,12 @@ end
147
153
  module Dokkit
148
154
  module Environment
149
155
  module Basic
156
+
150
157
  # Define a setup container.
151
158
  class Container
152
159
  include Dokkit::Environment::Basic
153
160
  end
161
+
154
162
  end
155
163
  end
156
164
  end
@@ -0,0 +1,27 @@
1
+ #
2
+ # File 'erb.rb' created on 23 lug 2008 at 15:40:59.
3
+ #
4
+ # See 'dokkit.rb' or +LICENSE+ for licence information.
5
+ #
6
+ # (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
7
+ #
8
+
9
+ require 'erb'
10
+
11
+ module Dokkit
12
+ module Filter
13
+
14
+ class ERB
15
+
16
+ def initialize(binding)
17
+ @binding = binding
18
+ end
19
+
20
+ def filter(text)
21
+ ::ERB.new(text).result(@binding)
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # File 'tidy.rb' created on 27 lug 2008 at 12:02:48.
3
+ #
4
+ # See 'dokkit.rb' or +LICENSE+ for licence information.
5
+ #
6
+ # (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
7
+ #
8
+
9
+ require 'maruku'
10
+
11
+ module Dokkit
12
+ module Filter
13
+
14
+ class Tidy
15
+
16
+ def filter(text)
17
+ cmd = "tidy -q -i"
18
+ out = IO.popen(cmd, 'r+') do |tidy|
19
+ tidy.write text
20
+ tidy.close_write
21
+ tidy.read
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
29
+
@@ -7,6 +7,7 @@
7
7
  #
8
8
 
9
9
  require 'dokkit/filters/nil'
10
+ require 'dokkit/filters/erb'
10
11
  require 'dokkit/filters/deplate'
11
12
  require 'dokkit/filters/maruku'
12
-
13
+ require 'dokkit/filters/tidy'
@@ -25,11 +25,15 @@ module Dokkit
25
25
 
26
26
  # Set the default filters chain for commonly used output format.
27
27
  DEFAULT_FILTERS_CHAIN = {
28
- 'html' => ['deplate-html'],
29
- 'latex' => ['deplate-latex'],
30
- 'text' => ['deplate-text']
28
+ 'html' => ['erb', 'deplate-html'],
29
+ 'latex' => ['erb', 'deplate-latex'],
30
+ 'text' => ['erb', 'deplate-text']
31
31
  }
32
-
32
+ DEFAULT_POST_FILTERS_CHAIN = {
33
+ 'html' => ['erb'],
34
+ 'latex' => ['erb'],
35
+ 'text' => ['erb']
36
+ }
33
37
  attr_reader :configuration
34
38
  attr_reader :source_fn
35
39
  attr_reader :basename, :name_noext, :dirname, :relativename
@@ -121,7 +125,22 @@ module Dokkit
121
125
  @logger.error("No defined filters chain for format '#{format}'!")
122
126
  end
123
127
  end
124
-
128
+
129
+ # Return the post filters chain associated with the given format.
130
+ def post_filters_for(format)
131
+ if @targets.has_key?(format)
132
+ if @targets[format].has_key?('postfilter')
133
+ @targets[format]['postfilter']
134
+ elsif DEFAULT_POST_FILTERS_CHAIN.has_key?(format)
135
+ DEFAULT_POST_FILTERS_CHAIN[format]
136
+ end
137
+ elsif DEFAULT_POST_FILTERS_CHAIN.has_key?(format)
138
+ DEFAULT_POST_FILTERS_CHAIN[format]
139
+ else
140
+ @logger.error("No defined post filters chain for format '#{format}'!")
141
+ end
142
+ end
143
+
125
144
  def target_for(format)
126
145
  @targets[format][:target_fn]
127
146
  end
@@ -215,24 +234,16 @@ module Dokkit
215
234
 
216
235
  # Produce output from source.
217
236
  def render_source!(format)
218
- unless @source.nil?
219
- erb = ERB.new(@source)
220
- erb.filename = @source_fn
221
- @content_for_layout = apply_filters(erb.result(binding), format)
222
- end
237
+ @content_for_layout = apply_filters(@source, filters_for(format), format) unless @source.nil?
223
238
  end
224
239
 
240
+ def render_layout!(layout_fn, format)
241
+ @content_for_layout = apply_filters(File.read(layout_fn), post_filters_for(format), format) unless File.read(layout_fn).nil?
242
+ end
243
+
225
244
  # Injects rendered content from +source_fn+ in the layout chain.
226
245
  def render_all_layouts!(format)
227
- unless !@layouts[format] || @layouts[format].empty?
228
- @layouts[format].each { |layout_fn| render_layout!(layout_fn) }
229
- end
230
- end
231
-
232
- def render_layout!(layout_fn)
233
- erb = ERB.new(File.read(layout_fn))
234
- erb.filename = layout_fn
235
- @content_for_layout = erb.result(binding)
246
+ @layouts[format].each { |layout_fn| render_layout!(layout_fn, format) } unless !@layouts[format] || @layouts[format].empty?
236
247
  end
237
248
 
238
249
  # Collect all dependencies.
@@ -259,7 +270,7 @@ module Dokkit
259
270
  def collect_layouts
260
271
  @targets.each_key do |format|
261
272
  @layouts[format] = []
262
-
273
+
263
274
  process_layout_configuration_key(format)
264
275
 
265
276
  @layouts[format].uniq!
@@ -292,7 +303,8 @@ module Dokkit
292
303
  if opts
293
304
  ext = (opts['ext'] if opts.has_key?('ext')) || format_key
294
305
  filters = (opts['filter'] if opts.has_key?('filter')) || DEFAULT_FILTERS_CHAIN['html']
295
- { :target_fn => target_fn(ext.to_sym), 'filter' => filters }
306
+ post_filters = (opts['postfilter'] if opts.has_key?('postfilter')) || DEFAULT_POST_FILTERS_CHAIN['html']
307
+ { :target_fn => target_fn(ext.to_sym), 'filter' => filters, 'postfilter' => post_filters }
296
308
  else
297
309
  @logger.error("You must define format '#{format}'!")
298
310
  end
@@ -366,17 +378,8 @@ module Dokkit
366
378
  end
367
379
 
368
380
  # Apply filters on text to produce the given format.
369
- def apply_filters(text, format)
370
- filters_chain = @targets[format]['filter'] || DEFAULT_FILTERS_CHAIN[format]
371
- filters = []
372
- if filters_chain
373
- filters_chain.each do |filter|
374
- filters << @filter_factory.get(filter)
375
- end
376
- filters.inject(text) { |s, f| f.filter(s) }
377
- else
378
- @logger.error("Don't know how to render '#{source_fn}': cannot find filters for format '#{format}'!")
379
- end
381
+ def apply_filters(text, filters_chain, format)
382
+ filters_chain.collect { |filter| @filter_factory.get(filter, binding) }.inject(text) { |s, f| f.filter(s) }
380
383
  end
381
384
 
382
385
  end
data/lib/dokkit.rb CHANGED
@@ -51,5 +51,5 @@ rescue LoadError
51
51
  end
52
52
 
53
53
  module Dokkit
54
- VERSION = '0.4.0'
54
+ VERSION = '0.4.1'
55
55
  end
@@ -95,6 +95,9 @@ module Dokkit
95
95
  it 'should initialize only one instance of resource factory' do
96
96
  @container.resource_factory.object_id.should == @container.resource_factory.object_id
97
97
  end
98
+ it 'should construct a ERB filter instance through filter factory' do
99
+ @container.filter_factory.get('erb', binding).is_a?(Filter::ERB).should be_true
100
+ end
98
101
  it 'should construct a DeplateHTML filter instance through filter factory' do
99
102
  @container.filter_factory.get('deplate-html').is_a?(Filter::DeplateHTML).should be_true
100
103
  end
@@ -0,0 +1,26 @@
1
+ #
2
+ # File 'erb_spec.rb' created on 23 lug 2008 at 15:38:04.
3
+ # See 'dokkit.rb' or +LICENSE+ for licence information.
4
+ #
5
+ # (c)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
6
+ # #
7
+ # To execute this spec run:
8
+ #
9
+ # spec spec/dokkit/filters/erb_spec.rb
10
+ #
11
+
12
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'../../../lib')))
13
+
14
+ require 'rubygems'
15
+ require 'spec'
16
+ require 'dokkit'
17
+ require 'dokkit/filters/erb'
18
+
19
+ describe Dokkit::Filter::ERB do
20
+ before do
21
+ @erb = Dokkit::Filter::ERB.new(binding)
22
+ end
23
+ it 'should compile an erb template' do
24
+ @erb.filter('<%= "process this" %>').should == "process this"
25
+ end
26
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # File 'tidy_spec.rb' created on 27 lug 2008 at 14:30:55.
3
+ # See 'dokkit.rb' or +LICENSE+ for licence information.
4
+ #
5
+ # (c)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
6
+ #
7
+
8
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'../../../lib')))
9
+
10
+ require 'rubygems'
11
+ require 'spec'
12
+ require 'dokkit'
13
+ require 'dokkit/filters/tidy'
14
+
15
+ INPUT = <<EOI
16
+ <html>
17
+ <body>
18
+ <p>content</p>
19
+ </body>
20
+ </html>
21
+ EOI
22
+
23
+ OUTPUT = <<EOO
24
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
25
+
26
+ <html>
27
+ <head>
28
+ <meta name="generator" content=
29
+ "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">
30
+
31
+ <title></title>
32
+ </head>
33
+
34
+ <body>
35
+ <p>content</p>
36
+ </body>
37
+ </html>
38
+ EOO
39
+
40
+ describe Dokkit::Filter::Tidy do
41
+ before do
42
+ @tidy = Dokkit::Filter::Tidy.new
43
+ end
44
+ it 'should compile an erb template' do
45
+ @tidy.filter(INPUT).should == OUTPUT
46
+ end
47
+ end
48
+
@@ -9,7 +9,6 @@
9
9
  # spec spec/document_spec.rb
10
10
  #
11
11
 
12
-
13
12
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'../../../lib')))
14
13
 
15
14
  require 'rubygems'
@@ -107,17 +106,17 @@ describe Dokkit::Resource::Document, ' when inizialized with document.ext' do
107
106
  @document.target_for(@document.default_format).should == 'output/subdir/document.html'
108
107
  end
109
108
  it 'should have a default filter chain for the default output format' do
110
- @document.filters_for(@document.default_format).should == ['deplate-html']
109
+ @document.filters_for(@document.default_format).should == ['erb', 'deplate-html']
111
110
  end
112
111
  it 'should have a default filter chain for latex output' do
113
- @document.filters_for('latex').should == ['deplate-latex']
112
+ @document.filters_for('latex').should == ['erb', 'deplate-latex']
114
113
  end
115
114
  it 'should have a default filter chain for text output' do
116
- @document.filters_for('text').should == ['deplate-text']
115
+ @document.filters_for('text').should == ['erb', 'deplate-text']
117
116
  end
118
117
  it 'should fail if a filter chain for a given output format was not found' do
119
118
  @logger.should_receive(:error).with(/defined filter/)
120
- @document.filters_for(:'notexists')
119
+ @document.filters_for('notexists')
121
120
  end
122
121
  it 'should return the target filename for the given format' do
123
122
  @document.target_for('html').should == 'output/subdir/document.html'
@@ -148,7 +147,7 @@ describe Dokkit::Resource::Document, ' when inizialized with document.ext' do
148
147
  'doc/pages/COMMON.yaml',
149
148
  'doc/configs/subdir/document.yaml',
150
149
  { 'key_in_header' => 'value in header'}
151
- )
150
+ )
152
151
  end
153
152
  it 'should collect config filenames' do
154
153
  @document.config_fns.should == ['doc/configs/subdir/document.yaml',
@@ -166,12 +165,12 @@ describe Dokkit::Resource::Document, ' when inizialized with document.ext' do
166
165
  end
167
166
  it 'should store the names of its dependencies grouped by format' do
168
167
  @document.deps_for('html').should == ['doc/pages/subdir/document.ext',
169
- 'doc/configs/subdir/document.yaml',
170
- File.expand_path('doc/pages/COMMON.yaml'),
171
- File.expand_path('doc/pages/subdir/COMMON.yaml'),
172
- 'doc/pages/subdir/document.yaml',
173
- 'doc/configs/required.yaml',
174
- 'doc/layouts/subdir/document.html']
168
+ 'doc/configs/subdir/document.yaml',
169
+ File.expand_path('doc/pages/COMMON.yaml'),
170
+ File.expand_path('doc/pages/subdir/COMMON.yaml'),
171
+ 'doc/pages/subdir/document.yaml',
172
+ 'doc/configs/required.yaml',
173
+ 'doc/layouts/subdir/document.html']
175
174
  end
176
175
  it 'should fail if config file doesn''t exist' do
177
176
  @logger.should_receive(:error).with("Configuration file 'notexists' not found for '#{@document.source_fn}'!")
@@ -186,12 +185,17 @@ describe Dokkit::Resource::Document, ' when inizialized with document.ext' do
186
185
  @document.configuration['notexists'].should == @document.default_configuration_value
187
186
  end
188
187
  describe ' and rendered in html' do
189
- it 'should produce html output' do
190
- filter = mock('filter', :filter => '<h1>Title</h1>')
191
- @filter_factory.should_receive(:get).with('deplate-html').and_return(filter)
192
- @document.render.should match(/\<h1\>Title\<\/h1\>/)
188
+ before do
189
+ @filter = mock('filter')
190
+ @filter.stub!(:filter)
191
+ end
192
+ it 'should use erb and deplate-html filters' do
193
+ @filter_factory.should_receive(:get).twice.with('erb', :anything).and_return(@filter)
194
+ @filter_factory.should_receive(:get).with('deplate-html', :anything).and_return(@filter)
195
+ @document.render
193
196
  end
194
197
  end
198
+
195
199
  describe ' and rendered in a unknown format' do
196
200
  it 'should fail if output format doesn''t exist' do
197
201
  @logger.should_receive(:error).with(/format.*is unknown/)
@@ -216,18 +220,19 @@ describe Dokkit::Resource::Document, ' when inizialized with document_with_many_
216
220
  cache,
217
221
  @resource_factory,
218
222
  @filter_factory
219
- )
223
+ )
220
224
  end
221
225
  after(:all) do
222
226
  Dir.chdir(@initial_dir)
223
227
  end
224
228
  it 'should collect all the targets grouped by format' do
225
229
  @document.targets.should == {
226
- # 'html' => { :target_fn => 'output/document_with_many_targets.html' },
230
+ # 'html' => { :target_fn => 'output/document_with_many_targets.html' },
227
231
  'latex' => { :target_fn => 'output/document_with_many_targets.latex' },
228
232
  'text' => { :target_fn => 'output/document_with_many_targets.text' },
229
233
  'custom' => {
230
234
  :target_fn => 'output/document_with_many_targets.html',
235
+ 'postfilter' => ['erb'],
231
236
  'filter' => ['maruku-html']
232
237
  }
233
238
  }
@@ -235,42 +240,48 @@ describe Dokkit::Resource::Document, ' when inizialized with document_with_many_
235
240
  it 'should return filter_chain for custom format' do
236
241
  @document.filters_for('custom').should == ['maruku-html']
237
242
  end
238
- # describe ' and rendered in html format' do
239
- # it 'should produce html output' do
240
- # result = "<h1>Title</h1>"
241
- # filter = mock('filter', :filter => result)
242
- # @filter_factory.should_receive(:get).with('deplate-html').and_return(filter)
243
- # @document.render(:format => 'html').should match(/#{result}/)
244
- # end
245
- # end
243
+ # describe ' and rendered in html format' do
244
+ # it 'should produce html output' do
245
+ # result = "<h1>Title</h1>"
246
+ # filter = mock('filter', :filter => result)
247
+ # @filter_factory.should_receive(:get).with('deplate-html').and_return(filter)
248
+ # @document.render(:format => 'html').should match(/#{result}/)
249
+ # end
250
+ # end
246
251
  describe ' and rendered in latex format' do
247
- it 'should produce latex output' do
248
- result = "\section"
249
- filter = mock('filter', :filter => result)
250
- @filter_factory.should_receive(:get).with('deplate-latex').and_return(filter)
251
- @document.render(:format => 'latex').should match(/#{result}/)
252
+ before do
253
+ @filter = mock('filter')
254
+ @filter.stub!(:filter)
255
+ end
256
+ it 'should use erb and deplate-latex filters' do
257
+ @filter_factory.should_receive(:get).twice.with('erb', :anything).and_return(@filter)
258
+ @filter_factory.should_receive(:get).with('deplate-latex', :anything).and_return(@filter)
259
+ @document.render(:format => 'latex')
252
260
  end
253
261
  end
254
262
  describe ' and rendered in text format' do
255
- it 'should produce text output' do
256
- result = "=====\nTitle\n====="
257
- filter = mock('filter', :filter => result)
258
- @filter_factory.should_receive(:get).with('deplate-text').and_return(filter)
259
- @document.render(:format => 'text').should match(/#{result}/)
263
+ before do
264
+ @filter = mock('filter')
265
+ @filter.stub!(:filter)
266
+ end
267
+ it 'should use erb and deplate-text filters' do
268
+ @filter_factory.should_receive(:get).with('erb', :anything).and_return(@filter)
269
+ @filter_factory.should_receive(:get).with('deplate-text', :anything).and_return(@filter)
270
+ @document.render(:format => 'text')
260
271
  end
261
272
  end
262
273
  describe ' and rendered in custom format' do
263
274
  it 'should produce html output using maruku' do
264
275
  result = "<h1>Title</h1>"
265
276
  filter = mock('filter', :filter => result)
266
- @filter_factory.should_receive(:get).with('maruku-html').and_return(filter)
277
+ @filter_factory.should_receive(:get).with('maruku-html', :anything).and_return(filter)
267
278
  @document.render(:format => 'custom').should match(/#{result}/)
268
279
  end
269
280
  end
270
281
  end
271
282
 
272
283
  describe Dokkit::Resource::Document, ' when inizialized with document_with_nested_layout.ext' do
273
- include SpecHelper::Logger, SpecHelper::Cache, SpecHelper::Configuration, SpecHelper::Resource
284
+ include SpecHelper::Logger, SpecHelper::Cache, SpecHelper::Configuration, SpecHelper::Resource, SpecHelper::Filter
274
285
  before(:all) do
275
286
  @initial_dir = Dir.pwd
276
287
  Dir.chdir(File.join(File.dirname(__FILE__), SpecHelper::Path::TEST_DATA))
@@ -284,7 +295,7 @@ describe Dokkit::Resource::Document, ' when inizialized with document_with_neste
284
295
  cache,
285
296
  @resource_factory,
286
297
  @filter_factory
287
- )
298
+ )
288
299
  end
289
300
  after(:all) do
290
301
  Dir.chdir(@initial_dir)
@@ -294,13 +305,14 @@ describe Dokkit::Resource::Document, ' when inizialized with document_with_neste
294
305
  end
295
306
  describe ' and rendered in html format' do
296
307
  it 'should produce html output using layout chain' do
297
- result = "<p>Some content</p>"
298
- filter = mock('filter', :filter => result)
299
- @filter_factory.should_receive(:get).with('deplate-html').and_return(filter)
308
+ @filter_factory.should_receive(:get).with('erb', :anything).and_return(filter('<p>some content</p>'),
309
+ filter('<div id="nested"><p>some content</p></div>'),
310
+ filter('<html><div id="nested"><p>some content</p></div></html>'))
311
+ @filter_factory.should_receive(:get).with('deplate-html', :anything).and_return(filter('<p>some content</p>'))
300
312
  render_result = @document.render
301
313
  render_result.should match(/\A\<html\>/)
302
314
  render_result.should match(/<div id=\"nested\"\>/)
303
- render_result.should match(/Some content/)
315
+ render_result.should match(/some content/)
304
316
  end
305
317
  end
306
318
  end
@@ -320,7 +332,7 @@ describe Dokkit::Resource::Document, ' when inizialized with document_with_many_
320
332
  cache,
321
333
  @resource_factory,
322
334
  @filter_factory
323
- )
335
+ )
324
336
  end
325
337
  after(:all) do
326
338
  Dir.chdir(@initial_dir)
@@ -470,12 +482,12 @@ describe Dokkit::Resource::Document, ' when render partial' do
470
482
  @resource_factory = resource_factory
471
483
  end
472
484
  before do
473
- # @document = Dokkit::Resource::Document.new('doc/pages/document_with_partial.ext',
474
- # configuration,
475
- # @logger,
476
- # cache,
477
- # @resource_factory,
478
- # @filter_factory)
485
+ # @document = Dokkit::Resource::Document.new('doc/pages/document_with_partial.ext',
486
+ # configuration,
487
+ # @logger,
488
+ # cache,
489
+ # @resource_factory,
490
+ # @filter_factory)
479
491
  end
480
492
  after(:all) do
481
493
  Dir.chdir(@initial_dir)
@@ -483,3 +495,29 @@ describe Dokkit::Resource::Document, ' when render partial' do
483
495
  it 'should instantiate a document object'
484
496
  it 'should cache document'
485
497
  end
498
+
499
+ describe Dokkit::Resource::Document, 'post filtering' do
500
+ include SpecHelper::Logger, SpecHelper::Cache, SpecHelper::Configuration, SpecHelper::Resource
501
+ include SpecHelper::Filter
502
+
503
+ before(:all) do
504
+ @initial_dir = Dir.pwd
505
+ Dir.chdir(File.join(File.dirname(__FILE__), SpecHelper::Path::TEST_DATA))
506
+ end
507
+ after(:all) do
508
+ Dir.chdir(@initial_dir)
509
+ end
510
+ before do
511
+ @filter_factory = filter_factory
512
+ @document = Dokkit::Resource::Document.new('doc/pages/document_with_postfilter.ext',
513
+ configuration,
514
+ logger,
515
+ cache,
516
+ resource_factory,
517
+ @filter_factory)
518
+ end
519
+ it 'should postfilter the document' do
520
+ @filter_factory.should_receive(:get).twice.with('erb', :anything).twice.and_return(filter('filtered output'))
521
+ @document.render
522
+ end
523
+ end
@@ -0,0 +1,10 @@
1
+ ---
2
+ format:
3
+ - html:
4
+ filter:
5
+ - erb
6
+ postfilter:
7
+ - erb
8
+ ---
9
+
10
+ Document body.
data/spec/spec_helper.rb CHANGED
@@ -91,6 +91,11 @@ module SpecHelper
91
91
  :add_dependency => nil)
92
92
  end
93
93
  end
94
+ module Filter
95
+ def filter(output)
96
+ mock('filter', :filter => output)
97
+ end
98
+ end
94
99
  module Configuration
95
100
  def configuration
96
101
  { :document_dir => 'doc/pages',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dokkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Fazzi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-18 00:00:00 +00:00
12
+ date: 2008-07-27 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -68,8 +68,10 @@ files:
68
68
  - lib/dokkit/factory/factory.rb
69
69
  - lib/dokkit/filters.rb
70
70
  - lib/dokkit/filters/deplate.rb
71
+ - lib/dokkit/filters/erb.rb
71
72
  - lib/dokkit/filters/maruku.rb
72
73
  - lib/dokkit/filters/nil.rb
74
+ - lib/dokkit/filters/tidy.rb
73
75
  - lib/dokkit/hash.rb
74
76
  - lib/dokkit/logging.rb
75
77
  - lib/dokkit/logging/logger.rb
@@ -111,8 +113,10 @@ files:
111
113
  - spec/dokkit/environment/test_data/doc/pages/subdir/document_1
112
114
  - spec/dokkit/factory/factory_spec.rb
113
115
  - spec/dokkit/filters/deplate_spec.rb
116
+ - spec/dokkit/filters/erb_spec.rb
114
117
  - spec/dokkit/filters/maruku_spec.rb
115
118
  - spec/dokkit/filters/nil_spec.rb
119
+ - spec/dokkit/filters/tidy_spec.rb
116
120
  - spec/dokkit/hash_spec.rb
117
121
  - spec/dokkit/logging/logger_spec.rb
118
122
  - spec/dokkit/logging/observers/console_spec.rb
@@ -139,6 +143,7 @@ files:
139
143
  - spec/dokkit/resource/test_data/doc/pages/document_with_nil_target.ext
140
144
  - spec/dokkit/resource/test_data/doc/pages/document_with_not_defined_target.ext
141
145
  - spec/dokkit/resource/test_data/doc/pages/document_with_one_target.ext
146
+ - spec/dokkit/resource/test_data/doc/pages/document_with_postfilter.ext
142
147
  - spec/dokkit/resource/test_data/doc/pages/subdir/COMMON.yaml
143
148
  - spec/dokkit/resource/test_data/doc/pages/subdir/document.ext
144
149
  - spec/dokkit/resource/test_data/doc/pages/subdir/document.yaml