Module: BaseHelper
- Includes:
- BlogHelper
- Defined in:
- app/helpers/base_helper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#author_picture(status) ⇒ Object
-
#avatar_tag(options = {}) ⇒ Object
-
#content_array ⇒ Object
-
#display_date(date) ⇒ Object
-
#display_date_and_time(timestamp) ⇒ Object
-
#display_time(time) ⇒ Object
-
#display_user_avatar(user, size = "avatar", klass = "alignleft") ⇒ Object
-
#feed_atom ⇒ Object
-
#feed_rss ⇒ Object
-
#feed_title ⇒ Object
-
#get_reply_context_twitter_link(reply) ⇒ Object
-
#get_reply_context_url(reply) ⇒ Object
-
#html(content, what = :all, _deprecated = false) ⇒ Object
-
#link_to_permalink(item, title, anchor = nil, style = nil, nofollow = nil, only_path = false) ⇒ Object
-
#markup_help_popup(markup, text) ⇒ Object
-
#meta_tag(name, value) ⇒ Object
-
#onhover_show_admin_tools(type, id = nil) ⇒ Object
-
#page_header_includes ⇒ Object
-
#render_sidebar(sidebar) ⇒ Object
-
#render_sidebars ⇒ Object
-
#render_to_string(*args, &block) ⇒ Object
-
#show_meta_keyword ⇒ Object
-
#stop_index_robots?(blog) ⇒ Boolean
-
#themeable_javascript_include_tag(name) ⇒ Object
-
#themeable_stylesheet_link_tag(name) ⇒ Object
Methods included from BlogHelper
#blog_base_url, #this_blog
Instance Attribute Details
#page_title ⇒ Object
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
128
129
130
131
132
133
|
# File 'app/helpers/base_helper.rb', line 128
def author_picture(status)
return if status.user..blank?
image_tag(status.user., 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_array ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
|
# File 'app/helpers/base_helper.rb', line 156
def content_array
if @articles
@articles
elsif @article
[@article]
elsif @page
[@page]
else
[]
end
end
|
#display_date(date) ⇒ Object
168
169
170
|
# File 'app/helpers/base_helper.rb', line 168
def display_date(date)
l(date, format: this_blog.date_format)
end
|
#display_date_and_time(timestamp) ⇒ Object
176
177
178
179
180
181
182
183
184
|
# File 'app/helpers/base_helper.rb', line 176
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
172
173
174
|
# File 'app/helpers/base_helper.rb', line 172
def display_time(time)
time.strftime(this_blog.time_format)
end
|
#display_user_avatar(user, size = "avatar", klass = "alignleft") ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'app/helpers/base_helper.rb', line 105
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..present?
avatar_url = user.
end
return unless avatar_url
image_tag(avatar_url, alt: user.nickname, class: klass)
end
|
#feed_atom ⇒ Object
148
149
150
|
# File 'app/helpers/base_helper.rb', line 148
def feed_atom
feed_for("atom")
end
|
152
153
154
|
# File 'app/helpers/base_helper.rb', line 152
def
feed_for("rss")
end
|
#feed_title ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'app/helpers/base_helper.rb', line 91
def feed_title
if @feed_title.present?
@feed_title
elsif @page_title.present?
@page_title
else
this_blog.blog_name
end
end
|
206
207
208
209
|
# File 'app/helpers/base_helper.rb', line 206
def (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
199
200
201
202
203
204
|
# File 'app/helpers/base_helper.rb', line 199
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
101
102
103
|
# File 'app/helpers/base_helper.rb', line 101
def html(content, what = :all, _deprecated = false)
content.html(what)
end
|
#link_to_permalink(item, title, anchor = nil, style = nil, nofollow = nil, only_path = false) ⇒ Object
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
|
72
73
74
75
76
77
78
79
80
|
# File 'app/helpers/base_helper.rb', line 72
def (markup, text)
if markup && markup..size > 1
link_to(text,
url_for(controller: "articles", action: "markup_help", id: markup.name),
onclick: "return popup(this, 'Publify Markup Help')")
else
""
end
end
|
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
|
82
83
84
85
86
87
88
89
|
# File 'app/helpers/base_helper.rb', line 82
def onhover_show_admin_tools(type, id = nil)
admin_id = "#admin_#{[type, id].compact.join("_")}"
tag = []
tag << %{ onmouseover="if (getCookie('publify_user_profile') == 'admin')\
{ $('#{admin_id}').show(); }" }
tag << %{ onmouseout="$('#{admin_id}').hide();" }
safe_join(tag, " ")
end
|
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'app/helpers/base_helper.rb', line 135
def
content_array.map(&:whiteboard).map do |w|
w.select { |k, _v| k =~ /^page_header_/ }.map do |_, v|
v = v.chomp
spaces = /\A[ \t]*/.match(v)[0].gsub(/\t/, " ")
v.gsub!(/^#{spaces}/, " ")
end
end.flatten.uniq.join("\n")
end
|
25
26
27
28
|
# File 'app/helpers/base_helper.rb', line 25
def ()
render_to_string(partial: .content_partial, locals: .to_locals_hash,
layout: false)
end
|
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/helpers/base_helper.rb', line 12
def
= .order(:active_position).map do |sb|
= sb
sb.parse_request(content_array, params)
(sb)
end
safe_join
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
|
186
187
188
189
190
|
# File 'app/helpers/base_helper.rb', line 186
def show_meta_keyword
return unless this_blog.use_meta_keyword
meta_tag "keywords", @keywords if @keywords.present?
end
|
#stop_index_robots?(blog) ⇒ Boolean
192
193
194
195
196
197
|
# File 'app/helpers/base_helper.rb', line 192
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
|
#themeable_stylesheet_link_tag(name) ⇒ Object
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
|