Class: Harbor::View
- Inherits:
-
Object
show all
- Defined in:
- lib/harbor/view_context/helpers/cache.rb,
lib/harbor/view.rb
Overview
Set Harbor::View.cache equal to a supported Cache Store for use in the ViewContext#cache helper.
Defined Under Namespace
Classes: LayoutNotFoundError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(view, context = {}) ⇒ View
Returns a new instance of View.
48
49
50
51
52
53
|
# File 'lib/harbor/view.rb', line 48
def initialize(view, context = {})
@content_type = "text/html"
@extension = ".html.erb"
@context = context.is_a?(ViewContext) ? context : ViewContext.new(self, context)
@filename = ::File.extname(view) == "" ? (view + @extension) : view
end
|
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
46
47
48
|
# File 'lib/harbor/view.rb', line 46
def content_type
@content_type
end
|
#context ⇒ Object
Returns the value of attribute context.
46
47
48
|
# File 'lib/harbor/view.rb', line 46
def context
@context
end
|
#extension ⇒ Object
Returns the value of attribute extension.
46
47
48
|
# File 'lib/harbor/view.rb', line 46
def extension
@extension
end
|
#path ⇒ Object
Returns the value of attribute path.
46
47
48
|
# File 'lib/harbor/view.rb', line 46
def path
@path
end
|
Class Method Details
.cache ⇒ Object
17
18
19
|
# File 'lib/harbor/view_context/helpers/cache.rb', line 17
def cache
@__cache__
end
|
.cache=(value) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/harbor/view_context/helpers/cache.rb', line 9
def cache=(value)
if value && !value.is_a?(Harbor::Cache)
raise ArgumentError.new("Harbor::View.cache must be nil or an instance of Harbor::Cache")
end
@__cache__ = value
end
|
.cache_templates! ⇒ Object
38
39
40
|
# File 'lib/harbor/view.rb', line 38
def self.cache_templates!
@cache_templates = true
end
|
.cache_templates? ⇒ Boolean
34
35
36
|
# File 'lib/harbor/view.rb', line 34
def self.cache_templates?
@cache_templates
end
|
.exists?(filename) ⇒ Boolean
42
43
44
|
# File 'lib/harbor/view.rb', line 42
def self.exists?(filename)
self.path.detect { |dir| ::File.file?(dir + filename) }
end
|
.layouts ⇒ Object
23
24
25
|
# File 'lib/harbor/view.rb', line 23
def self.layouts
@layouts ||= Harbor::Layouts.new
end
|
.path ⇒ Object
19
20
21
|
# File 'lib/harbor/view.rb', line 19
def self.path
@path ||= []
end
|
.plugins(key) ⇒ Object
27
28
29
30
31
|
# File 'lib/harbor/view.rb', line 27
def self.plugins(key)
@plugins ||= Hash.new { |h, k| h[k] = PluginList.new }
@plugins[key.to_s.gsub(/^\/+/, '')]
end
|
Instance Method Details
#content ⇒ Object
59
60
61
|
# File 'lib/harbor/view.rb', line 59
def content
@content ||= _erubis_render(@context)
end
|
#supports_layouts? ⇒ Boolean
55
56
57
|
# File 'lib/harbor/view.rb', line 55
def supports_layouts?
true
end
|
#to_s(layout = nil) ⇒ Object
63
64
65
66
67
|
# File 'lib/harbor/view.rb', line 63
def to_s(layout = nil)
layout = self.class.layouts.match(@filename) if layout == :search
layout ? View.new(layout, @context.merge(:content => content)).to_s : content
end
|