awestruct 0.2.18 → 0.4.2.x1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/bin/awestruct +2 -274
  2. data/lib/awestruct/astruct.rb +22 -0
  3. data/lib/awestruct/astruct_mixin.rb +81 -0
  4. data/lib/awestruct/cli/auto.rb +34 -0
  5. data/lib/awestruct/cli/deploy.rb +38 -0
  6. data/lib/awestruct/{commands → cli}/generate.rb +3 -3
  7. data/lib/awestruct/cli/invoker.rb +120 -0
  8. data/lib/awestruct/cli/options.rb +116 -0
  9. data/lib/awestruct/{commands → cli}/server.rb +1 -1
  10. data/lib/awestruct/config.rb +20 -8
  11. data/lib/awestruct/context.rb +22 -0
  12. data/lib/awestruct/dependencies.rb +102 -0
  13. data/lib/awestruct/deploy/github_pages_deploy.rb +61 -0
  14. data/lib/awestruct/{commands/deploy.rb → deploy/rsync_deploy.rb} +10 -6
  15. data/lib/awestruct/deployers.rb +15 -0
  16. data/lib/awestruct/engine.rb +172 -411
  17. data/lib/awestruct/extensions/atomizer.rb +7 -4
  18. data/lib/awestruct/extensions/coffeescripttransform.rb +42 -0
  19. data/lib/awestruct/extensions/minify.rb +21 -23
  20. data/lib/awestruct/extensions/paginator.rb +6 -4
  21. data/lib/awestruct/extensions/partial.rb +0 -1
  22. data/lib/awestruct/extensions/pipeline.rb +5 -0
  23. data/lib/awestruct/extensions/posts.rb +11 -9
  24. data/lib/awestruct/extensions/sitemap.rb +2 -1
  25. data/lib/awestruct/extensions/tagger.rb +0 -2
  26. data/lib/awestruct/extensions/template.atom.haml +4 -3
  27. data/lib/awestruct/handler_chain.rb +28 -0
  28. data/lib/awestruct/handler_chains.rb +48 -0
  29. data/lib/awestruct/handlers/asciidoc_handler.rb +57 -0
  30. data/lib/awestruct/handlers/base_handler.rb +111 -0
  31. data/lib/awestruct/handlers/base_sass_handler.rb +42 -0
  32. data/lib/awestruct/handlers/coffeescript_handler.rb +48 -0
  33. data/lib/awestruct/handlers/erb_handler.rb +44 -0
  34. data/lib/awestruct/handlers/file_handler.rb +64 -0
  35. data/lib/awestruct/handlers/front_matter_handler.rb +85 -0
  36. data/lib/awestruct/handlers/haml_handler.rb +54 -0
  37. data/lib/awestruct/handlers/interpolation_handler.rb +28 -0
  38. data/lib/awestruct/handlers/layout_handler.rb +63 -0
  39. data/lib/awestruct/handlers/markdown_handler.rb +50 -0
  40. data/lib/awestruct/handlers/no_op_handler.rb +34 -0
  41. data/lib/awestruct/handlers/orgmode_handler.rb +48 -0
  42. data/lib/awestruct/handlers/page_delegating_handler.rb +54 -0
  43. data/lib/awestruct/handlers/restructuredtext_handler.rb +67 -0
  44. data/lib/awestruct/handlers/sass_handler.rb +21 -0
  45. data/lib/awestruct/handlers/scss_handler.rb +21 -0
  46. data/lib/awestruct/handlers/string_handler.rb +29 -0
  47. data/lib/awestruct/handlers/textile_handler.rb +58 -0
  48. data/lib/awestruct/handlers/yaml_handler.rb +25 -0
  49. data/lib/awestruct/layouts.rb +16 -0
  50. data/lib/awestruct/page.rb +141 -0
  51. data/lib/awestruct/page_loader.rb +82 -0
  52. data/lib/awestruct/pipeline.rb +56 -0
  53. data/lib/awestruct/site.rb +29 -35
  54. data/lib/awestruct/version.rb +1 -1
  55. data/lib/guard/awestruct.rb +38 -0
  56. metadata +115 -88
  57. data/lib/awestruct.rb +0 -2
  58. data/lib/awestruct/asciidoc_file.rb +0 -24
  59. data/lib/awestruct/asciidocable.rb +0 -35
  60. data/lib/awestruct/commands/frameworks/960/base_layout.html.haml +0 -10
  61. data/lib/awestruct/commands/frameworks/base_index.html.haml +0 -5
  62. data/lib/awestruct/commands/frameworks/base_pipeline.rb +0 -6
  63. data/lib/awestruct/commands/frameworks/blueprint/base_layout.html.haml +0 -12
  64. data/lib/awestruct/commands/frameworks/bootstrap/base_index.html.haml +0 -27
  65. data/lib/awestruct/commands/frameworks/bootstrap/base_layout.html.haml +0 -29
  66. data/lib/awestruct/commands/git_hub_pages.rb +0 -55
  67. data/lib/awestruct/commands/init.rb +0 -40
  68. data/lib/awestruct/commands/manifest.rb +0 -205
  69. data/lib/awestruct/erb_file.rb +0 -24
  70. data/lib/awestruct/erbable.rb +0 -19
  71. data/lib/awestruct/front_matter_file.rb +0 -54
  72. data/lib/awestruct/haml/filters/asciidoc.rb +0 -8
  73. data/lib/awestruct/haml_file.rb +0 -27
  74. data/lib/awestruct/hamlable.rb +0 -19
  75. data/lib/awestruct/markdown_file.rb +0 -23
  76. data/lib/awestruct/markdownable.rb +0 -18
  77. data/lib/awestruct/orgmode_file.rb +0 -23
  78. data/lib/awestruct/orgmodeable.rb +0 -15
  79. data/lib/awestruct/renderable.rb +0 -18
  80. data/lib/awestruct/renderable_file.rb +0 -39
  81. data/lib/awestruct/restructuredtext_file.rb +0 -23
  82. data/lib/awestruct/restructuredtextable.rb +0 -38
  83. data/lib/awestruct/sass_file.rb +0 -24
  84. data/lib/awestruct/sassable.rb +0 -33
  85. data/lib/awestruct/scss_file.rb +0 -24
  86. data/lib/awestruct/textilable.rb +0 -22
  87. data/lib/awestruct/textile_file.rb +0 -23
  88. data/lib/awestruct/verbatim_file.rb +0 -12
@@ -1,13 +1,15 @@
1
+ require 'awestruct/deployers'
2
+
1
3
  require 'open3'
2
4
 
3
5
  module Awestruct
4
- module Commands
6
+ module Deploy
7
+ class RSyncDeploy
5
8
 
6
- class Deploy
7
- def initialize(site_path, opts)
8
- @site_path = File.join( site_path, '/' )
9
- @host = opts['host']
10
- @path = File.join( opts['path'], '/' )
9
+ def initialize(site_config, deploy_config)
10
+ @site_path = File.join( site_config.output_dir, '/' )
11
+ @host = deploy_config['host']
12
+ @path = File.join( deploy_config['path'], '/' )
11
13
  end
12
14
 
13
15
  def run
@@ -45,3 +47,5 @@ module Awestruct
45
47
  end
46
48
  end
47
49
  end
50
+
51
+ Awestruct::Deployers.instance[ :rsync ] = Awestruct::Deploy::RSyncDeploy
@@ -0,0 +1,15 @@
1
+
2
+ module Awestruct
3
+
4
+ class Deployers < Hash
5
+ def self.instance
6
+ @instance ||= Deployers.new
7
+ end
8
+
9
+ def self.register( key, cls )
10
+ Deployers.instance[ key.to_sym ] = cls
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -1,222 +1,85 @@
1
- require 'ostruct'
2
- require 'find'
3
- require 'compass'
4
- require 'ninesixty'
5
- require 'bootstrap-sass'
6
- require 'time'
7
- require 'notifier'
8
-
9
- require 'hashery/opencascade'
1
+ require 'awestruct/util/inflector'
2
+ require 'awestruct/util/default_inflections'
10
3
 
11
4
  require 'awestruct/config'
12
5
  require 'awestruct/site'
13
- require 'awestruct/haml_file'
14
- require 'awestruct/erb_file'
15
- require 'awestruct/textile_file'
16
- require 'awestruct/markdown_file'
17
- require 'awestruct/asciidoc_file'
18
- require 'awestruct/sass_file'
19
- require 'awestruct/scss_file'
20
- require 'awestruct/orgmode_file'
21
- require 'awestruct/verbatim_file'
22
- require 'awestruct/restructuredtext_file'
23
-
24
- require 'awestruct/context_helper'
6
+ require 'awestruct/pipeline'
7
+ require 'awestruct/page'
8
+ require 'awestruct/page_loader'
25
9
 
26
10
  require 'awestruct/extensions/pipeline'
27
- require 'awestruct/extensions/posts'
28
- require 'awestruct/extensions/indexifier'
29
- require 'awestruct/extensions/data_dir'
30
- require 'awestruct/extensions/paginator'
31
- require 'awestruct/extensions/atomizer'
32
- require 'awestruct/extensions/tagger'
33
- require 'awestruct/extensions/tag_cloud'
34
- require 'awestruct/extensions/intense_debate'
35
- require 'awestruct/extensions/disqus'
36
- require 'awestruct/extensions/flattr'
37
- require 'awestruct/extensions/google_analytics'
38
- require 'awestruct/extensions/partial'
39
- require 'awestruct/extensions/sitemap'
40
- require 'awestruct/extensions/cachebuster'
41
- require 'awestruct/extensions/obfuscate'
42
- require 'awestruct/extensions/relative'
43
- require 'awestruct/extensions/assets'
44
- require 'awestruct/extensions/minify'
45
11
 
46
- require 'awestruct/util/inflector'
47
- require 'awestruct/util/default_inflections'
12
+ require 'fileutils'
13
+ require 'set'
14
+
15
+ class OpenStruct
16
+ def inspect
17
+ "OpenStruct{...}"
18
+ end
19
+ end
48
20
 
49
21
  module Awestruct
50
22
 
51
23
  class Engine
52
24
 
53
- attr_reader :config
54
- attr_reader :dir
55
25
  attr_reader :site
26
+ attr_reader :pipeline
56
27
 
57
- def initialize(config)
58
- @dir = config.input_dir
59
- @config = config
60
-
61
- @site = Site.new( config )
62
- @site.engine = self
28
+ def self.instance
29
+ @instance
30
+ end
63
31
 
64
- @helpers = []
65
- @max_site_mtime = nil
66
- adjust_load_path
32
+ def self.instance=(engine)
33
+ @instance = engine
67
34
  end
68
35
 
69
- def skin_dir
70
- @site.skin_dir
36
+ def initialize(config=Awestruct::Config.new)
37
+ Engine.instance = self
38
+ @site = Site.new( self, config)
39
+ @pipeline = Pipeline.new
40
+ @site_page_loader = PageLoader.new( @site )
41
+ @layout_page_loader = PageLoader.new( @site, :layouts )
71
42
  end
72
43
 
73
44
  def config
74
- @config
45
+ site.config
75
46
  end
76
47
 
77
- def generate(profile=nil, base_url=nil, default_base_url=nil, force=false)
78
- @base_url = base_url
79
- @default_base_url = default_base_url
80
- @max_site_mtime = nil
48
+ def run(profile, base_url, default_base_url, force=false)
49
+ adjust_load_path
81
50
  load_site_yaml(profile)
51
+ set_base_url( base_url, default_base_url )
82
52
  load_yamls
83
- set_base_url
84
- load_layouts
53
+ load_pipeline
85
54
  load_pages
86
- load_extensions
87
- set_urls(site.pages)
55
+ execute_pipeline
88
56
  configure_compass
89
- generate_files(force)
90
- end
91
-
92
- def find_and_load_site_page(simple_path)
93
- path_glob = File.join( config.input_dir, simple_path + '.*' )
94
- candidates = Dir[ path_glob ]
95
- return nil if candidates.empty?
96
- throw Exception.new( "too many choices for #{simple_path}" ) if candidates.size != 1
97
- dir_pathname = Pathname.new( dir )
98
- path_name = Pathname.new( candidates[0] )
99
- relative_path = path_name.relative_path_from( dir_pathname ).to_s
100
- load_page( candidates[0], :relative_path => relative_path )
101
- end
102
-
103
- def load_site_page(relative_path)
104
- load_page( File.join( dir, relative_path ) )
57
+ set_urls( site.pages )
58
+ build_page_index
59
+ generate_output
105
60
  end
106
61
 
107
- def load_page(path, options = {})
108
- page = nil
109
- if ( options[:relative_path].nil? )
110
- #dir_pathname = Pathname.new( dir )
111
- #path_name = Pathname.new( path )
112
- #relative_path = path_name.relative_path_from( dir_pathname ).to_s
113
- end
114
-
115
- fixed_relative_path = ( options[:relative_path].nil? ? nil : File.join( '', options[:relative_path] ) )
116
-
117
- if ( path =~ /\.haml$/ )
118
- page = HamlFile.new( site, path, fixed_relative_path, options )
119
- elsif ( path =~ /\.erb$/ )
120
- page = ErbFile.new( site, path, fixed_relative_path, options )
121
- elsif ( path =~ /\.textile$/ )
122
- page = TextileFile.new( site, path, fixed_relative_path, options )
123
- elsif ( path =~ /\.md$/ )
124
- page = MarkdownFile.new( site, path, fixed_relative_path, options )
125
- elsif ( path =~ /\.(asciidoc|adoc)$/ )
126
- page = AsciiDocFile.new( site, path, fixed_relative_path, options )
127
- elsif ( path =~ /\.sass$/ )
128
- page = SassFile.new( site, path, fixed_relative_path, options )
129
- elsif ( path =~ /\.scss$/ )
130
- page = ScssFile.new( site, path, fixed_relative_path, options )
131
- elsif ( path =~ /\.org$/ )
132
- page = OrgmodeFile.new( site, path, fixed_relative_path, options )
133
- elsif ( path =~ /\.rst$/ )
134
- page = ReStructuredTextFile.new( site, path, fixed_relative_path, options )
135
- elsif ( File.file?( path ) )
136
- page = VerbatimFile.new( site, path, fixed_relative_path, options )
137
- end
138
- page
139
- end
140
-
141
- def create_context(page, content='')
142
- context = OpenStruct.new( :site=>site, :content=>content )
143
- context.extend( Awestruct::ContextHelper )
144
- @helpers.each do |h|
145
- context.extend( h )
146
- end
147
- context.page = page
148
- class << context
149
- def interpolate_string(str)
150
- if site.interpolate
151
- str = str || ''
152
- str = str.gsub( /\\/, '\\\\\\\\' )
153
- str = str.gsub( /\\\\#/, '\\#' )
154
- str = str.gsub( '@', '\@' )
155
- str = "%@#{str}@"
156
- result = instance_eval( str )
157
- result
158
- else
159
- str || ''
160
- end
161
- end
162
- def evaluate_erb(erb)
163
- erb.result( binding )
62
+ def build_page_index
63
+ site.pages_by_relative_source_path = {}
64
+ site.pages.each do |p|
65
+ if ( p.relative_source_path )
66
+ site.pages_by_relative_source_path[ p.relative_source_path ] = p
164
67
  end
165
68
  end
166
- context
167
- end
168
-
169
- def set_urls(pages)
170
- pages.each do |page|
171
- page_path = page.output_path
172
- if ( page_path =~ /^\// )
173
- page.url = page_path
174
- else
175
- page.url = "/#{page_path}"
176
- end
177
- if ( page.url =~ /^(.*\/)index.html$/ )
178
- page.url = $1
179
- end
180
- end
181
- end
182
-
183
- private
184
-
185
- def adjust_load_path
186
- ext_dir = File.join( config.extension_dir )
187
- if ( $LOAD_PATH.index( ext_dir ).nil? )
188
- $LOAD_PATH << ext_dir
189
- end
190
- if ( skin_dir )
191
- skin_ext_dir = File.join( skin_dir, config.extension_dir )
192
- if ( $LOAD_PATH.index( skin_ext_dir ).nil? )
193
- $LOAD_PATH << skin_ext_dir
69
+ site.layouts.each do |p|
70
+ if ( p.relative_source_path )
71
+ site.pages_by_relative_source_path[ p.relative_source_path ] = p
194
72
  end
195
73
  end
196
74
  end
197
75
 
198
- def configure_compass
199
- Compass.configuration.project_type = :standalone
200
- Compass.configuration.project_path = dir
201
- Compass.configuration.sass_dir = 'stylesheets'
202
-
203
- site.images_dir = File.join( config.output_dir, 'images' )
204
- site.stylesheets_dir = File.join( config.output_dir, 'stylesheets' )
205
- site.javascripts_dir = File.join( config.output_dir, 'javascripts' )
206
-
207
- Compass.configuration.css_dir = site.css_dir
208
- Compass.configuration.javascripts_dir = 'javascripts'
209
- Compass.configuration.images_dir = 'images'
210
-
211
- end
212
-
213
- def set_base_url
214
- if ( @base_url )
215
- site.base_url = @base_url
76
+ def set_base_url(base_url, default_base_url)
77
+ if ( base_url )
78
+ site.base_url = base_url
216
79
  end
217
80
 
218
81
  if ( site.base_url.nil? )
219
- site.base_url = @default_base_url
82
+ site.base_url = default_base_url
220
83
  end
221
84
 
222
85
  if ( site.base_url )
@@ -226,114 +89,9 @@ module Awestruct
226
89
  end
227
90
  end
228
91
 
229
- def generate_files(force)
230
- site.pages.each do |page|
231
- begin
232
- generate_page( page, force )
233
- rescue Exception => e
234
- Notifier.notify(:title=>"Error generating page #{page.name}", :message=>e.to_s)
235
- puts "Cannot render page #{page.source_path}. #{e.to_s}"
236
- end
237
- end
238
- end
239
-
240
- def generate_page(page, force)
241
- return unless requires_generation?(page, force)
242
-
243
- generated_path = File.join( config.output_dir, page.output_path )
244
- $stderr.puts "rendering #{page.source_path} -> #{page.output_path}"
245
- rendered = render_page(page, true)
246
- FileUtils.mkdir_p( File.dirname( generated_path ) )
247
- File.open( generated_path, 'w' ) do |file|
248
- file << rendered
249
- end
250
- end
251
-
252
- def requires_generation?(page, force)
253
- return true if force
254
- generated_path = File.join( config.output_dir, page.output_path )
255
- return true unless File.exist?( generated_path )
256
- now = Time.now
257
- generated_mtime = File.mtime( generated_path )
258
- return true if ( ( @max_site_mtime || Time.at(0) ) > generated_mtime )
259
-
260
- while true
261
- now = Time.now
262
- source_mtime = File.mtime( page.source_path )
263
- if ( now - source_mtime > 1 )
264
- if ( source_mtime - generated_mtime >= 0 )
265
- return true
266
- else
267
- break
268
- end
269
- end
270
- sleep 0.1
271
- end
272
-
273
- ext = page.output_extension
274
- layout_name = page.layout
275
- while ( ! layout_name.nil? )
276
- layout = site.layouts[ layout_name + ext ]
277
- if ( layout )
278
- layout_mtime = File.mtime( layout.source_path )
279
- return true if layout_mtime > generated_mtime
280
- layout_name = layout.layout
281
- else
282
- return false
283
- end
284
- end
285
- false
286
- end
287
-
288
- def render_page(page, with_layouts=true)
289
- context = create_context( page )
290
- rendered = page.render( context )
291
- if ( with_layouts )
292
- cur = page
293
- while ( ! cur.nil? && ! cur.layout.nil? )
294
- layout_name = cur.layout.to_s + page.output_extension
295
- cur = site.layouts[ layout_name ]
296
- if ! cur.nil?
297
- context.content = rendered.to_s
298
- rendered = cur.render( context )
299
- end
300
- end
301
- end
302
- @transformers.each do |transformer|
303
- rendered = transformer.transform(site, page, rendered)
304
- end if @transformers
305
- rendered
306
- end
307
-
308
- def load_layouts
309
- site.layouts.clear
310
- dir_pathname = Pathname.new( dir )
311
- Dir[ File.join( config.layouts_dir, '*.haml' ) ].each do |layout_path|
312
- layout_pathname = Pathname.new( layout_path )
313
- relative_path = layout_pathname.relative_path_from( dir_pathname ).to_s
314
- name = File.basename( layout_path, '.haml' )
315
- site.layouts[ name ] = load_page( layout_path, :relative_path => relative_path )
316
- end
317
- if ( skin_dir )
318
- skin_dir_pathname = Pathname.new( skin_dir )
319
- Dir[ File.join( skin_dir, config.layouts_dir, '*.haml' ) ].each do |layout_path|
320
- layout_pathname = Pathname.new( layout_path )
321
- relative_path = layout_pathname.relative_path_from( skin_dir_pathname ).to_s
322
- name = File.basename( layout_path, '.haml' )
323
- unless ( site.layouts.key?( name ) )
324
- site.layouts[ name ] = load_page( layout_path, :relative_path => relative_path )
325
- end
326
- end
327
- end
328
- end
329
-
330
92
  def load_site_yaml(profile)
331
- site_yaml = File.join( config.config_dir, 'site.yml' )
93
+ site_yaml = File.join( site.config.config_dir, 'site.yml' )
332
94
  if ( File.exist?( site_yaml ) )
333
- mtime = File.mtime( site_yaml )
334
- if ( mtime > ( @max_site_mtime || Time.at(0) ) )
335
- @max_site_mtime = mtime
336
- end
337
95
  data = YAML.load( File.read( site_yaml ) )
338
96
  site.interpolate = true
339
97
  profile_data = {}
@@ -353,85 +111,17 @@ module Awestruct
353
111
  end
354
112
 
355
113
  def load_yamls
356
- Dir[ File.join( config.config_dir, '*.yml' ) ].each do |yaml_path|
114
+ Dir[ File.join( site.config.config_dir, '*.yml' ) ].each do |yaml_path|
357
115
  load_yaml( yaml_path ) unless ( File.basename( yaml_path ) == 'site.yml' )
358
116
  end
359
117
  end
360
118
 
361
119
  def load_yaml(yaml_path)
362
- mtime = File.mtime( yaml_path )
363
- if ( mtime > ( @max_site_mtime || Time.at(0) ) )
364
- @max_site_mtime = mtime
365
- end
366
120
  data = YAML.load( File.read( yaml_path ) )
367
121
  name = File.basename( yaml_path, '.yml' )
368
122
  site.send( "#{name}=", massage_yaml( data ) )
369
123
  end
370
124
 
371
- def inherit_front_matter( page )
372
- layout = page.layout
373
- while ( layout )
374
- layout_name = layout.to_s + page.output_extension
375
- current = site.layouts[ layout_name ]
376
- raise "Unknown layout '#{layout_name}' #{site.layouts.keys} for page #{page}" if current == nil
377
- current.front_matter.each { |k,v| page.send( "#{k}=", v ) unless page.send( "#{k}" ) } if current
378
- layout = current.layout
379
- end
380
- end
381
-
382
- def load_pages()
383
- visited_pages = {}
384
- dir_pathname = Pathname.new( dir )
385
- Find.find( dir ) do |path|
386
- next if path == dir
387
- basename = File.basename( path )
388
- if ( basename == '.htaccess' )
389
- #special case
390
- elsif ( basename =~ /^[_.]/ )
391
- Find.prune
392
- next
393
- end
394
- file_pathname = Pathname.new( path )
395
- relative_path = file_pathname.relative_path_from( dir_pathname ).to_s
396
- if config.ignore.include?(relative_path)
397
- Find.prune
398
- next
399
- end
400
- page = load_page( path, :relative_path => relative_path )
401
- if ( page )
402
- inherit_front_matter( page )
403
- visited_pages[ path ] = page
404
- end
405
- end
406
-
407
- if ( skin_dir )
408
- skin_dir_pathname = Pathname( skin_dir )
409
- Find.find( skin_dir ) do |path|
410
- next if path == skin_dir
411
- basename = File.basename( path )
412
- if ( basename == '.htaccess' )
413
- #special case
414
- elsif ( basename =~ /^[_.]/ )
415
- Find.prune
416
- next
417
- end
418
- file_pathname = Pathname.new( path )
419
- relative_path = file_pathname.relative_path_from( skin_dir_pathname ).to_s
420
- if config.ignore.include?(relative_path)
421
- Find.prune
422
- next
423
- end
424
- page = load_page( path, :relative_path => relative_path )
425
- if ( page )
426
- inherit_front_matter( page )
427
- visited_pages[ path ] = page
428
- end
429
- end
430
- end
431
-
432
- site.pages = visited_pages.values
433
- end
434
-
435
125
  def massage_yaml(obj)
436
126
  result = obj
437
127
  case ( obj )
@@ -440,7 +130,7 @@ module Awestruct
440
130
  obj.each do |k,v|
441
131
  result[k] = massage_yaml(v)
442
132
  end
443
- result = OpenCascade.new(result.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo })
133
+ result = AStruct.new( result ).cascade_for_nils!
444
134
  when Array
445
135
  result = []
446
136
  obj.each do |v|
@@ -450,78 +140,149 @@ module Awestruct
450
140
  result
451
141
  end
452
142
 
453
- def load_extensions
454
- watched_dirs = []
455
- pipeline = nil
456
- skin_pipeline = nil
457
-
458
- ext_dir = File.join( config.extension_dir )
459
- pipeline_file = File.join( ext_dir, 'pipeline.rb' )
460
- if ( File.exists?( pipeline_file ) )
461
- pipeline = eval(File.read( pipeline_file ), nil, pipeline_file, 1)
462
- @helpers = pipeline.helpers || []
463
- @transformers = pipeline.transformers || []
464
- watched_dirs << ext_dir.to_s
143
+ def adjust_load_path
144
+ ext_dir = File.join( site.config.extension_dir )
145
+ if ( $LOAD_PATH.index( ext_dir ).nil? )
146
+ $LOAD_PATH << ext_dir
465
147
  end
148
+ end
466
149
 
467
- if ( skin_dir )
468
- skin_ext_dir = File.join( skin_dir, config.extension_dir.sub(/^#{Dir.pwd}/, "") )
469
- if ( $LOAD_PATH.index( skin_ext_dir ).nil? )
470
- $LOAD_PATH << skin_ext_dir
150
+ def set_urls(pages)
151
+ pages.each do |page|
152
+ #puts "relative_source_path #{page.relative_source_path}"
153
+ page_path = page.output_path
154
+ if ( page_path =~ /^\// )
155
+ page.url = page_path
156
+ else
157
+ page.url = "/#{page_path}"
471
158
  end
472
- skin_pipeline_file = File.join( skin_ext_dir, 'pipeline.rb' )
473
- if ( File.exists?( skin_pipeline_file ) )
474
- skin_pipeline = eval(File.read( skin_pipeline_file ), nil, skin_pipeline_file, 1)
475
- @helpers = ( @helpers + skin_pipeline.helpers || [] ).flatten
476
- @transformers = ( @transformers + skin_pipeline.transformers || [] ).flatten
477
- watched_dirs << skin_dir.to_s
159
+ if ( page.url =~ /^(.*\/)index.html$/ )
160
+ page.url = $1
478
161
  end
479
162
  end
163
+ end
480
164
 
481
- #if _partials directory (from Partial helper) is present, watch
482
- partials = File.join( '_partials' )
483
- if ( File.exists?( partials ) )
484
- watched_dirs << partials
165
+ def load_pipeline
166
+ ext_dir = File.join( site.config.extension_dir )
167
+ pipeline_file = File.join( ext_dir, 'pipeline.rb' )
168
+ if ( File.exists?( pipeline_file ) )
169
+ p = eval(File.read( pipeline_file ), nil, pipeline_file, 1)
170
+ p.extensions.each do |e|
171
+ pipeline.extension( e )
172
+ end
173
+ p.helpers.each do |h|
174
+ pipeline.helper( h )
175
+ end
176
+ p.transformers.each do |e|
177
+ pipeline.transformer( e )
178
+ end
485
179
  end
180
+ end
181
+
182
+ def execute_pipeline
183
+ pipeline.execute( site )
184
+ end
185
+
186
+ def configure_compass
187
+ Compass.configuration.project_type = :standalone
188
+ Compass.configuration.project_path = site.config.dir
189
+ Compass.configuration.sass_dir = 'stylesheets'
190
+
191
+ site.images_dir = File.join( site.config.output_dir, 'images' )
192
+ site.stylesheets_dir = File.join( site.config.output_dir, 'stylesheets' )
193
+ site.javascripts_dir = File.join( site.config.output_dir, 'javascripts' )
486
194
 
487
- pipeline.watch(watched_dirs) if pipeline
488
- skin_pipeline.watch(watched_dirs) if skin_pipeline
489
- check_dir_for_change(watched_dirs)
195
+ Compass.configuration.css_dir = site.css_dir
196
+ Compass.configuration.javascripts_dir = 'javascripts'
197
+ Compass.configuration.images_dir = 'images'
198
+ end
490
199
 
491
- pipeline.execute( site ) if pipeline
492
- skin_pipeline.execute( site ) if skin_pipeline
200
+ def load_pages
201
+ @layout_page_loader.load_all( :post )
202
+ @site_page_loader.load_all( :inline )
493
203
  end
494
204
 
495
- def check_dir_for_change(watched_dirs)
496
- watched_dirs.each do |dir|
497
- Dir.chdir(dir){check_dir_for_change_recursively()}
205
+ def generate_output
206
+ @site.pages.each do |page|
207
+ generated_path = File.join( site.config.output_dir, page.output_path )
208
+ if ( page.stale_output?( generated_path ) )
209
+ generate_page( page, generated_path )
210
+ else
211
+ generate_page( page, generated_path, false )
212
+ end
498
213
  end
499
214
  end
500
215
 
501
- def check_dir_for_change_recursively()
502
- directories=[]
503
- Dir['*'].sort.each do |name|
504
- if File.file?(name)
505
- mtime = File.mtime(name)
506
- if ( mtime > ( @max_site_mtime || Time.at(0) ) )
507
- @max_site_mtime = mtime
508
- end
509
- elsif File.directory?(name)
510
- directories << name
216
+ def generate_page(page, generated_path, produce_output=true)
217
+ if ( produce_output )
218
+ puts "Generating: #{generated_path}"
219
+ FileUtils.mkdir_p( File.dirname( generated_path ) )
220
+ File.open( generated_path, 'w' ) do |file|
221
+ file << page.rendered_content
222
+ end
223
+ elsif ( site.config.track_dependencies )
224
+ if page.dependencies.load!
225
+ puts "Cached: #{generated_path}"
226
+ else
227
+ puts "Analyzing: #{generated_path}"
228
+ page.rendered_content
511
229
  end
512
230
  end
513
- directories.each do |name|
514
- #don't descend into . or .. on linux
515
- Dir.chdir(name){check_dir_for_change_recursively()} if !Dir.pwd[File.expand_path(name)]
231
+ end
232
+
233
+ def generate_page_by_output_path(path)
234
+ full_path = File.join( '', path )
235
+ page = site.pages.find{|p| p.relative_source_path.to_s==full_path} || site.layouts.find{|p| p.relative_source_path.to_s==full_path}
236
+ return if page.nil?
237
+
238
+ #puts "regen page #{page.inspect}"
239
+ #puts "page.dependents #{page.dependencies.dependents.inspect}"
240
+
241
+ regen_pages = Set.new
242
+ regen_pages << page unless ( page.output_path.nil? )
243
+ regen_pages += page.dependencies.dependents
244
+
245
+ #puts regen_pages.collect{|e|e.output_path}.inspect
246
+ regen_pages.each do |p|
247
+ unless ( p.output_path.nil? || p.__is_layout )
248
+ generated_path = File.join( site.config.output_dir, p.output_path )
249
+ generate_page( p, generated_path )
250
+ end
516
251
  end
517
252
  end
518
253
 
519
- def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
520
- if first_letter_in_uppercase
521
- lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
522
- else
523
- lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
254
+ ####
255
+ ##
256
+ ## compat with awestruct 0.2.x
257
+ ##
258
+ ####
259
+
260
+ def load_page(path, options={})
261
+ page = @site_page_loader.load_page( path )
262
+ if ( options[:relative_path] )
263
+ fixed_relative_path = ( options[:relative_path].nil? ? nil : File.join( '', options[:relative_path] ) )
264
+ page.relative_path = fixed_relative_path
524
265
  end
266
+ page
267
+ end
268
+
269
+ def load_site_page(relative_path)
270
+ load_page( File.join( site.config.dir, relative_path ) )
271
+ end
272
+
273
+ def find_and_load_site_page(simple_path)
274
+ path_glob = File.join( site.config.input_dir, simple_path + '.*' )
275
+ candidates = Dir[ path_glob ]
276
+ return nil if candidates.empty?
277
+ throw Exception.new( "too many choices for #{simple_path}" ) if candidates.size != 1
278
+ dir_pathname = Pathname.new( site.config.dir )
279
+ path_name = Pathname.new( candidates[0] )
280
+ relative_path = path_name.relative_path_from( dir_pathname ).to_s
281
+ load_page( candidates[0] )
282
+ end
283
+
284
+ def create_context(page, content='')
285
+ page.create_context( content )
525
286
  end
526
287
 
527
288
  end