Module: Virgo::ApplicationHelper

Included in:
ApplicationController
Defined in:
app/helpers/virgo/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#action?(*action) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/helpers/virgo/application_helper.rb', line 7

def action?(*action)
  action.include?(params[:action])
end

#admin?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/helpers/virgo/application_helper.rb', line 19

def admin?
  current_user && current_user.admin?
end

#admin_access?Boolean

Returns:

  • (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

Returns:

  • (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(options={})
  render_to_string(:partial => "/virgo/common/alerts", locals: options).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_timestamp(category_id)
  Rails.cache.fetch(redis_timestamp_key_for(Virgo::Category, category_id)) do
    "#{redis_timestamp_key_for(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_timestamp(column_id)
  Rails.cache.fetch(redis_timestamp_key_for(Virgo::Column, column_id)) do
    "#{redis_timestamp_key_for(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

Returns:

  • (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 expanded_post_url(post, extra_opts={})
  virgo.post_detail_url(post)
end

#is_admin_view?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/helpers/virgo/application_helper.rb', line 104

def is_admin_view?
  @_is_admin_view || false
end

#page_urlObject



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_formatObject



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(redis_timestamp_key_for(Virgo::Post, post_id)) do
    "#{redis_timestamp_key_for(Post, post_id)}-#{Time.now.to_i}"
  end
end

#production?Boolean

Returns:

  • (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 redis_timestamp_key_for(klass, record_id)
  ActiveRecord::Base.redis_timestamp_key_for(klass, record_id)
end

#siteObject



94
95
96
# File 'app/helpers/virgo/application_helper.rb', line 94

def site
  @site ||= Site.instance
end

#site_keyObject



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

Returns:

  • (Boolean)


15
16
17
# File 'app/helpers/virgo/application_helper.rb', line 15

def superuser?
  current_user && current_user.superuser?
end

#tabbed_paramObject



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