Class: Bade::Runtime::Block
- Inherits:
-
Object
- Object
- Bade::Runtime::Block
- Defined in:
- lib/bade/runtime/block.rb
Direct Known Subclasses
Defined Under Namespace
Classes: MissingBlockDefinitionError
Instance Attribute Summary collapse
- #block ⇒ Proc readonly
- #name ⇒ String readonly
- #render_binding ⇒ RenderBinding readonly
Instance Method Summary collapse
-
#call(*args) ⇒ Object
— Calling methods.
- #call!(*args) ⇒ Object
-
#initialize(name, render_binding, &block) ⇒ Block
constructor
A new instance of Block.
-
#render(*args) ⇒ Object
— Rendering methods.
- #render!(*args) ⇒ Object
Constructor Details
#initialize(name, render_binding, &block) ⇒ Block
Returns a new instance of Block.
47 48 49 50 51 |
# File 'lib/bade/runtime/block.rb', line 47 def initialize(name, render_binding, &block) @name = name @render_binding = render_binding @block = block end |
Instance Attribute Details
#block ⇒ Proc (readonly)
33 34 35 |
# File 'lib/bade/runtime/block.rb', line 33 def block @block end |
#render_binding ⇒ RenderBinding (readonly)
41 42 43 |
# File 'lib/bade/runtime/block.rb', line 41 def render_binding @render_binding end |
Instance Method Details
#call(*args) ⇒ Object
— Calling methods
55 56 57 |
# File 'lib/bade/runtime/block.rb', line 55 def call(*args) call!(*args) unless @block.nil? end |
#call!(*args) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/bade/runtime/block.rb', line 59 def call!(*args) if @block.nil? raise MissingBlockDefinitionError.new(name, :call) else render_binding.__buff.concat(@block.call(*args)) end end |
#render(*args) ⇒ Object
— Rendering methods
69 70 71 72 73 74 75 |
# File 'lib/bade/runtime/block.rb', line 69 def render(*args) if @block.nil? '' else render!(*args) end end |
#render!(*args) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/bade/runtime/block.rb', line 77 def render!(*args) if @block.nil? raise MissingBlockDefinitionError.new(name, :render) else @block.call(*args).join end end |