Class: BarefootJS::Backend::Erb::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/barefoot_js/backend/erb.rb

Overview

A dedicated per-render binding host. bf and v are the ONLY locals a compiled template may reference (see the class docstring); giving each render its own tiny object (rather than reusing a shared binding) means concurrent / nested renders never see each other's v.

Instance Method Summary collapse

Constructor Details

#initialize(bf, v) ⇒ Renderer

Returns a new instance of Renderer.



105
106
107
108
# File 'lib/barefoot_js/backend/erb.rb', line 105

def initialize(bf, v)
  @bf = bf
  @v = v
end

Instance Method Details

#render(template) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/barefoot_js/backend/erb.rb', line 110

def render(template)
  # `bf` / `v` must be real LOCAL variables (not instance
  # variables) at the point `binding` is captured -- ERB templates
  # reference them as bare identifiers (`bf.h(...)`, `v[:x]`), and
  # `Binding` only exposes locals in scope + the object's own
  # instance variables under their own `@`-prefixed names.
  bf = @bf
  v = @v
  template.result(binding)
end