Sha256: ec7285c8dabd6ed5ba8723f12a5f1eaa6b5c982b5d459540420c6c9330f5d674

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

module Plate
  # Allow for partials within views
  module PartialsHelper
    def render(options = {}, locals = {})
      path = options

      # If a hash is passed as the first option, use it for locals
      if Hash === options
        path = options.delete(:partial)
        locals = options.clone
      end

      locals.symbolize_keys!
      
      render_partial(path.to_s, locals)
    rescue
      site.log("Oops. There was a problem rendering the partial: #{path}")
      ""
    end

    protected
      # Create a new partial with the given options, and return its content
      def render_partial(path, locals)
        partial_name = Partial.name(self.site, path, self.file)
        partial = Partial.find(self.site, partial_name)
      
        self.page.partials << partial_name unless self.page.partials.include?(partial_name)
        
        if partial
          partial.pages << self.page unless partial.pages.include?(self.page)
          partial.render(locals)
        else
          nil
        end
      end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
plate-0.7.8 lib/plate/helpers/partials_helper.rb
plate-0.7.7 lib/plate/helpers/partials_helper.rb
plate-0.7.6 lib/plate/helpers/partials_helper.rb
plate-0.7.5 lib/plate/helpers/partials_helper.rb
plate-0.7.4 lib/plate/helpers/partials_helper.rb
plate-0.7.3 lib/plate/helpers/partials_helper.rb
plate-0.7.2 lib/plate/helpers/partials_helper.rb
plate-0.7.1 lib/plate/helpers/partials_helper.rb
plate-0.7.0 lib/plate/helpers/partials_helper.rb