Sha256: 8c12de2fe7bbdb2ba2f6b489bdc623e8e98d36b689d5ee116f1faa5d4bbcc7c3

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

module PhantomProxy
  class ReloadTemplateRenderer
    def initialize(binding_)
      @binding = binding_
    end

    def render(template_name, bind=nil)
      TemplateRenderer.new(bind||@binding).render(template_name)
    end
  end

  class TemplateRenderer
    def self.create(binding_)
      (PhantomProxy.respond_to?(:env) && PhantomProxy.env == :production) ? TemplateRenderer.new(binding_) : ReloadTemplateRenderer.new(binding_)
    end

    def initialize(controller_binding_)
      @controller_binding=controller_binding_
    end

    def render(template_name, bind=nil)
      template(template_name).result(bind||controller_binding)
    end

    private

    def controller_binding
      @controller_binding
    end

    def template(template_name)
      begin
        templates[template_name]||=::ERB.new(File.read(PhantomProxy.root.join("views", "#{template_name}.erb")))
      rescue Errno::ENOENT => e
        templates[template_name]||=::ERB.new(File.read(PhantomProxy.root_gem.join("templates/views", "#{template_name}.erb")))
      end
    end

    def templates
      @templates||={}
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
phantom_proxy-1.4.0 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.12 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.11 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.10 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.9 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.8 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.7 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.6 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.5 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.3 lib/phantom_proxy/helper/template_renderer.rb
phantom_proxy-1.3.0 lib/phantom_proxy/helper/template_renderer.rb