Sha256: 493fee4a5ef9fbabed48378735f92684cf0f5b217924cb592c4d001bad49df5e
Contents?: true
Size: 1.4 KB
Versions: 15
Compression:
Stored size: 1.4 KB
Contents
# -*- encoding: utf-8 -*- module WatchTower module Server module Helpers module ImprovedPartials def self.included(base) base.send :include, InstanceMethods end module InstanceMethods # Define partial as a helper helpers do # Render a partial with support for collections # # stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb # and made a lot more robust by Sam Elliott <sam@lenary.co.uk> # https://gist.github.com/119874 # # @param [Symbol] The template to render # @param [Hash] Options def partial(template, *args) template_array = template.to_s.split('/') template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" options = args.last.is_a?(Hash) ? args.pop : {} options.merge!(:layout => false) if collection = options.delete(:collection) then collection.inject([]) do |buffer, member| buffer << haml(:"#{template}", options.merge(:layout => false, :locals => {template_array[-1].to_sym => member})) end.join("\n") else haml(:"#{template}", options) end end end end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems