Sha256: 5da9f485d057f4c10249b8d20ccf27a6493954f883e74f88f1c1d5a6b491fd39

Contents?: true

Size: 778 Bytes

Versions: 2

Compression:

Stored size: 778 Bytes

Contents

require 'spire/http'
 
module Spire
  class MainController
    
    def initialize(base_path)
      @base_path = base_path
    end
    
    def render(view)
      data = {}
      instance_variables.each do |var|
        data[var] = instance_variable_get(var)
      end
      
      type = view.split('.')[1]

      if type == "html"
        File.open(@base_path+'/views/'+view, 'r').read
      elsif type == "haml"
        require 'haml' 
        file = File.open(@base_path+'/views/'+view, 'r').read
        Haml::Engine.new(file).render(Object.new, data)
      elsif type == "rhtml"
        require 'erubis'
        file = File.open(@base_path+'/views/'+view, 'r').read
        eruby = Erubis::Eruby.new(file)
        return eruby.result(data)
      end
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spire-0.2.3 lib/spire/class/MainController.rb
spire-0.2.2 lib/spire/class/MainController.rb