Module: Cadenza

Defined in:
lib/cadenza/racc_parser.rb,
lib/cadenza.rb,
lib/cadenza/cli.rb,
lib/cadenza/lexer.rb,
lib/cadenza/token.rb,
lib/cadenza/error.rb,
lib/cadenza/parser.rb,
lib/cadenza/context.rb,
lib/cadenza/version.rb,
lib/cadenza/library.rb,
lib/cadenza/tree_node.rb,
lib/cadenza/base_context.rb,
lib/cadenza/text_renderer.rb,
lib/cadenza/nodes/if_node.rb,
lib/cadenza/base_renderer.rb,
lib/cadenza/context/stack.rb,
lib/cadenza/nodes/for_node.rb,
lib/cadenza/context_object.rb,
lib/cadenza/library/blocks.rb,
lib/cadenza/context/loaders.rb,
lib/cadenza/block_hierarchy.rb,
lib/cadenza/library/filters.rb,
lib/cadenza/nodes/text_node.rb,
lib/cadenza/source_renderer.rb,
lib/cadenza/nodes/block_node.rb,
lib/cadenza/standard_library.rb,
lib/cadenza/library/functions.rb,
lib/cadenza/filesystem_loader.rb,
lib/cadenza/nodes/filter_node.rb,
lib/cadenza/nodes/variable_node.rb,
lib/cadenza/nodes/document_node.rb,
lib/cadenza/nodes/constant_node.rb,
lib/cadenza/library/expectation.rb,
lib/cadenza/source_tree_renderer.rb,
lib/cadenza/nodes/operation_node.rb,
lib/cadenza/standard_library/blocks.rb,
lib/cadenza/nodes/generic_block_node.rb,
lib/cadenza/standard_library/filters.rb,
lib/cadenza/nodes/filtered_value_node.rb,
lib/cadenza/standard_library/functions.rb,
lib/cadenza/nodes/boolean_inverse_node.rb

Overview

racc_parser.rb : generated by racc

Defined Under Namespace

Modules: Cli, Library, StandardLibrary, TreeNode, Version Classes: BaseContext, BaseRenderer, BlockHierarchy, BlockNode, BooleanInverseNode, ConstantNode, Context, ContextObject, DocumentNode, Error, FilesystemLoader, FilterNode, FilteredValueNode, ForNode, GenericBlockNode, IfNode, InvalidArgumentCountError, InvalidArgumentTypeError, Lexer, OperationNode, ParseError, Parser, RaccParser, RenderError, SourceRenderer, SourceTreeRenderer, TextNode, TextRenderer, Token, VariableNode

Constant Summary collapse

BlockNotDefinedError =
Class.new(Cadenza::Error)
TemplateNotFoundError =
Class.new(Cadenza::Error)
FilterNotDefinedError =
Class.new(Cadenza::Error)
FunctionNotDefinedError =
Class.new(Cadenza::Error)

Class Method Summary collapse

Class Method Details

.const_missing(const_name) ⇒ Object

TODO: remove in v0.9.x


6
7
8
9
10
# File 'lib/cadenza/library/functions.rb', line 6

def self.const_missing(const_name)
   super unless const_name == :FunctionalVariableNotDefinedError
   warn "`Cadenza::FunctionalVariableNotDefinedError` has been deprecated. Use `Cadenza::FunctionNotDefinedError` instead."
   FunctionNotDefinedError
end

.render(template_text, scope = nil, options = {}) ⇒ Object

this utility method sets up the standard Cadenza lexer/parser/renderer stack and renders the given template text with the given variable scope using the BaseContext. the result of rendering is returned as a string.

Parameters:

  • template_text (String)

    the content of the template to parse/render

  • scope (Hash) (defaults to: nil)

    any variables to define as a new scope for BaseContext in this template.


42
43
44
45
46
# File 'lib/cadenza.rb', line 42

def self.render(template_text, scope=nil, options={})
   context = create_context(scope, options)

   do_render(Parser.new.parse(template_text), context)
end

.render_template(template_name, scope = nil, options = {}) ⇒ Object

similar to #render except the given template name will be loaded using BaseContexts predefined list of loaders.

Parameters:

  • template_name (String)

    the name of the template to load then parse and render

  • scope (Hash) (defaults to: nil)

    any variables to define as a new scope for BaseContext in this template.


54
55
56
57
58
# File 'lib/cadenza.rb', line 54

def self.render_template(template_name, scope=nil, options={})
   context = create_context(scope, options)

   do_render(context.load_template(template_name), context)
end