Harbor::View
Set Harbor::View.cache equal to a supported Cache Store for use in the ViewContext#cache helper.
Attributes
- content_type [RW] (Not documented)
- context [RW] (Not documented)
- extension [RW] (Not documented)
- path [RW] (Not documented)
Public Class Methods
cache()
# File lib/harbor/view_context/helpers/cache.rb, line 17 17: def cache 18: @__cache__ 19: end
cache=(value)
# File lib/harbor/view_context/helpers/cache.rb, line 9 9: def cache=(value) 10: if value && !value.is_a?(Harbor::Cache) 11: raise ArgumentError.new("Harbor::View.cache must be nil or an instance of Harbor::Cache") 12: end 13: 14: @__cache__ = value 15: end
cache_templates!()
# File lib/harbor/view.rb, line 42 42: def self.cache_templates! 43: @cache_templates = true 44: end
cache_templates?()
# File lib/harbor/view.rb, line 38 38: def self.cache_templates? 39: @cache_templates 40: end
exists?(filename)
# File lib/harbor/view.rb, line 46 46: def self.exists?(filename) 47: self.path.detect { |dir| ::File.file?(dir + filename) } 48: end
layouts()
# File lib/harbor/view.rb, line 27 27: def self.layouts 28: @layouts ||= Harbor::Layouts.new 29: end
new(view, context = {})
# File lib/harbor/view.rb, line 52 52: def initialize(view, context = {}) 53: @content_type = "text/html" 54: @extension = ".html.erb" 55: @context = context.is_a?(ViewContext) ? context : ViewContext.new(self, context) 56: @filename = ::File.extname(view) == "" ? (view + @extension) : view 57: end
Private Class Methods
Public Instance Methods
Private Instance Methods
_erubis_render(context)
# File lib/harbor/view.rb, line 75 75: def _erubis_render(context) 76: @path ||= self.class.exists?(@filename) 77: raise "Could not find '#{@filename}' in #{self.class.path.inspect}" unless @path 78: 79: full_path = @path + @filename 80: 81: if self.class.cache_templates? 82: (self.class.__templates[full_path] ||= Erubis::FastEruby.new(::File.read(full_path), :filename => full_path)).evaluate(context) 83: else 84: Erubis::FastEruby.new(::File.read(full_path), :filename => full_path).evaluate(context) 85: end 86: end