Module: Charyf::Controller::Renderers
- Included in:
- Base
- Defined in:
- lib/charyf/engine/controller/renderers.rb
Defined Under Namespace
Modules: ClassMethods
Classes: InvalidState, NoResponseFound, ResponseFileMissingError
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
13
14
15
|
# File 'lib/charyf/engine/controller/renderers.rb', line 13
def self.included(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#ensure_responses_for(action) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/charyf/engine/controller/renderers.rb', line 39
def ensure_responses_for(action)
unless response_folder
raise Charyf::Controller::Renderers::InvalidState.new('Controller without skill can not render views')
end
if responses_for(action).empty?
raise Charyf::Controller::Renderers::NoResponseFound.new('No responses files found for action ' + action.to_s + "\n" +
"Expected #{action}.[html|txt].erb in #{response_folder}")
end
end
|
#render_html_response(action) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/charyf/engine/controller/renderers.rb', line 62
def render_html_response(action)
file_path = response_folder.join("#{action}.html.erb")
return nil unless exists?(file_path)
_render_response file_path
end
|
#render_text_response(action) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/charyf/engine/controller/renderers.rb', line 54
def render_text_response(action)
file_path = response_folder.join("#{action}.txt.erb")
return nil unless exists?(file_path)
_render_sample_response file_path
end
|
#response_folder ⇒ Object
33
34
35
36
37
|
# File 'lib/charyf/engine/controller/renderers.rb', line 33
def response_folder
return nil if skill.nil?
return skill.skill_root.join('responses', controller_path)
end
|
#responses_for(action) ⇒ Object
50
51
52
|
# File 'lib/charyf/engine/controller/renderers.rb', line 50
def responses_for(action)
Dir[response_folder.join("#{action}**")]
end
|