Module: Mack::ViewHelpers::HtmlHelpers
- Defined in:
- lib/mack-javascript/view_helpers/html_helpers.rb
Instance Method Summary collapse
- #js ⇒ Object
- #link_to_function(link_text, *args, &block) ⇒ Object
- #link_to_remote(link_text, ajax_options, options = {}) ⇒ Object
-
#remote_function(options) ⇒ Object
Returns javascript that does an Ajax call.
-
#update_page {|gs| ... } ⇒ Object
Renders javascript in an html file.
Instance Method Details
#js ⇒ Object
40 41 42 |
# File 'lib/mack-javascript/view_helpers/html_helpers.rb', line 40 def js Mack::JavaScript::ScriptGenerator.new end |
#link_to_function(link_text, *args, &block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/mack-javascript/view_helpers/html_helpers.rb', line 27 def link_to_function(link_text, *args, &block) function = args[0] || '' = args[1] || {} function = yield(js).chop if block_given? [:onclick] = ([:onclick] ? "#{[:onclick]}; " : "") + "#{function}; return false;" link_to(link_text, '#', ) end |
#link_to_remote(link_text, ajax_options, options = {}) ⇒ Object
23 24 25 |
# File 'lib/mack-javascript/view_helpers/html_helpers.rb', line 23 def link_to_remote(link_text, , = {}) link_to_function(link_text, remote_function(), ) end |
#remote_function(options) ⇒ Object
Returns javascript that does an Ajax call
36 37 38 |
# File 'lib/mack-javascript/view_helpers/html_helpers.rb', line 36 def remote_function() Mack::JavaScript::ScriptGenerator.framework.remote_function() end |
#update_page {|gs| ... } ⇒ Object
Renders javascript in an html file
Example:
<%= update_page do |page|
page.alert('this gets translated to js!')
page.show('my_hidden_div')
end
%>
This returns (assuming Prototype is your Js Framework):
<script type='text/javascript'>
alert('this gets translated to js!');
$('my_hidden_div').show();
</script>
17 18 19 20 21 |
# File 'lib/mack-javascript/view_helpers/html_helpers.rb', line 17 def update_page(&block) gs = js yield(gs) "<script type='#{Mack::Utils::MimeTypes[:js]}'>\n" + gs.to_s.gsub(';', ";\n") + "</script>" end |