Class: Bridgetown::RubyTemplateView
- Inherits:
-
Object
- Object
- Bridgetown::RubyTemplateView
show all
- Includes:
- Streamlined
- Defined in:
- bridgetown-core/lib/bridgetown-core/helpers.rb,
bridgetown-core/lib/bridgetown-core/ruby_template_view.rb
Defined Under Namespace
Classes: Helpers
Instance Attribute Summary collapse
Instance Method Summary
collapse
#helper
Methods included from ERBCapture
#capture
Constructor Details
Returns a new instance of RubyTemplateView.
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 31
def initialize(convertible)
if convertible.is_a?(Layout)
@layout = convertible
@resource = layout.current_document
@content = layout.current_document_output
else
@layout = convertible.site.layouts[convertible.data["layout"]]
@resource = convertible
end
@paginator = resource.paginator if resource.respond_to?(:paginator)
@site = resource.site
@support_data_as_view_methods = @site.config.support_data_as_view_methods
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 86
def method_missing(method_name, ...)
if helpers.respond_to?(method_name.to_sym)
helpers.send(method_name.to_sym, ...)
elsif data_key?(method_name, ...)
data[method_name]
else
super
end
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
28
29
30
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 28
def content
@content
end
|
#layout ⇒ Object
Returns the value of attribute layout.
28
29
30
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 28
def layout
@layout
end
|
#paginator ⇒ Object
Returns the value of attribute paginator.
28
29
30
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 28
def paginator
@paginator
end
|
#resource ⇒ Object
Also known as:
page
Returns the value of attribute resource.
28
29
30
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 28
def resource
@resource
end
|
#site ⇒ Object
Returns the value of attribute site.
28
29
30
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 28
def site
@site
end
|
Instance Method Details
#collections ⇒ Object
47
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 47
def collections = site.collections
|
#data ⇒ Object
45
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 45
def data = resource.data
|
#data_key?(key, *args, **kwargs) ⇒ Boolean
80
81
82
83
84
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 80
def data_key?(key, *args, **kwargs)
return false unless @support_data_as_view_methods
args.empty? && kwargs.empty? && !block_given? && data.key?(key)
end
|
#helpers ⇒ Object
76
77
78
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 76
def helpers
@helpers ||= Helpers.new(self, site)
end
|
#inspect ⇒ Object
100
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 100
def inspect = "#<#{self.class} layout=#{layout&.label} resource=#{resource.relative_path}>"
|
#liquid_render(component, options = {}, &block) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 62
def liquid_render(component, options = {}, &block)
options[:_block_content] = capture(&block) if block && respond_to?(:capture)
render_statement = _render_statement(component, options)
template = site.liquid_renderer.file(
"#{resource.path}.#{Digest::SHA2.hexdigest(render_statement)}"
).parse(render_statement)
template.warnings.each do |e|
Bridgetown.logger.warn "Liquid Warning:",
LiquidRenderer.format_error(e, path || document.relative_path)
end
template.render!(options.as_dots, _liquid_context).html_safe
end
|
#partial(_partial_name = nil, **_options) ⇒ Object
51
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 51
def partial(_partial_name = nil, **_options) = raise("Must be implemented in a subclass")
|
#render(item, **options) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 53
def render(item, **options, &)
if item.respond_to?(:render_in)
result = item.render_in(self, &)
result&.html_safe
else
partial(item, **options, &)&.html_safe
end
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
96
97
98
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 96
def respond_to_missing?(method_name, include_private = false)
helpers.respond_to?(method_name.to_sym, include_private) || super
end
|
#site_drop ⇒ Object
49
|
# File 'bridgetown-core/lib/bridgetown-core/ruby_template_view.rb', line 49
def site_drop = site.site_payload.site
|