Class: Module

### Home Classes Methods

### In Files

- lib/liquid/module_ex.rb

### Parent

Object

### Methods

- ::new
- #liquid_methods

### 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::If
- Liquid::Ifchanged
- Liquid::Include
- Liquid::Increment
- Liquid::Interrupt
- Liquid::LocalFileSystem
- Liquid::MemoryError
- 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.

# Module

Copyright 2007 by Domizio Demichelis This library is free software. It may be used, redistributed and/or modified under the same terms as Ruby itself

This extension is used in order to expose the object of the implementing class to liquid as it were a Drop. It also limits the liquid-callable methods of the instance to the allowed method passed with the liquid_methods call Example:

class SomeClass

    liquid_methods :an_allowed_method

    def an_allowed_method
      'this comes from an allowed method'
    end
    def unallowed_method
      'this will never be an output'
    end

end

if you want to extend the drop to other methods you can defines more methods in the class <YourClass>::LiquidDropClass

    class SomeClass::LiquidDropClass
      def another_allowed_method
        'and this from another allowed method'
      end
    end

end

usage: @something = SomeClass.new

template: {{something.an_allowed_method}}{{something.unallowed_method}} {{something.another_allowed_method}}

output: 'this comes from an allowed method and this from another allowed method'

You can also chain associations, by adding the liquid_method call in the association models.

### Public Class Methods

new(object) click to toggle source

    # File lib/liquid/module_ex.rb, line 51
    def initialize(object)
      @object = object
    end

### Public Instance Methods

liquid_methods(*allowed_methods) click to toggle source

    # File lib/liquid/module_ex.rb, line 45
    def liquid_methods(*allowed_methods)
      drop_class = eval "class #{self.to_s}::LiquidDropClass < Liquid::Drop; self; end"
      define_method :to_liquid do
        drop_class.new(self)
      end
      drop_class.class_eval do
        def initialize(object)
          @object = object
        end
        allowed_methods.each do |sym|
          define_method sym do
            @object.send sym
          end
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.