Class: Hobix::Out::ERB
- Inherits:
-
BaseOutput
- Object
- BasePlugin
- BaseOutput
- Hobix::Out::ERB
- Defined in:
- lib/hobix/out/erb.rb
Direct Known Subclasses
Instance Method Summary collapse
- #expand(fname) ⇒ Object
- #extension ⇒ Object
- #import(fname, bindto = @bind) ⇒ Object
- #import_erb(fname) ⇒ Object
-
#initialize(weblog) ⇒ ERB
constructor
A new instance of ERB.
- #load(file_name, vars) ⇒ Object
Methods inherited from BasePlugin
Constructor Details
#initialize(weblog) ⇒ ERB
Returns a new instance of ERB.
23 24 25 |
# File 'lib/hobix/out/erb.rb', line 23 def initialize( weblog ) @path = weblog.skel_path end |
Instance Method Details
#expand(fname) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/hobix/out/erb.rb', line 44 def ( fname ) if fname =~ /^\// File.join( @path, fname ) else File.join( @relpath, fname ) end end |
#extension ⇒ Object
26 27 28 |
# File 'lib/hobix/out/erb.rb', line 26 def extension "erb" end |
#import(fname, bindto = @bind) ⇒ Object
51 52 53 |
# File 'lib/hobix/out/erb.rb', line 51 def import( fname, bindto = @bind ) import_erb( ( fname ) ).result( bindto ) end |
#import_erb(fname) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/hobix/out/erb.rb', line 54 def import_erb(fname) File.open(fname) do |fp| src = fp.read.gsub( /<\+\s*([\w\.\/\\\-]+)\s*\+>/ ) do File.read( ( $1 ) ) end ::ERB.new( src, nil, nil, "_hobixout#{ rand( 9999999 ) }" ) end end |
#load(file_name, vars) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hobix/out/erb.rb', line 29 def load( file_name, vars ) @bind = binding vars.each do |k, v| k.untaint k_inspect = k.inspect.untaint eval( "#{ k } = vars[#{ k_inspect }]", @bind ) end @relpath = File.dirname( file_name ) @load_erb = import_erb( file_name ) begin @load_erb.result( @bind ) rescue Exception => e raise ERBError, "Error `#{ e. }' in erb #{ file_name }." end end |