Module: AbAdmin::Views::Helpers
- Defined in:
- lib/ab_admin/views/helpers.rb
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #as_html(text) ⇒ Object
- #external_link(raw_link, options = {}, &block) ⇒ Object
- #full_locale ⇒ Object
- #image_tag_if(image, options = {}) ⇒ Object
- #init_js(js) ⇒ Object
- #locale_path ⇒ Object
- #moderator? ⇒ Boolean
- #render_description ⇒ Object
- #render_keywords ⇒ Object
- #render_title ⇒ Object
- #skype_link(skype, options = {}) ⇒ Object
-
#swf_object(swf, id, width, height, flash_version, options = {}) ⇒ Object
swf_object.
Instance Method Details
#admin? ⇒ 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 |
#external_link(raw_link, options = {}, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ab_admin/views/helpers.rb', line 37 def external_link(raw_link, ={}, &block) return unless raw_link.present? .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, , &block else link_to [:title], link, end end |
#full_locale ⇒ Object
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, ={}) return unless image image_tag image, 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_path ⇒ Object
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
9 10 11 |
# File 'lib/ab_admin/views/helpers.rb', line 9 def moderator? user_signed_in? && current_user.moderator? end |
#render_description ⇒ Object
70 71 72 |
# File 'lib/ab_admin/views/helpers.rb', line 70 def render_description @page_description || I18n.t("page.description") end |
#render_keywords ⇒ Object
66 67 68 |
# File 'lib/ab_admin/views/helpers.rb', line 66 def render_keywords @page_keywords || I18n.t("page.keywords") end |
#render_title ⇒ Object
62 63 64 |
# File 'lib/ab_admin/views/helpers.rb', line 62 def render_title @page_title || I18n.t("page.title") end |
#skype_link(skype, options = {}) ⇒ Object
48 49 50 51 |
# File 'lib/ab_admin/views/helpers.rb', line 48 def skype_link(skype, ={}) return '' if skype.blank? link_to skype, "skype:#{skype.strip}?chat", 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, = {}) .symbolize_keys! params = .delete(:params) || {} attributes = .delete(:attributes) || {} flashvars = .delete(:flashvars) || {} attributes[:classid] ||= "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" attributes[:id] ||= id attributes[:name] ||= id output_buffer = ActiveSupport::SafeBuffer.new if [:create_div] output_buffer << content_tag(: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 |