Sha256: 4b81ac7b3c31d81f38692a21f0e03efc8aaaa8e97d855f86b21fe4cd58f0f039

Contents?: true

Size: 673 Bytes

Versions: 4

Compression:

Stored size: 673 Bytes

Contents

# This code is borrowed from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
module Sinatra::Partials
  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 << erb(:"#{template}", options.merge(:layout =>
        false, :locals => {template_array[-1].to_sym => member}))
      end.join("\n")
    else
      erb(:"#{template}", options)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ginatra-4.1.0 lib/sinatra/partials.rb
ginatra-4.0.2 lib/sinatra/partials.rb
ginatra-4.0.1 lib/sinatra/partials.rb
ginatra-4.0.0 lib/sinatra/partials.rb