Class: Stencil::Directive

Inherits:
Object
  • Object
show all
Defined in:
lib/stencil/directives/base.rb

Direct Known Subclasses

Apply, Block, End, Include, Interpolate, Literal

Defined Under Namespace

Classes: Source

Constant Summary collapse

@@directives =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, string) ⇒ Directive

Returns a new instance of Directive.



52
53
54
55
# File 'lib/stencil/directives/base.rb', line 52

def initialize(source, string)
  @source = source
  setup_parameters(string)
end

Class Method Details

.create(location, string) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/stencil/directives/base.rb', line 35

def self.create(location, string)
  string = string.sub(/^\s*/,"").sub(/\s*$/,"")
  name, arguments = string.split(/\s+/, 2)
  klass = @@directives[name]
  raise "Unrecognized directive: #{name}" if klass.nil?
  return klass.new(location, arguments)
end

.register(as) ⇒ Object



43
44
45
# File 'lib/stencil/directives/base.rb', line 43

def self.register(as)
  @@directives[as.to_s] = self
end

Instance Method Details

#checked_render(state) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/stencil/directives/base.rb', line 75

def checked_render(state)
  begin
    render(state)
  rescue RenderError
    raise
  rescue Object => ex
    raise @source, ex
  end
end

#inspectObject



60
61
62
# File 'lib/stencil/directives/base.rb', line 60

def inspect
  "[#{self.class.name.split("::").last} #{inspect_args}]"
end

#inspect_argsObject



64
65
66
# File 'lib/stencil/directives/base.rb', line 64

def inspect_args
  nil
end

#interpret(code, data) ⇒ Object



47
48
49
50
# File 'lib/stencil/directives/base.rb', line 47

def interpret(code, data)
  env = EvaluationHost.new(data)
  return env.run(code)
end

#parsed(stack) ⇒ Object



68
69
70
# File 'lib/stencil/directives/base.rb', line 68

def parsed(stack)
  stack.last.add(self)
end

#postrender(state) ⇒ Object



89
90
# File 'lib/stencil/directives/base.rb', line 89

def postrender(state)
end

#pre_end(state) ⇒ Object



92
93
# File 'lib/stencil/directives/base.rb', line 92

def pre_end(state)
end

#prerender(state) ⇒ Object



72
73
# File 'lib/stencil/directives/base.rb', line 72

def prerender(state)
end

#render(data) ⇒ Object



85
86
87
# File 'lib/stencil/directives/base.rb', line 85

def render(data)
  nil
end

#render_end(data) ⇒ Object



95
96
97
# File 'lib/stencil/directives/base.rb', line 95

def render_end(data)
  nil
end

#setup_parameters(string) ⇒ Object



57
58
# File 'lib/stencil/directives/base.rb', line 57

def setup_parameters(string)
end