Class: Hyde::Template Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/hyde/template.rb

Overview

This class is abstract.

does not represent any actual template engine.

Interface for Template engines

Direct Known Subclasses

Hyde::Templates::ERB

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, toplevel: nil, locals: nil) ⇒ Template

Returns a new instance of Template.

Parameters:

  • input (String, File)
  • context (Binding, nil)
  • locals (Hash, nil) (defaults to: nil)


30
31
32
33
34
35
36
37
38
# File 'lib/hyde/template.rb', line 30

def initialize(input, toplevel: nil, locals: nil)
  @template = input.is_a?(File) ? input.read : input
  input.close if input.is_a? File
  @binding = toplevel or binding
  locals&.each do |k, v|
    @binding.local_variable_set(k,v)
  end
  @context = TemplateContext.new(self)
end

Instance Attribute Details

#bindingObject

Returns the value of attribute binding.



74
75
76
# File 'lib/hyde/template.rb', line 74

def binding
  @binding
end

Instance Method Details

#local_variable_get(key) ⇒ Object

Get local variable

Parameters:

  • key (Symbol)

Returns:

  • (Object)


50
51
52
# File 'lib/hyde/template.rb', line 50

def local_variable_get(key)
  @binding.local_variable_get(key)
end

#local_variable_set(key, value) ⇒ Object

Set local variable

Parameters:

  • key (Symbol)
  • value (Object)


43
44
45
# File 'lib/hyde/template.rb', line 43

def local_variable_set(key, value)
  @binding.local_variable_set(key, value)
end

#local_variablesArray(Symbol)

Get an array of defined local variables

Returns:

  • (Array(Symbol))


56
57
58
# File 'lib/hyde/template.rb', line 56

def local_variables
  @binding.local_variables
end

#override_locals(vars) ⇒ Object

Override binding variables.

Parameters:

  • vars (Hash{Symbol => Object})


62
63
64
65
66
# File 'lib/hyde/template.rb', line 62

def override_locals(vars)
  vars.each do |k, v|
    @binding.local_variable_set(k, v)
  end
end

#runObject

Note:

This method is a stub.

Run the template



70
71
72
# File 'lib/hyde/template.rb', line 70

def run
  # ... (stub)
end