Class: Tilt::ClearSilverTemplate

Inherits:
Template
  • Object
show all
Defined in:
lib/tarpaulin/tilt/clearsilver_template.rb

Overview

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.old_apiObject

Returns the value of attribute old_api.



28
29
30
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 28

def old_api
  @old_api
end

Instance Attribute Details

#additive_parsingObject

Returns the value of attribute additive_parsing.



35
36
37
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 35

def additive_parsing
  @additive_parsing
end

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 18

def self.engine_initialized?
  # defined? ::ClearSilver
  defined? ::Neo::Cs
end

.old_api?Boolean

Returns:

  • (Boolean)


29
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 29

def old_api? ; old_api end

Instance Method Details

#additive_parsing?Boolean

Returns:

  • (Boolean)


36
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 36

def additive_parsing? ; additive_parsing end

#debugObject

implicit



38
39
40
41
42
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 38

def debug # implicit
  if $DEBUG and $L
    $L.debug(&Proc.new) # pass it along
  end
end

#evaluate(scope, locals, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 57

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
    #binding.pry
  end
  @output = @engine.render locals[:locale] # it's actually called render in CS C API
end

#initialize_engineObject



23
24
25
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 23

def initialize_engine
  #require_template_library 'neo' # not thread-safe apparently
end

#prepareObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tarpaulin/tilt/clearsilver_template.rb', line 44

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