Module: BaseHelper

Includes:
BlogHelper
Defined in:
app/helpers/base_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlogHelper

#blog_base_url, #this_blog

Instance Attribute Details

#page_titleObject (readonly)

Need to rewrite this one, quick hack to test my changes.



10
11
12
# File 'app/helpers/base_helper.rb', line 10

def page_title
  @page_title
end

Instance Method Details

#author_picture(status) ⇒ Object



136
137
138
139
140
141
# File 'app/helpers/base_helper.rb', line 136

def author_picture(status)
  return if status.user.twitter_profile_image.blank?

  image_tag(status.user.twitter_profile_image, class: "alignleft",
                                               alt: status.user.nickname)
end

#avatar_tag(options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/base_helper.rb', line 57

def avatar_tag(options = {})
  begin
    avatar_class = this_blog.plugin_avatar.constantize
  rescue NameError
    return ""
  end
  return "" unless avatar_class.respond_to?(:get_avatar)

  avatar_class.get_avatar(options)
end

#content_arrayObject



164
165
166
167
168
169
170
171
172
173
174
# File 'app/helpers/base_helper.rb', line 164

def content_array
  if @articles
    @articles
  elsif @article
    [@article]
  elsif @page
    [@page]
  else
    []
  end
end

#display_date(date) ⇒ Object



176
177
178
# File 'app/helpers/base_helper.rb', line 176

def display_date(date)
  l(date, format: this_blog.date_format)
end

#display_date_and_time(timestamp) ⇒ Object



184
185
186
187
188
189
190
191
192
# File 'app/helpers/base_helper.rb', line 184

def display_date_and_time(timestamp)
  return if timestamp.blank?

  if this_blog.date_format == "setting_date_format_distance_of_time_in_words"
    timeago_tag timestamp, date_only: false
  else
    "#{display_date(timestamp)} #{t("helper.at")} #{display_time(timestamp)}"
  end
end

#display_time(time) ⇒ Object



180
181
182
# File 'app/helpers/base_helper.rb', line 180

def display_time(time)
  time.strftime(this_blog.time_format)
end

#display_user_avatar(user, size = "avatar", klass = "alignleft") ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/helpers/base_helper.rb', line 113

def display_user_avatar(user, size = "avatar", klass = "alignleft")
  if user.resource.present?
    avatar_path = case size
                  when "thumb"
                    user.resource.upload.thumb.url
                  when "medium"
                    user.resource.upload.medium.url
                  when "large"
                    user.resource.upload.large.url
                  else
                    user.resource.upload.avatar.url
                  end
    return if avatar_path.nil?

    avatar_url = this_blog.file_url(avatar_path)
  elsif user.twitter_profile_image.present?
    avatar_url = user.twitter_profile_image
  end
  return unless avatar_url

  image_tag(avatar_url, alt: user.nickname, class: klass)
end

#feed_atomObject



156
157
158
# File 'app/helpers/base_helper.rb', line 156

def feed_atom
  feed_for("atom")
end

#feed_rssObject



160
161
162
# File 'app/helpers/base_helper.rb', line 160

def feed_rss
  feed_for("rss")
end

#feed_titleObject



99
100
101
102
103
104
105
106
107
# File 'app/helpers/base_helper.rb', line 99

def feed_title
  if @feed_title.present?
    @feed_title
  elsif @page_title.present?
    @page_title
  else
    this_blog.blog_name
  end
end


214
215
216
217
# File 'app/helpers/base_helper.rb', line 214

def get_reply_context_twitter_link(reply)
  link_to(display_date_and_time(reply["created_at"].to_time.in_time_zone),
          "https://twitter.com/#{reply["user"]["screen_name"]}/status/#{reply["id_str"]}")
end

#get_reply_context_url(reply) ⇒ Object



207
208
209
210
211
212
# File 'app/helpers/base_helper.rb', line 207

def get_reply_context_url(reply)
  link_to(reply["user"]["name"],
          reply["user"]["entities"]["url"]["urls"][0]["expanded_url"])
rescue
  link_to(reply["user"]["name"], "https://twitter.com/#{reply["user"]["name"]}")
end

#html(content, what = :all, _deprecated = false) ⇒ Object



109
110
111
# File 'app/helpers/base_helper.rb', line 109

def html(content, what = :all, _deprecated = false)
  content.html(what)
end


44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/base_helper.rb', line 44

def link_to_permalink(item, title,
                      anchor: nil, style: nil, nofollow: nil, only_path: false)
  options = {}
  options[:class] = style if style
  options[:rel] = "nofollow" if nofollow
  url = item.permalink_url(anchor, only_path)
  if url
    link_to title, url, options
  else
    title
  end
end

#markup_help_popup(markup, text) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/helpers/base_helper.rb', line 72

def markup_help_popup(markup, text)
  if markup && markup.commenthelp.size > 1
    modal = tag.dialog id: "this_markup_help_popup_dialog", class: "markup-help-popup" do
      tag.div do
        close_div = tag.div tag.span("\u2a09", class: "markup-help-popup-close")
        content = tag.div class: "content-target"
        safe_join [close_div, content]
      end
    end

    url = url_for(controller: "articles", action: "markup_help", id: markup.name)

    link = link_to(text, "#", class: "markup-help-popup-link",
                              data: { target: "this_markup_help_popup_dialog",
                                      url: url })

    safe_join [modal, link]
  else
    ""
  end
end

#meta_tag(name, value) ⇒ Object



68
69
70
# File 'app/helpers/base_helper.rb', line 68

def meta_tag(name, value)
  tag.meta(name: name, content: value) if value.present?
end

#onhover_show_admin_tools(_type, _id = nil) ⇒ Object

This method’s original implementation was broken. Now it does nothing.



95
96
97
# File 'app/helpers/base_helper.rb', line 95

def onhover_show_admin_tools(_type, _id = nil)
  ""
end

#page_header_includesObject



143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/helpers/base_helper.rb', line 143

def page_header_includes
  content_array.map(&:whiteboard).map do |w|
    w.select { |k, _v| k.start_with?("page_header_") }.map do |_, v|
      v = v.chomp
      # trim the same number of spaces from the beginning of each line
      # this way plugins can indent nicely without making ugly source output
      spaces = /\A[ \t]*/.match(v)[0].gsub("\t", "  ")
      # add 2 spaces to line up with the assumed position of the surrounding tags
      v.gsub!(/^#{spaces}/, "  ")
    end
  end.flatten.uniq.join("\n")
end

#render_sidebar(sidebar) ⇒ Object



25
26
27
28
# File 'app/helpers/base_helper.rb', line 25

def render_sidebar(sidebar)
  render_to_string(partial: sidebar.content_partial, locals: sidebar.to_locals_hash,
                   layout: false)
end

#render_sidebarsObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/base_helper.rb', line 12

def render_sidebars
  rendered_sidebars = Sidebar.order(:active_position).map do |sb|
    @sidebar = sb
    sb.parse_request(content_array, params)
    render_sidebar(sb)
  end
  safe_join rendered_sidebars
rescue => e
  logger.error e
  logger.error e.backtrace.join("\n")
  I18n.t("errors.render_sidebar")
end

#render_to_string(*args, &block) ⇒ Object



40
41
42
# File 'app/helpers/base_helper.rb', line 40

def render_to_string(*args, &block)
  controller.send(:render_to_string, *args, &block)
end

#show_meta_keywordObject



194
195
196
197
198
# File 'app/helpers/base_helper.rb', line 194

def show_meta_keyword
  return unless this_blog.use_meta_keyword

  meta_tag "keywords", @keywords if @keywords.present?
end

#stop_index_robots?(blog) ⇒ Boolean

Returns:

  • (Boolean)


200
201
202
203
204
205
# File 'app/helpers/base_helper.rb', line 200

def stop_index_robots?(blog)
  stop = params[:year].present? || params[:page].present?
  stop = blog.unindex_tags if controller_name == "tags"
  stop = blog.unindex_categories if controller_name == "categories"
  stop
end

#themeable_javascript_include_tag(name) ⇒ Object



35
36
37
38
# File 'app/helpers/base_helper.rb', line 35

def themeable_javascript_include_tag(name)
  src = this_blog.current_theme.path + "/javascripts/#{name}.js"
  javascript_include_tag "/javascripts/theme/#{name}.js" if File.exist? src
end


30
31
32
33
# File 'app/helpers/base_helper.rb', line 30

def themeable_stylesheet_link_tag(name)
  src = this_blog.current_theme.path + "/stylesheets/#{name}.css"
  stylesheet_link_tag "/stylesheets/theme/#{name}.css" if File.exist? src
end