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 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

path()

      # File lib/harbor/view.rb, line 19
19:     def self.path
20:       @path ||= if ::File.directory?("lib/views")
21:         [ Pathname("lib/views") ]
22:       else
23:         []
24:       end
25:     end

plugins(key)

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

Private Class Methods

__templates()

      # File lib/harbor/view.rb, line 88
88:     def self.__templates
89:       @__templates ||= {}
90:     end

Public Instance Methods

content()

      # File lib/harbor/view.rb, line 63
63:     def content
64:       @content ||= _erubis_render(@context)
65:     end

supports_layouts?()

      # File lib/harbor/view.rb, line 59
59:     def supports_layouts?
60:       true
61:     end

to_s(layout = nil)

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

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