Class Mustache
In: lib/mustache.rb
lib/mustache/sinatra.rb
lib/mustache/version.rb
lib/mustache/parser.rb
lib/mustache/template.rb
lib/mustache/settings.rb
lib/mustache/generator.rb
lib/mustache/context.rb
Parent: Object

Settings which can be configured for all view classes, a single view class, or a single Mustache instance.

Methods

Classes and Modules

Module Mustache::Sinatra
Class Mustache::Context
Class Mustache::ContextMiss
Class Mustache::Generator
Class Mustache::Parser
Class Mustache::Template

Constants

Version = VERSION = '0.99.4'

External Aliases

render -> to_html
render -> to_text

Public Class methods

template_partial => TemplatePartial template/partial => Template::Partial

Has this template already been compiled? Compilation is somewhat expensive so it may be useful to check this before attempting it.

Supercharged version of Module#const_get.

Always searches under Object and can find constants by their full name,

  e.g. Mustache::Views::Index

name - The full constant name to find.

Returns the constant if found Returns nil if nothing is found

Return the value of the configuration setting on the superclass, or return the default.

attr_name - Symbol name of the attribute. It should match the instance variable. default - Default value to use if the superclass does not respond.

Returns the inherited or default configuration setting.

Given a name, attempts to read a file and return the contents as a string. The file is not rendered, so it might contain {{mustaches}}.

Call `render` if you need to process it.

Should an exception be raised when we cannot find a corresponding method or key in the current context? By default this is false to emulate ctemplate‘s behavior, but it may be useful to enable when debugging or developing.

If set to true and there is a context miss, `Mustache::ContextMiss` will be raised.

Instantiates an instance of this class and calls `render` with the passed args.

Returns a rendered String version of a template

Given a file name and an optional context, attempts to load and render the file as a template.

The template is the actual string Mustache uses as its template. There is a bit of magic here: what we get back is actually a Mustache::Template object, but you can still safely use `template=`

 with a string.

A Mustache template‘s default extension is ‘mustache’, but this can be changed.

The template file is the absolute path of the file Mustache will use as its template. By default it‘s ./class_name.mustache

The template name is the Mustache template file without any extension or other information. Defaults to `class_name`.

You may want to change this if your class is named Stat but you want to re-use another template.

  class Stat
    self.template_name = "graphs" # use graphs.mustache
  end

The template path informs your Mustache view where to look for its corresponding template. By default it‘s the current directory (".")

A class named Stat with a template_path of "app/templates" will look for "app/templates/stat.mustache"

Turns a string into a Mustache::Template. If passed a Template, returns it.

  TemplatePartial => template_partial

Template::Partial => template/partial Takes a string but defaults to using the current class’ name.

When given a symbol or string representing a class, will try to produce an appropriate view class. e.g.

  Mustache.view_namespace = Hurl::Views
  Mustache.view_class(:Partial) # => Hurl::Views::Partial

The constant under which Mustache will look for views when autoloading. By default the view namespace is `Object`, but it might be nice to set it to something like `Hurl::Views` if your app‘s main namespace is `Hurl`.

Mustache searches the view path for .rb files to require when asked to find a view class. Defaults to "."

Public Instance methods

Context accessors.

view = Mustache.new view[:name] = "Jon" view.template = "Hi, {{name}}!" view.render # => "Hi, Jon!"

Has this instance or its class already compiled a template?

A helper method which gives access to the context at a given time. Kind of a hack for now, but useful when you‘re in an iterating section and want access to the hash currently being iterated over.

Override this to provide custom escaping.

class PersonView < Mustache

  def escapeHTML(str)
    my_html_escape_method(str)
  end

end

Returns a String

Override this in your subclass if you want to do fun things like reading templates from a database. It will be rendered by the context, so all you need to do is return a string.

path()

Alias for template_path

path=(path)

Alias for template_path=

Instance level version of `Mustache.raise_on_context_miss?`

Parses our fancy pants template file and returns normal file with all special {{tags}} and {{sections}}replaced{{/sections}}.

data - A String template or a Hash context. If a Hash is given,

       we'll try to figure out the template from the class.
 ctx - A Hash context if `data` is a String template.

Examples

  @view.render("Hi {{thing}}!", :thing => :world)

  View.template = "Hi {{thing}}!"
  @view = View.new
  @view.render(:thing => :world)

Returns a rendered String version of a template

Given a file name and an optional context, attempts to load and render the file as a template.

The template can be set at the instance level.

The template file is the absolute path of the file Mustache will use as its template. By default it‘s ./class_name.mustache

to_html(data = template, ctx = {})

Alias for render

to_text(data = template, ctx = {})

Alias for render

[Validate]