Class: News::Template

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

Defined Under Namespace

Classes: Context

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Template

Returns a new instance of Template.



300
301
302
# File 'lib/newscast.rb', line 300

def initialize( text )
  @template = ERB.new( text )
end

Instance Method Details

#render(**kwargs) ⇒ Object

todo: use locals / assigns or something instead of **kwargs - why? why not?

allow/support (extra) locals / assigns - why? why not?


306
307
308
309
# File 'lib/newscast.rb', line 306

def render( **kwargs )
  ## note: Ruby >= 2.5 has ERB#result_with_hash - use later - why? why not?
  @template.result( Context.new( **kwargs ).get_binding )
end