Module: Sunrise::Views::Helper
- Defined in:
- lib/sunrise/views/helper.rb
Instance Method Summary collapse
- #encode_email(email_address, _options = {}) ⇒ Object
- #javascript(*args) ⇒ Object
- #link_by_href(name, options = {}) ⇒ Object
- #link_to_if_tag(condition, name, options = {}, html_options = {}, &block) ⇒ Object
- #link_to_unless_current_span(name, options = {}, html_options = {}, &block) ⇒ Object
- #link_to_unless_current_tag(name, options = {}, html_options = {}, &block) ⇒ Object
- #link_to_unless_span(condition, name, options = {}, html_options = {}, &block) ⇒ Object
- #link_to_unless_tag(condition, name, options = {}, html_options = {}, &block) ⇒ Object
- #stylesheet(*args) ⇒ Object
-
#swf_object(swf, id, width, height, flash_version, options = {}) ⇒ Object
swf_object.
Instance Method Details
#encode_email(email_address, _options = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sunrise/views/helper.rb', line 97 def encode_email(email_address, = {}) email_address = email_address.to_s string = '' "document.write('#{email_address}');".each_byte do |c| string << format('%%%x', c) end "<script type=\"#{Mime::JS}\">eval(decodeURIComponent('#{string}'))</script>" end |
#javascript(*args) ⇒ Object
6 7 8 |
# File 'lib/sunrise/views/helper.rb', line 6 def javascript(*args) content_for(:head) { javascript_include_tag(*args) } end |
#link_by_href(name, options = {}) ⇒ Object
14 15 16 |
# File 'lib/sunrise/views/helper.rb', line 14 def link_by_href(name, = {}) link_to name, name, end |
#link_to_if_tag(condition, name, options = {}, html_options = {}, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sunrise/views/helper.rb', line 38 def link_to_if_tag(condition, name, = {}, = {}, &block) tag_name = .delete(:tag) || :span if condition link_to(name, , ) else if block_given? block.arity <= 1 ? yield(name) : yield(name, , ) else content_tag(tag_name, name, ) end end end |
#link_to_unless_current_span(name, options = {}, html_options = {}, &block) ⇒ Object
18 19 20 |
# File 'lib/sunrise/views/helper.rb', line 18 def link_to_unless_current_span(name, = {}, = {}, &block) link_to_unless_span current_page?(), name, , , &block end |
#link_to_unless_current_tag(name, options = {}, html_options = {}, &block) ⇒ Object
34 35 36 |
# File 'lib/sunrise/views/helper.rb', line 34 def link_to_unless_current_tag(name, = {}, = {}, &block) link_to_unless_tag current_page?(), name, , , &block end |
#link_to_unless_span(condition, name, options = {}, html_options = {}, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sunrise/views/helper.rb', line 22 def link_to_unless_span(condition, name, = {}, = {}, &block) if condition if block_given? block.arity <= 1 ? yield(name) : yield(name, , ) else content_tag(:span, name, ) end else link_to(name, , ) end end |
#link_to_unless_tag(condition, name, options = {}, html_options = {}, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sunrise/views/helper.rb', line 51 def link_to_unless_tag(condition, name, = {}, = {}, &block) tag_name = .delete(:tag) || :span if condition if block_given? block.arity <= 1 ? yield(name) : yield(name, , ) else content_tag(tag_name, name, ) end else link_to(name, , ) end end |
#stylesheet(*args) ⇒ Object
10 11 12 |
# File 'lib/sunrise/views/helper.rb', line 10 def stylesheet(*args) content_for(:head) { stylesheet_link_tag(*args) } end |
#swf_object(swf, id, width, height, flash_version, options = {}) ⇒ Object
swf_object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sunrise/views/helper.rb', line 65 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 |