### Home Classes Methods

### In Files

- lib/ramaze/view/liquid.rb

### Namespace

- CLASS Ramaze::View::Liquid::Tag

### Methods

- ::call
- ::register_tag

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::AppGraph
- Ramaze::Bin
- Ramaze::Bin::Console
- Ramaze::Bin::Create
- Ramaze::Bin::Helper
- Ramaze::Bin::Restart
- Ramaze::Bin::Runner
- Ramaze::Bin::Start
- Ramaze::Bin::Status
- Ramaze::Bin::Stop
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Array
- Ramaze::CoreExtensions::Binding
- Ramaze::CoreExtensions::Kernel
- Ramaze::CoreExtensions::Numeric
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::Proc
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Dictionary
- Ramaze::Fiber
- Ramaze::Files
- Ramaze::GemSetup
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Disqus
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Ultraviolet
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Analogger
- Ramaze::Logger::Growl
- Ramaze::Logger::Informer
- Ramaze::Logger::Knotify
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logger::Xosd
- Ramaze::Logging
- Ramaze::MiddlewareCompiler
- Ramaze::Plugin
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Reloader::Watcher
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::Struct
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- Fiber
- FiberError
- MainController
- Object
- OrderedSet
- Thread

No matching classes.

# Ramaze::View::Liquid

Liquid is a smarty-style templating engine that restricts the usage of code inside templates. This is mostly helpful if you want to let users submit templates but prevent them from running arbitrary code.

Liquid offers a pipe-like syntax for chaining operations on objects. Any instance variable from your Controller is available as a variable inside Liquid, so be sensitive about what data you provide.

If you want to allow partials you can provide a kind of virtual filesystem that contains partials. These can be rendered using the Liquid `{% include 'name' %}` tag. The include tag has no relation to the Ramaze::Helper::Render, it simply inlines the file.

To tell Liquid where to find partials, you have to set the file_system. The naming-convention for liquid-partials is to use a '_' prefix to the filename and the '.liquid' filename extension. The names of partials are restricted to ASCII alpha-numeric characters and underscores. You can also use '/' to use templates located in deeper directories. The partial has access to the same variables as the template including it.

@example setting file_system

    template_path = './partials/'
    Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_path)

@example using include

    {% include 'foo' %}
    {% include 'bar/foo' %}

This will include the files located at './partials/_foo.liquid' and './partials/bar/_foo.liquid'.

This functionality gets even more interesting if you customize it with your own virtual file-system, you can use anything that responds to `read_template_file(path)`. That way you can even fetch templates from a database or instruct Liquid to allow you access to your own templates in the '/views' directory.

### Public Class Methods

call(action, string) click to toggle source

Liquid requires the variable keys to be strings, most likely for security resons (don't allow arbitrary symbols).

    # File lib/ramaze/view/liquid.rb, line 49
    def self.call(action, string)
      action.sync_variables(action)
      variables = {}
      action.variables.each{|k,v| variables[k.to_s] = v }

      liquid = View.compile(string){|s| ::Liquid::Template.parse(s) }
      html = liquid.render(variables)

      return html, 'text/html'
    end

register_tag(name, helper, &block) click to toggle source

Liquid has intentionally? no support for binding, in order to use helpers you have to register them as tags.

Creating a tag needs boilerplate, so we reduce that for your convenience.

This is not the most performant way, it seems like Liquid uses initialize to compile templates and gives you the chance to process the arguments to the tag only once, but if you want that please contribute.

Further below are a couple of tags that map to the most common helpers, this also needs contribution as I simply don't have the time to write all of that and invent a consistent syntax.

    # File lib/ramaze/view/liquid.rb, line 80
    def self.register_tag(name, helper, &block)
      klass = Class.new(Tag)
      klass.send(:include, helper)
      klass.send(:define_method, :render, &block)

      ::Liquid::Template.register_tag(name, klass)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.