Class Amrita::Template
In: lib/amrita/parts.rb
lib/amrita/template.rb
Parent: Object

Methods

Included Modules

Amrita PartsTemplate HtmlCompiler::RuntimeRoutines Amrita

Attributes

amrita_id  [RW]  The name of attribute that will be used for template expandion by amrita. You will need to set this if you use id attribute fom DOM. For expample, if this was set to "amrita_id", you can use amrita_id for amrita and id for DOM.
asxml  [RW]  If set, the output is an xhtml document.
cache_manager  [RW] 
compact_space  [RW]  compact spaces and delete new line of output if set. you can’t set prettyprint and compact_space both in same Template.
debug_compiler  [RW]  debug compiler
escaped_id  [RW]  The name of attribute that turns into id. You will need to set this if you use id attribute for DOM/CSS/etc… For expample, if this was set to "__id", you can use id for amrita and __id for DOM/CSS/etc.…
expand_attr  [RW]  If set, expand attribute which value is "@xxxx"
keep_id  [RW]  keep id attribute of output if set.
pre_format  [RW]  If Set, use pre_format method
prettyprint  [RW]  output is pretty printed if set.
src  [R]  The source code that generated by template compiler
template  [R] 
use_compiler  [RW]  If Set, use compiler.
xml  [RW]  If set, use REXML-based parser instead of Amrita’s own html-parser

Public Class methods

[Source]

# File lib/amrita/template.rb, line 93
    def initialize
      @hint = nil
      @template = nil
      @xml = @prettyprint = @compact_space = @asxml = @pre_format = @expand_attr= false
      @keep_id = false
      @escaped_id = @dom_id = @amrita_id = nil
      @parser_filter = nil
      @use_compiler = false
      @cache_manager = DummyCacheManager.new
      @debug_compiler = false
    end

Public Instance methods

  1. load template if it was changed
  2. compile template if use_compiler was set.
  3. expand template with model
  4. print template to stream

[Source]

# File lib/amrita/template.rb, line 114
    def expand(stream, model)
      setup_template if need_update?
      context = setup_context
      formatter = setup_formatter(stream)
      do_expand(model, context, formatter)
    end

[Source]

# File lib/amrita/parts.rb, line 64
    def install_parts_template(mod, ee, cls_name)
      e = ee.clone
      e[:id] = nil
      parts_mod = nil
      if mod.const_defined?(cls_name)
        parts_mod = mod.const_get(cls_name)
        raise "#{cls_name} is not a Module but [#{parts_mod.type}]" unless parts_mod.kind_of?(Module)
      else
        parts_mod = Module.new
        mod.const_set(cls_name, parts_mod)
      end
      parts_mod.module_eval {
        include Amrita
        include PartsTemplate
        include HtmlCompiler::RuntimeRoutines
        extend HtmlCompiler::RuntimeRoutines
      }
      compile_partstemplate(parts_mod, e, cls_name)
    end

[Source]

# File lib/amrita/parts.rb, line 52
    def install_parts_to(mod)
      setup_template if need_update?
      template.each_element do |e|
        cls_name = e[:class]
        next unless cls_name
        next unless cls_name =~ /[A-Z]\w*/
        
        e[:class] = nil
        install_parts_template(mod, e, cls_name) 
      end
    end

set Hint data (undocumented now) and compile template by it.

[Source]

# File lib/amrita/template.rb, line 122
    def set_hint(hint)
      @hint = hint
      compile_template if @use_compiler
    end

generate Hint from data and compile template by it.

[Source]

# File lib/amrita/template.rb, line 128
    def set_hint_by_sample_data(data)
      hint = data.amrita_generate_hint
      set_hint(hint)
    end

[Validate]