Module: CoreLinkHelper
- Defined in:
- app/helpers/core_link_helper.rb
Overview
common link generation helpers
Instance Method Summary collapse
-
#action_link_tag(condition, path, options = {}) ⇒ Object
Show a list of things if the condition is true.
-
#action_list_tag(condition, path, options = {}) ⇒ Object
Show a list of things in a pull down list if the condition is true.
-
#add_link_tag(klass, path) ⇒ Object
Add a thingy.
-
#copy_tag(copy_text, options = {}) ⇒ Object
Create a copy tag for data to be copied to the clipboard.
-
#copy_text_tag(copy_text, options = {}) ⇒ Object
Create a text element that is easy to copy.
-
#delete_link_tag(obj, path, options = {}) ⇒ Object
Delete an thingy.
-
#delete_list_tag(obj, path, options = {}) ⇒ Object
Delete a thingy in a pull down list.
-
#edit_class_link_tag(klass, path) ⇒ Object
Edit a page.
-
#edit_link_tag(obj, path, options = {}) ⇒ Object
Edit an thingy.
-
#edit_list_tag(obj, path, options = {}) ⇒ Object
Edit a thingy in a pull down list.
- #edit_modal_tag(obj, path, _options = {}) ⇒ Object
-
#form_cancel_button_tag(path) ⇒ Object
Form cancel button.
-
#form_submit_button_tag(obj) ⇒ Object
Form submit button.
-
#info_link_tag(obj, path, options = {}) ⇒ Object
Details of a thingy.
-
#info_list_tag(obj, path, options = {}) ⇒ Object
Details of a thingy in a pull down list.
-
#link_tag(title, path, options = {}) ⇒ Object
Generic link tag.
-
#materialize_icon(name, options = {}) ⇒ Object
Add a material icon by name.
-
#replay_link_tag(obj, path, options = {}) ⇒ Object
Restart a thingy.
-
#replay_list_tag(obj, path, options = {}) ⇒ Object
Restart a thingy.
-
#table_action_button(action_id, icon_name = 'more_horiz') ⇒ Object
Add the table action button and setup the drop down.
Instance Method Details
#action_link_tag(condition, path, options = {}) ⇒ Object
Show a list of things if the condition is true.
162 163 164 165 166 167 168 169 170 171 |
# File 'app/helpers/core_link_helper.rb', line 162 def action_link_tag(condition, path, = {}) return unless condition content_tag(:a, href: path, class: [:link_classes]) do concat(content_tag(:i, class: 'material-icons') do [:icon_name] || 'info' end) concat([:label]) if [:label].present? end end |
#action_list_tag(condition, path, options = {}) ⇒ Object
Show a list of things in a pull down list if the condition is true
150 151 152 153 154 155 156 157 |
# File 'app/helpers/core_link_helper.rb', line 150 def action_list_tag(condition, path, = {}) return unless condition raise('Label Required') if [:label].blank? content_tag(:li) do action_link_tag(condition, path, ) end end |
#add_link_tag(klass, path) ⇒ Object
Add a thingy
217 218 219 220 221 222 223 224 225 |
# File 'app/helpers/core_link_helper.rb', line 217 def add_link_tag(klass, path) return unless can?(:manage, klass) content_tag(:div, class: 'fixed-action-btn horizontal') do concat(content_tag(:a, href: path, class: 'btn-floating btn-large right', style: 'padding: 0;margin: 0px 15px') do concat(content_tag(:i, class: 'material-icons') { 'add' }) end) end end |
#copy_tag(copy_text, options = {}) ⇒ Object
Create a copy tag for data to be copied to the clipboard
10 11 12 13 14 15 |
# File 'app/helpers/core_link_helper.rb', line 10 def copy_tag(copy_text, = {}) content_tag(:p, class: 'stack-tight') do concat(copy_text) concat(copy_text_tag(copy_text, )) end end |
#copy_text_tag(copy_text, options = {}) ⇒ Object
Create a text element that is easy to copy
20 21 22 23 24 25 26 27 |
# File 'app/helpers/core_link_helper.rb', line 20 def copy_text_tag(copy_text, = {}) [:icon_name] ||= 'content_copy' content_tag(:a, class: 'copy', href: '#', data: { 'clipboard-text' => copy_text }, onclick: 'return false;') do concat(content_tag(:i, class: 'material-icons') do [:icon_name] end) end end |
#delete_link_tag(obj, path, options = {}) ⇒ Object
Delete an thingy
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/helpers/core_link_helper.rb', line 188 def delete_link_tag(obj, path, = {}) return unless can? :delete, obj data = { method: :delete, confirm: [:confirm] || t('links.deletion_confirmation', name: obj.class.to_s.underscore.humanize) } content_tag(:a, href: path, data: data) do concat(content_tag(:i, class: 'material-icons') do [:icon_name] || 'delete' end) concat([:label]) if [:label].present? end end |
#delete_list_tag(obj, path, options = {}) ⇒ Object
Delete a thingy in a pull down list
176 177 178 179 180 181 182 183 |
# File 'app/helpers/core_link_helper.rb', line 176 def delete_list_tag(obj, path, = {}) return unless can? :delete, obj [:label] ||= I18n.t('ui_form.actions.delete') content_tag(:li) do delete_link_tag(obj, path, ) end end |
#edit_class_link_tag(klass, path) ⇒ Object
Edit a page
204 205 206 207 208 209 210 211 212 |
# File 'app/helpers/core_link_helper.rb', line 204 def edit_class_link_tag(klass, path) return unless can?(:edit, klass) content_tag(:div, class: 'fixed-action-btn horizontal') do concat(content_tag(:a, href: path, class: 'btn-floating btn-large right', style: 'padding: 0;margin: 0px 15px') do concat(content_tag(:i, class: 'material-icons') { 'edit' }) end) end end |
#edit_link_tag(obj, path, options = {}) ⇒ Object
Edit an thingy
76 77 78 79 80 81 82 83 84 85 |
# File 'app/helpers/core_link_helper.rb', line 76 def edit_link_tag(obj, path, = {}) return unless can? :edit, obj content_tag(:a, href: path) do concat(content_tag(:i, class: 'material-icons') do 'edit' end) concat([:label]) if [:label].present? end end |
#edit_list_tag(obj, path, options = {}) ⇒ Object
Edit a thingy in a pull down list
64 65 66 67 68 69 70 71 |
# File 'app/helpers/core_link_helper.rb', line 64 def edit_list_tag(obj, path, = {}) return unless can? :edit, obj [:label] ||= I18n.t('ui_form.actions.edit') content_tag(:li) do edit_link_tag(obj, path, ) end end |
#edit_modal_tag(obj, path, _options = {}) ⇒ Object
87 88 89 90 91 92 93 |
# File 'app/helpers/core_link_helper.rb', line 87 def edit_modal_tag(obj, path, = {}) return unless can? :edit, obj content_tag(:a, href: path, class: 'modal-action') do concat(I18n.t('ui_form.actions.edit')) end end |
#form_cancel_button_tag(path) ⇒ Object
Form cancel button
230 231 232 233 234 235 |
# File 'app/helpers/core_link_helper.rb', line 230 def (path) = { class: 'btn-large waves-effect waves-light secondary', href: path } content_tag(:a, ) do concat(t('ui_form.actions.cancel')) end end |
#form_submit_button_tag(obj) ⇒ Object
Form submit button
240 241 242 243 244 245 246 247 248 |
# File 'app/helpers/core_link_helper.rb', line 240 def (obj) return unless can? :update, obj = { class: 'btn-large waves-effect waves-light', type: :submit } content_tag(:button, ) do concat(t('ui_form.actions.save')) concat(content_tag(:i, class: 'material-icons right') { 'save' }) end end |
#info_link_tag(obj, path, options = {}) ⇒ Object
Details of a thingy
136 137 138 139 140 141 142 143 144 145 |
# File 'app/helpers/core_link_helper.rb', line 136 def info_link_tag(obj, path, = {}) return unless can? :read, obj content_tag(:a, href: path, class: [:link_classes]) do concat(content_tag(:i, class: 'material-icons') do 'info' end) concat([:label]) if [:label].present? end end |
#info_list_tag(obj, path, options = {}) ⇒ Object
Details of a thingy in a pull down list
126 127 128 129 130 131 |
# File 'app/helpers/core_link_helper.rb', line 126 def info_list_tag(obj, path, = {}) [:label] ||= I18n.t('ui_form.actions.info') content_tag(:li) do info_link_tag(obj, path, ) end end |
#link_tag(title, path, options = {}) ⇒ Object
Generic link tag
54 55 56 57 58 59 |
# File 'app/helpers/core_link_helper.rb', line 54 def link_tag(title, path, = {}) content_tag(:a, href: path) do concat(content_tag(:i, class: 'material-icons left') { [:icon_name] }) if [:icon_name].present? concat(title) end end |
#materialize_icon(name, options = {}) ⇒ Object
Add a material icon by name
45 46 47 48 49 |
# File 'app/helpers/core_link_helper.rb', line 45 def materialize_icon(name, = {}) classes = %w[material-icons] classes += [:classes] if [:classes].present? content_tag(:i, class: classes.join(' '), title: [:title]) { name } end |
#replay_link_tag(obj, path, options = {}) ⇒ Object
Restart a thingy
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/helpers/core_link_helper.rb', line 98 def replay_link_tag(obj, path, = {}) return unless can? :edit, obj icon_name = [:icon_name] || 'replay' data = { confirm: [:confirm] || t('links.replay_confirmation', name: obj.class.to_s.underscore.humanize) } content_tag(:a, href: path, data: data, class: [:link_classes]) do concat(content_tag(:i, class: 'material-icons') do icon_name end) concat([:label]) if [:label].present? end end |
#replay_list_tag(obj, path, options = {}) ⇒ Object
Restart a thingy
114 115 116 117 118 119 120 121 |
# File 'app/helpers/core_link_helper.rb', line 114 def replay_list_tag(obj, path, = {}) return unless can? :edit, obj [:label] ||= I18n.t('ui_form.actions.replay') content_tag(:li) do replay_link_tag(obj, path, ) end end |
#table_action_button(action_id, icon_name = 'more_horiz') ⇒ Object
Add the table action button and setup the drop down
32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/core_link_helper.rb', line 32 def (action_id, icon_name = 'more_horiz') datum = { activates: action_id, constrainWidth: false, gutter: 28, alignment: 'right' } content_tag(:a, class: 'dropdown-button', data: datum) do concat(materialize_icon(icon_name)) end end |