Module: Padrino::Helpers::RenderHelpers

### Home Classes Methods

### In Files

- lib/padrino-helpers/render_helpers.rb

### Methods

- #partial
- #render_partial

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Helpers
- Padrino::Helpers::AssetTagHelpers
- Padrino::Helpers::FormBuilder
- Padrino::Helpers::FormBuilder::AbstractFormBuilder
- Padrino::Helpers::FormBuilder::DeprecatedBuilderMethods
- Padrino::Helpers::FormBuilder::StandardFormBuilder
- Padrino::Helpers::FormHelpers
- Padrino::Helpers::FormHelpers::Errors
- Padrino::Helpers::FormHelpers::Options
- Padrino::Helpers::FormHelpers::Security
- Padrino::Helpers::NumberHelpers
- Padrino::Helpers::OutputHelpers
- Padrino::Helpers::OutputHelpers::AbstractHandler
- Padrino::Helpers::OutputHelpers::ErbHandler
- Padrino::Helpers::OutputHelpers::HamlHandler
- Padrino::Helpers::OutputHelpers::SinatraCurrentEngine
- Padrino::Helpers::OutputHelpers::SlimHandler
- Padrino::Helpers::RenderHelpers
- Padrino::Helpers::TagHelpers
- Padrino::Helpers::TranslationHelpers
- Padrino::Rendering
- Padrino::Rendering::ClassMethods
- Padrino::Rendering::ErubisTemplate
- Padrino::Rendering::HamlTemplate
- Padrino::Rendering::InstanceMethods
- Padrino::Rendering::SafeBufferEnhancer
- Padrino::Rendering::SafeEruby
- Padrino::Rendering::SafeTemplate
- Padrino::Rendering::SlimTemplate
- Padrino::Rendering::TemplateNotFound
- Haml
- Haml::Helpers
- Haml::Util

No matching classes.

# Padrino::Helpers::RenderHelpers

Helpers related to rendering within templates (i.e partials).

### Public Instance Methods

partial(template, options={}, &block) click to toggle source

Render a partials with collections support.

@param [String] template

    Relative path to partial template.

@param [Hash] options

    Options hash for rendering options.

@option options [Object] :object

    Object rendered in partial.

@option options [Array<Object>] :collection

    Partial is rendered for each object in this collection.

@option options [Hash] :locals ({})

    Local variables accessible in the partial.

@option options [Symbol] :engine

    Explicit rendering engine to use for this partial.

@return [String] The html generated from this partial.

@example

    partial 'photo/item', :object => @photo
    partial 'photo/item', :collection => @photos
    partial 'photo/item', :locals => { :foo => :bar }
    partial 'photo/item', :engine => :erb

@note If using this from Sinatra, pass explicit `:engine` option

    # File lib/padrino-helpers/render_helpers.rb, line 33
    def partial(template, options={}, &block)
      options = { :locals => {}, :layout => false }.update(options)
      explicit_engine = options.delete(:engine)

      path,_,name = template.to_s.rpartition(File::SEPARATOR)
      template_path = File.join(path,"_#{name}").to_sym
      item_name = name.partition('.').first.to_sym

      items, counter = if options[:collection].respond_to?(:inject)
        [options.delete(:collection), 0]
      else
        [[options.delete(:object)], nil]
      end

      locals = options[:locals]
      items.each_with_object(ActiveSupport::SafeBuffer.new) do |item,html|
        locals[item_name] = item if item
        locals["#{item_name}_counter".to_sym] = counter += 1 if counter
        content =
          if block_given?
            concat_content render(explicit_engine, template_path, options){ capture_html(&block) }
          else
            render(explicit_engine, template_path, options)
          end
        html.safe_concat content if content
      end
    end

Also aliased as: render_partial
render_partial(template, options={}, &block) click to toggle source
Alias for: partial

[Validate]

Generated with the Darkfish Rdoc Generator 2.