Module: WelltreatStoreFramework::HamlRenderer
- Extended by:
- ActiveSupport::Concern
- Included in:
- StoreApp
- Defined in:
- lib/welltreat_store_framework/haml_renderer.rb,
lib/welltreat_store_framework/haml_renderer/paths.rb,
lib/welltreat_store_framework/haml_renderer/context.rb,
lib/welltreat_store_framework/haml_renderer/partial.rb,
lib/welltreat_store_framework/haml_renderer/url_join.rb,
lib/welltreat_store_framework/haml_renderer/tags_helper.rb,
lib/welltreat_store_framework/haml_renderer/lorem_helper.rb
Defined Under Namespace
Modules: LoremHelper, Partial, Paths, TagsHelper
Classes: Context, UrlJoin
Instance Method Summary
collapse
Instance Method Details
#_full_layout_path(response) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/welltreat_store_framework/haml_renderer.rb', line 49
def _full_layout_path(response)
Dir.glob(File.join(self.views_path,
'layouts',
"#{response.layout.to_s}.*"
)).first
end
|
#_full_partial_template_path(response, _partial) ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/welltreat_store_framework/haml_renderer.rb', line 63
def _full_partial_template_path(response, _partial)
Dir.glob(File.join(self.views_path,
response.controller_name.to_s.underscore,
"#{_partial.to_s}.*"
)).first ||
Dir.glob(File.join(self.views_path,
"#{_partial.to_s}.*"
)).first
end
|
#_full_template_path(response) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/welltreat_store_framework/haml_renderer.rb', line 56
def _full_template_path(response)
Dir.glob(File.join(self.views_path,
response.controller_name.to_s.underscore,
"#{response.template.to_s}.*"
)).first
end
|
#_haml_engines ⇒ Object
45
46
47
|
# File 'lib/welltreat_store_framework/haml_renderer.rb', line 45
def _haml_engines
@_haml_engines ||= { }
end
|
#_singleton_haml_instance(_key, _file) ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/welltreat_store_framework/haml_renderer.rb', line 34
def _singleton_haml_instance(_key, _file)
raise StoreApp::TemplateNotFound.new(_file) if _file.nil? || !File.exist?(_file)
if WelltreatStoreFramework::Core.configuration.auto_reload
Haml::Engine.new(File.read(_file), filename: _file, encoding: 'UTF-8')
else
_haml_engines[_key] ||=
Haml::Engine.new(File.read(_file), filename: _file)
end
end
|
#render!(request, response, options) ⇒ Object
Render HAML template and set content in response.content variable
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/welltreat_store_framework/haml_renderer.rb', line 9
def render!(request, response, options)
return if response.redirect?
return if response.content.present?
_layout_key = response.layout.to_s
_template_key = [
response.controller_name,
response.layout.to_s,
response.template.to_s,
].join('_')
_template_file = _full_template_path(response)
_layout_file = _full_layout_path(response)
raise StoreApp::TemplateNotFound.new(_template_key) if _template_file.nil?
context = Context.new(self, request, response, options)
context.set :body, _singleton_haml_instance(_template_key, _template_file).render(context)
response.content = _singleton_haml_instance(_layout_key, _layout_file).render(context)
end
|