lib/awestruct/pipeline.rb in awestruct-0.5.6.beta8 vs lib/awestruct/pipeline.rb in awestruct-0.5.6.beta9

- old
+ new

@@ -4,46 +4,96 @@ module Awestruct class Pipeline attr_reader :handler_chains + attr_reader :before_all_extensions + attr_reader :extensions + attr_reader :after_all_extensions + attr_reader :helpers + attr_reader :transformers + attr_reader :after_generation_extensions def initialize() @handler_chains = HandlerChains.new - @extensions = [] - @helpers = [] - @transformers = [] + @before_all_extensions = [] + @extensions = [] + @helpers = [] + @transformers = [] + @after_all_extensions = [] + @after_generation_extensions = [] end + def add_before_extension(e) + @before_all_extensions << e + end + def extension(e) @extensions << e # TC: why? transformer and extension? - e.transform(@transformers) if e.respond_to?('transform') + e.transform(@transformers) if e.respond_to?(:transform) end + def add_after_extension(e) + @after_all_extensions << e + end + def helper(h) @helpers << h end def transformer(t) @transformers << t end - def execute(site) - execute_extensions(site) + def add_after_generation_extension(e) + @after_generation_extensions << e end - def execute_extensions(site) + def execute(site, on_reload = false) + execute_extensions(site, on_reload) + end + + def execute_extensions(site, on_reload) + @before_all_extensions.each do |e| + e.on_reload(site) if (on_reload && e.respond_to?(:on_reload)) + if (e.respond_to? :execute) + e.execute(site) + else + e.before_extensions(site) + end + end + @extensions.each do |e| + e.on_reload(site) if (on_reload && e.respond_to?(:on_reload)) e.execute(site) end + + @after_all_extensions.each do |e| + e.on_reload(site) if (on_reload && e.respond_to?(:on_reload)) + if e.respond_to? :execute + e.execute(site) + else + e.after_generation(site) + end + end end def apply_transformers(site, page, rendered) @transformers.each do |t| rendered = t.transform( site, page, rendered ) end rendered + end + + def execute_after_generation(site) + @after_generation_extensions.each do |e| + if e.respond_to? :execute + e.execute(site) + else + e.after_generation(site) + end + end end def mixin_helpers(context) context.extend( Awestruct::ContextHelper ) @helpers.each do |h|