Class: LiquidView

### Home Classes Methods

### In Files

- lib/extras/liquid_view.rb

### Parent

Object

### Methods

- ::call
- ::new
- #compilable?
- #render

### Class/Module Index

Quicksearch

- Liquid
- Liquid::ArgumentError
- Liquid::Assign
- Liquid::BlankFileSystem
- Liquid::Block
- Liquid::Break
- Liquid::BreakInterrupt
- Liquid::Capture
- Liquid::Case
- Liquid::Comment
- Liquid::Context
- Liquid::ContextError
- Liquid::Continue
- Liquid::ContinueInterrupt
- Liquid::Cycle
- Liquid::Decrement
- Liquid::Document
- Liquid::Drop
- Liquid::ElseCondition
- Liquid::Error
- Liquid::FileSystemError
- Liquid::FilterNotFound
- Liquid::For
- Liquid::I18n
- Liquid::I18n::TranslationError
- Liquid::If
- Liquid::Ifchanged
- Liquid::Include
- Liquid::Increment
- Liquid::Interrupt
- Liquid::Lexer
- Liquid::LocalFileSystem
- Liquid::MemoryError
- Liquid::Parser
- Liquid::Raw
- Liquid::StackLevelError
- Liquid::StandardError
- Liquid::StandardFilters
- Liquid::SyntaxError
- Liquid::TableRow
- Liquid::Tag
- Liquid::Template
- Liquid::Unless
- Liquid::Utils
- Liquid::Variable
- FalseClass
- LiquidView
- Module
- NilClass
- TrueClass

No matching classes.

# LiquidView

LiquidView is a action view extension class. You can register it with rails and use liquid as an template system for .liquid files

Example

    ActionView::Base::register_template_handler :liquid, LiquidView

### Constants

PROTECTED_ASSIGNS
PROTECTED_INSTANCE_VARIABLES

### Public Class Methods

call(template) click to toggle source

    # File lib/extras/liquid_view.rb, line 14
    def self.call(template)
      "LiquidView.new(self).render(template, local_assigns)"
    end

new(view) click to toggle source

    # File lib/extras/liquid_view.rb, line 18
    def initialize(view)
      @view = view
    end

### Public Instance Methods

compilable?() click to toggle source

    # File lib/extras/liquid_view.rb, line 47
    def compilable?
      false
    end

render(template, local_assigns = nil) click to toggle source

    # File lib/extras/liquid_view.rb, line 22
    def render(template, local_assigns = nil)
      @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'

      # Rails 2.2 Template has source, but not locals
      if template.respond_to?(:source) && !template.respond_to?(:locals)
        assigns = (@view.instance_variables - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, ivar|
                    hash[ivar[1..-1]] = @view.instance_variable_get(ivar)
                    hash
                  end
      else
        assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
      end

      source = template.respond_to?(:source) ? template.source : template
      local_assigns = (template.respond_to?(:locals) ? template.locals : local_assigns) || {}

      if content_for_layout = @view.instance_variable_get("@content_for_layout")
        assigns['content_for_layout'] = content_for_layout
      end
      assigns.merge!(local_assigns.stringify_keys)

      liquid = Liquid::Template.parse(source)
      liquid.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.