Module: Tenon::TenonHelper

Defined in:
app/helpers/tenon/tenon_helper.rb

Instance Method Summary collapse

Instance Method Details

default tenon action link



15
16
17
18
19
# File 'app/helpers/tenon/tenon_helper.rb', line 15

def action_link(title, link, icon, options = {})
  icon_tag = (:i, '', class: "fa fa-#{icon} fa-fw")
  default_options = { title: title, data: { tooltip: title } }
  link_to icon_tag, link, default_options.deep_merge(options)
end

#browser_detection(http) ⇒ Object

browser detection and warning message



58
59
60
61
62
# File 'app/helpers/tenon/tenon_helper.rb', line 58

def browser_detection(http)
  if http.match(/MSIE 6|MSIE 7|MSIE 8.0/)
    (:div, "For an optimal Tenon experience, please upgrade Internet Explorer to the #{link_to 'latest version', 'http://browsehappy.com/', target: '_blank'} or switch to another #{link_to 'modern browser', 'http://browsehappy.com/', target: '_blank'}.".html_safe, id: 'flash-warning', class: 'flash-msg')
  end
end

default tenon delete link



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/tenon/tenon_helper.rb', line 44

def delete_link(obj, options = {})
  if can?(:destroy, obj)
    default_options = { data: {
      confirm: 'Are you sure? There is no undo for this!',
      tooltip: 'Delete',
      method: 'Delete',
      remote: 'true'
    } }
    url = polymorphic_url(obj)
    action_link('Delete', url, 'trash-o', default_options.deep_merge(options))
  end
end

#display_action(action) ⇒ Object



8
9
10
11
12
# File 'app/helpers/tenon/tenon_helper.rb', line 8

def display_action(action)
  action = 'edit' if action == 'update'
  action = 'new' if action == 'create'
  action.titleize.humanize
end

#display_controller(controller) ⇒ Object



3
4
5
6
# File 'app/helpers/tenon/tenon_helper.rb', line 3

def display_controller(controller)
  controller = controller.split('/')[1] if controller.match('/')
  controller.humanize.titleize
end

default tenon edit link



36
37
38
39
40
41
# File 'app/helpers/tenon/tenon_helper.rb', line 36

def edit_link(obj, options = {})
  if can?(:edit, obj)
    url = polymorphic_url([:edit] + Array(obj))
    action_link('Edit', url, 'pencil', options)
  end
end

#publish_box(f, object) ⇒ Object

form row helper for boolean published block



65
66
67
68
69
70
71
72
73
# File 'app/helpers/tenon/tenon_helper.rb', line 65

def publish_box(f, object)
  if can?(:publish, object)
    content = [
      f.check_box(:published, class: 'tn-checkbox-right'),
      f.super_label(:published, 'Published?')
    ].join(' ').html_safe
    (:div, content, class: 'form-group inline')
  end
end

extention of action_link for boolean toggles



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/tenon/tenon_helper.rb', line 22

def toggle_link(object, field, link, true_values, false_values)
  state = object.send(field)
  icon = state ? true_values[0] : false_values[0]
  tooltip = state ? true_values[1] : false_values[1]
  data = {
    trueicon:     true_values[0],
    falseicon:    false_values[0],
    truetooltip:  true_values[1],
    falsetooltip: false_values[1]
  }
  action_link tooltip, link, icon, class: "toggle #{field} #{state}", data: data
end