Module: Cmtool::ApplicationHelper
- Defined in:
- app/helpers/cmtool/application_helper.rb
Instance Method Summary collapse
-
#application_title ⇒ Object
Return the title of the application.
- #are_you_sure(obj = nil) ⇒ Object (also: #are_you_sure?)
- #boolean_text(yes) ⇒ Object
-
#cmtool_user ⇒ Object
Add extra helper method since cmtool layouts may be used outside the cmtool scope.
-
#collapsible_content(options = {}, &blk) ⇒ Object
This is a wrapper to create collapsible content.
- #create_button_text(obj = nil) ⇒ Object
- #destroy_td(obj, options = {}) ⇒ Object
- #edit_td(obj, options = {}) ⇒ Object
- #empty_result(model) ⇒ Object
- #human_size(n) ⇒ Object
-
#l(*args) ⇒ Object
overwrite i18n l, to handle nil values.
- #link_separator ⇒ Object
- #link_to_destroy_content(obj) ⇒ Object
- #link_to_edit_content(obj) ⇒ Object
- #link_to_index_content(model) ⇒ Object
- #link_to_new_content(model) ⇒ Object
- #link_to_show_content(obj) ⇒ Object
-
#no_content_given(model) ⇒ Object
Standard return content when empty listing is found called with the model as argument = no_content_given Album.
- #site_title ⇒ Object
-
#title(*args) ⇒ Object
Set the page title, allow setting a resource title like: - title :index, Album or - title :show, Album or normal text behaviour: - title “Home”.
- #tree_options_for_select(roots, options = {}) ⇒ Object
- #update_button_text(obj = nil) ⇒ Object
- #warnings ⇒ Object
Instance Method Details
#application_title ⇒ Object
Return the title of the application
5 6 7 |
# File 'app/helpers/cmtool/application_helper.rb', line 5 def application_title 'Cmtool' end |
#are_you_sure(obj = nil) ⇒ Object Also known as: are_you_sure?
50 51 52 53 54 55 56 |
# File 'app/helpers/cmtool/application_helper.rb', line 50 def are_you_sure(obj = nil) if name = obj && obj.respond_to?(:name) && obj.name.presence t('cmtool.general.are_you_sure_with_name', name: name, model: obj.class.model_name.human) else t('cmtool.general.are_you_sure') end end |
#boolean_text(yes) ⇒ Object
63 64 65 |
# File 'app/helpers/cmtool/application_helper.rb', line 63 def boolean_text(yes) yes.present? ? t('cmtool.general.yes') : t('cmtool.general.no') end |
#cmtool_user ⇒ Object
Add extra helper method since cmtool layouts may be used outside the cmtool scope
131 132 133 |
# File 'app/helpers/cmtool/application_helper.rb', line 131 def cmtool_user controller.respond_to?(:cmtool_user) ? controller.send(:cmtool_user) :nil end |
#collapsible_content(options = {}, &blk) ⇒ Object
This is a wrapper to create collapsible content.
109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/cmtool/application_helper.rb', line 109 def collapsible_content( = {}, &blk) = {title: } if .is_a?(String) # Single argument is title content = capture(&blk) if blk.present? content ||= [:content] [:collapsed] = true unless .has_key?(:collapsed) classes = Array.wrap([:class]) | ["collapsible-container", [:collapsed] ? 'collapsed' : nil] title_tag = content_tag(:div, "<span></span>#{[:title]}".html_safe, class: 'collapsible-title') content_tag(:div, title_tag + content_tag(:div, content, class: 'collapsible-content'), class: classes) end |
#create_button_text(obj = nil) ⇒ Object
85 86 87 |
# File 'app/helpers/cmtool/application_helper.rb', line 85 def (obj = nil) t('cmtool.action.create.label', model: obj ? obj.class.model_name.human : '') end |
#destroy_td(obj, options = {}) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/cmtool/application_helper.rb', line 148 def destroy_td(obj, = {}) path = [:path] || case obj when Array then polymorphic_path(obj) when SimplyStored::Couch then polymorphic_path([[:scope] || cmtool, obj]) else obj end content_tag( :td, link_to(content_tag(:span, '', class: [:destroy, 'fa fa-lg fa-trash']), path, method: :delete, class: 'tiny alert button', data: {confirm: are_you_sure(obj) }), class: [:action, :destroy] ) end |
#edit_td(obj, options = {}) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/helpers/cmtool/application_helper.rb', line 135 def edit_td(obj, = {}) path = [:path] || case obj when Array then edit_polymorphic_path(obj) when SimplyStored::Couch then edit_polymorphic_path([[:scope] || cmtool, obj]) else obj end content_tag( :td, link_to((content_tag(:span, '', class: [:edit, 'fa fa-lg fa-pencil'])), path, class: 'tiny warning button'), class: [:action, :edit] ) end |
#empty_result(model) ⇒ Object
66 67 68 |
# File 'app/helpers/cmtool/application_helper.rb', line 66 def empty_result(model) t('cmtool.general.empty_result', models: model.model_name.human_plural.downcase ) end |
#human_size(n) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'app/helpers/cmtool/application_helper.rb', line 119 def human_size(n) return '0 MB' unless n n = n.to_i count = 0 while n >= 1024 and count < 4 n /= 1024.0 count += 1 end format("%.2f",n) + %w(B KB MB GB TB)[count] end |
#l(*args) ⇒ Object
overwrite i18n l, to handle nil values
18 19 20 21 |
# File 'app/helpers/cmtool/application_helper.rb', line 18 def l(*args) return '' unless args.first super(*args) end |
#link_separator ⇒ Object
91 92 93 |
# File 'app/helpers/cmtool/application_helper.rb', line 91 def link_separator ' | ' end |
#link_to_destroy_content(obj) ⇒ Object
81 82 83 |
# File 'app/helpers/cmtool/application_helper.rb', line 81 def link_to_destroy_content(obj) t('cmtool.action.destroy.title', model: obj.class.model_name.human) end |
#link_to_edit_content(obj) ⇒ Object
72 73 74 |
# File 'app/helpers/cmtool/application_helper.rb', line 72 def link_to_edit_content(obj) t('cmtool.action.edit.title', model: obj.class.model_name.human) end |
#link_to_index_content(model) ⇒ Object
78 79 80 |
# File 'app/helpers/cmtool/application_helper.rb', line 78 def link_to_index_content(model) t('cmtool.action.index.title', models: model.model_name.human_plural) end |
#link_to_new_content(model) ⇒ Object
69 70 71 |
# File 'app/helpers/cmtool/application_helper.rb', line 69 def link_to_new_content(model) t('cmtool.action.new.title', model: model.model_name.human) end |
#link_to_show_content(obj) ⇒ Object
75 76 77 |
# File 'app/helpers/cmtool/application_helper.rb', line 75 def link_to_show_content(obj) t('cmtool.action.show.title', model: obj.class.model_name.human) end |
#no_content_given(model) ⇒ Object
Standard return content when empty listing is found called with the model as argument
= no_content_given Album
13 14 15 |
# File 'app/helpers/cmtool/application_helper.rb', line 13 def no_content_given(model) t('helpers.no_content_given', models: model.model_name.human_plural) end |
#site_title ⇒ Object
23 24 25 |
# File 'app/helpers/cmtool/application_helper.rb', line 23 def site_title 'Cmtool' end |
#title(*args) ⇒ Object
Set the page title, allow setting a resource title like:
- title :index, Album
or
- title :show, Album
or normal text behaviour:
- title "Home"
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/cmtool/application_helper.rb', line 33 def title(*args) res = content_tag :h1, class: 'page-title' do if args.first.is_a?(Symbol) && (args[1].respond_to?(:model_name) || args[1].class.respond_to?(:model_name)) model = args[1].respond_to?(:model_name) ? args[1] : args[1].class if args.first == :index t('cmtool.action.index.title', models: model.model_name.human_plural) else t("cmtool.action.#{args.first}.title", model: model.model_name.human) end else args.first end end content_for :page_title, res res end |
#tree_options_for_select(roots, options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/cmtool/application_helper.rb', line 94 def (roots, = {}) iterator = Proc.new do |add_to, elements| for element in elements if ![:exclude].present? || (element.path_ids & Array.wrap([:exclude])).empty? add_to << ['- '*element.tree_depth + element.name, element.id] iterator.call(add_to, element.children) if element.children.any? end end end = [] iterator.call(, roots) (, [:selected]) end |
#update_button_text(obj = nil) ⇒ Object
88 89 90 |
# File 'app/helpers/cmtool/application_helper.rb', line 88 def (obj = nil) t('cmtool.action.update.label', model: obj ? obj.class.model_name.human : '') end |
#warnings ⇒ Object
59 60 61 |
# File 'app/helpers/cmtool/application_helper.rb', line 59 def warnings @cmtool_warnings || [] end |