class Tilt::ClearSilverTemplate

ClearSilver implementation. See: my github.com/igravious/clearsilver gist

Attributes

old_api[RW]
additive_parsing[RW]

Public Class Methods

engine_initialized?() click to toggle source
# File lib/tarpaulin/tilt/clearsilver_template.rb, line 17
def self.engine_initialized?
  # defined? ::ClearSilver
  defined? ::Neo::Cs
end
old_api?() click to toggle source
# File lib/tarpaulin/tilt/clearsilver_template.rb, line 28
def old_api? ; old_api end

Public Instance Methods

additive_parsing?() click to toggle source
# File lib/tarpaulin/tilt/clearsilver_template.rb, line 35
def additive_parsing? ; additive_parsing end
debug() click to toggle source
# File lib/tarpaulin/tilt/clearsilver_template.rb, line 37
def debug # implicit
  if $DEBUG and $L
    $L.debug(&Proc.new) # pass it along
  end
end
evaluate(scope, locals, &block) click to toggle source
# File lib/tarpaulin/tilt/clearsilver_template.rb, line 56
def evaluate(scope, locals, &block)

  debug { scope }
  debug { locals }
  debug { block }
  if block
    hd = block.call
    #obj = scope
    #method = :fooish
    debug { scope.methods.sort }
    e = scope.instance_variable_get(:@env)
    debug {e}
    m = scope.instance_variable_get(:@method)
    debug {m}
    pack = [e, m]
    obj, method = scope.class.respond_to?(:parent) ? [scope.class.parent, :dispatch] : [nil, nil]
    debug {[obj, method]}
  else
    hd = scope
    obj = nil
  end
  if ClearSilverTemplate.old_api
  debug { "#2" }
    @engine = Neo::Cs.new hd unless @engine # CS Ruby API, traditional
    if !@already_parsed or additive_parsing?
  debug { "#2.5" }
      # boooooh, can't be a singleton cuz of parse_string
      # either way, only do it once per tilt/cs obj, unless you don't wanna
      @already_parsed = true
      @engine.parse_string @data # CS C API
    end
  else
  debug { "#3" }
    @engine = Neo::Cs.new # CS Ruby API, revamped
    @engine.use hd # CS Ruby/C API
    if obj
      @engine.register_fileload(obj, method, pack)
      # @engine.register_fileload(obj, method, locals) # call before parse_x, should use splat
    end
    @engine.parse_string @data # CS C API
  end
  @output = @engine.render locals[:locale] 
  # @output = @engine.render locals[:locale] # it's actually called render in CS C API
end
initialize_engine() click to toggle source
# File lib/tarpaulin/tilt/clearsilver_template.rb, line 22
def initialize_engine
  #require_template_library 'neo' # not thread-safe apparently
end
prepare() click to toggle source
# File lib/tarpaulin/tilt/clearsilver_template.rb, line 43
def prepare
  # data comes from tilt
  debug { "#0" }
  unless data.length.zero?
  debug { "#1" }
    @data = data
    @engine = nil
    @output = nil
    @already_parsed = false
    @additive_parsing = false
  end
end