Class: Occi::Core::Renderers::Text::Category
- Defined in:
- lib/occi/core/renderers/text/category.rb
Overview
Implements routines required to render ‘Occi::Core::Category` and its subclasses to a text-based representation. Supports rendering to plain and header-like formats. Internally, the rendering itself is done via ERB templates.
Constant Summary collapse
- CATEGORY_KEY_PLAIN =
Category key constants
'Category'.freeze
- CATEGORY_KEY_HEADERS =
'X-OCCI-Category'.freeze
Constants inherited from Base
Base::DELEGATED, Base::RENDER_SAFE
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.category_key_headers ⇒ String
Returns word used to key all categories rendered to headers.
-
.category_key_plain ⇒ String
Returns keyword used to prefix all categories rendered to plain text.
-
.template ⇒ String
Returns a static ERB template used to render ‘Category`-like instances to plain text.
Instance Method Summary collapse
-
#category_key_headers ⇒ String
Returns word used to key all categories rendered to headers.
-
#category_key_plain ⇒ String
Returns keyword used to prefix all categories rendered to plain text.
-
#render_headers ⇒ Hash
Renders ‘object` into text for headers and returns the result as `Hash`.
-
#render_plain ⇒ String
Renders ‘object` into plain text and returns the result as `String`.
Methods inherited from Base
#initialize, #render, #render_safe, render_safe
Constructor Details
This class inherits a constructor from Occi::Core::Renderers::Text::Base
Class Method Details
.category_key_headers ⇒ String
Returns word used to key all categories rendered to headers.
61 62 63 |
# File 'lib/occi/core/renderers/text/category.rb', line 61 def category_key_headers CATEGORY_KEY_HEADERS end |
.category_key_plain ⇒ String
Returns keyword used to prefix all categories rendered to plain text.
54 55 56 |
# File 'lib/occi/core/renderers/text/category.rb', line 54 def category_key_plain CATEGORY_KEY_PLAIN end |
.template ⇒ String
Returns a static ERB template used to render ‘Category`-like instances to plain text.
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/occi/core/renderers/text/category.rb', line 168 def template '<%= obj_data[:term] %>; ' \ 'scheme="<%= obj_data[:schema] %>"; ' \ 'class="<%= obj_data[:subclass] %>"' \ '<% if long? && obj_data[:title] %>; title="<%= obj_data[:title] %>"<% end %>' \ '<% if long? && obj_data[:rel] %>; rel="<%= obj_data[:rel] %>"<% end %>' \ '<% if long? && obj_data[:location] %>; location="<%= obj_data[:location] %>"<% end %>' \ '<% if long? && obj_data[:attributes] %>; attributes="<%= obj_data[:attributes] %>"<% end %>' \ '<% if long? && obj_data[:actions] %>; actions="<%= obj_data[:actions] %>"<% end %>' end |
Instance Method Details
#category_key_headers ⇒ String
Returns word used to key all categories rendered to headers.
46 47 48 |
# File 'lib/occi/core/renderers/text/category.rb', line 46 def category_key_headers CATEGORY_KEY_HEADERS end |
#category_key_plain ⇒ String
Returns keyword used to prefix all categories rendered to plain text.
39 40 41 |
# File 'lib/occi/core/renderers/text/category.rb', line 39 def category_key_plain CATEGORY_KEY_PLAIN end |
#render_headers ⇒ Hash
Renders ‘object` into text for headers and returns the result as `Hash`.
31 32 33 34 |
# File 'lib/occi/core/renderers/text/category.rb', line 31 def render_headers obj_data = object_data { CATEGORY_KEY_HEADERS => [erb_render(obj_data)] } end |
#render_plain ⇒ String
Renders ‘object` into plain text and returns the result as `String`.
22 23 24 25 |
# File 'lib/occi/core/renderers/text/category.rb', line 22 def render_plain obj_data = object_data "#{CATEGORY_KEY_PLAIN}: #{erb_render(obj_data)}" end |