class Divebar::Driver::View::Erb

Public Class Methods

new(instance_bind) click to toggle source
# File lib/divebar/drivers/view/erb.rb, line 10
def initialize(instance_bind)
  @instance = instance_bind
end

Public Instance Methods

register_view(filepath) click to toggle source
# File lib/divebar/drivers/view/erb.rb, line 14
def register_view(filepath)
  ERB.new(File.read(find_file(filepath)))
end
render(view) click to toggle source
# File lib/divebar/drivers/view/erb.rb, line 18
def render(view)
  view.result(@instance).chomp
end

Private Instance Methods

find_file(filepath) click to toggle source
# File lib/divebar/drivers/view/erb.rb, line 22
        def find_file(filepath)
  searchpath = [filepath,
                "#{Dir.pwd}/views/#{filepath}",
                "#{Dir.pwd}/views/#{filepath}.erb",
                "#{File.dirname(__FILE__)}/views/#{filepath}",
                "#{File.dirname(__FILE__)}/views/#{filepath}.erb"] +
                Gem.path.map { |p| "#{p}/gems/divebar-#{Divebar::VERSION}/views/#{filepath}" } +
                Gem.path.map { |p| "#{p}/gems/divebar-#{Divebar::VERSION}/views/#{filepath}.erb" }
  realpath = searchpath.find { |file| File.exist?(file) }
  raise IOError, "Could not find template file #{filepath} in searchpath #{searchpath}" if realpath.nil?

  realpath
end