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



40
41
42
43
44
45
46
47
48
49
# File 'lib/charyf/engine/controller/renderers.rb', line 40

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

TODO sig



66
67
68
69
70
71
72
# File 'lib/charyf/engine/controller/renderers.rb', line 66

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

TODO sig



57
58
59
60
61
62
63
# File 'lib/charyf/engine/controller/renderers.rb', line 57

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_folderObject

TODO sig



34
35
36
37
38
# File 'lib/charyf/engine/controller/renderers.rb', line 34

def response_folder
  return nil if skill.nil?

  return skill.skill_root.join('responses', controller_path)
end

#responses_for(action) ⇒ Object

TODO sig



52
53
54
# File 'lib/charyf/engine/controller/renderers.rb', line 52

def responses_for(action)
  Dir[response_folder.join("#{action}**")]
end