Module: AbAdmin::Views::Helpers

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

Instance Method Summary collapse

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


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

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

#as_html(text) ⇒ Object



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

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

#full_localeObject



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

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



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

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

#init_js(js) ⇒ Object



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

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

#locale_pathObject



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

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

#moderator?Boolean

Returns:

  • (Boolean)


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

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


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

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



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
82
# File 'lib/ab_admin/views/helpers.rb', line 52

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