awestruct 0.5.7.RC2 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -8,7 +8,11 @@ module Awestruct
8
8
  @num_entries = opts[:num_entries] || 50
9
9
  @content_url = opts[:content_url]
10
10
  @feed_title = opts[:feed_title]
11
- @template = opts[:template] || File.join( File.dirname(__FILE__), 'template.atom.haml' )
11
+ if opts[:template] && Pathname.new(opts[:template]).relative?
12
+ @template = Pathname.new(::Awestruct::Engine.instance.site.config.dir).join(opts[:template])
13
+ else
14
+ @template = File.join( File.dirname(__FILE__), 'template.atom.haml' )
15
+ end
12
16
  end
13
17
 
14
18
  def execute(site)
@@ -51,9 +51,9 @@ module Awestruct
51
51
 
52
52
  html = ''
53
53
  html += %Q(<script>\n)
54
- html += %Q( (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n
55
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n
56
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n
54
+ html += %Q( (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
55
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
56
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
57
57
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n )
58
58
  html += %Q(\n)
59
59
  html += %Q(ga('create', '#{options[:account]}', 'auto');\n)
@@ -3,7 +3,7 @@ module Awestruct
3
3
  module Partial
4
4
 
5
5
  def partial(path, params = {})
6
- filename = File.join( '_partials', path )
6
+ filename = File.join( ::Awestruct::Engine.instance.config.dir, '_partials', path )
7
7
 
8
8
  if !File.exists?( filename )
9
9
  $LOG.error "Could not find #{filename}" if $LOG.error?
@@ -42,8 +42,6 @@ module Awestruct
42
42
 
43
43
  def extension(ext)
44
44
  @extensions << ext if ext.respond_to?(:execute)
45
- # TC: why? transformer and extension?
46
- transformer(ext) if ext.respond_to?(:transform)
47
45
 
48
46
  @before_all_extensions << ext if ext.respond_to?(:before_extensions)
49
47
  @after_all_extensions << ext if ext.respond_to?(:after_extensions)
@@ -2,7 +2,7 @@ module Awestruct
2
2
  module Extensions
3
3
  class Posts
4
4
 
5
- attr_accessor :path_prefix, :assign_to, :archive_template, :archive_path, :default_layout
5
+ attr_accessor :path_prefix, :assign_to, :archive_template, :archive_path, :default_layout, :wp_compat
6
6
 
7
7
  def initialize(path_prefix='', assign_to=:posts, archive_template=nil, archive_path=nil, opts={})
8
8
  @archive_template = archive_template
@@ -10,6 +10,7 @@ module Awestruct
10
10
  @path_prefix = path_prefix
11
11
  @assign_to = assign_to
12
12
  @default_layout = opts[:default_layout] || 'post'
13
+ @wp_compat = opts.has_key?(:wp_compat) ? opts[:wp_compat] : false
13
14
  end
14
15
 
15
16
  def execute(site)
@@ -54,7 +55,11 @@ module Awestruct
54
55
  page.layout ||= @default_layout if @default_layout
55
56
  page.slug ||= slug
56
57
  context = page.create_context
57
- page.output_path = "#{@path_prefix}/#{year}/#{month}/#{day}/#{page.slug}.html"
58
+ if (@wp_compat)
59
+ page.output_path = "#{@path_prefix}/#{year}/#{month}/#{page.slug}.html"
60
+ else
61
+ page.output_path = "#{@path_prefix}/#{year}/#{month}/#{day}/#{page.slug}.html"
62
+ end
58
63
  posts << page
59
64
  end
60
65
  end
@@ -7,7 +7,11 @@ module Awestruct
7
7
  @output_path = output_path
8
8
  @layout = opts[:layout].to_s
9
9
  @title = opts[:title] || 'Tags'
10
- @template = opts[:template] || File.join( File.dirname( __FILE__ ), 'tag_cloud.html.haml' )
10
+ if opts[:template] && Pathname.new(opts[:template]).relative?
11
+ @template = Pathname.new(::Awestruct::Engine.instance.site.config.dir).join(opts[:template])
12
+ else
13
+ @template = File.join( File.dirname(__FILE__), 'tag_cloud.html.haml' )
14
+ end
11
15
  end
12
16
 
13
17
  def execute(site)
@@ -14,7 +14,7 @@ module Awestruct
14
14
  def match(path)
15
15
  matcher = ::Tilt[File.basename(path)]
16
16
  if matcher.nil?
17
- $LOG.warn(%(Copying #{path})) if $LOG.warn? && Awestruct::Engine.instance.config.verbose
17
+ $LOG.debug(%(Copying #{path})) if Awestruct::Engine.instance.config.verbose
18
18
  return false
19
19
  end
20
20
 
@@ -134,19 +134,23 @@ module Awestruct
134
134
  return template.render(context)
135
135
  rescue LoadError => e
136
136
  error_page = context[:page]
137
- ExceptionHelper.log_message "Could not load template library required for rendering #{File.join site.dir, error_page.source_path}."
138
- ExceptionHelper.log_message "Please see #{File.join site.dir, error_page.output_path} for more information"
137
+ ExceptionHelper.log_message "Could not load template library required for rendering #{error_page.source_path}."
138
+ ExceptionHelper.log_message "Please see #{error_page.output_path} for more information"
139
139
  return ExceptionHelper.html_error_report e, error_page.source_path
140
140
  rescue => e
141
141
  error_page = context[:page]
142
- if error_page[:__is_layout] == true
143
- ExceptionHelper.log_message "An error during rendering layout file #{File.join site.dir, error_page.source_path} occurred."
142
+ if error_page[:__is_layout] == true || context[:__is_layout] == true
143
+ ExceptionHelper.log_message "An error during rendering layout file #{context[:__effective_page].relative_source_path} for #{error_page.relative_source_path} occurred."
144
144
  ExceptionHelper.log_building_error e, error_page.source_path
145
+
146
+ elsif error_page.is_partial?
147
+ ExceptionHelper.log_message "An error during rendering partial file #{error_page.relative_source_path} for #{error_page[:real_page].relative_source_path} occurred."
148
+ ExceptionHelper.log_building_error e, error_page[:real_page].source_path
145
149
  else
146
- ExceptionHelper.log_message "An error during rendering #{File.join site.dir, error_page.source_path} occurred."
150
+ ExceptionHelper.log_message "An error during rendering #{error_page.relative_source_path} occurred."
147
151
  ExceptionHelper.log_building_error e, error_page.source_path
148
152
  end
149
- ExceptionHelper.log_message "Please see #{File.join site.dir, error_page.output_path} for more information"
153
+ ExceptionHelper.log_message "Please see .awestruct/error.log for more information"
150
154
  return ExceptionHelper.html_error_report e, error_page.source_path
151
155
  end
152
156
  end
@@ -22,12 +22,7 @@ module Awestruct
22
22
 
23
23
  def relative_source_path
24
24
  begin
25
- p = path.relative_path_from( site.dir )
26
- if !! ( %r(^\.\.) =~ p.to_s )
27
- return nil
28
- end
29
- r = File.join( '', p )
30
- return r
25
+ "/#{Pathname.new path.relative_path_from( site.dir )}"
31
26
  rescue Exception=>e
32
27
  nil
33
28
  end
@@ -43,7 +43,7 @@ module Awestruct
43
43
  end
44
44
 
45
45
  def rendered_content(context, with_layouts=true)
46
- $LOG.debug "rendering content with layout #{with_layouts} for #{context}" if $LOG.debug?
46
+ $LOG.debug "rendering content with layout #{with_layouts} for #{context.page.output_path}" if $LOG.debug?
47
47
  content = delegate.rendered_content( context, with_layouts )
48
48
 
49
49
  if ( with_layouts )
@@ -51,11 +51,12 @@ module Awestruct
51
51
  for_layout_chain(context.__effective_page || context.page) do |layout|
52
52
  context.content = content
53
53
  context.__effective_page = layout
54
+ context[:__is_layout] = true
54
55
  content = layout.rendered_content( context, false )
55
- end
56
+ end
56
57
  end
57
58
 
58
- $LOG.debug "finished rendering content for #{context}" if $LOG.debug?
59
+ $LOG.debug "finished rendering content for #{context.page.output_path}" if $LOG.debug?
59
60
  content
60
61
  end
61
62
 
@@ -42,9 +42,9 @@ module Awestruct
42
42
  end
43
43
 
44
44
  def inherit_front_matter_from(hash)
45
- $LOG.debug "inherit_front_matter_from for #{self.inspect}" if $LOG.debug?
45
+ $LOG.debug "inherit_front_matter_from for #{self.inspect}"
46
46
  hash.each do |k,v|
47
- $LOG.debug "#{output_path} overwrite key: #{k}:#{self[k]} -> #{v}" if ( key?( k ) and !self[k].nil? and !self[k].eql? v) if $LOG.debug?
47
+ $LOG.debug "#{output_path} overwrite key: #{k}:#{self[k]} -> #{v}" if ( key?( k ) and !self[k].nil? and !self[k].eql? v)
48
48
  unless ( key?( k ) )
49
49
  self[k.to_sym] = v
50
50
  end
@@ -139,7 +139,7 @@ module Awestruct
139
139
  c = nil
140
140
 
141
141
  begin
142
- $LOG.debug "calling rendered_content on handler for page #{self.output_path}" if $LOG.debug?
142
+ $LOG.debug "calling rendered_content on handler for page #{self.output_path}"
143
143
  c = handler.rendered_content( context, with_layouts )
144
144
  # c = site.engine.pipeline.apply_transformers( context.site, self, c )
145
145
  rescue StandardError => e
@@ -11,7 +11,7 @@ module Awestruct
11
11
 
12
12
  @root_dir = site.config.dir
13
13
  if ( @target == :layouts )
14
- @root_dir = Pathname.new( File.join( root_dir, '_layouts/' ) )
14
+ @root_dir = site.config.layouts_dir
15
15
  end
16
16
  end
17
17
 
@@ -24,25 +24,25 @@ module Awestruct
24
24
  pages = []
25
25
  root_dir.find do |path|
26
26
  if ( path == root_dir )
27
- $LOG.debug "skip #{path}" if (site.config.verbose) if $LOG.debug?
27
+ $LOG.debug "skip #{path}" if site.config.verbose
28
28
  next
29
29
  end
30
30
  basename = File.basename( path )
31
31
  if ( basename == '.htaccess' )
32
32
  #special case
33
33
  elsif ( basename =~ /^[_.]/ )
34
- $LOG.debug "skip #{path} and prune" if (site.config.verbose) if $LOG.debug?
34
+ $LOG.debug "skip #{path} and prune" if (site.config.verbose && $LOG.debug?)
35
35
  Find.prune
36
36
  next
37
37
  end
38
38
  relative_path = path.relative_path_from( root_dir ).to_s
39
39
  if ignore?(relative_path)
40
- $LOG.debug "skip ignored #{path} and prune" if (site.config.verbose) if $LOG.debug?
40
+ $LOG.debug "skip ignored #{path} and prune" if site.config.verbose
41
41
  Find.prune
42
42
  next
43
43
  end
44
44
  unless path.directory?
45
- $LOG.debug "loading #{relative_path}" if (site.config.verbose) if $LOG.debug?
45
+ $LOG.debug "loading #{relative_path}" if site.config.verbose
46
46
  page = load_page( path, prepare )
47
47
  if ( page )
48
48
  next if (page.draft && !(@site.show_drafts || @site.profile == 'development'))
@@ -66,7 +66,7 @@ module Awestruct
66
66
  chain = site.engine.pipeline.handler_chains[ path ]
67
67
  return nil if chain.nil?
68
68
  handler = chain.create(site, Pathname.new(path))
69
- p = Page.new( site, handler )
69
+ p = ::Awestruct::Page.new( site, handler )
70
70
  if ( @target == :layouts )
71
71
  p.__is_layout = true
72
72
  else
@@ -13,7 +13,7 @@ module Awestruct
13
13
  attr_reader :transformers
14
14
  attr_reader :after_generation_extensions
15
15
 
16
- def initialize()
16
+ def initialize
17
17
  @handler_chains = HandlerChains.new
18
18
  @before_all_extensions = []
19
19
  @extensions = []
@@ -29,8 +29,6 @@ module Awestruct
29
29
 
30
30
  def extension(e)
31
31
  @extensions << e
32
- # TC: why? transformer and extension?
33
- e.transform(@transformers) if e.respond_to?(:transform)
34
32
  end
35
33
 
36
34
  def add_after_extension(e)
@@ -55,43 +53,73 @@ module Awestruct
55
53
 
56
54
  def execute_extensions(site, on_reload)
57
55
  @before_all_extensions.each do |e|
58
- e.on_reload(site) if (on_reload && e.respond_to?(:on_reload))
59
- if (e.respond_to? :execute)
56
+ $LOG.verbose "Executing before all extension #{e.class}"
57
+
58
+ if on_reload && e.respond_to?
59
+ start_time = DateTime.now
60
+ e.on_reload(site) if (on_reload && e.respond_to?(:on_reload))
61
+ $LOG.trace "Total time in #{e.class}.on_reload #{DateTime.now.to_time - start_time.to_time} seconds"
62
+ end
63
+
64
+ start_time = DateTime.now
65
+ if e.respond_to? :execute
60
66
  e.execute(site)
61
67
  else
62
68
  e.before_extensions(site)
63
69
  end
70
+ $LOG.trace "Total time in #{e.class}.before_extensions #{DateTime.now.to_time - start_time.to_time} seconds"
64
71
  end
65
72
 
66
73
  @extensions.each do |e|
67
- e.on_reload(site) if (on_reload && e.respond_to?(:on_reload))
74
+ $LOG.verbose "Executing extension #{e.class}"
75
+ if on_reload && e.respond_to?(:on_reload)
76
+ start_time = DateTime.now
77
+ e.on_reload(site)
78
+ $LOG.trace "Total time in #{e.class}.on_reload #{DateTime.now.to_time - start_time.to_time} seconds"
79
+ end
80
+ start_time = DateTime.now
68
81
  e.execute(site)
82
+ $LOG.trace "Total time in #{e.class}.execute #{DateTime.now.to_time - start_time.to_time} seconds"
69
83
  end
70
84
 
71
85
  @after_all_extensions.each do |e|
72
- e.on_reload(site) if (on_reload && e.respond_to?(:on_reload))
86
+ $LOG.verbose "Executing after all extension #{e.class}"
87
+ if on_reload && e.respond_to?(:on_reload)
88
+ start_time = DateTime.now
89
+ e.on_reload(site)
90
+ $LOG.trace "Total time in #{e.class}.on_reload #{DateTime.now.to_time - start_time.to_time} seconds"
91
+ end
92
+
93
+ start_time = DateTime.now
73
94
  if e.respond_to? :execute
74
95
  e.execute(site)
75
96
  else
76
97
  e.after_generation(site)
77
98
  end
99
+ $LOG.trace "Total time in #{e.class}.after_generation #{DateTime.now.to_time - start_time.to_time} seconds"
78
100
  end
79
101
  end
80
102
 
81
103
  def apply_transformers(site, page, rendered)
82
104
  @transformers.each do |t|
105
+ $LOG.debug "Applying transformer #{t.class} for page #{page}" if site.config.verbose
106
+ start_time = DateTime.now
83
107
  rendered = t.transform( site, page, rendered )
108
+ $LOG.trace "Total time in #{t.class}.transform #{DateTime.now.to_time - start_time.to_time} seconds" if site.config.verbose
84
109
  end
85
110
  rendered
86
111
  end
87
112
 
88
113
  def execute_after_generation(site)
89
114
  @after_generation_extensions.each do |e|
115
+ $LOG.verbose "Executing after generation #{e.class}"
116
+ start_time = DateTime.now
90
117
  if e.respond_to? :execute
91
118
  e.execute(site)
92
119
  else
93
120
  e.after_generation(site)
94
121
  end
122
+ $LOG.trace "Total time in #{e.class}.after_generation #{DateTime.now.to_time - start_time.to_time} seconds"
95
123
  end
96
124
  end
97
125
 
@@ -28,20 +28,24 @@ module Awestruct
28
28
 
29
29
  if debug_exp.size == 0
30
30
  html = IO.read(File.join(File.dirname(__FILE__), 'trace.html'))
31
- return [200,
32
- {'Content-Type'.freeze => 'text/html', 'Content-Length'.freeze => html.size.to_s},
33
- [html] ]
31
+ return [
32
+ 200,
33
+ {'Content-Type'.freeze => 'text/html', 'Content-Length'.freeze => html.size.to_s},
34
+ [html]
35
+ ]
34
36
  else
35
37
  json = ''
36
38
  begin
37
- json = dump(introspect(page, {}, debug_exp))
39
+ json = dump(introspect(page, {}, debug_exp)).freeze
38
40
  rescue Exception => e
39
- json += e.message
41
+ json += "#{e.message.freeze} \n#{e.backtrace.freeze}"
40
42
  end
41
43
 
42
- return [200,
43
- {'Content-Type'.freeze => 'application/json', 'Content-Length'.freeze => json.size.to_s},
44
- [json] ]
44
+ return [
45
+ 200,
46
+ {'Content-Type'.freeze => 'application/json', 'Content-Length'.freeze => json.size.to_s},
47
+ [json]
48
+ ]
45
49
  end
46
50
  else
47
51
  source_call = @app.call(env)
@@ -77,33 +81,44 @@ module Awestruct
77
81
  return target_arr
78
82
  else
79
83
  target_arr = []
80
- source.each{ |var| target_arr << introspect(var, {}, exp, depth+1)}
84
+ source.each do |var|
85
+ if var.respond_to? :to_h
86
+ target_arr << introspect(var, {}, ['*'], depth+1)
87
+ else
88
+ target_arr << introspect(var, {}, exp, depth+1)
89
+ end
90
+ end
81
91
  return target_arr
82
92
  end
83
93
  end
84
94
 
85
- return target if exp_curr.nil?
95
+ return source if source.is_a? String
96
+
97
+ if exp_curr.nil?
98
+ return source if target.empty?
99
+ return target
100
+ end
86
101
 
87
102
  data = nil
88
103
 
89
104
  if source.is_a? Awestruct::Page
90
- data = source.original_entries
105
+ data = source.original_entries.freeze
91
106
  elsif source.is_a? Hash
92
107
  data = source
93
108
  elsif source.is_a? OpenStruct
94
- data = source.to_h
109
+ data = source.to_h.freeze
95
110
  end
96
111
 
97
112
  return source.to_s if data.nil?
98
113
 
99
114
  data.each do |key, value|
100
115
  if key.to_s == exp_curr or exp_curr == '*'
101
- if value.is_a? Hash or value.is_a? OpenStruct or value.is_a? Awestruct::Page
102
- target[key] = introspect(value, {}, exp_all_curr, depth+1)
103
- elsif value.is_a? Array
116
+ if value.is_a? Hash or value.is_a? OpenStruct or value.is_a? Awestruct::Page or value.is_a? Array
104
117
  target[key] = introspect(value, {}, exp_all_curr, depth+1)
118
+ elsif value.respond_to? :to_h
119
+ target[key] = introspect(value.to_h.freeze, {}, exp_all_curr, depth+1)
105
120
  else
106
- target[key] = value
121
+ target[key] = value.to_s
107
122
  end
108
123
  elsif exp_curr[/^-?\d+$/]
109
124
  if value.is_a? Array
@@ -118,8 +133,8 @@ module Awestruct
118
133
  end
119
134
 
120
135
  def dump(value)
121
- value = value.to_h if value.is_a? OpenStruct
122
- JSON.pretty_generate(value)
136
+ value = value.to_h.freeze if value.respond_to? :to_h
137
+ "#{JSON.dump(value)} \n\n "
123
138
  end
124
139
  end
125
140
  end
@@ -541,6 +541,10 @@ var prettyPrint = (function() {
541
541
  return typeDealer['array'](obj, depth, key, true);
542
542
  },
543
543
  object: function(obj, depth, key) {
544
+ if (Object.keys(obj).length === 0) {
545
+ return '{}';
546
+ }
547
+
544
548
  obj_stack.push(key);
545
549
  console.log("object push " + key)
546
550
 
@@ -6,20 +6,20 @@ module Awestruct
6
6
  @@failed = false
7
7
 
8
8
  def self.log_message message
9
- $LOG.error message if $LOG.error?
9
+ $LOG.error message
10
10
  end
11
11
 
12
12
  def self.log_error exception
13
13
  mark_failed
14
- $LOG.error "An error occurred: #{exception.message}" if $LOG.error?
14
+ $LOG.error "An error occurred: #{exception.message}"
15
15
  end
16
16
 
17
17
  def self.log_backtrace exception
18
- $LOG.error "#{exception.backtrace.join("\n")}" if $LOG.error?
18
+ $LOG.error "#{exception.backtrace.join("\n")}"
19
19
  end
20
20
 
21
21
  def self.log_building_error exception, relative_source_path
22
- $LOG.error "While processing file #{relative_source_path}" if $LOG.error?
22
+ $LOG.error "While processing file #{relative_source_path}"
23
23
  self.log_error exception
24
24
  self.log_backtrace exception
25
25
  end