Class: Foobara::CommandConnectors::Http::Commands::Help::Presenter
- Inherits:
-
Object
- Object
- Foobara::CommandConnectors::Http::Commands::Help::Presenter
- Defined in:
- foobara-http-command-connector-1.1.5/src/http/commands/help/presenter.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/root.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/type.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/error.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/model.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/domain.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/entity.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/command.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/processor.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/organization.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/request_failed.rb,
foobara-http-command-connector-1.1.5/src/http/commands/help/presenter/processor_class.rb
Defined Under Namespace
Classes: Command, Domain, Entity, Error, Model, Organization, Processor, ProcessorClass, RequestFailed, Root, Type
Instance Attribute Summary collapse
-
#manifest ⇒ Object
Returns the value of attribute manifest.
Class Method Summary collapse
Instance Method Summary collapse
- #foobara_reference_link(manifest) ⇒ Object
-
#initialize(manifest) ⇒ Presenter
constructor
A new instance of Presenter.
- #method_missing(method_name) ⇒ Object
- #render_html_list(data) ⇒ Object
- #render_list_child(child, label = nil) ⇒ Object
- #rendered_as_collection?(data) ⇒ Boolean
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #root_manifest ⇒ Object
- #template_path ⇒ Object
Constructor Details
#initialize(manifest) ⇒ Presenter
Returns a new instance of Presenter.
69 70 71 |
# File 'src/http/commands/help/presenter.rb', line 69 def initialize(manifest) self.manifest = manifest end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'src/http/commands/help/presenter.rb', line 189 def method_missing(method_name, *, &) if manifest.respond_to?(method_name) manifest.send(method_name, *, &) else # :nocov: super # :nocov: end end |
Instance Attribute Details
#manifest ⇒ Object
Returns the value of attribute manifest.
67 68 69 |
# File 'src/http/commands/help/presenter.rb', line 67 def manifest @manifest end |
Class Method Details
.for(manifest) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'src/http/commands/help/presenter.rb', line 21 def for(manifest) case manifest when Manifest::RootManifest Presenter::Root when Manifest::Command Presenter::Command # TODO: do we need a dedicated presenter for this?? when Manifest::Entity, Manifest::DetachedEntity Presenter::Entity when Manifest::Model Presenter::Model when Manifest::Type Presenter::Type when Manifest::Error Presenter::Error when Manifest::Domain Presenter::Domain when Manifest::Organization Presenter::Organization when Manifest::Processor Presenter::Processor when Manifest::ProcessorClass Presenter::ProcessorClass when ErrorCollection Presenter::RequestFailed else # :nocov: raise "No presenter found for #{manifest.path}" # :nocov: end.new(manifest) end |
.template_path ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'src/http/commands/help/presenter.rb', line 57 def template_path template_path = File.join( __dir__, "templates", "#{template_symbol}.html.erb" ) Pathname.new(template_path).cleanpath.to_s end |
.template_symbol ⇒ Object
53 54 55 |
# File 'src/http/commands/help/presenter.rb', line 53 def template_symbol Util.underscore(Util.non_full_name(self)) end |
Instance Method Details
#foobara_reference_link(manifest) ⇒ Object
175 176 177 178 179 |
# File 'src/http/commands/help/presenter.rb', line 175 def (manifest) path = "/help/#{manifest.reference}" "<a href=\"#{path}\">#{manifest.reference.split("::").last}</a>" end |
#render_html_list(data) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'src/http/commands/help/presenter.rb', line 73 def render_html_list(data) html = +"" is_rendered_as_a_collection = rendered_as_collection?(data) html << "<ul>" if is_rendered_as_a_collection case data when ::Hash data.each do |key, value| html << render_list_child(value, key) end when ::Array if is_rendered_as_a_collection data.each do |item| html << render_list_child(item) end else data = data.map { |item| render_html_list(item) } html << "[#{data.join(", ")}]" end when Manifest::Attributes data.relevant_manifest.each_pair do |key, value| if key.to_s == "type" next end if key.to_s == "element_type_declarations" key = :attributes value = data.attribute_declarations end html << render_list_child(value, key) end when Manifest::Array data.relevant_manifest.each_pair do |key, value| next if key == :element_type_declaration if key.to_s == "type" value = root_manifest.lookup_path(key, value) end html << render_list_child(value, key) end html << render_html_list({ element_type: data.element_type }) when Manifest::TypeDeclaration manifest = data.relevant_manifest if manifest.is_a?(::Symbol) html << (data.to_type) else data.relevant_manifest.each_pair do |key, value| if key.to_s == "type" value = root_manifest.lookup_path(key, value) end html << render_list_child(value, key) end end when Manifest::Type, Manifest::Command, Manifest::Error html << (data) when Manifest::PossibleError html << render_html_list(data.error) else html << case data when Numeric, TrueClass, FalseClass, NilClass data.inspect when ::String data when ::Symbol, ::Time data.to_s else # :nocov: raise "Not sure how to render #{data.class}" # :nocov: end end html << "</ul>" if is_rendered_as_a_collection html end |
#render_list_child(child, label = nil) ⇒ Object
170 171 172 173 |
# File 'src/http/commands/help/presenter.rb', line 170 def render_list_child(child, label = nil) label = "#{label}:" if label "<li>#{label}\n#{render_html_list(child)}\n</li>" end |
#rendered_as_collection?(data) ⇒ Boolean
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'src/http/commands/help/presenter.rb', line 156 def rendered_as_collection?(data) if data.is_a?(::Array) data.size > 5 || data.any? { |element| rendered_as_collection?(element) } elsif data.is_a?(Manifest::TypeDeclaration) !data.relevant_manifest.is_a?(::Symbol) else [ ::Hash, Manifest::Attributes, Manifest::Array ].any? { |klass| data.is_a?(klass) } end end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
199 200 201 202 203 |
# File 'src/http/commands/help/presenter.rb', line 199 def respond_to_missing?(method_name, include_private = false) # :nocov: manifest.respond_to?(method_name, include_private) # :nocov: end |
#root_manifest ⇒ Object
181 182 183 |
# File 'src/http/commands/help/presenter.rb', line 181 def root_manifest @root_manifest ||= Manifest::RootManifest.new(manifest.root_manifest) end |
#template_path ⇒ Object
185 186 187 |
# File 'src/http/commands/help/presenter.rb', line 185 def template_path self.class.template_path end |