Module: Clot::LinkFilters

Includes:
ActionView::Helpers::TagHelper
Included in:
LinkItem, LiquidForm
Defined in:
lib/clot/link_filters.rb

Instance Method Summary collapse

Instance Method Details



16
17
18
19
# File 'lib/clot/link_filters.rb', line 16

def delete_link(target, message = "Delete", class_name = "")
  url = object_url target, class_name
  gen_delete_link(url,message)
end


5
6
7
8
# File 'lib/clot/link_filters.rb', line 5

def edit_link(target, message = "Edit", class_name = "")
  url = object_url target, class_name
   :a, message, :href => url + "/edit"
end


21
22
23
# File 'lib/clot/link_filters.rb', line 21

def gen_delete_link(url, message = nil)
  '<a href="' + url + '" onClick="' + gen_delete_onclick + '">' + message + '</a>'
end

#gen_delete_onclickObject



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


37
38
39
40
41
42
43
44
# File 'lib/clot/link_filters.rb', line 37

def index_link(controller, message = nil)
  if message.blank?
    controller_array = controller.split("_")
    controller_array.map! {|item| item.capitalize }
    message = controller_array.join(" ") + " Index"
  end
'<a href="/' + controller +'">' + message + '</a>'
end


46
47
48
49
50
51
52
53
54
# File 'lib/clot/link_filters.rb', line 46

def new_link(controller, message = nil)
  if message.blank?
    controller_array = controller.split("_")
    controller_array.map! {|item| item.capitalize }
    message = "New "  + controller_array.join(" ")
    message.chomp!("s")
  end
'<a href="/' + controller +'/new">' + message + '</a>'
end


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


10
11
12
13
# File 'lib/clot/link_filters.rb', line 10

def view_link(target, message = "View", class_name = "")
  url = object_url target, class_name
   :a, message, :href => url
end