lib/stasis.rb in stasis-0.1.22 vs lib/stasis.rb in stasis-0.1.23

- old
+ new

@@ -69,10 +69,13 @@ attr_accessor :plugins # `String` -- the root path passed to `Stasis.new`. attr_accessor :root + # `String` -- the view output from Tilt. + attr_accessor :output + def initialize(root, *args) @options = {} @options = args.pop if args.last.is_a?(::Hash) @root = File.expand_path(root) @@ -204,21 +207,24 @@ end # If a layout was specified via the `layout` method... if @action._layout # Render the layout with a block for the layout to `yield` to. - @action.render(@action._layout) { output } + @action.render(@action._layout, render_opts) { output } # If a layout was not specified... else output end # If the path does not have an extension supported by [Tilt][ti] and `render` was # called within the `before` block for this path... elsif @action._render @action._render end + # Set @output instance variable for manipulation from within plugins + @output = view + # Trigger all plugin `after_render` events. trigger(:after_render) # Cut the `root` out of the `path` to get the relative destination. relative = @path[root.length..-1] @@ -239,34 +245,37 @@ if render_options[:write] != false FileUtils.mkdir_p(File.dirname(dest)) end # If markup was rendered... - if view + if @output # Write the rendered markup to the destination. if render_options[:write] != false File.open(dest, 'w') do |f| - f.write(view) + f.write(@output) end end # Collect render output. if render_options[:collect] - collect[relative[1..-1]] = view + collect[relative[1..-1]] = @output end # If markup was not rendered and the path exists... elsif File.exists?(@path) # Copy the file located at the path to the destination path. if render_options[:write] != false FileUtils.cp(@path, dest) end end + + # Trigger all plugin `after_write` events. Only fires if view was created. + trigger(:after_write) end # Trigger all plugin `after_all` events, passing the `Stasis` instance. trigger(:after_all) # Unset class-level instance variables. - @action, @path = nil, nil + @action, @path, @output = nil, nil, nil # Respond with collected render output if `collect` option given. collect if render_options[:collect] end