Module: AbAdmin::Views::Helpers

Defined in:
lib/ab_admin/views/helpers.rb

Instance Method Summary collapse

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/ab_admin/views/helpers.rb', line 5

def admin?
  user_signed_in? && current_user.admin?
end

#as_html(text) ⇒ Object



13
14
15
16
# File 'lib/ab_admin/views/helpers.rb', line 13

def as_html(text)
  return ''.html_safe if text.nil?
  Nokogiri::HTML.fragment(text).to_html.html_safe
end


37
38
39
40
41
42
43
44
45
46
# File 'lib/ab_admin/views/helpers.rb', line 37

def external_link(raw_link, options={}, &block)
  return unless raw_link.present?
  options.reverse_merge!(:title => raw_link, :target => '_blank', :rel => 'nofollow')
  link = raw_link =~ /^http[s]?:\/\// ? raw_link : "http://#{raw_link}"
  if block_given?
    link_to link, options, &block
  else
    link_to options[:title], link, options
  end
end

#full_localeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ab_admin/views/helpers.rb', line 18

def full_locale
  case I18n.locale
    when :en
      'en_US'
    when :ru
      'ru_RU'
    when :it
      'it_IT'
    when :uk
      'uk_UA'
    else
      'ru_RU'
  end
end

#image_tag_if(image, options = {}) ⇒ Object



57
58
59
60
# File 'lib/ab_admin/views/helpers.rb', line 57

def image_tag_if(image, options={})
  return unless image
  image_tag image, options
end

#init_js(js) ⇒ Object



53
54
55
# File 'lib/ab_admin/views/helpers.rb', line 53

def init_js(js)
  %Q[<script type='text/javascript'>$(function(){#{js}})</script>].html_safe
end

#locale_pathObject



33
34
35
# File 'lib/ab_admin/views/helpers.rb', line 33

def locale_path
  I18n.locale == I18n.default_locale ? '' : "/#{I18n.locale}"
end

#moderator?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/ab_admin/views/helpers.rb', line 9

def moderator?
  user_signed_in? && current_user.moderator?
end

#render_descriptionObject



70
71
72
# File 'lib/ab_admin/views/helpers.rb', line 70

def render_description
  @page_description || I18n.t("page.description")
end

#render_keywordsObject



66
67
68
# File 'lib/ab_admin/views/helpers.rb', line 66

def render_keywords
  @page_keywords || I18n.t("page.keywords")
end

#render_titleObject



62
63
64
# File 'lib/ab_admin/views/helpers.rb', line 62

def render_title
  @page_title || I18n.t("page.title")
end


48
49
50
51
# File 'lib/ab_admin/views/helpers.rb', line 48

def skype_link(skype, options={})
  return '' if skype.blank?
  link_to skype, "skype:#{skype.strip}?chat", options
end

#swf_object(swf, id, width, height, flash_version, options = {}) ⇒ Object

swf_object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ab_admin/views/helpers.rb', line 75

def swf_object(swf, id, width, height, flash_version, options = {})
  options.symbolize_keys!

  params = options.delete(:params) || {}
  attributes = options.delete(:attributes) || {}
  flashvars = options.delete(:flashvars) || {}

  attributes[:classid] ||= "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  attributes[:id] ||= id
  attributes[:name] ||= id

  output_buffer = ActiveSupport::SafeBuffer.new

  if options[:create_div]
    output_buffer << (:div,
                                 "This website requires <a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW' target='_blank'>Flash player</a> #{flash_version} or higher.",
                                 :id => id)
  end

  js = []

  js << "var params = {#{params.to_a.map { |item| "#{item[0]}:'#{item[1]}'" }.join(',')}};"
  js << "var attributes = {#{attributes.to_a.map { |item| "#{item[0]}:'#{item[1]}'" }.join(',')}};"
  js << "var flashvars = {#{flashvars.to_a.map { |item| "#{item[0]}:'#{item[1]}'" }.join(',')}};"

  js << "swfobject.embedSWF('#{swf}', '#{id}', '#{width}', '#{height}', '#{flash_version}', '/swf/expressInstall.swf', flashvars, params, attributes);"

  output_buffer << javascript_tag(js.join)

  output_buffer
end