Harbor Documentation

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

path()

      # File lib/harbor/view.rb, line 19
19:     def self.path
20:       @path ||= []
21:     end

plugins(key)

      # File lib/harbor/view.rb, line 27
27:     def self.plugins(key)
28:       @plugins ||= Hash.new { |h, k| h[k] = PluginList.new }
29: 
30:       @plugins[key.to_s.gsub(/^\/+/, '')]
31:     end

Private Class Methods

__templates()

      # File lib/harbor/view.rb, line 84
84:     def self.__templates
85:       @__templates ||= {}
86:     end

Public Instance Methods

content()

      # File lib/harbor/view.rb, line 59
59:     def content
60:       @content ||= _erubis_render(@context)
61:     end

supports_layouts?()

      # File lib/harbor/view.rb, line 55
55:     def supports_layouts?
56:       true
57:     end

to_s(layout = nil)

      # File lib/harbor/view.rb, line 63
63:     def to_s(layout = nil)
64:       layout = self.class.layouts.match(@filename) if layout == :search
65: 
66:       layout ? View.new(layout, @context.merge(:content => content)).to_s : content
67:     end

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