awestruct 0.5.7.RC2 → 0.5.7

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/awestruct.gemspec +4 -2
  3. data/lib/awestruct/cli/auto.rb +1 -0
  4. data/lib/awestruct/cli/generate.rb +2 -0
  5. data/lib/awestruct/cli/init.rb +7 -2
  6. data/lib/awestruct/cli/invoker.rb +32 -8
  7. data/lib/awestruct/cli/manifest.rb +5 -8
  8. data/lib/awestruct/cli/options.rb +37 -25
  9. data/lib/awestruct/cli/server.rb +2 -2
  10. data/lib/awestruct/config.rb +2 -2
  11. data/lib/awestruct/deploy/base_deploy.rb +2 -2
  12. data/lib/awestruct/engine.rb +103 -54
  13. data/lib/awestruct/extensions/atomizer.rb +5 -1
  14. data/lib/awestruct/extensions/google_analytics.rb +3 -3
  15. data/lib/awestruct/extensions/partial.rb +1 -1
  16. data/lib/awestruct/extensions/pipeline.rb +0 -2
  17. data/lib/awestruct/extensions/posts.rb +7 -2
  18. data/lib/awestruct/extensions/tag_cloud.rb +5 -1
  19. data/lib/awestruct/handlers/base_tilt_handler.rb +11 -7
  20. data/lib/awestruct/handlers/file_handler.rb +1 -6
  21. data/lib/awestruct/handlers/layout_handler.rb +4 -3
  22. data/lib/awestruct/page.rb +3 -3
  23. data/lib/awestruct/page_loader.rb +6 -6
  24. data/lib/awestruct/pipeline.rb +35 -7
  25. data/lib/awestruct/rack/debug.rb +33 -18
  26. data/lib/awestruct/rack/trace.html +4 -0
  27. data/lib/awestruct/util/exception_helper.rb +4 -4
  28. data/lib/awestruct/version.rb +1 -1
  29. data/spec/awestruct/cli/invoker_spec.rb +4 -0
  30. data/spec/awestruct/cli/options_spec.rb +22 -1
  31. data/spec/awestruct/engine_spec.rb +28 -12
  32. data/spec/awestruct/handlers/file_handler_spec.rb +3 -6
  33. data/spec/awestruct/handlers/page_delegating_handler_spec.rb +5 -2
  34. data/spec/awestruct/handlers/tilt_handler_spec.rb +1 -4
  35. data/spec/awestruct/page_loader_spec.rb +16 -17
  36. data/spec/awestruct/rack/debug_spec.rb +15 -29
  37. metadata +72 -54
  38. data/lib/awestruct/logger.rb +0 -66
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6bd8ffa639608665b03402fe19c453dd79f9fc9
4
- data.tar.gz: 9de33bc224111e00dc785563af42799ec25028c2
3
+ metadata.gz: 24c840fbe2701d3bc0b3d4d123511d086c984959
4
+ data.tar.gz: ef9ff0655b1c9c8641b59a9b97900de62b40f8c8
5
5
  SHA512:
6
- metadata.gz: e664a8badfbbb367e90e8681ca57333ba544ffe6d7febccfd75f442687caa870b543be38ce098972b1c781c78df8e9cc56ecf3dbab49d65e5ba92ed4cb527214
7
- data.tar.gz: 2d2b7a6c6610f629739fbcffdabb477c8d1eb3879c0522a760612350c6b8f1bc52e1aba1970a38db04b62c55098f42fee092ff987e545a6edf0bca27fbdb9af3
6
+ metadata.gz: d9bcb190ec4213a565778883fe1bc9ae656439ae27ae096cf6185bd48e5b5f9b6c0e8ece38767d543242c5625e22915cbe3e1a30a7e29dde46312f0fce413859
7
+ data.tar.gz: 3444c4427e1101927cc7cd7e9bdaf193dac163bf8ed52a7ef264aad4b809d93c07ca9b5ba8e5111374f5d0a34665031627b41ede42a77f4a0eb2e876da0c86f1
@@ -4,7 +4,7 @@ require 'awestruct/version'
4
4
  spec = Gem::Specification.new do |s|
5
5
  s.name = 'awestruct'
6
6
  s.version = Awestruct::VERSION
7
- s.date = '2015-10-19'
7
+ s.date = '2016-02-09'
8
8
 
9
9
  s.authors = ['Bob McWhirter', 'Jason Porter', 'Lance Ball', 'Dan Allen', 'Torsten Curdt', 'other contributors']
10
10
  s.email = ['bob@mcwhirter.org', 'lightguard.jp@gmail.com', 'lball@redhat.com', 'dan.j.allen@gmail.com', 'tcurdt@vafer.org']
@@ -42,8 +42,10 @@ Compass and sass are no longer hard dependencies. You'll need too add them on yo
42
42
  s.add_dependency 'listen', '>= 2.7.1', '<= 4.0'
43
43
  s.add_dependency 'rack', '~> 1.5', '>= 1.5.2'
44
44
  s.add_dependency 'git', '~> 1.2', '>= 1.2.6'
45
+ s.add_dependency 'guard', '~> 2.13', '>= 2.13.0'
45
46
  s.add_dependency 'guard-livereload', '~> 2.1', '>= 2.1.2'
46
- s.add_dependency 'colorize', '~> 0.7', '>= 0.7.1'
47
+ # s.add_dependency 'colorize', '~> 0.7', '>= 0.7.1'
48
+ s.add_dependency 'logging', '~> 2.0'
47
49
  s.add_dependency 'oga', '~> 1.3'
48
50
  s.add_dependency 'parallel', '~> 1.1', '> 1.1.1'
49
51
 
@@ -1,6 +1,7 @@
1
1
  require 'awestruct/util/exception_helper'
2
2
 
3
3
  require 'listen'
4
+ require 'guard'
4
5
  require 'guard/livereload'
5
6
 
6
7
  module Awestruct
@@ -18,7 +18,9 @@ module Awestruct
18
18
  begin
19
19
  base_url = @base_url || @default_base_url
20
20
  $LOG.info "Generating site: #{base_url}" if $LOG.info?
21
+ start_time = DateTime.now
21
22
  @engine.run( @profile, @base_url, @default_base_url, @force, @generate )
23
+ $LOG.trace "Total time in engine.run #{DateTime.now.to_time - start_time.to_time} seconds"
22
24
  rescue =>e
23
25
  ExceptionHelper.log_building_error e, ''
24
26
  return false
@@ -37,8 +37,13 @@ module Awestruct
37
37
  when 'foundation'
38
38
  lib = 'zurb-foundation'
39
39
  end
40
- require lib unless lib.nil?
41
- manifest.install_compass(@framework) unless lib.nil?
40
+ unless lib.nil?
41
+ require 'sass/callbacks'
42
+ require 'compass'
43
+ require 'compass/commands'
44
+ require lib
45
+ manifest.install_compass(@framework, lib)
46
+ end
42
47
  if (@scaffold)
43
48
  manifest.copy_file('_config/site.yml', framework_path('base_site.yml'), :overwrite => true)
44
49
  manifest.copy_file('_layouts/base.html.haml', framework_path('base_layout.html.haml', scaffold_name))
@@ -1,6 +1,5 @@
1
1
  require 'pathname'
2
- require 'logger'
3
- require 'awestruct/logger'
2
+ require 'logging'
4
3
  require 'awestruct/cli/options'
5
4
  require 'awestruct/util/exception_helper'
6
5
  require 'erb'
@@ -17,7 +16,7 @@ module Awestruct
17
16
 
18
17
  def initialize(*options)
19
18
  options = options.flatten
20
- if ( ( ! options.empty? ) && ( options.first === Awestruct::CLI::Options ) )
19
+ if (!options.empty?) && (options.first === Awestruct::CLI::Options)
21
20
  @options = options.first
22
21
  else
23
22
  @options = Awestruct::CLI::Options.parse! options
@@ -25,11 +24,36 @@ module Awestruct
25
24
  @threads = []
26
25
  @profile = nil
27
26
  @success = true
28
- logging_path = Pathname.new '.awestruct'
29
- logging_path.mkdir unless logging_path.exist?
30
- $LOG = Logger.new(Awestruct::AwestructLoggerMultiIO.new(@options.debug, STDOUT, File.open('.awestruct/debug.log', 'w')))
31
- $LOG.level = @options.debug ? Logger::DEBUG : Logger::INFO
32
- $LOG.formatter = Awestruct::AwestructLogFormatter.new
27
+ logging_path = Pathname.new File.join(@options.source_dir, '.awestruct')
28
+ logging_path.mkpath unless logging_path.exist?
29
+
30
+ Logging.init :trace, :debug, :verbose, :info, :warn, :error, :fatal
31
+ $LOG = Logging.logger.new 'awestruct'
32
+ $LOG.add_appenders(
33
+ Logging.appenders.stdout({level: (@options.verbose ? :verbose : :info),
34
+ layout: Logging.layouts.pattern(pattern: "%m\n", format_as: :string),
35
+ color_scheme: :default}),
36
+ Logging.appenders.file('error', {filename: File.join(logging_path, 'error.log'),
37
+ layout: Logging.layouts.parseable.json(format_as: :string),
38
+ truncate: true, level: :error})
39
+ )
40
+
41
+ if @options.debug
42
+ $LOG.add_appenders(
43
+ Logging.appenders.file('debug', {filename: File.join(logging_path, 'debug.log'),
44
+ layout: Logging.layouts.parseable.json(format_as: :string),
45
+ truncate: true, level: :debug})
46
+ )
47
+ end
48
+
49
+ if @options.perf_log
50
+ $LOG.add_appenders(
51
+ Logging.appenders.file('perf', {filename: File.join(logging_path, 'perf.log'),
52
+ truncate: true, level: :trace,
53
+ layout: Logging.layouts.parseable.json(format_as: :string),
54
+ filters: Logging::Filters::Level.new(:trace)})
55
+ )
56
+ end
33
57
 
34
58
  # these requires are deferred until after $LOG is set
35
59
  require 'awestruct/cli/init'
@@ -43,8 +43,8 @@ module Awestruct
43
43
  steps << AddRequires.new(path, libs)
44
44
  end
45
45
 
46
- def install_compass(framework)
47
- steps << InstallCompass.new(framework)
46
+ def install_compass(framework, lib)
47
+ steps << InstallCompass.new(framework, lib)
48
48
  end
49
49
 
50
50
  def perform(dir)
@@ -236,7 +236,7 @@ module Awestruct
236
236
  rendered = ERB.new(File.read(@input_path), nil, '<>').result(
237
237
  OpenStruct.new(@state).instance_eval { binding })
238
238
  rescue => e
239
- puts "::DEBUG:: #{e.message} state - #{@state}"
239
+ $LOG.debug "::DEBUG:: #{e.message} state - #{@state}"
240
240
  end
241
241
 
242
242
  p = File.join(dir, @path)
@@ -250,15 +250,12 @@ module Awestruct
250
250
  end
251
251
 
252
252
  class InstallCompass
253
- def initialize(framework='compass')
253
+ def initialize(framework='compass', lib)
254
254
  @framework = framework
255
+ @lib = lib
255
256
  end
256
257
 
257
258
  def perform(dir)
258
- require 'sass/callbacks'
259
- require 'compass'
260
- require 'compass/commands'
261
-
262
259
  ::Compass.configuration.sass_dir = 'stylesheets'
263
260
  ::Compass.configuration.css_dir = '_site/stylesheets'
264
261
  ::Compass.configuration.images_dir = 'images'
@@ -31,31 +31,39 @@ module Awestruct
31
31
  attr_accessor :livereload
32
32
  attr_accessor :debug
33
33
  attr_accessor :generate_on_access
34
-
35
- def initialize()
36
- @generate = nil
37
- @server = false
38
- @port = DEFAULT_PORT
39
- @bind_addr = DEFAULT_BIND_ADDR
40
- @auto = false
41
- @force = false
42
- @init = false
43
- @framework = 'compass'
44
- @scaffold = true
45
- @base_url = DEFAULT_BASE_URL
46
- @profile = nil
47
- @deploy = false
48
- @script = nil
49
- @verbose = false
50
- @quiet = false
51
- @livereload = false
52
- @source_dir = Dir.pwd
53
- @output_dir = File.expand_path '_site'
54
- @generate_on_access = DEFAULT_GENERATE_ON_ACCESS
34
+ attr_accessor :perf_log
35
+
36
+ def initialize(opts = {})
37
+ default_opts = { server: false, port: DEFAULT_PORT, bind_addr: DEFAULT_BIND_ADDR, auto: false, force: false,
38
+ init: false, framework: 'compass', scaffold: true, base_url: DEFAULT_BASE_URL, deploy: false,
39
+ verbose: false, quiet: false, livereload: false, source_dir: Dir.pwd,
40
+ output_dir: File.expand_path('_site'), generate_on_access: DEFAULT_GENERATE_ON_ACCESS,
41
+ perf_log: false
42
+ }.merge opts
43
+ @generate = default_opts[:generate]
44
+ @server = default_opts[:server]
45
+ @port = default_opts[:port]
46
+ @bind_addr = default_opts[:bind_addr]
47
+ @auto = default_opts[:auto]
48
+ @force = default_opts[:force]
49
+ @init = default_opts[:init]
50
+ @framework = default_opts[:framework]
51
+ @scaffold = default_opts[:scaffold]
52
+ @base_url = default_opts[:base_url]
53
+ @profile = default_opts[:profile]
54
+ @deploy = default_opts[:deploy]
55
+ @script = default_opts[:script]
56
+ @verbose = default_opts[:verbose]
57
+ @quiet = default_opts[:quiet]
58
+ @livereload = default_opts[:livereload]
59
+ @source_dir = default_opts[:source_dir]
60
+ @output_dir = default_opts[:output_dir]
61
+ @generate_on_access = default_opts[:generate_on_access]
62
+ @perf_log = default_opts[:perf_log]
55
63
  end
56
64
 
57
65
  def self.parse!(args)
58
- Options.new.parse! args
66
+ Options.new({output_dir: nil}).parse! args
59
67
  end
60
68
 
61
69
  def parse!(args)
@@ -130,15 +138,18 @@ module Awestruct
130
138
  #opts.on( '--run SCRIPT', 'Invoke a script after initialization' ) do |script|
131
139
  # self.script = script
132
140
  #end
133
- opts.on( '--source-dir DIR', 'Location of sources (default: .' ) do |source_dir|
141
+ opts.on( '--source-dir DIR', 'Location of sources (default: .)' ) do |source_dir|
134
142
  self.source_dir = File.expand_path source_dir
135
- self.output_dir = File.expand_path File.join(self.source_dir, '_site')
136
143
  end
137
144
 
138
- opts.on( '--output-dir DIR', 'Location to output generated site (default: _site' ) do |output_dir|
145
+ opts.on( '--output-dir DIR', 'Location to output generated site (default: _site)' ) do |output_dir|
139
146
  self.output_dir = File.expand_path output_dir
140
147
  end
141
148
 
149
+ opts.on('--perf', 'Enable performance logging to .awestruct/perf.log') do
150
+ self.perf_log = true
151
+ end
152
+
142
153
  opts.separator ''
143
154
  opts.separator "Common options:"
144
155
 
@@ -157,6 +168,7 @@ module Awestruct
157
168
  opts.parse!(args)
158
169
  self.port ||= DEFAULT_PORT
159
170
  self.base_url = %(http://#{self.bind_addr}:#{self.port}) if self.base_url === DEFAULT_BASE_URL
171
+ self.output_dir ||= File.expand_path(File.join(self.source_dir, '_site'))
160
172
 
161
173
  self.generate = true if self.generate.nil?
162
174
  self
@@ -20,12 +20,12 @@ module Awestruct
20
20
 
21
21
  def run
22
22
  unless port_open? @bind_addr, @port
23
- $LOG.error "#{@bind_addr}:#{@port} not available for server" if $LOG.error?
23
+ $LOG.error "#{@bind_addr}:#{@port} not available for server"
24
24
  abort
25
25
  end
26
26
  url = %(http://#{@bind_addr}:#{@port})
27
27
  msg = %(Starting preview server at #{url} (Press Ctrl-C to shutdown))
28
- $LOG.info %(#{'*' * msg.length}\n#{msg}\n#{'*' * msg.length}\n) if $LOG.info?
28
+ $LOG.info %(#{'*' * msg.length}\n#{msg}\n#{'*' * msg.length}\n)
29
29
 
30
30
  path = @path
31
31
  generate_on_access = @generate_on_access
@@ -23,11 +23,11 @@ module Awestruct
23
23
  attr_accessor :options
24
24
 
25
25
  def initialize(opts = Awestruct::CLI::Options.new)
26
- @dir = Pathname.new( opts.source_dir )
26
+ @dir = Pathname.new(File.expand_path(Pathname.new( opts.source_dir )))
27
27
  @layouts_dir = Pathname.new( File.join(@dir, '_layouts') )
28
28
  @config_dir = Pathname.new( File.join(@dir, '_config') )
29
29
  @input_dir = @dir
30
- @output_dir = Pathname.new( opts.output_dir )
30
+ @output_dir = Pathname.new(File.expand_path(Pathname.new( opts.output_dir )))
31
31
  @extension_dir = Pathname.new( File.join(@dir, '_ext') )
32
32
  @skin_dir = Pathname.new( File.join(@dir, '_skin') )
33
33
  @tmp_dir = Pathname.new( File.join(@dir, '_tmp') )
@@ -46,11 +46,11 @@ module Awestruct
46
46
  end
47
47
 
48
48
  def publish_site
49
- $LOG.error( "#{self.class.name}#publish_site not implemented." ) if $LOG.error?
49
+ $LOG.error( "#{self.class.name}#publish_site not implemented." )
50
50
  end
51
51
 
52
52
  def existing_changes
53
- $LOG.error UNCOMMITTED_CHANGES if $LOG.error?
53
+ $LOG.error UNCOMMITTED_CHANGES
54
54
  end
55
55
 
56
56
  def compress_site
@@ -53,42 +53,75 @@ module Awestruct
53
53
  end
54
54
 
55
55
  def run(profile, base_url, default_base_url, force=false, generate=true)
56
- $LOG.debug 'adjust_load_path' if $LOG.debug?
56
+ start_time = DateTime.now
57
+ $LOG.verbose 'adjust_load_path'
57
58
  adjust_load_path
58
- $LOG.debug 'load_default_site_yaml' if $LOG.debug?
59
+ $LOG.trace "Total time in adjust_load_path: #{DateTime.now.to_time - start_time.to_time} seconds"
60
+
61
+ $LOG.verbose 'load_default_site_yaml'
62
+ start_time = DateTime.now
59
63
  load_default_site_yaml( profile )
60
- $LOG.debug 'load_user_site_yaml -- profile' if $LOG.debug?
64
+ $LOG.trace "Total time in load_default_site_yaml #{DateTime.now.to_time - start_time.to_time} seconds"
65
+
66
+ $LOG.verbose 'load_user_site_yaml -- profile'
67
+ start_time = DateTime.now
61
68
  load_user_site_yaml( profile )
62
- $LOG.debug 'set_base_url' if $LOG.debug?
69
+ $LOG.trace "Total time in load_user_site_yaml #{DateTime.now.to_time - start_time.to_time} seconds"
70
+
71
+ $LOG.verbose 'set_base_url'
72
+ start_time = DateTime.now
63
73
  set_base_url( base_url, default_base_url )
64
- $LOG.debug 'load_yamls' if $LOG.debug?
74
+ $LOG.trace "Total time in set_base_url #{DateTime.now.to_time - start_time.to_time} seconds"
75
+
76
+ $LOG.verbose 'load_yamls'
77
+ start_time = DateTime.now
65
78
  load_yamls
66
- $LOG.debug 'load_pipeline' if $LOG.debug?
79
+ $LOG.trace "Total time in load_yamls #{DateTime.now.to_time - start_time.to_time} seconds"
80
+
81
+ $LOG.verbose 'load_pipeline'
82
+ start_time = DateTime.now
67
83
  load_pipeline
68
- $LOG.debug 'load_pages' if $LOG.debug?
84
+ $LOG.trace "Total time in load_pipeline #{DateTime.now.to_time - start_time.to_time} seconds"
85
+
86
+ $LOG.verbose 'load_pages'
87
+ start_time = DateTime.now
69
88
  load_pages
70
- $LOG.debug 'execute_pipeline' if $LOG.debug?
71
- $LOG.info 'Excecuting pipeline...' if $LOG.info?
89
+ $LOG.trace "Total time in load_pages #{DateTime.now.to_time - start_time.to_time} seconds"
90
+
91
+ $LOG.verbose 'execute_pipeline'
92
+ $LOG.info 'Excecuting pipeline...'
93
+ start_time = DateTime.now
72
94
  execute_pipeline(false)
95
+ $LOG.trace "Total time in execute_pipeline #{DateTime.now.to_time - start_time.to_time} seconds"
96
+
73
97
  begin
74
98
  if defined?(::Compass)
75
- $LOG.debug 'configure_compass' if $LOG.debug?
99
+ $LOG.verbose 'configure_compass'
100
+ start_time = DateTime.now
76
101
  configure_compass
102
+ $LOG.trace "Total time in configure_compass #{DateTime.now.to_time - start_time.to_time} seconds"
77
103
  end
78
104
  rescue LoadError
79
105
  # doesn't matter if we can't load it
80
106
  end
81
- $LOG.debug 'set_urls' if $LOG.debug?
107
+ $LOG.verbose 'set_urls'
108
+ start_time = DateTime.now
82
109
  set_urls( site.pages )
83
- $LOG.debug 'build_page_index' if $LOG.debug?
110
+ $LOG.trace "Total time in set_urls #{DateTime.now.to_time - start_time.to_time} seconds"
111
+
112
+ $LOG.verbose 'build_page_index'
113
+ start_time = DateTime.now
84
114
  build_page_index
115
+ $LOG.trace "Total time in build_page_index #{DateTime.now.to_time - start_time.to_time} seconds"
85
116
 
86
- if ( generate )
87
- $LOG.debug 'generate_output' if $LOG.debug?
88
- $LOG.info 'Generating pages...' if $LOG.info?
117
+ if generate
118
+ $LOG.debug 'generate_output'
119
+ $LOG.info 'Generating pages...'
120
+ start_time = DateTime.now
89
121
  generate_output
122
+ $LOG.trace "Total time in generate_output #{DateTime.now.to_time - start_time.to_time} seconds"
90
123
  end
91
- return Awestruct::ExceptionHelper::EXITCODES[:success]
124
+ Awestruct::ExceptionHelper::EXITCODES[:success]
92
125
  end
93
126
 
94
127
  def build_page_index
@@ -97,7 +130,7 @@ module Awestruct
97
130
  site.pages.each do |p|
98
131
  # Add the layout to the set of dependencies
99
132
  p.dependencies.add_dependency(site.layouts.find_matching(p.layout, p.output_extension))
100
- if ( p.relative_source_path )
133
+ if p.relative_source_path
101
134
  site.pages_by_relative_source_path[ p.relative_source_path ] = p
102
135
  end
103
136
  site.pages_by_output_path[ p.output_path ] = p
@@ -106,23 +139,23 @@ module Awestruct
106
139
  # Add the layout to the set of dependencies
107
140
  p.dependencies.add_dependency(site.layouts.find_matching(p.layout, p.output_extension))
108
141
 
109
- if ( p.relative_source_path )
142
+ if p.relative_source_path
110
143
  site.pages_by_relative_source_path[ p.relative_source_path ] = p
111
144
  end
112
145
  end
113
146
  end
114
147
 
115
148
  def set_base_url(base_url, default_base_url)
116
- if ( base_url )
149
+ if base_url
117
150
  site.base_url = base_url
118
151
  end
119
152
 
120
- if ( site.base_url.nil? )
153
+ if site.base_url.nil?
121
154
  site.base_url = default_base_url
122
155
  end
123
156
 
124
- if ( site.base_url )
125
- if ( site.base_url =~ /^(.*)\/$/ )
157
+ if site.base_url
158
+ if site.base_url =~ /^(.*)\/$/
126
159
  site.base_url = $1
127
160
  end
128
161
  end
@@ -146,15 +179,15 @@ module Awestruct
146
179
  end
147
180
 
148
181
  def load_site_yaml(yaml_path, profile = nil)
149
- if ( File.exist?( yaml_path ) )
182
+ if File.exist?(yaml_path)
150
183
  begin
151
184
  data = YAML.load( ERB.new(File.read( yaml_path, :encoding => 'bom|utf-8' )).result )
152
- if ( profile )
185
+ if profile
153
186
  # JP: Interpolation now turned off by default, turn it per page if needed
154
187
  site.interpolate = false
155
188
  profile_data = {}
156
189
  data.each do |k,v|
157
- if ( ( k == 'profiles' ) && ( ! profile.nil? ) )
190
+ if (k == 'profiles') && (!profile.nil?)
158
191
  profile_data = ( v[profile] || {} )
159
192
  else
160
193
  site.send( "#{k}=", merge_data( site.send( "#{k}" ), v ) )
@@ -227,21 +260,21 @@ module Awestruct
227
260
 
228
261
  def adjust_load_path
229
262
  ext_dir = File.join( site.config.extension_dir )
230
- if ( $LOAD_PATH.index( ext_dir ).nil? )
263
+ if $LOAD_PATH.index(ext_dir).nil?
231
264
  $LOAD_PATH << ext_dir
232
265
  end
233
266
  end
234
267
 
235
268
  def set_urls(pages)
236
269
  pages.each do |page|
237
- $LOG.debug "relative_source_path #{page.relative_source_path}" if $LOG.debug?
270
+ $LOG.debug "relative_source_path #{page.relative_source_path}"
238
271
  page_path = page.output_path
239
- if ( page_path =~ /^\// )
272
+ if page_path =~ /^\//
240
273
  page.url = page_path
241
274
  else
242
275
  page.url = "/#{page_path}"
243
276
  end
244
- if ( page.url =~ /^(.*\/)index.html$/ )
277
+ if page.url =~ /^(.*\/)index.html$/
245
278
  page.url = $1
246
279
  end
247
280
  end
@@ -250,7 +283,7 @@ module Awestruct
250
283
  def load_pipeline
251
284
  ext_dir = File.join( site.config.extension_dir )
252
285
  pipeline_file = File.join( ext_dir, 'pipeline.rb' )
253
- if ( File.exists?( pipeline_file ) )
286
+ if File.exists?(pipeline_file)
254
287
  p = eval(File.read( pipeline_file ), nil, pipeline_file, 1)
255
288
  p.before_all_extensions.each do |e|
256
289
  pipeline.add_before_extension( e )
@@ -346,7 +379,7 @@ module Awestruct
346
379
  end
347
380
 
348
381
  compass_config_file = File.join(site.config.config_dir, 'compass.rb')
349
- if (File.exists? compass_config_file)
382
+ if File.exists? compass_config_file
350
383
  ::Compass.add_configuration ::Compass::Configuration::FileData.new_from_file(compass_config_file)
351
384
  end
352
385
  ::Compass.configuration # return for use elsewhere
@@ -355,9 +388,9 @@ module Awestruct
355
388
  end
356
389
 
357
390
  def load_pages
358
- $LOG.debug "layout_page_loader.load_all :post" if $LOG.debug?
391
+ $LOG.debug "layout_page_loader.load_all :post"
359
392
  @layout_page_loader.load_all( :post )
360
- $LOG.debug "site_page_loader.load_all :inline" if $LOG.debug?
393
+ $LOG.debug "site_page_loader.load_all :inline"
361
394
  @site_page_loader.load_all( :inline )
362
395
  end
363
396
 
@@ -366,9 +399,14 @@ module Awestruct
366
399
  return_value = [Awestruct::ExceptionHelper::EXITCODES[:success]]
367
400
  begin
368
401
  return_value = Parallel.map(@site.pages, site.generation) do |page|
369
- generate_page( page )
402
+ start_time = DateTime.now
403
+ return_value = generate_page( page )
404
+ $LOG.trace "Total time generating #{page.output_path} #{DateTime.now.to_time - start_time.to_time} seconds" if site.config.verbose
405
+
406
+ return_value
370
407
  end
371
408
  rescue Exception => e
409
+ Awestruct::ExceptionHelper.log_error e
372
410
  return_value = [Awestruct::ExceptionHelper::EXITCODES[:generation_error]]
373
411
  end
374
412
 
@@ -380,24 +418,31 @@ module Awestruct
380
418
  end
381
419
 
382
420
  def generate_page(page, produce_output=true)
383
- if ( produce_output )
384
- $LOG.debug "Generating: #{generated_path}" if $LOG.debug? && config.verbose
421
+ if produce_output
422
+ generated_path = File.join( site.config.output_dir, page.output_path )
423
+ $LOG.debug "Generating: #{generated_path}" if config.verbose
385
424
 
386
- c = page.rendered_content
387
- c = site.engine.pipeline.apply_transformers( site, page, c )
425
+ c = ''
426
+ begin
427
+ c = page.rendered_content
428
+ c = site.engine.pipeline.apply_transformers( site, page, c )
388
429
 
389
- generated_path = File.join( site.config.output_dir, page.output_path )
390
- FileUtils.mkdir_p( File.dirname( generated_path ) )
430
+ FileUtils.mkdir_p( File.dirname( generated_path ) )
391
431
 
392
- File.open( generated_path, 'wb' ) do |file|
393
- file << c
432
+ File.open( generated_path, 'wb' ) do |file|
433
+ file << c
434
+ end
435
+ rescue Exception => e
436
+ Awestruct::ExceptionHelper.log_building_error e, page.relative_source_path
437
+ ensure
438
+ return Awestruct::ExceptionHelper::EXITCODES[:generation_error] if c.include? 'Backtrace:'
394
439
  end
395
- return Awestruct::ExceptionHelper::EXITCODES[:generation_error] if c.include? 'Backtrace:'
396
- elsif ( site.config.track_dependencies )
440
+ Awestruct::ExceptionHelper::EXITCODES[:success]
441
+ elsif site.config.track_dependencies
397
442
  if page.dependencies.load!
398
- $LOG.debug "Cached: #{generated_path}" if $LOG.debug?
443
+ $LOG.debug "Cached: #{generated_path}"
399
444
  else
400
- $LOG.debug "Analyzing: #{generated_path}" if $LOG.debug?
445
+ $LOG.debug "Analyzing: #{generated_path}"
401
446
  page.rendered_content
402
447
  end
403
448
  return Awestruct::ExceptionHelper::EXITCODES[:success]
@@ -406,9 +451,9 @@ module Awestruct
406
451
 
407
452
  # path - relative to output dir
408
453
  def page_by_source_path(path)
409
- if (path.include? '_layout')
454
+ if path.include? '_layout'
410
455
  site.layouts.find { |p| p.source_path.to_s.include? path }
411
- elsif (path.include? '_partial')
456
+ elsif path.include? '_partial'
412
457
  site.partials.find { |p| p.source_path.to_s.include? path }
413
458
  else
414
459
  site.pages.find { |p| p.source_path.to_s.include? path }
@@ -427,10 +472,10 @@ module Awestruct
427
472
 
428
473
  regen_pages = page_dependencies( page )
429
474
 
430
- $LOG.debug "Starting regeneration of content dependent pages:" if regen_pages.size > 0 && $LOG.debug?
475
+ $LOG.debug 'Starting regeneration of content dependent pages:' if regen_pages.size > 0
431
476
 
432
477
  regen_pages.each do |p|
433
- $LOG.info "Regenerating page #{p.output_path}" if $LOG.info?
478
+ $LOG.info "Regenerating page #{p.output_path}"
434
479
  generate_page_internal(p)
435
480
  end
436
481
 
@@ -465,7 +510,7 @@ module Awestruct
465
510
  load_pipeline
466
511
  execute_pipeline(true)
467
512
 
468
- if ( generate )
513
+ if generate
469
514
  site.pages.each do |p|
470
515
  generate_page_internal(p)
471
516
  end
@@ -474,7 +519,7 @@ module Awestruct
474
519
  end
475
520
 
476
521
  def generate_page_internal(p)
477
- unless ( p.output_path.nil? || p.__is_layout || !p.stale_output?(p.output_path) )
522
+ unless p.output_path.nil? || p.__is_layout || !p.stale_output?(p.output_path)
478
523
  generate_page( p )
479
524
  end
480
525
  end
@@ -485,7 +530,7 @@ module Awestruct
485
530
 
486
531
  def load_page(path, options={})
487
532
  page = @site_page_loader.load_page( path )
488
- if ( options[:relative_path] )
533
+ if options[:relative_path]
489
534
  fixed_relative_path = ( options[:relative_path].nil? ? nil : File.join( '', options[:relative_path] ) )
490
535
  page.relative_path = fixed_relative_path
491
536
  end
@@ -493,7 +538,11 @@ module Awestruct
493
538
  end
494
539
 
495
540
  def load_site_page(relative_path)
496
- load_page( File.join( site.config.dir, relative_path ) )
541
+ if Pathname.new(relative_path).absolute?
542
+ load_page( relative_path )
543
+ else
544
+ load_page( Pathname.new(File.join(site.config.dir, relative_path)) )
545
+ end
497
546
  end
498
547
 
499
548
  def find_and_load_site_page(simple_path)