Module: Sinicum::MgnlHelper

Includes:
HelperUtils
Included in:
MgnlHelper5
Defined in:
app/helpers/sinicum/mgnl_helper.rb

Constant Summary

Constants included from HelperUtils

HelperUtils::DEFAULT_DOCUMENT_WORKSPACE, HelperUtils::FINGERPRINT_REGEX

Instance Method Summary collapse

Instance Method Details

#mgnl_content_dataObject



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

Returns:

  • (Boolean)


45
46
47
48
# File 'app/helpers/sinicum/mgnl_helper.rb', line 45

def mgnl_exists?(key_or_object, options = {})
  object = object_from_key_or_object(key_or_object, options[:workspace] || "website")
  !object.nil?
end


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, options = {}, &block)
  options = options.dup
  object = object_from_key_or_object(key_or_object, options[:workspace] || "website")
  object = key_or_object if object.nil? && key_or_object.is_a?(String)
  if object
    tag_params = link_tag_params(object, options)
    if block_given?
      (:a, tag_params) do
        capture(&block)
      end
    else
      (:a, nil, tag_params)
    end
  elsif block && options[: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 mgnl_meta(options = {})
  result = tag(
    :meta, :'http-equiv' => 'content-type', 'content' => 'text/html; charset=utf-8')
  result << "\n"
  result << (options)
  result << "\n"
  result << meta_simple_meta_tag(:description, :meta_description)
  result << meta_simple_meta_tag(:keywords, :meta_keywords)
  result << meta_simple_meta_tag(:'X-Search-Weight', :meta_keywords)
  result << meta_simple_meta_tag(:'X-Search-Boost', :meta_search_boost)
  if meta_tag_value(:meta_noindex) || meta_tag_value(:robots) == 'false'
    result << meta_simple_meta_tag(:robots, 'noindex, nofollow')
  end
  result << meta_simple_meta_tag(:language, I18n.locale.to_s)
  result << meta_simple_meta_tag(:'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

navigation

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 mgnl_navigation(base_node_or_path, type, options = {}, &block)
  elements = []
  if type == :children
    handler = Navigation::NavigationHandler.children(base_node_or_path, options[: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_contentObject



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, options = {})
  value = mgnl_value(key)
  value = "" if value.nil?
  value = value.to_s
  if options[:format] == :sanitize
    value = sanitize(value)
  elsif options[:format] == :strip_tags
    value = strip_tags(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, options = {})
  path = nil
  object = object_from_key_or_object(key_or_object, options[:workspace] || "website")
  if object
    if object.respond_to?(:path)
      path = object.path
      path = object.path(converter: options[:renderer]) if options.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, options = {})
  workspace = options[: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