Module: Wallaby::LinksHelper

Included in:
CoreHelper
Defined in:
lib/helpers/wallaby/links_helper.rb

Instance Method Summary collapse

Instance Method Details



74
75
76
77
# File 'lib/helpers/wallaby/links_helper.rb', line 74

def cancel_link(html_options = {}, &block)
  block ||= -> { ct 'link.cancel' }
  link_to :back, html_options, &block
end


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/helpers/wallaby/links_helper.rb', line 62

def delete_link(resource, html_options = {}, &block)
  return if cannot? :destroy, extract(resource)

  block ||= -> { ct 'link.delete' }
  html_options[:class]  = 'text-danger' unless html_options.has_key? :class
  html_options[:method] ||= :delete
  html_options[:data]   ||= {}
  html_options[:data][:confirm] ||= ct('link.confirm.delete')

  link_to show_path(resource), html_options, &block
end


53
54
55
56
57
58
59
60
# File 'lib/helpers/wallaby/links_helper.rb', line 53

def edit_link(resource, html_options = {}, &block)
  return if cannot? :edit, extract(resource)

  block ||= -> { "#{ ct 'link.edit' } #{ decorate(resource).to_label }" }
  html_options[:class] = 'text-warning' unless html_options.has_key? :class

  link_to edit_path(resource), html_options, &block
end

#edit_path(resource) ⇒ Object



18
19
20
21
# File 'lib/helpers/wallaby/links_helper.rb', line 18

def edit_path(resource)
  decorated = decorate resource
  wallaby_engine.edit_resource_path decorated.resources_name, decorated.primary_key_value
end


23
24
25
26
27
28
29
# File 'lib/helpers/wallaby/links_helper.rb', line 23

def index_link(model_class = nil, html_options = {}, &block)
  model_class ||= current_model_class
  return if cannot? :index, model_class
  block ||= -> { to_model_label model_class }

  link_to index_path(model_class, html_options.delete(:extra_params)), html_options, &block
end

#index_path(model_class = nil, extra_params = nil) ⇒ Object



2
3
4
5
6
# File 'lib/helpers/wallaby/links_helper.rb', line 2

def index_path(model_class = nil, extra_params = nil)
  model_class   ||= current_model_class
  extra_params  ||= {}
  wallaby_engine.resources_path to_resources_name(model_class), extra_params
end


31
32
33
34
35
36
37
38
39
40
# File 'lib/helpers/wallaby/links_helper.rb', line 31

def new_link(model_class = nil, html_options = {}, &block)
  model_class ||= current_model_class
  return if cannot? :new, model_class

  block ||= -> { "#{ ct 'link.new' } #{ to_model_label model_class }" }
  html_options[:class] = 'text-success' unless html_options.has_key? :class

  prepend_if html_options
  link_to new_path(model_class), html_options, &block
end

#new_path(model_class = nil) ⇒ Object



8
9
10
11
# File 'lib/helpers/wallaby/links_helper.rb', line 8

def new_path(model_class = nil)
  model_class ||= current_model_class
  wallaby_engine.new_resource_path to_resources_name model_class
end

#prepend_if(html_options = {}) ⇒ Object



79
80
81
82
# File 'lib/helpers/wallaby/links_helper.rb', line 79

def prepend_if(html_options = {})
  prepend = html_options.delete :prepend
  concat "#{ prepend } " if prepend.present?
end


42
43
44
45
46
47
48
49
50
51
# File 'lib/helpers/wallaby/links_helper.rb', line 42

def show_link(resource, html_options = {}, &block)
  return if cannot? :show, extract(resource)

  # NOTE: to_s is a must
  # if a block is returning integer (e.g. `{ 1 }`)
  # `link_to` will render blank text note inside hyper link
  block ||= -> { decorate(resource).to_label.to_s }

  link_to show_path(resource), html_options, &block
end

#show_path(resource) ⇒ Object



13
14
15
16
# File 'lib/helpers/wallaby/links_helper.rb', line 13

def show_path(resource)
  decorated = decorate resource
  wallaby_engine.resource_path decorated.resources_name, decorated.primary_key_value
end