Module: Gluttonberg::Public
- Included in:
- Admin::Membership::MembersController, ApplicationHelper
- Defined in:
- app/helpers/gluttonberg/public.rb,
app/controllers/gluttonberg/public/flag_controller.rb,
app/controllers/gluttonberg/public/blogs_controller.rb,
app/controllers/gluttonberg/public/pages_controller.rb,
app/controllers/gluttonberg/public/members_controller.rb,
app/controllers/gluttonberg/public/articles_controller.rb,
app/controllers/gluttonberg/public/comments_controller.rb,
app/controllers/gluttonberg/public/public_assets_controller.rb,
app/controllers/gluttonberg/public/member_sessions_controller.rb,
app/controllers/gluttonberg/public/member_password_resets_controller.rb
Overview
A few simple helpers to be used when rendering page templates.
Defined Under Namespace
Classes: ArticlesController, BaseController, BlogsController, CommentsController, FlagController, MemberPasswordResetsController, MemberSessionsController, MembersController, PagesController, PublicAssetsController
Instance Method Summary
collapse
Instance Method Details
#body_class(page) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
|
# File 'app/helpers/gluttonberg/public.rb', line 175
def body_class(page)
if !@page.blank?
"page #{@page.current_localization.slug} #{@page.home? ? 'home' : ''}"
elsif !@article.blank?
"post #{@article.slug}"
elsif !@blog.blank?
"blog #{@blog.slug}"
elsif !@custom_model_object.blank?
"#{@custom_model_object.class.name.downcase} #{@custom_model_object.slug}"
end
end
|
#clean_public_query(string) ⇒ Object
275
276
277
278
279
280
281
282
283
|
# File 'app/helpers/gluttonberg/public.rb', line 275
def clean_public_query(string)
unless string.blank?
string = string.gsub("'", "\\\\'")
string = string.gsub("\"", "\\\"")
string = string.gsub(/\${2,}/, "$")
else
string
end
end
|
#clean_public_query_for_sphinx(string) ⇒ Object
285
286
287
288
289
290
291
292
293
|
# File 'app/helpers/gluttonberg/public.rb', line 285
def clean_public_query_for_sphinx(string)
unless string.blank?
string = clean_public_query(string)
string = string.gsub("$", "")
string = string.gsub(/[\!\*'"″′‟‘’‛„‚”“”˝\(\)\;\:\.\@\&\=\+\-\$\,\/?\%\#\[\]]/,'')
else
string
end
end
|
#db_stylesheet_link_tag ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'app/helpers/gluttonberg/public.rb', line 155
def db_stylesheet_link_tag
if Rails.configuration.cms_based_public_css == true
html = ""
Gluttonberg::Stylesheet.all.each do |stylesheet|
html << "\n"
unless stylesheet.css_prefix.blank?
html << stylesheet.css_prefix
html << "\n"
end
html << stylesheet_link_tag( stylesheets_path(stylesheet.slug) +".css?#{stylesheet.version}" )
unless stylesheet.css_postfix.blank?
html << "\n"
html << stylesheet.css_postfix
end
end
html << "\n"
html.html_safe
end
end
|
84
85
86
|
# File 'app/helpers/gluttonberg/public.rb', line 84
def description_meta_tag
tag("meta",{:content => Gluttonberg::Setting.get_setting("description") , :name => "description" } )
end
|
#google_analytics_js_tag ⇒ Object
Returns the code for google analytics
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/helpers/gluttonberg/public.rb', line 58
def google_analytics_js_tag
code = Gluttonberg::Setting.get_setting("google_analytics")
output = ""
unless code.blank?
output += "<script type='text/javascript'>\n"
output += "//<![CDATA[\n"
output += "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n"
output += "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n"
output += "//]]>\n"
output += "</script>\n"
output += "<script type='text/javascript'>\n"
output += "//<![CDATA[\n"
output += "try {\n"
output += "var pageTracker = _gat._getTracker(\"#{code}\");\n"
output += "pageTracker._trackPageview();\n"
output += "} catch(err) {}\n"
output += "//]]>\n"
output += "</script>\n"
end
output.html_safe
end
|
#html_truncate(html, truncate_length, options = {}) ⇒ Object
Does NOT behave identical to current Rails truncate method you must pass options as a hash not just values Sample usage: <%= html_truncate(category.description, :length => 120, :omission => “(continued…)” ) -%>…
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
|
# File 'app/helpers/gluttonberg/public.rb', line 113
def html_truncate(html, truncate_length, options={})
text, result = [], []
previous_tags = []
html.scan(/<\/?[^>]*>|[A-Za-z0-9.,\/&#;\!\+\(\)\-"'?]+/).each { |t| text << t }
text.each do |str|
if truncate_length > 0
if str =~ /<\/?[^>]*>/
if str[0..1] != "</"
previous_tags.push(str)
else
previous_tags.pop()
end
result << str
else
result << str
truncate_length -= str.length
end
else
while previous_tags.length > 0
previous_tag = previous_tags.pop()
unless previous_tag.start_with?("<br") || previous_tag.start_with?("<hr") || previous_tag.start_with?("<input")
tokens = previous_tag.split(" ")
if tokens.length == 1
closing_tag = tokens.first.insert(1 , '/')
else
closing_tag = "#{tokens.first.insert(1 , '/')}>"
end
result << closing_tag
end
end
end
end
return result.join(" ") + options[:omission].to_s
end
|
80
81
82
|
# File 'app/helpers/gluttonberg/public.rb', line 80
def keywords_meta_tag
tag("meta",{:content => Gluttonberg::Setting.get_setting("keywords") , :name => "keywords" } )
end
|
#link_to_inappropriate(obj) ⇒ Object
99
100
101
102
103
104
105
|
# File 'app/helpers/gluttonberg/public.rb', line 99
def link_to_inappropriate(obj)
if current_user and current_user.flagged?(obj)
content_tag(:p, "You have already flagged this item.")
else
link_to "Inappropriate" , mark_as_flag_path(obj.class.name , obj.id)
end
end
|
#navigation_tree(pages, opts = {}) ⇒ Object
A simple helper which loops through a heirarchy of pages and produces a set of nested lists with links to each page.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/helpers/gluttonberg/public.rb', line 8
def navigation_tree(pages, opts = {})
content = ""
pages.each do |page|
if page.hide_in_nav.blank? || page.hide_in_nav == false
li_opts = {:id => page.slug + "Nav"}
li_opts[:class] = "current" if page == @page
page.load_localization(@locale)
if page.home?
li_content = content_tag(:a, page.nav_label, :href => page_url(page , opts)).html_safe
else
if page.description && page.description.top_level_page?
li_content = content_tag(:a, page.nav_label, :href=>"javascript:;", :class => "menu_disabled").html_safe
else
li_content = content_tag(:a, page.nav_label, :href => page_url(page , opts)).html_safe
end
end
children = page.children.published
li_content << navigation_tree(children , opts).html_safe unless children.blank?
content << content_tag(:li, li_content.html_safe, li_opts).html_safe
end
end
content_tag(:ul, content.html_safe, opts).html_safe
end
|
#page_description ⇒ Object
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'app/helpers/gluttonberg/public.rb', line 212
def page_description
wd = Gluttonberg::Setting.get_setting("description")
pd = ""
if !@page.blank?
pd = @page.current_localization.seo_description if @page.current_localization.respond_to?(:seo_description)
elsif !@article.blank?
pd = @article.current_localization.seo_description if @article.current_localization.respond_to?(:seo_description)
elsif !@blog.blank?
pd = @blog.seo_description if @blog.respond_to?(:seo_description)
elsif !@custom_model_object.blank?
pd = @custom_model_object.seo_description if @custom_model_object.respond_to?(:seo_description)
end
if !pd.blank?
pd
else !wd.blank?
wd
end
end
|
#page_fb_icon_path ⇒ Object
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
# File 'app/helpers/gluttonberg/public.rb', line 252
def page_fb_icon_path
wk = Gluttonberg::Setting.get_setting("fb_icon")
pk = ""
if !@page.blank?
pk = @page.current_localization.fb_icon if @page.current_localization.respond_to?(:fb_icon)
elsif !@article.blank?
pk = @article.current_localization.fb_icon if @article.current_localization.respond_to?(:fb_icon)
elsif !@blog.blank?
pk = @blog.fb_icon if @blog.respond_to?(:fb_icon)
elsif !@custom_model_object.blank?
pk = @custom_model_object.fb_icon if @custom_model_object.respond_to?(:fb_icon)
end
if !pk.blank?
asset = pk
else !wk.blank?
asset = Asset.find(:first , :conditions => { :id => wk } )
end
unless asset.blank?
path = asset.url
end
end
|
#page_keywords ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# File 'app/helpers/gluttonberg/public.rb', line 232
def page_keywords
wk = Gluttonberg::Setting.get_setting("keywords")
pk = ""
if !@page.blank?
pk = @page.current_localization.seo_keywords if @page.current_localization.respond_to?(:seo_keywords)
elsif !@article.blank?
pk = @article.current_localization.seo_keywords if @article.current_localization.respond_to?(:seo_keywords)
elsif !@blog.blank?
pk = @blog.seo_keywords if @blog.respond_to?(:seo_keywords)
elsif !@custom_model_object.blank?
pk = @custom_model_object.seo_keywords if @custom_model_object.respond_to?(:seo_keywords)
end
if !pk.blank?
pk
elsif !wk.blank?
wk
end
end
|
#page_title ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'app/helpers/gluttonberg/public.rb', line 187
def page_title
wt = website_title
pt = ""
if !@page.blank?
pt = @page.current_localization.seo_title if @page.current_localization.respond_to?(:seo_title)
pt = @page.title if pt.blank?
elsif !@article.blank?
pt = @article.current_localization.seo_title if @article.current_localization.respond_to?(:seo_title)
pt = @article.current_localization.title if pt.blank?
elsif !@blog.blank?
pt = @blog.seo_title if @blog.respond_to?(:seo_title)
pt = @blog.name if pt.blank?
elsif !@custom_model_object.blank?
pt = @custom_model_object.seo_title if @custom_model_object.respond_to?(:seo_title)
pt = @custom_model_object.title_or_name? if pt.blank?
end
if pt.blank?
wt
elsif wt.blank?
pt
else
"#{pt} | #{wt}"
end
end
|
#page_url(path_or_page, opts = {}) ⇒ Object
This is hacked together. It is working at the moment but needs further work.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/helpers/gluttonberg/public.rb', line 35
def page_url(path_or_page , opts = {})
if path_or_page.is_a?(String)
if Gluttonberg.localized? == true
"/#{opts[:slug]}/#{path_or_page}"
else
"/#{path_or_page}"
end
else
if path_or_page.rewrite_required?
url = Rails.application.routes.recognize_path(path_or_page.description.rewrite_route)
url[:host] = Rails.configuration.host_name
Rails.application.routes.url_for(url)
else
if Gluttonberg.localized? && !opts[:slug].blank?
"/#{opts[:slug]}/#{path_or_page.path}"
else
"#{path_or_page.public_path}"
end
end
end
end
|
#render_match_partial(result) ⇒ Object
88
89
90
91
92
93
94
95
96
97
|
# File 'app/helpers/gluttonberg/public.rb', line 88
def render_match_partial(result)
begin
klass = result.class.name.demodulize.underscore
render :partial => "search/#{klass}", :locals => { :result => result }
rescue ActionView::MissingTemplate => e
"Missing search template for model #{klass}. Create a search/_#{klass}.html.erb partial in the correct plugin and try again."
rescue RuntimeError => e
"Unable to find the class name of the following match #{debug result}"
end
end
|