Class: VRB
- Inherits:
-
Object
- Object
- VRB
- Defined in:
- lib/vrb.rb,
lib/vrb/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Instance Method Summary collapse
-
#initialize ⇒ VRB
constructor
A new instance of VRB.
- #view(path) ⇒ Object
- #view_erb(text) ⇒ Object
Constructor Details
#initialize ⇒ VRB
Returns a new instance of VRB.
5 6 7 |
# File 'lib/vrb.rb', line 5 def initialize @view_erb_count = 0 end |
Instance Method Details
#view(path) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vrb.rb', line 9 def view( path ) text = "" Dir.chdir( File.dirname( path ) ){ begin text = File.read( path ) rescue return "File Read Error: #{path}" end ext = File.extname( path ) func_name = "view#{ext.gsub( /\./, '_' )}" begin text = self.send( func_name, text ) if self.respond_to?( func_name ) rescue => err return <<EOS View Error: #{path} #{err.} #{err.backtrace.first} EOS end } text end |
#view_erb(text) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/vrb.rb', line 36 def view_erb( text ) @view_erb_count += 1 result = ERB.new( text, nil, "-", "_erbout_#{@view_erb_count}" ).result( binding ) @view_erb_count -= 1 result end |