Class: RLSL::CodeGenerator::TemplateContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rlsl/code_generator/template_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, uniforms:, helpers_block:, fragment_block:) ⇒ TemplateContext

Returns a new instance of TemplateContext.



8
9
10
11
12
13
# File 'lib/rlsl/code_generator/template_context.rb', line 8

def initialize(name:, uniforms:, helpers_block:, fragment_block:)
  @name = name
  @uniforms = uniforms
  @helpers_block = helpers_block
  @fragment_block = fragment_block
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rlsl/code_generator/template_context.rb', line 6

def name
  @name
end

Instance Method Details

#fragment_codeObject



25
26
27
# File 'lib/rlsl/code_generator/template_context.rb', line 25

def fragment_code
  @fragment_block.call
end

#helpers_codeObject



19
20
21
22
23
# File 'lib/rlsl/code_generator/template_context.rb', line 19

def helpers_code
  return "" unless @helpers_block

  @helpers_block.call
end

#render_arityObject



15
16
17
# File 'lib/rlsl/code_generator/template_context.rb', line 15

def render_arity
  3 + @uniforms.size
end

#uniform_argument_listObject



35
36
37
38
# File 'lib/rlsl/code_generator/template_context.rb', line 35

def uniform_argument_list
  arguments = @uniforms.map { |uniform_name, _| "VALUE rb_#{uniform_name}" }
  arguments.empty? ? "" : ", #{arguments.join(', ')}"
end

#uniform_entriesObject



29
30
31
32
33
# File 'lib/rlsl/code_generator/template_context.rb', line 29

def uniform_entries
  @uniform_entries ||= @uniforms.map do |uniform_name, type|
    [uniform_name, UniformTypes.compiled_spec(type)]
  end
end