Module: Sunrise::Views::Helpers
- Defined in:
- lib/sunrise/views/helpers.rb
Instance Method Summary collapse
- #anchor_to(name, options = {}) ⇒ Object
- #description(content) ⇒ Object
- #encode_email(email_address, options = {}) ⇒ Object
- #javascript(*args) ⇒ Object
- #keywords(content) ⇒ Object
- #link_by_href(name, options = {}) ⇒ Object
- #link_to_if_tag(condition, name, options = {}, html_options = {}, &block) ⇒ Object
- #link_to_remote_if(condition, name, options = {}, html_options = nil) ⇒ 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
- #locale_image_tag(source, options = {}) ⇒ Object
- #manage_form_for(object, *args, &block) ⇒ Object
- #record_asset_tag(record, method_name, default_image, options = {}) ⇒ Object
- #render_description ⇒ Object
- #render_keywords ⇒ Object
- #render_title ⇒ Object
- #stylesheet(*args) ⇒ Object
- #submit_image(name, src, options = {}) ⇒ Object
- #submit_image_to_remote(name, value, options = {}) ⇒ Object
-
#swf_object(swf, id, width, height, flash_version, options = {}) ⇒ Object
swf_object.
- #title(content) ⇒ Object
Instance Method Details
#anchor_to(name, options = {}) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/sunrise/views/helpers.rb', line 37 def anchor_to(name, ={}) return if name.blank? [:name] = name content_tag(:a, '', ) end |
#description(content) ⇒ Object
17 18 19 |
# File 'lib/sunrise/views/helpers.rb', line 17 def description(content) content_for(:description) { tag(:meta, :content=>content, :name=>"description") } unless content.blank? end |
#encode_email(email_address, options = {}) ⇒ Object
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/sunrise/views/helpers.rb', line 159 def encode_email(email_address, = {}) email_address = email_address.to_s string = '' "document.write('#{email_address}');".each_byte do |c| string << sprintf("%%%x", c) end "<script type=\"#{Mime::JS}\">eval(decodeURIComponent('#{string}'))</script>" end |
#javascript(*args) ⇒ Object
9 10 11 |
# File 'lib/sunrise/views/helpers.rb', line 9 def javascript(*args) content_for(:head) { javascript_include_tag(*args) } end |
#keywords(content) ⇒ Object
21 22 23 |
# File 'lib/sunrise/views/helpers.rb', line 21 def keywords(content) content_for(:keywords) { tag(:meta, :content=>content, :name=>"keywords") } unless content.blank? end |
#link_by_href(name, options = {}) ⇒ Object
44 45 46 |
# File 'lib/sunrise/views/helpers.rb', line 44 def link_by_href(name, ={}) link_to name, name, end |
#link_to_if_tag(condition, name, options = {}, html_options = {}, &block) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sunrise/views/helpers.rb', line 68 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_remote_if(condition, name, options = {}, html_options = nil) ⇒ Object
94 95 96 97 |
# File 'lib/sunrise/views/helpers.rb', line 94 def link_to_remote_if(condition, name, = {}, = nil) return name unless condition link_to_function(name, remote_function(), || .delete(:html)) end |
#link_to_unless_current_span(name, options = {}, html_options = {}, &block) ⇒ Object
48 49 50 |
# File 'lib/sunrise/views/helpers.rb', line 48 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
64 65 66 |
# File 'lib/sunrise/views/helpers.rb', line 64 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
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sunrise/views/helpers.rb', line 52 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
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sunrise/views/helpers.rb', line 81 def link_to_unless_tag(condition, name, = {}, = {}, &block) tag_name = .delete(:tag) || :span unless condition link_to(name, , ) else if block_given? block.arity <= 1 ? yield(name) : yield(name, , ) else content_tag(tag_name, name, ) end end end |
#locale_image_tag(source, options = {}) ⇒ Object
121 122 123 124 |
# File 'lib/sunrise/views/helpers.rb', line 121 def locale_image_tag(source, = {}) source = "#{I18n.locale}/#{source}" image_tag(source, ) end |
#manage_form_for(object, *args, &block) ⇒ Object
182 183 184 185 186 187 |
# File 'lib/sunrise/views/helpers.rb', line 182 def manage_form_for(object, *args, &block) = args. [:builder] ||= Sunrise::Views::FormBuilder simple_form_for([:manage, object].flatten, *(args << ), &block) end |
#record_asset_tag(record, method_name, default_image, options = {}) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/sunrise/views/helpers.rb', line 170 def record_asset_tag(record, method_name, default_image, = {}) asset = record ? record.send(method_name) : nil asset_type = .has_key?(:type) ? .delete(:type).to_sym : nil extname = File.extname(default_image) image_path = asset_type.nil? ? default_image : "#{File.basename(default_image, extname)}_#{asset_type}#{extname}" image_full = default_image.gsub(File.basename(default_image), image_path) path = (asset && (asset.respond_to?(:persisted?) ? asset.persisted? : true)) ? asset.url(asset_type) : image_full image_tag(path, ) end |
#render_description ⇒ Object
33 34 35 |
# File 'lib/sunrise/views/helpers.rb', line 33 def render_description @page_description || I18n.t("page.description") end |
#render_keywords ⇒ Object
29 30 31 |
# File 'lib/sunrise/views/helpers.rb', line 29 def render_keywords @page_keywords || I18n.t("page.keywords") end |
#render_title ⇒ Object
25 26 27 |
# File 'lib/sunrise/views/helpers.rb', line 25 def render_title @page_title || I18n.t("page.title") end |
#stylesheet(*args) ⇒ Object
13 14 15 |
# File 'lib/sunrise/views/helpers.rb', line 13 def stylesheet(*args) content_for(:head) { stylesheet_link_tag(*args) } end |
#submit_image(name, src, options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/sunrise/views/helpers.rb', line 99 def submit_image(name, src, ={}) = .dup.symbolize_keys [:name] = name [:src] = src [:type] ||= 'image' tag(:input, ) end |
#submit_image_to_remote(name, value, options = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/sunrise/views/helpers.rb', line 109 def submit_image_to_remote(name, value, = {}) [:with] ||= 'Form.serialize(this.form)' = .delete(:html) || {} [:name] = name [:type] ||= 'button' onclick = .delete(:onclick) || remote_function() tag(:input, .merge(:value => name, :onclick => onclick)) end |
#swf_object(swf, id, width, height, flash_version, options = {}) ⇒ Object
swf_object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/sunrise/views/helpers.rb', line 127 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 |
#title(content) ⇒ Object
5 6 7 |
# File 'lib/sunrise/views/helpers.rb', line 5 def title(content) content_for(:title) { content } unless content.blank? end |