Module: Sinicum::MgnlHelper
Constant Summary
Constants included from HelperUtils
HelperUtils::DEFAULT_DOCUMENT_WORKSPACE, HelperUtils::FINGERPRINT_REGEX
Instance Method Summary collapse
- #mgnl_content_data ⇒ Object
- #mgnl_exists?(key_or_object, options = {}) ⇒ Boolean
- #mgnl_link(key_or_object, options = {}, &block) ⇒ Object
-
#mgnl_meta(options = {}) ⇒ Object
Public: Displays the ‘<title>` tag and the `<meta>` tags for a page.
-
#mgnl_navigation(base_node_or_path, type, options = {}, &block) ⇒ Object
Public: Iterates over an array with NavigationElement instances.
- #mgnl_original_content ⇒ Object
- #mgnl_out(key, options = {}) ⇒ Object
-
#mgnl_path(key_or_object, options = {}) ⇒ Object
Public: Returns the path for an object:.
- #mgnl_push(key_or_object, options = {}) ⇒ Object
- #mgnl_value(key) ⇒ Object
Instance Method Details
#mgnl_content_data ⇒ Object
61 62 63 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 61 def mgnl_content_data Content::Aggregator.content_data end |
#mgnl_exists?(key_or_object, options = {}) ⇒ Boolean
45 46 47 48 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 45 def mgnl_exists?(key_or_object, = {}) object = object_from_key_or_object(key_or_object, [:workspace] || "website") !object.nil? end |
#mgnl_link(key_or_object, options = {}, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 27 def mgnl_link(key_or_object, = {}, &block) = .dup object = object_from_key_or_object(key_or_object, [:workspace] || "website") object = key_or_object if object.nil? && key_or_object.is_a?(String) if object tag_params = link_tag_params(object, ) if block_given? content_tag(:a, tag_params) do capture(&block) end else content_tag(:a, nil, tag_params) end elsif block && [:show_content] capture(&block) end end |
#mgnl_meta(options = {}) ⇒ Object
Public: Displays the ‘<title>` tag and the `<meta>` tags for a page. The attributes must follow the default naming conventions.
Currently used attributes:
-
title
-
meta_title
-
meta_description
-
meta_keywords
-
meta_noindex
-
meta_search_weight
-
meta_search_boost
Returns a String with all necessary ‘<meta>` tags and the `<title>` tag.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 99 def ( = {}) result = tag( :meta, :'http-equiv' => 'content-type', 'content' => 'text/html; charset=utf-8') result << "\n" result << () result << "\n" result << (:description, :meta_description) result << (:keywords, :meta_keywords) result << (:'X-Search-Weight', :meta_keywords) result << (:'X-Search-Boost', :meta_search_boost) if (:meta_noindex) || (:robots) == 'false' result << (:robots, 'noindex, nofollow') end result << (:language, I18n.locale.to_s) result << (:'DC.language', I18n.locale.to_s) result.html_safe end |
#mgnl_navigation(base_node_or_path, type, options = {}, &block) ⇒ Object
Public: Iterates over an array with NavigationElement instances.
base_node_or_path - The node or the path that should be the base of the
type - Type of the navigation. Currently supports only
`:children`.
options - Options for the navigation:
:depth - The depth of a `children` based navigation.
block - The block with the content of the navigation. It
yields with an instance of a NavigationElement.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 127 def (base_node_or_path, type, = {}, &block) elements = [] if type == :children handler = Navigation::NavigationHandler.children(base_node_or_path, [:depth]) elements = handler.elements elsif type == :parents handler = Navigation::NavigationHandler.parents(base_node_or_path) elements = handler.elements end if block_given? elements.each do |element, status| block.call(element, status) end else elements end end |
#mgnl_original_content ⇒ Object
65 66 67 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 65 def mgnl_original_content Content::Aggregator.original_content end |
#mgnl_out(key, options = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 73 def mgnl_out(key, = {}) value = mgnl_value(key) value = "" if value.nil? value = value.to_s if [:format] == :sanitize value = sanitize(value) elsif [:format] == :strip_tags value = (value) end value.html_safe end |
#mgnl_path(key_or_object, options = {}) ⇒ Object
Public: Returns the path for an object:
-
If the object is a Node, it returns the path of the node
-
If the object is a UUID-String, it is resolved to the Node and the node’s path is returned
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 11 def mgnl_path(key_or_object, = {}) path = nil object = object_from_key_or_object(key_or_object, [:workspace] || "website") if object if object.respond_to?(:path) path = object.path path = object.path(converter: [:renderer]) if .key?(:renderer) elsif object.is_a?(String) path = object.dup end elsif key_or_object.is_a?(String) path = key_or_object.dup end path end |
#mgnl_push(key_or_object, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 50 def mgnl_push(key_or_object, = {}) workspace = [:workspace] pushed_content = object_from_key_or_object(key_or_object, workspace) if pushed_content Content::Aggregator.push(pushed_content) do yield end end nil end |
#mgnl_value(key) ⇒ Object
69 70 71 |
# File 'app/helpers/sinicum/mgnl_helper.rb', line 69 def mgnl_value(key) value_from_content(Content::Aggregator.content_data, key) end |