Module: Clot::LinkFilters
- Includes:
- ActionView::Helpers::TagHelper
- Included in:
- LinkItem, LiquidForm
- Defined in:
- lib/clot/link_filters.rb
Instance Method Summary collapse
- #delete_link(target, message = "Delete", class_name = "") ⇒ Object
- #edit_link(target, message = "Edit", class_name = "") ⇒ Object
- #gen_delete_link(url, message = nil) ⇒ Object
- #gen_delete_onclick ⇒ Object
- #index_link(controller, message = nil) ⇒ Object
- #new_link(controller, message = nil) ⇒ Object
- #stylesheet_link(sheet_name) ⇒ Object
- #view_link(target, message = "View", class_name = "") ⇒ Object
Instance Method Details
#delete_link(target, message = "Delete", class_name = "") ⇒ Object
16 17 18 19 |
# File 'lib/clot/link_filters.rb', line 16 def delete_link(target, = "Delete", class_name = "") url = object_url target, class_name gen_delete_link(url,) end |
#edit_link(target, message = "Edit", class_name = "") ⇒ Object
5 6 7 8 |
# File 'lib/clot/link_filters.rb', line 5 def edit_link(target, = "Edit", class_name = "") url = object_url target, class_name content_tag :a, , :href => url + "/edit" end |
#gen_delete_link(url, message = nil) ⇒ Object
21 22 23 |
# File 'lib/clot/link_filters.rb', line 21 def gen_delete_link(url, = nil) '<a href="' + url + '" onClick="' + gen_delete_onclick + '">' + + '</a>' end |
#gen_delete_onclick ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/clot/link_filters.rb', line 25 def gen_delete_onclick token_string = "var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', '__CROSS_SITE_REQUEST_FORGERY_PROTECTION_TOKEN__') ;f.appendChild(s);" if @context['page'] page_string = "var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'page_slug'); s.setAttribute('value', '" + @context['page'].slug + "') ;f.appendChild(s);" else page_string = "" end "if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);" + token_string + page_string + "f.submit(); };return false;" end |
#index_link(controller, message = nil) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/clot/link_filters.rb', line 37 def index_link(controller, = nil) if .blank? controller_array = controller.split("_") controller_array.map! {|item| item.capitalize } = controller_array.join(" ") + " Index" end '<a href="/' + controller +'">' + + '</a>' end |
#new_link(controller, message = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/clot/link_filters.rb', line 46 def new_link(controller, = nil) if .blank? controller_array = controller.split("_") controller_array.map! {|item| item.capitalize } = "New " + controller_array.join(" ") .chomp!("s") end '<a href="/' + controller +'/new">' + + '</a>' end |
#stylesheet_link(sheet_name) ⇒ Object
56 57 58 |
# File 'lib/clot/link_filters.rb', line 56 def stylesheet_link(sheet_name) '<link href="'+ stylesheet_url(sheet_name) +'" media="screen" rel="stylesheet" type="text/css" />' end |
#view_link(target, message = "View", class_name = "") ⇒ Object
10 11 12 13 |
# File 'lib/clot/link_filters.rb', line 10 def view_link(target, = "View", class_name = "") url = object_url target, class_name content_tag :a, , :href => url end |