Class: PHPRB

Inherits:
Object show all
Defined in:
lib/web/phprb.rb,
lib/web/phprb.rb,
lib/web/phprb.rb,
lib/web/phprb.rb,
lib/web/phprb.rb

Overview

PHPRB::DefMethod

Defined Under Namespace

Modules: DefMethod, Util Classes: Compiler

Constant Summary collapse

Revision =

:nodoc: all

'$Date: 2003/12/10 09:07:52 $'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, safe_level = nil, trim_mode = nil, eoutvar = '_erbout') ⇒ PHPRB

Returns a new instance of PHPRB.



393
394
395
396
397
398
399
# File 'lib/web/phprb.rb', line 393

def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
  @safe_level = safe_level
  compiler = PHPRB::Compiler.new(trim_mode)
  set_eoutvar(compiler, eoutvar)
  @src = compiler.compile(str)
  @filename = nil
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



401
402
403
# File 'lib/web/phprb.rb', line 401

def filename
  @filename
end

#srcObject (readonly)

Returns the value of attribute src.



400
401
402
# File 'lib/web/phprb.rb', line 400

def src
  @src
end

Class Method Details

.versionObject



11
12
13
# File 'lib/web/phprb.rb', line 11

def self.version
  "erb.rb [2.0.4 #{PHPRB::Revision.split[1]}]"
end

Instance Method Details

#def_class(superklass = Object, methodname = 'result') ⇒ Object



443
444
445
446
447
# File 'lib/web/phprb.rb', line 443

def def_class(superklass=Object, methodname='result')
  cls = Class.new(superklass)
  def_method(cls, methodname)
  cls
end

#def_method(mod, methodname, fname = '(PHPRB)') ⇒ Object



433
434
435
# File 'lib/web/phprb.rb', line 433

def def_method(mod, methodname, fname='(PHPRB)')
  mod.module_eval("def #{methodname}\n" + self.src + "\nend\n", fname, 0)
end

#def_module(methodname = 'erb') ⇒ Object



437
438
439
440
441
# File 'lib/web/phprb.rb', line 437

def def_module(methodname='erb')
  mod = Module.new
  def_method(mod, methodname)
  mod
end

#result(b = TOPLEVEL_BINDING) ⇒ Object



421
422
423
424
425
426
427
428
429
430
431
# File 'lib/web/phprb.rb', line 421

def result(b=TOPLEVEL_BINDING)
  if @safe_level
    th = Thread.start { 
	$SAFE = @safe_level
	eval(@src, b)
    }
    return th.value
  else
    return eval(@src, b, (@filename || '(erb)'), 1)
  end
end

#run(b = TOPLEVEL_BINDING) ⇒ Object



417
418
419
# File 'lib/web/phprb.rb', line 417

def run(b=TOPLEVEL_BINDING)
  print self.result(b)
end

#set_eoutvar(compiler, eoutvar = '_erbout') ⇒ Object



403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/web/phprb.rb', line 403

def set_eoutvar(compiler, eoutvar = '_erbout')
  compiler.put_cmd = "#{eoutvar}.concat"

  cmd = []
  cmd.push "#{eoutvar} = ''"
  
  compiler.pre_cmd = cmd

  cmd = []
  cmd.push(eoutvar)

  compiler.post_cmd = cmd
end