Settings which can be configured for all view classes, a single view class, or a single Mustache instance.
Version | = | VERSION = '0.99.4' |
render | -> | to_html |
render | -> | to_text |
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.
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.
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"
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`.
Context accessors.
view = Mustache.new view[:name] = "Jon" view.template = "Hi, {{name}}!" view.render # => "Hi, Jon!"
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.
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