0
@@ -2,59 +2,6 @@ module Mack
0
module ViewHelpers # :nodoc:
0
- # This is just an alias to
0
- # <%= link_to("http://www.mackframework.com") %> # => <a href="http://www.mackframework.com">http://www.mackframework.com</a>
0
- # <%= link_to("Mack", "http://www.mackframework.com") %> # => <a href="http://www.mackframework.com">Mack</a>
0
- # <%= link_to("Mack", "http://www.mackframework.com", :target => "_blank") %> # => <a href="http://www.mackframework.com" target="_blank">Mack</a>
0
- # <%= link_to("Mack", "http://www.mackframework.com", :target => "_blank", :rel => :nofollow) %> # => <a href="http://www.mackframework.com" target="_blank" rel="nofollow">Mack</a>
0
- # If you pass in :method as an option it will be a JavaScript form that will post to the specified link with the
0
- # <%= link_to("Mack", "http://www.mackframework.com", :method => :delete) %>
0
- # If you use the :method option you can also pass in a :confirm option. The :confirm option will generate a
0
- # javascript confirmation window. If 'OK' is selected the the form will submit. If 'cancel' is selected, then
0
- # nothing will happen. This is extremely useful for 'delete' type of links.
0
- # <%= link_to("Mack", "http://www.mackframework.com", :method => :delete, :confirm => "Are you sure?") %>
0
- def link_to(link_text, url = link_text, html_options = {})
0
- options = {:href => url}.merge(html_options)
0
- # Used in views to create href links. It takes link_text, url, and a Hash that gets added
0
- # to the href as options.
0
- # a("http://www.mackframework.com") # => <a href="http://www.mackframework.com">http://www.mackframework.com</a>
0
- # a("Mack", :href => "http://www.mackframework.com") # => <a href="http://www.mackframework.com">Mack</a>
0
- # a("Mack", :href => "http://www.mackframework.com", :target => "_blank") # => <a href="http://www.mackframework.com" target="_blank">Mack</a>
0
- # a("Mack", :href => "http://www.mackframework.com", :target => "_blank", :rel => :nofollow) # => <a href="http://www.mackframework.com" target="_blank" rel="nofollow">Mack</a>
0
- # If you pass in :method as an option it will be a JavaScript form that will post to the specified link with the
0
- # a("Mack", :href => "http://www.mackframework.com", :method => :delete)
0
- # If you use the :method option you can also pass in a :confirm option. The :confirm option will generate a
0
- # javascript confirmation window. If 'OK' is selected the the form will submit. If 'cancel' is selected, then
0
- # nothing will happen. This is extremely useful for 'delete' type of links.
0
- # a("Mack", :href => "http://www.mackframework.com", :method => :delete, :confirm => "Are you sure?")
0
- def a(link_text, options = {})
0
- options = {:href => link_text}.merge(options)
0
- meth = %{var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', '_method'); s.setAttribute('value', '#{options[:method]}'); f.appendChild(s);f.submit()}
0
- options.delete(:method)
0
- confirm = %{if (confirm('#{options[:confirm]}'))}
0
- options.delete(:confirm)
0
- options[:onclick] = (confirm ? (confirm + " { ") : "") << meth << (confirm ? (" } ") : "") << ";return false;"
0
- content_tag(:a, options, link_text)
0
@@ -84,74 +31,12 @@ module Mack
0
non_content_tag(:img, {:src => image_src}.merge(options))
0
- # Builds an HTML submit tag
0
- def submit_tag(value = "Submit", options = {})
0
- non_content_tag(:input, {:type => :submit, :value => value}.merge(options))
0
- # Wraps an image tag with a link tag.
0
- # <%= link_image_to("/images/foo.jpg", "#" %> # => <a href="#"><img src="/images/foo.jpg"></a>
0
- def link_image_to(image_url, url, image_options = {}, html_options = {})
0
- link_to(img(image_url, image_options), url, html_options)
0
# <%= rss_tag(posts_index_url(:format => :xml)) %>
0
"<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"#{url}\">"
0
- def form(action, options = {}, &block)
0
- options = {:method => :post, :action => action}.merge(options)
0
- options = {:class => options[:id]}.merge(options)
0
- if options[:multipart]
0
- options = {:enctype => "multipart/form-data"}.merge(options)
0
- options.delete(:multipart)
0
- unless options[:method] == :get || options[:method] == :post
0
- meth = "<input name=\"_method\" type=\"hidden\" value=\"#{options[:method]}\" />\n"
0
- options[:method] = :post
0
- concat("<form#{build_options(options)}>\n", block.binding)
0
- concat(meth, block.binding) unless meth.blank?
0
- concat("</form>", block.binding)
0
- # content_tag(:form, options, &block)
0
- # Builds a mailto href. By default it will generate
0
- # JavaScript to help prevent phishing. To turn this off
0
- # pass in the option :format => :plain
0
- # mail_to("Saul Frami", "frami.saul@klocko.ca") # =>
0
- # <script>document.write(String.fromCharCode(60,97,32,104,114,101,
0
- # 102,61,34,109,97,105,108,116,111,58,102,114,97,109,105,46,115,97,117,
0
- # 108,64,107,108,111,99,107,111,46,99,97,34,62,83,97,117,108,32,70,114,97,109,105,60,47,97,62));</script>
0
- def mail_to(text, email_address = nil, options = {})
0
- email_address = text if email_address.blank?
0
- options = {:format => :js}.merge(options)
0
- format = options[:format]
0
- link = link_to(text, "mailto:#{email_address}", options)
0
- link.size.times {y << 'a'}
0
- link.each_byte {|c| c_code << c}
0
- js_link << "document.write(String.fromCharCode(#{c_code.join(",")}));"
0
- js_link << "</script>"
0
def build_options(options)