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

#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



46
47
48
49
# File 'lib/ab_admin/views/helpers.rb', line 46

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

#init_js(js) ⇒ Object



42
43
44
# File 'lib/ab_admin/views/helpers.rb', line 42

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


37
38
39
40
# File 'lib/ab_admin/views/helpers.rb', line 37

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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ab_admin/views/helpers.rb', line 51

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