Class: Lvr::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/lvr/template.rb,
lib/lvr/template/tags.rb,
lib/lvr/template/filters.rb

Defined Under Namespace

Modules: Filters, Tags

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ void

Parameters:

  • input (String, #to_s)


24
25
26
27
28
29
30
# File 'lib/lvr/template.rb', line 24

def initialize(**options)
  @env = Liquid::Environment.new
  @env.register_filter(Lvr::Template::Filters)
  @env.register_tag('footer', Lvr::Template::Tags::Footer)
  @template = Liquid::Template.new(environment: @env)
  @options = options
end

Class Method Details

.load(input_path) ⇒ Template

Parameters:

  • input_path (Pathname, #to_s)

Returns:



14
# File 'lib/lvr/template.rb', line 14

def self.load(input_path) = self.new.load(input_path)

.parse(input) ⇒ Template

Parameters:

  • input (String, #to_s)

Returns:



19
# File 'lib/lvr/template.rb', line 19

def self.parse(input) = self.new.parse(input)

Instance Method Details

#load(input_path) ⇒ Template

Returns ‘self`.

Parameters:

  • input_path (Pathname, #to_s)

Returns:



35
36
37
38
# File 'lib/lvr/template.rb', line 35

def load(input_path)
  @template.parse(File.read(input_path.to_s))
  self
end

#parse(input) ⇒ Template

Returns ‘self`.

Parameters:

  • input (String, #to_s)

Returns:



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

def parse(input)
  @template.parse(input.to_s)
  self
end

#render(**context) ⇒ Object

Parameters:

  • context (Hash, #to_h)

Returns:

  • (Object)


51
52
53
54
55
56
57
# File 'lib/lvr/template.rb', line 51

def render(**context)
  @template.render!(context.deep_stringify_keys!, {
    error_mode: :strict,
    strict_filters: true,
    strict_variables: true,
  }.merge(@options))
end