gumdrop 0.6.3 → 0.6.4

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.
data/ChangeLog.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v0.6.4
2
+ - Callbacks are cleared on each `Site#rescan()` to prevent duplicates.
3
+ - Callback blocks are called with `site` as the parameter.
4
+ - Added `Gumdrop.change_log`.
5
+ - Added on_before* event for scan, generate, and render.
6
+
1
7
  # v0.6.3
2
8
  - Added `generated` flag to Content object
3
9
  - Added `config` to Generator context
@@ -9,12 +9,15 @@ module Gumdrop
9
9
  if block
10
10
  @_#{name} = [] if @_#{name}.nil?
11
11
  @_#{name} << block
12
- elsif @_#{name}
12
+ elsif @_#{name} and !@_#{name}.nil?
13
13
  @_#{name}.each do |cb|
14
14
  cb.call(*args)
15
15
  end
16
16
  end
17
17
  end
18
+ def clear_#{name}()
19
+ @_#{name} = nil
20
+ end
18
21
  EOF
19
22
  end
20
23
  end
@@ -46,7 +46,6 @@ module Gumdrop
46
46
  context.reset_data 'current_depth'=>@level, 'current_slug'=>@slug, 'page'=>self, 'layout'=>default_layout, 'params'=>self.params
47
47
  end
48
48
  context.set_content self, locals
49
- @site.report " Rendering: #{@uri}", :warning
50
49
  content= @template.render(context)
51
50
  return content if ignore_layout
52
51
  layout= context.get_template()
@@ -59,7 +58,7 @@ module Gumdrop
59
58
 
60
59
  def renderTo(context, output_path, filters=[], opts={})
61
60
  return copyTo(output_path, opts) unless useLayout?
62
- # @site.report " Rendering: #{@uri}", :warning
61
+ @site.report " Rendering: #{@uri}", :warning
63
62
  output= render(context)
64
63
  filters.each {|f| output= f.call(output, self) }
65
64
  File.open output_path, 'w' do |f|
@@ -93,6 +92,10 @@ module Gumdrop
93
92
  def useLayout?
94
93
  !@template.nil?
95
94
  end
95
+
96
+ def ignore?
97
+ @ignored
98
+ end
96
99
 
97
100
  def to_s
98
101
  @uri
data/lib/gumdrop/site.rb CHANGED
@@ -36,8 +36,11 @@ module Gumdrop
36
36
  extend Callbacks
37
37
 
38
38
  callbacks :on_start,
39
+ :on_before_scan,
39
40
  :on_scan,
41
+ :on_before_generate,
40
42
  :on_generate,
43
+ :on_before_render,
41
44
  :on_render,
42
45
  :on_end
43
46
 
@@ -49,7 +52,9 @@ module Gumdrop
49
52
  reset_all()
50
53
  end
51
54
 
52
- def contents(pattern=nil, opts={})
55
+ def contents(*args)
56
+ opts= args.extract_options!
57
+ pattern= args[0] || nil
53
58
  if pattern.nil?
54
59
  if opts[:as] == :hash
55
60
  @node_tree
@@ -71,29 +76,22 @@ module Gumdrop
71
76
  end
72
77
  end
73
78
 
74
- def scan
75
- build_tree()
76
- on_scan()
77
- run_generators()
78
- on_generate()
79
- @last_run= Time.now
80
- self
81
- end
82
-
83
79
  def rescan
80
+ on_start(self)
84
81
  reset_all()
85
82
  scan()
86
83
  @last_run= Time.now
84
+ # TODO: should on_before_render and on_render be called for rescan()?
85
+ on_end(self)
87
86
  self
88
87
  end
89
88
 
90
89
  def build
91
- on_start()
90
+ on_start(self)
92
91
  scan()
93
92
  render()
94
- on_render()
95
93
  @last_run= Time.now
96
- on_end()
94
+ on_end(self)
97
95
  self
98
96
  end
99
97
 
@@ -119,6 +117,13 @@ module Gumdrop
119
117
 
120
118
  private
121
119
 
120
+ def scan
121
+ build_tree()
122
+ run_generators()
123
+ self
124
+ end
125
+
126
+
122
127
  def reset_all
123
128
  @content_filters = []
124
129
  @blacklist = []
@@ -132,6 +137,15 @@ module Gumdrop
132
137
 
133
138
  @config = Gumdrop::Config.new DEFAULT_OPTIONS
134
139
 
140
+ clear_on_start()
141
+ clear_on_before_scan()
142
+ clear_on_scan()
143
+ clear_on_before_generate()
144
+ clear_on_generate()
145
+ clear_on_before_render()
146
+ clear_on_render()
147
+ clear_on_end()
148
+
135
149
  load_sitefile()
136
150
 
137
151
  @data_path = get_expanded_path(@config.data_dir)
@@ -148,6 +162,7 @@ module Gumdrop
148
162
  @log = Logger.new @config.log, 'daily'
149
163
  rescue
150
164
  @log = Logger.new STDOUT
165
+ report "Using STDOUT for logging because of exception: #{ $! }"
151
166
  end
152
167
  @log.formatter = proc do |severity, datetime, progname, msg|
153
168
  "#{datetime}: #{msg}\n"
@@ -164,13 +179,14 @@ module Gumdrop
164
179
 
165
180
  def load_sitefile
166
181
  source= File.read( @sitefile )
167
- dsl = SitefileDSL.new self
182
+ dsl = Sitefile.new self
168
183
  dsl.instance_eval source
169
184
  dsl
170
185
  end
171
186
 
172
187
  def build_tree
173
188
  report "[Scanning from #{src_path}]", :info
189
+ on_before_scan(self)
174
190
  # Report blacklists and greylists
175
191
  blacklist.each do |path|
176
192
  report " blacklist: #{path}", :info
@@ -178,7 +194,6 @@ module Gumdrop
178
194
  greylist.each do |path|
179
195
  report " greylist: #{path}", :info
180
196
  end
181
-
182
197
  # Scan Filesystem
183
198
  Dir.glob("#{src_path}/**/*", File::FNM_DOTMATCH).each do |path|
184
199
  unless File.directory? path or @config.ignore.include?( File.basename(path) )
@@ -209,21 +224,25 @@ module Gumdrop
209
224
  end
210
225
  end
211
226
  end
227
+ on_scan(self)
212
228
  end
213
229
 
214
230
  def run_generators
215
231
  report "[Executing Generators]", :info
232
+ on_before_generate(self)
216
233
  generators.each_pair do |path, generator|
217
234
  generator.execute()
218
235
  end
236
+ on_generate(self)
219
237
  end
220
238
 
221
239
  def render
222
240
  unless opts[:dry_run]
223
241
  report "[Compiling to #{@out_path}]", :info
242
+ on_before_render(self)
224
243
  @node_tree.keys.sort.each do |path|
225
244
  node= @node_tree[path]
226
- unless node.ignored
245
+ unless node.ignore?
227
246
  output_path= File.join(@out_path, node.to_s)
228
247
  FileUtils.mkdir_p File.dirname(output_path)
229
248
  node.renderTo render_context, output_path, content_filters
@@ -231,6 +250,7 @@ module Gumdrop
231
250
  report " -ignoring: #{node.to_s}", :info
232
251
  end
233
252
  end
253
+ on_render(self)
234
254
  end
235
255
  end
236
256
 
@@ -240,7 +260,7 @@ module Gumdrop
240
260
  end
241
261
  end
242
262
 
243
- class SitefileDSL
263
+ class Sitefile
244
264
 
245
265
  def initialize(site)
246
266
  @site= site
@@ -282,12 +302,21 @@ module Gumdrop
282
302
  def on_start(&block)
283
303
  @site.on_start &block
284
304
  end
305
+ def on_before_scan(&block)
306
+ @site.on_before_scan &block
307
+ end
285
308
  def on_scan(&block)
286
309
  @site.on_scan &block
287
310
  end
311
+ def on_before_generate(&block)
312
+ @site.on_before_generate &block
313
+ end
288
314
  def on_generate(&block)
289
315
  @site.on_generate &block
290
316
  end
317
+ def on_before_render(&block)
318
+ @site.on_before_render &block
319
+ end
291
320
  def on_render(&block)
292
321
  @site.on_render &block
293
322
  end
@@ -1,5 +1,5 @@
1
1
  module Gumdrop
2
2
 
3
- VERSION = "0.6.3" unless defined?(::Gumdrop::VERSION)
3
+ VERSION = "0.6.4" unless defined?(::Gumdrop::VERSION)
4
4
 
5
5
  end
data/lib/gumdrop.rb CHANGED
@@ -59,6 +59,11 @@ module Gumdrop
59
59
  File.dirname( fetch_site_file( filename ) )
60
60
  end
61
61
 
62
+ def change_log
63
+ here= File.dirname(__FILE__)
64
+ File.read File.join(here, "../ChangeLog.md")
65
+ end
66
+
62
67
  end
63
68
 
64
69
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 3
9
- version: 0.6.3
8
+ - 4
9
+ version: 0.6.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matt McCray