Class: Goat::ERBRunner
- Includes:
- FlashHelper, HTMLHelpers
- Defined in:
- lib/goat.rb
Instance Attribute Summary collapse
-
#delegate ⇒ Object
Returns the value of attribute delegate.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #erb(name, opts = {}, &blk) ⇒ Object
-
#initialize(req, resp, params) ⇒ ERBRunner
constructor
A new instance of ERBRunner.
- #method_missing(meth, *args) ⇒ Object
- #partial_erb(name, opts = {}) ⇒ Object
- #take_delegate_ivars ⇒ Object
Methods included from FlashHelper
Methods included from HTMLHelpers
Constructor Details
#initialize(req, resp, params) ⇒ ERBRunner
Returns a new instance of ERBRunner.
404 405 406 407 408 |
# File 'lib/goat.rb', line 404 def initialize(req, resp, params) @request = req @response = resp @params = params end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
421 422 423 424 425 426 427 |
# File 'lib/goat.rb', line 421 def method_missing(meth, *args) if @delegate @delegate.send(meth, *args) else super end end |
Instance Attribute Details
#delegate ⇒ Object
Returns the value of attribute delegate.
411 412 413 |
# File 'lib/goat.rb', line 411 def delegate @delegate end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
410 411 412 |
# File 'lib/goat.rb', line 410 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
410 411 412 |
# File 'lib/goat.rb', line 410 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
410 411 412 |
# File 'lib/goat.rb', line 410 def response @response end |
Instance Method Details
#erb(name, opts = {}, &blk) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/goat.rb', line 429 def erb(name, opts={}, &blk) take_delegate_ivars if @delegate opts = { :partial => false, :layout => true, :locals => {} }.merge(opts) if self.kind_of?(Page) opts[:locals][:page] ||= self end partial = opts[:partial] use_layout = opts[:layout] locals = opts[:locals] if partial name = name.to_s d = File.dirname(name) d = d == '.' ? '' : "#{d}/" f = File.basename(name) # slashes are actually allowed in syms name = "#{d}_#{f}".to_sym end if name =~ /\.erb$/ # allow an absolute path to be passed erbf = name else erbf = File.join(Goat.config.get!(:root), 'views', "#{name}.erb") end layf = File.join(Goat.config.get!(:root), 'views', 'layout.erb') template = Tilt[:erb].new(erbf) { File.read(erbf) } layout = File.read(layf) if File.exists?(layf) && !partial && use_layout out = template.render(self, locals, &blk) if layout laytpl = Tilt[:erb].new(layf) { layout } laytpl.render(self, locals) { out } else out end end |
#partial_erb(name, opts = {}) ⇒ Object
476 477 478 |
# File 'lib/goat.rb', line 476 def partial_erb(name, opts={}) erb(name, {:partial => true}.merge(opts)) end |
#take_delegate_ivars ⇒ Object
413 414 415 416 417 418 419 |
# File 'lib/goat.rb', line 413 def take_delegate_ivars @delegate.instance_variables.each do |ivar| unless self.instance_variables.include?(ivar) self.instance_variable_set(ivar, @delegate.instance_variable_get(ivar)) end end end |