Module: Wallaby::LinksHelper
- Included in:
- CoreHelper
- Defined in:
- lib/helpers/wallaby/links_helper.rb
Instance Method Summary collapse
- #cancel_link(html_options = {}, &block) ⇒ Object
- #delete_link(resource, html_options = {}, &block) ⇒ Object
- #edit_link(resource, html_options = {}, &block) ⇒ Object
- #edit_path(resource) ⇒ Object
- #index_link(model_class = nil, html_options = {}, &block) ⇒ Object
- #index_path(model_class = nil, extra_params = nil) ⇒ Object
- #new_link(model_class = nil, html_options = {}, &block) ⇒ Object
- #new_path(model_class = nil) ⇒ Object
- #prepend_if(html_options = {}) ⇒ Object
- #show_link(resource, html_options = {}, &block) ⇒ Object
- #show_path(resource) ⇒ Object
Instance Method Details
#cancel_link(html_options = {}, &block) ⇒ Object
74 75 76 77 |
# File 'lib/helpers/wallaby/links_helper.rb', line 74 def cancel_link( = {}, &block) block ||= -> { ct 'link.cancel' } link_to :back, , &block end |
#delete_link(resource, html_options = {}, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/helpers/wallaby/links_helper.rb', line 62 def delete_link(resource, = {}, &block) return if cannot? :destroy, extract(resource) block ||= -> { ct 'link.delete' } [:class] = 'text-danger' unless .has_key? :class [:method] ||= :delete [:data] ||= {} [:data][:confirm] ||= ct('link.confirm.delete') link_to show_path(resource), , &block end |
#edit_link(resource, html_options = {}, &block) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/helpers/wallaby/links_helper.rb', line 53 def edit_link(resource, = {}, &block) return if cannot? :edit, extract(resource) block ||= -> { "#{ ct 'link.edit' } #{ decorate(resource).to_label }" } [:class] = 'text-warning' unless .has_key? :class link_to edit_path(resource), , &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 |
#index_link(model_class = nil, html_options = {}, &block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/helpers/wallaby/links_helper.rb', line 23 def index_link(model_class = nil, = {}, &block) model_class ||= current_model_class return if cannot? :index, model_class block ||= -> { to_model_label model_class } link_to index_path(model_class, .delete(:extra_params)), , &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 |
#new_link(model_class = nil, html_options = {}, &block) ⇒ Object
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, = {}, &block) model_class ||= current_model_class return if cannot? :new, model_class block ||= -> { "#{ ct 'link.new' } #{ to_model_label model_class }" } [:class] = 'text-success' unless .has_key? :class prepend_if link_to new_path(model_class), , &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( = {}) prepend = .delete :prepend concat "#{ prepend } " if prepend.present? end |
#show_link(resource, html_options = {}, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/helpers/wallaby/links_helper.rb', line 42 def show_link(resource, = {}, &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), , &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 |