Module: Virgo::ApplicationHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/virgo/application_helper.rb
Instance Method Summary collapse
- #action?(*action) ⇒ Boolean
- #admin? ⇒ Boolean
- #admin_access? ⇒ Boolean
- #admin_view? ⇒ Boolean
- #alerts(options = {}) ⇒ Object
- #base_errors(record) ⇒ Object
- #category_timestamp(category_id) ⇒ Object
- #column_timestamp(column_id) ⇒ Object
-
#compact_html(text) ⇒ Object
replaces spaces between tags plus newline characters in an html string.
- #controller?(*controller) ⇒ Boolean
- #decode_html_entities(text) ⇒ Object
- #expanded_post_url(post, extra_opts = {}) ⇒ Object
- #is_admin_view? ⇒ Boolean
- #page_url ⇒ Object
- #post_time_format ⇒ Object
- #post_timestamp(post_id) ⇒ Object
- #production? ⇒ Boolean
- #redis_timestamp_key_for(klass, record_id) ⇒ Object
- #site ⇒ Object
- #site_key ⇒ Object
- #superuser? ⇒ Boolean
- #tabbed_param ⇒ Object
- #word_count(text) ⇒ Object
Instance Method Details
#action?(*action) ⇒ Boolean
7 8 9 |
# File 'app/helpers/virgo/application_helper.rb', line 7 def action?(*action) action.include?(params[:action]) end |
#admin? ⇒ Boolean
19 20 21 |
# File 'app/helpers/virgo/application_helper.rb', line 19 def admin? current_user && current_user.admin? end |
#admin_access? ⇒ Boolean
23 24 25 |
# File 'app/helpers/virgo/application_helper.rb', line 23 def admin_access? current_user && current_user.admin_access? end |
#admin_view? ⇒ Boolean
27 28 29 |
# File 'app/helpers/virgo/application_helper.rb', line 27 def admin_view? params[:controller].starts_with?('virgo/admin') end |
#alerts(options = {}) ⇒ Object
11 12 13 |
# File 'app/helpers/virgo/application_helper.rb', line 11 def alerts(={}) render_to_string(:partial => "/virgo/common/alerts", locals: ).html_safe end |
#base_errors(record) ⇒ Object
44 45 46 |
# File 'app/helpers/virgo/application_helper.rb', line 44 def base_errors(record) render_to_string(:partial => "/virgo/common/base_errors", locals: {record: record}).html_safe end |
#category_timestamp(category_id) ⇒ Object
78 79 80 81 82 |
# File 'app/helpers/virgo/application_helper.rb', line 78 def (category_id) Rails.cache.fetch((Virgo::Category, category_id)) do "#{(Category, category_id)}-#{Time.now.to_i}" end end |
#column_timestamp(column_id) ⇒ Object
84 85 86 87 88 |
# File 'app/helpers/virgo/application_helper.rb', line 84 def (column_id) Rails.cache.fetch((Virgo::Column, column_id)) do "#{(Column, column_id)}-#{Time.now.to_i}" end end |
#compact_html(text) ⇒ Object
replaces spaces between tags plus newline characters in an html string
53 54 55 56 57 58 |
# File 'app/helpers/virgo/application_helper.rb', line 53 def compact_html(text) _text = text.gsub(/\>(?<spaces>\s+)[\n|\<]/) { |m| m.gsub($1, "") } _text.gsub("\n", "").html_safe end |
#controller?(*controller) ⇒ Boolean
3 4 5 |
# File 'app/helpers/virgo/application_helper.rb', line 3 def controller?(*controller) controller.include?(params[:controller]) end |
#decode_html_entities(text) ⇒ Object
98 99 100 101 102 |
# File 'app/helpers/virgo/application_helper.rb', line 98 def decode_html_entities(text) @html_entities ||= HTMLEntities.new text = text.html_safe.gsub("'", "'") if text.present? @html_entities.decode(text) end |
#expanded_post_url(post, extra_opts = {}) ⇒ Object
60 61 62 |
# File 'app/helpers/virgo/application_helper.rb', line 60 def (post, extra_opts={}) virgo.post_detail_url(post) end |
#is_admin_view? ⇒ Boolean
104 105 106 |
# File 'app/helpers/virgo/application_helper.rb', line 104 def is_admin_view? @_is_admin_view || false end |
#page_url ⇒ Object
108 109 110 111 112 113 114 |
# File 'app/helpers/virgo/application_helper.rb', line 108 def page_url _url = "#{request.protocol}#{Rails.application.config.domain}" _url += ":#{request.port}" if request.port.present? && request.port != 80 && request.port != 443 _url += request.path end |
#post_time_format ⇒ Object
48 49 50 |
# File 'app/helpers/virgo/application_helper.rb', line 48 def post_time_format "%B %e, %Y at %l:%M%P" end |
#post_timestamp(post_id) ⇒ Object
72 73 74 75 76 |
# File 'app/helpers/virgo/application_helper.rb', line 72 def (post_id) Rails.cache.fetch((Virgo::Post, post_id)) do "#{(Post, post_id)}-#{Time.now.to_i}" end end |
#production? ⇒ Boolean
35 36 37 |
# File 'app/helpers/virgo/application_helper.rb', line 35 def production? Rails.env.production? end |
#redis_timestamp_key_for(klass, record_id) ⇒ Object
68 69 70 |
# File 'app/helpers/virgo/application_helper.rb', line 68 def (klass, record_id) ActiveRecord::Base.(klass, record_id) end |
#site ⇒ Object
94 95 96 |
# File 'app/helpers/virgo/application_helper.rb', line 94 def site @site ||= Site.instance end |
#site_key ⇒ Object
64 65 66 |
# File 'app/helpers/virgo/application_helper.rb', line 64 def site_key "#{Time.now.beginning_of_day.to_i}-#{Rails.cache.read('site_key')}" end |
#superuser? ⇒ Boolean
15 16 17 |
# File 'app/helpers/virgo/application_helper.rb', line 15 def superuser? current_user && current_user.superuser? end |
#tabbed_param ⇒ Object
90 91 92 |
# File 'app/helpers/virgo/application_helper.rb', line 90 def tabbed_param params.permit(:tabbed)[:tabbed].try(:to_bool) end |
#word_count(text) ⇒ Object
39 40 41 42 |
# File 'app/helpers/virgo/application_helper.rb', line 39 def word_count(text) text ||= "" text.scan(/\w+/).length end |