Sha256: 83030dd95c3e4c87fc0f8e23f2d73f50e74135bc2fb4fd9805649330ec0ac72f
Contents?: true
Size: 1.43 KB
Versions: 5
Compression:
Stored size: 1.43 KB
Contents
module Nanoc::Helpers # Nanoc::Helpers::Render provides functionality for rendering layouts as # partials. module Render # Returns a string containing the rendered given layout. # # +name_or_path+:: the name or the path of the layout that should be # rendered. # # +other_assigns+:: a hash containing assigns that will be made available # as instance variables. # # Example 1: a layout 'head' with content "HEAD" and a layout 'foot' with # content "FOOT": # # <%= render 'head' %> - MIDDLE - <%= render 'foot' %> # # => "HEAD - MIDDLE - FOOT" # # Example 2: a layout named 'head' with content "<h1><%= @title %></h1>": # # <%= render 'head', :title => 'Foo' %> # # => "<h1>Foo</h1>" def render(name_or_path, other_assigns={}) # Find layout layout = @_obj.site.layouts.find { |l| l.path == name_or_path.cleaned_path } raise Nanoc::Errors::UnknownLayoutError.new(name_or_path.cleaned_path) if layout.nil? # Find filter klass = layout.filter_class raise Nanoc::Errors::CannotDetermineFilterError.new(layout.path) if klass.nil? filter = klass.new(@_obj_rep, other_assigns) # Layout @_obj.site.compiler.stack.push(layout) result = filter.run(layout.content) @_obj.site.compiler.stack.pop result end end end # Include by default include Nanoc::Helpers::Render
Version data entries
5 entries across 5 versions & 1 rubygems