Class: Sbuilder::Ial::Action::Render::Renderer
- Includes:
- MyLogger
- Defined in:
- lib/action/render/renderer.rb
Constant Summary collapse
- PROGNAME =
progname for logger default class name
nil
Constants included from MyLogger
Instance Attribute Summary collapse
- #logger ⇒ Object readonly
- #partials ⇒ Object
- #preferences ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#EVAL(key) ⇒ Object
string lookup key in current context.
-
#initialize(options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #setPreferences(preferences) ⇒ Object
-
#to_str(template, data = nil) ⇒ Object
Use ‘to_str’ instead of ‘render’ to use non-default otag/ctag’s.
Methods included from MyLogger
Methods inherited from Mustache
Constructor Details
#initialize(options = {}) ⇒ Renderer
Returns a new instance of Renderer.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/action/render/renderer.rb', line 60 def initialize( ={} ) # exception raise if accessing unknown property self.raise_on_context_miss = true @options = @logger = getLogger( nil, ) @logger.info "#{__method__}: starting options=#{}" self.partials = {} end |
Instance Attribute Details
#logger ⇒ Object (readonly)
50 51 52 |
# File 'lib/action/render/renderer.rb', line 50 def logger @logger end |
#partials ⇒ Object
55 56 57 |
# File 'lib/action/render/renderer.rb', line 55 def partials @partials end |
#preferences ⇒ Object (readonly)
58 59 60 |
# File 'lib/action/render/renderer.rb', line 58 def preferences @preferences end |
Class Method Details
Instance Method Details
#EVAL(key) ⇒ Object
string lookup key in current context
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/action/render/renderer.rb', line 101 def EVAL( key ) logger.info "#{__method__}: key='#{key}', context.current=#{context.current}" if logger.debug? # find generate sexp( :sym, data ) to render if key == '.' sexp = context.current else # to evaluate hash = context.current.is_a?( Array ) ? context.current[1] : context.current sexp = hash[key] || hash[key.to_sym] raise MustacheException, "No such key #{key}:#{key.class} found in #{hash}" if sexp.nil? end sexp_type = sexp[0] data = sexp[1] logger.debug "#{__method__}: key=#{key}, sexp_type=#{sexp_type}" if logger.debug? # find correct template template = partials[sexp_type] raise MustacheException, <<-EOS if (template.nil?) Unknown partial for sexp_type '#{sexp_type}' Known partials: #{partials.keys.join(',')}" Conxt = #{context.current} EOS logger.debug "#{__method__}: template=#{template}, data=#{data}" if logger.debug? return render( template, data ) end |
#setPreferences(preferences) ⇒ Object
77 78 79 80 |
# File 'lib/action/render/renderer.rb', line 77 def setPreferences( preferences ) @preferences = preferences @logger.info "#{__method__}: preferences=#{preferences}" end |
#to_str(template, data = nil) ⇒ Object
Use ‘to_str’ instead of ‘render’ to use non-default otag/ctag’s
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/action/render/renderer.rb', line 83 def to_str( template, data=nil ) Mustache.otag = '{|' Mustache.ctag = '|}' begin ret = render( template, data ) ensure # restore default otag/ctag Mustache.otag = '{{' Mustache.ctag = '}}' end ret end |