Module: Goldencobra::ArticlesHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/goldencobra/articles_helper.rb

Instance Method Summary collapse

Instance Method Details

#index_of_articles(options = {}) ⇒ Object

Deprecated Helper Method, will be removed in GC 2.1



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/goldencobra/articles_helper.rb', line 68

def index_of_articles(options={})
  warn "Deprecated helper method 'index_of_articles'. Will be removed in GC 2.1"
  if @article && @article.article_for_index_id.present? && master_index_article = Goldencobra::Article.find_by_id(@article.article_for_index_id)
    result_list = ""
    result_list += (:h2, raw(" "), class: "boxheader")
    result_list += (:h1, "#{master_index_article.title}", class: "headline")
    dom_element = (options[:wrapper]).present? ? options[:wrapper] : :div
    master_index_article.descendants.order(:created_at).limit(@article.article_for_index_limit).each do |art|
      if @article.article_for_index_levels.to_i == 0 || (@article.depth + @article.article_for_index_levels.to_i > art.depth)
        rendered_article_list_item = render_article_list_item(art)
        result_list += (dom_element, rendered_article_list_item, id: "article_index_list_item_#{art.id}", class: "article_index_list_item")
      end
    end
    return (:article, raw(result_list), id: "article_index_list")
  end
end

#parse_glossar_entries(content, tag_name, parent_article_id = nil) ⇒ Object

Parse text for a single Word and make a link to an Article to this Word as a Subarticle of a given Article



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/goldencobra/articles_helper.rb', line 26

def parse_glossar_entries(content,tag_name, parent_article_id=nil)
  glossar_parent = nil
  if parent_article_id
    glossar_parent = Goldencobra::Article.find_by_id(parent_article_id)
    glossar_article = glossar_parent.children.where(breadcrumb: tag_name).first
  else
    glossar_article = Goldencobra::Article.where(breadcrumb: tag_name).first
  end
  unless glossar_article
    glossar_article = Goldencobra::Article.create(title: tag_name, breadcrumb: tag_name, article_type: "Default Show", parent: glossar_parent)
  end

  if glossar_article.present?
    replace_with = "<a href='#{glossar_article.public_url}' class='glossar'>#{tag_name}</a>"
    content = content.gsub(/\b(?<!\/)#{tag_name}(?!<)\b/, "#{replace_with}")
  end
end

#read_on(article, options = {}) ⇒ Object

‘Read on’ link to article for index-pages If external_url_redirect is set and a link_title is given, display this link title. Otherwise display a generic link title.



9
10
11
12
13
14
15
16
17
# File 'app/helpers/goldencobra/articles_helper.rb', line 9

def read_on(article, options={})
  target_window = article.redirection_target_in_new_window ? "_blank" : "_top"
  html_class = "more #{options[:class]}".strip
  if article.redirect_link_title.present?
    link_to article.redirect_link_title, article.external_url_redirect, class: html_class, target: target_window
  else
    link_to t(:read_on, scope: [:articles]), article.public_url, class: html_class, target: target_window, title: article.title
  end
end

#render_article_content_parts(article) ⇒ Object

Ausgabe aller Hauptbestandteile eines Artikels über “content_for :xy”



20
21
22
# File 'app/helpers/goldencobra/articles_helper.rb', line 20

def render_article_content_parts(article)
  render partial: "/goldencobra/articles/show", locals: {article: article}
end

#render_article_image_gallery(options = {}) ⇒ HTML

render_article_image_gallery description

Parameters:

  • options={}
    Hash

    :thumb, target_image_size: :large

Returns:

  • (HTML)

    ImageGallery



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/goldencobra/articles_helper.rb', line 49

def render_article_image_gallery(options = {})
  if @article && @article.image_gallery_tags.present?
    tags = @article.image_gallery_tags.split(",")
    uploads = Goldencobra::Upload.tagged_with(tags)
    list_items = ""
    uploads.order(:sorter_number).each do |upload|
      list_items << ("li") do
        link_to upload.image.url(options[:target_image_size] || :large), title: raw(upload.description) do
          image_tag(upload.image.url(options[:link_image_size] || :thumb), alt: upload.alt_text)
        end
      end
    end
    ("ul", raw(list_items), class: "goldencobra_article_image_gallery")
  elsif @article
    ("ul", raw(""), class: "goldencobra_article_image_gallery")
  end
end

#render_article_type_content(options = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'app/helpers/goldencobra/articles_helper.rb', line 85

def render_article_type_content(options={})
  if @article
    if @article.article_type.present? && @article.kind_of_article_type.present?
     render partial: "articletypes/#{@article.article_type_form_file.underscore.parameterize.downcase}/#{@article.kind_of_article_type.downcase}"
    else
      render partial: "articletypes/default/show"
    end
  end
end

#render_article_widgets(options = {}) ⇒ Object



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
155
156
157
158
159
160
161
162
163
# File 'app/helpers/goldencobra/articles_helper.rb', line 95

def render_article_widgets(options={})
  custom_css = options[:class] || ""
  tags = options[:tagged_with] || ""

  #include default widgets?
  include_defaults = options[:default].to_s == "true" || false

  #include article widgets?
  if options[:article].present?
    include_articles = options[:article].to_s == "true"
  else
    include_articles = true
  end

  widget_wrapper = options[:wrapper] || "section"
  result = ""
  if params[:frontend_tags] && params[:frontend_tags].class != String && params[:frontend_tags][:format] && params[:frontend_tags][:format] == "email"
    #Wenn format email, dann gibt es keinen realen webseit besucher
    ability = Ability.new()
  else
    if !defined?(current_user).nil? || !defined?(current_visitor).nil?
      operator = current_user || current_visitor
      ability = Ability.new(operator)
    else
      ability = Ability.new()
    end
  end

  # Get article Widgets
  if @article && include_articles
    article_widgets = @article.widgets.active.tagged_with(tags.split(","))
  else
    article_widgets = []
  end

  #Get default widgets
  if include_defaults == true
    default_widgets = Goldencobra::Widget.active.where(default: true)
    default_widgets = default_widgets.tagged_with(tags.split(",")) if tags.present?
  else
    default_widgets = []
  end

  # merge article and default widgets
  widgets = [default_widgets] + [article_widgets]
  widgets = widgets.flatten.uniq.compact

  #Sort widgets bei global sorter id
  widgets = widgets.sort_by(&:sorter)

  #render Widgets
  widgets.each do |widget|
    #check if current user has permissions to see this widget
    if ability.can?(:read, widget)
      template = Liquid::Template.parse(widget.content)
      html_data_options = {"class" => "#{widget.css_name} #{custom_css} goldencobra_widget",
                            "id" => widget.id_name.present? ? widget.id_name : "widget_id_#{widget.id}",
                            'data-id' => widget.id
                          }
      if widget_wrapper == ""
        result << raw(template.render(Goldencobra::Article::LiquidParser))
      else
        result << (widget_wrapper, raw(template.render(Goldencobra::Article::LiquidParser)), html_data_options)
      end
    end
  end

  return raw(result)
end