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 38 38: def self.cache_templates! 39: @cache_templates = true 40: end
cache_templates?()
# File lib/harbor/view.rb, line 34 34: def self.cache_templates? 35: @cache_templates 36: end
exists?(filename)
# File lib/harbor/view.rb, line 42 42: def self.exists?(filename) 43: self.path.detect { |dir| ::File.file?(dir + filename) } 44: end
layouts()
# File lib/harbor/view.rb, line 23 23: def self.layouts 24: @layouts ||= Harbor::Layouts.new 25: end
new(view, context = {})
# File lib/harbor/view.rb, line 48 48: def initialize(view, context = {}) 49: @content_type = "text/html" 50: @extension = ".html.erb" 51: @context = context.is_a?(ViewContext) ? context : ViewContext.new(self, context) 52: @filename = ::File.extname(view) == "" ? (view + @extension) : view 53: end
Private Class Methods
Public Instance Methods
Private Instance Methods
_erubis_render(context)
# File lib/harbor/view.rb, line 71 71: def _erubis_render(context) 72: @path ||= self.class.exists?(@filename) 73: raise "Could not find '#{@filename}' in #{self.class.path.inspect}" unless @path 74: 75: full_path = @path + @filename 76: 77: if self.class.cache_templates? 78: (self.class.__templates[full_path] ||= Erubis::FastEruby.new(::File.read(full_path), :filename => full_path)).evaluate(context) 79: else 80: Erubis::FastEruby.new(::File.read(full_path), :filename => full_path).evaluate(context) 81: end 82: end