Module: Symphonia::ApplicationHelper
- Includes:
- FontAwesome::Rails::IconHelper, FormHelper
- Defined in:
- app/helpers/symphonia/application_helper.rb
Defined Under Namespace
Classes: SymphoniaModalDialog
Instance Method Summary collapse
- #bootstrap_class_for(flash_type) ⇒ Object
- #ckeditor_for(field_id, options = {}) ⇒ Object
- #content_for(name, content = nil, &block) ⇒ Object
- #format_html(text) ⇒ Object
- #format_price(value, options = {}) ⇒ Object
- #format_text(text, _options = {}) ⇒ Object
- #has_content?(name) ⇒ Boolean
- #html_description(*args) ⇒ Object
- #html_title(*args) ⇒ Object
- #icon(fa, text = nil, **options) ⇒ Object
- #link_to_back(url = nil) ⇒ Object
- #link_to_new_entity(options = {}) ⇒ Object
- #multiselect_toggler(id = nil) ⇒ Object
-
#render_flash_messages(flash_messages = nil) ⇒ Object
Renders flash messages.
- #render_menu(menu, options = {}) ⇒ Object
- #render_menu_link(item, label, _options = {}) ⇒ Object
- #render_menu_node(menu, item, options = {}) ⇒ Object
- #render_no_data(message = nil) ⇒ Object
-
#render_super(template_name, engine: Symphonia::Engine, format: "html") ⇒ Object
Render original template from engine Useful for override part of engine view.
- #render_symphonia_dialog(*args, &block) ⇒ Object
- #title(*args, &block) ⇒ Object (also: #page_header)
-
#will_paginate(collection_or_options = nil, options = {}) ⇒ Object
change the default link renderer for will_paginate.
Methods included from FormHelper
#symphonia_form_for, #symphonia_form_tag
Instance Method Details
#bootstrap_class_for(flash_type) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/symphonia/application_helper.rb', line 7 def bootstrap_class_for(flash_type) case flash_type.to_sym when :notice 'alert-success' when :error, :alert 'alert-danger' when :warning 'alert-warning' when :info 'alert-info' else flash_type.to_s end end |
#ckeditor_for(field_id, options = {}) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'app/helpers/symphonia/application_helper.rb', line 216 def ckeditor_for(field_id, = {}) return '' unless !!defined?(Ckeditor) inline = .delete(:inline) opts = .inject({}) do |mem, var| key = var[0].to_s.camelcase(:lower) key[0].downcase! mem[key] = var[1] mem end opts['toolbar'] ||= 'Basic' # opts['customConfig'] ||= 'Basic' js = if inline "CKEDITOR.inline('#{field_id}', {toolbar: 'Basic'});" else " var ta_editor = CKEDITOR.instances['#{field_id}']; if (ta_editor) {CKEDITOR.remove(ta_editor);} CKEDITOR.replace('#{field_id}', #{opts.to_json.html_safe}); " end javascript_tag("$(document).ready(function() {#{js.html_safe}})".html_safe) end |
#content_for(name, content = nil, &block) ⇒ Object
160 161 162 163 164 |
# File 'app/helpers/symphonia/application_helper.rb', line 160 def content_for(name, content = nil, &block) @has_content ||= {} @has_content[name] = true super(name, content, &block) end |
#format_html(text) ⇒ Object
177 178 179 |
# File 'app/helpers/symphonia/application_helper.rb', line 177 def format_html(text) content_tag(:div, (defined?(Ckeditor) ? text.html_safe : format_text(text)), class: 'formatted-text') end |
#format_price(value, options = {}) ⇒ Object
181 182 183 |
# File 'app/helpers/symphonia/application_helper.rb', line 181 def format_price(value, = {}) number_to_currency(value, { precision: 1, strip_insignificant_zeros: true }.merge()) end |
#format_text(text, _options = {}) ⇒ Object
170 171 172 173 174 175 |
# File 'app/helpers/symphonia/application_helper.rb', line 170 def format_text(text, = {}) return '' if text.nil? markdown = RDiscount.new(text, :smart, :filter_html) markdown.to_html.html_safe end |
#has_content?(name) ⇒ Boolean
166 167 168 |
# File 'app/helpers/symphonia/application_helper.rb', line 166 def has_content?(name) !!(@has_content && @has_content[name]) end |
#html_description(*args) ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'app/helpers/symphonia/application_helper.rb', line 110 def html_description(*args) if args.empty? desc = @html_description desc ||= t(:meta_description) desc.to_s else @html_description ||= [] @html_description += args end end |
#html_title(*args) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'app/helpers/symphonia/application_helper.rb', line 99 def html_title(*args) if args.empty? title = @html_title || [] title << t(:meta_title) title.reject(&:blank?).join(' — ') else @html_title ||= [] @html_title += args end end |
#icon(fa, text = nil, **options) ⇒ Object
241 242 243 |
# File 'app/helpers/symphonia/application_helper.rb', line 241 def icon(fa, text = nil, **) fa_icon(fa, (text && { text: content_tag(:span, text, class: 'd-none d-sm-inline') } || {}).merge()) end |
#link_to_back(url = nil) ⇒ Object
189 190 191 |
# File 'app/helpers/symphonia/application_helper.rb', line 189 def link_to_back(url = nil) link_to(icon(:back, t(:button_back)), (params[:back_url] || url || :back), class: 'btn btn-link back') end |
#link_to_new_entity(options = {}) ⇒ Object
193 194 195 196 197 198 199 200 201 202 |
# File 'app/helpers/symphonia/application_helper.rb', line 193 def link_to_new_entity( = {}) return '' if !.has_key?(:skip_permission_check) && !User.current.allowed_to?(:"manage_#{controller_name}") anchor = .has_key?(:anchor) ? .delete(:anchor) : 'page_header' label = .delete(:label) || t("label_#{controller_name.singularize}_new") model = controller.try(:model) || controller_name.singularize url = .delete(:url) || new_polymorphic_path(model, anchor: anchor) link_to(fa_icon('add', text: label), url, { class: 'btn btn-primary' }.merge()) end |
#multiselect_toggler(id = nil) ⇒ Object
185 186 187 |
# File 'app/helpers/symphonia/application_helper.rb', line 185 def multiselect_toggler(id = nil) link_to(fa_icon(:plus), 'javascript:void(0);', onclick: "toggleMultiSelect(#{id || 'this'});return false", class: 'btn fa fa-border') end |
#render_flash_messages(flash_messages = nil) ⇒ Object
Renders flash messages
23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/symphonia/application_helper.rb', line 23 def ( = nil) s = '' Array( || flash).each do |type, | s << content_tag(:div, class: "d-print-none alert #{bootstrap_class_for(type)}") do content_tag(:button, '', class: 'fa fa-times-circle-o close', data: { dismiss: 'alert' }) + Array.wrap().collect { |m| fa_icon(type, text: m) }.join("<br>").html_safe end end return s.html_safe end |
#render_menu(menu, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/symphonia/application_helper.rb', line 34 def (, = {}) s = '' Symphonia::MenuManager.().each do |name, item| s << (name, item).to_s end [:container_class] ||= 'mr-auto' return content_tag(:ul, s.html_safe, itemscope: '', itemtype: 'http://schema.org/BreadcrumbList', class: "navbar-nav #{[:container_class]}", id: .to_s) end |
#render_menu_link(item, label, _options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/symphonia/application_helper.rb', line 75 def (item, label, = {}) url = case item[:url].class.name when 'Symbol' if item[:url].to_s.include?('.') endpoint, path = item[:url].to_s.split('.') send(endpoint).send(path) else main_app.send item[:url] end when 'Proc' item[:url].call(self) else item[:url] end link_to( (content_tag(:i, '', class: "#{item[:icon]}") + "\n" + content_tag(:span, label, itemprop: 'title')).html_safe, url, class: "nav-link #{item[:class]}", data: item[:data], method: item[:method], itemprop: 'url' ) end |
#render_menu_node(menu, item, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/symphonia/application_helper.rb', line 44 def (, item, = {}) condition = item[:if] ? item[:if].call : true selected = @menu_item.to_sym == label = case item[:label].class.name when 'NilClass' ' '.html_safe when 'String' item[:label] when 'Symbol' t(item[:label]) when 'Proc' item[:label].call(controller) else raise "MenuManager error: Label is unknown type: #{item[:label].class}" end if item[:children].blank? return content_tag(:li, (item, label, ), class: "nav-item #{} #{'active' if selected} #{[:class]}", id: item[:id]) if condition else children = '' item[:children].each do |child, subitem| children << (, subitem, class: 'dropdown-item').to_s end unless children.blank? return content_tag(:li, class: "nav-item dropdown #{}") do concat (item.merge({ class: 'dropdown-toggle', data: { toggle: 'dropdown' } }), label, { is_submenu: true }) concat content_tag(:ul, children.html_safe, class: 'dropdown-menu') end end end end |
#render_no_data(message = nil) ⇒ Object
156 157 158 |
# File 'app/helpers/symphonia/application_helper.rb', line 156 def render_no_data( = nil) content_tag(:div, || t(:text_no_data), class: 'nodata') end |
#render_super(template_name, engine: Symphonia::Engine, format: "html") ⇒ Object
Render original template from engine
Useful for override part of engine view
252 253 254 255 256 257 258 259 260 |
# File 'app/helpers/symphonia/application_helper.rb', line 252 def render_super(template_name, engine: Symphonia::Engine, format: "html") resolver = lookup_context.view_paths.paths.find do |resolver| resolver.path == engine.root.join("app", "views").to_s end template = resolver.find_all(template_name, engine.engine_name, false, { locale: ["."], formats: [format], variants: [], handlers: [:erb] }, nil, {}).first return "" unless template render template: template end |
#render_symphonia_dialog(*args, &block) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'app/helpers/symphonia/application_helper.rb', line 262 def render_symphonia_dialog(*args, &block) ActiveSupport::Deprecation.warn "Use `render_modal` instead" = args. title = [:title] || args.shift # first arg possible `title` body = args.shift [:form_disabled] = true size = .delete(:size) size ||= '90%' if .delete(:large) if size.to_s.match(%r(^\d+$)) size = size.to_s + '%' end @symphonia_modal_dialog = SymphoniaModalDialog.new(self, ) @symphonia_modal_dialog.size = size if block_given? yield @symphonia_modal_dialog else raise ArgumentError if body.nil? end @symphonia_modal_dialog.title ||= title if @symphonia_modal_dialog.body.blank? if body.is_a?(Hash) body.merge!(formats: [:html]) else body = { partial: body, formats: [:html] } end @symphonia_modal_dialog.body = render(body) end html = @symphonia_modal_dialog.to_html if [:render_only] html else js = %Q( $('##{@symphonia_modal_dialog.modal_id}').modal('hide').remove(); $('body').append('#{j html}'); showModal('##{@symphonia_modal_dialog.modal_id}'); $("##{@symphonia_modal_dialog.modal_id} .modal-dialog input:text").first().focus(); $("##{@symphonia_modal_dialog.modal_id} .modal-dialog .modal-body div.buttons").remove(); ) js.concat("$('##{@symphonia_modal_dialog.modal_id} .modal-dialog').css({width: '#{size}'});") if size.present? js.html_safe end end |
#title(*args, &block) ⇒ Object Also known as: page_header
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/helpers/symphonia/application_helper.rb', line 121 def title(*args, &block) = args. header = args.shift small = args.shift || '' header_text = if header.is_a?(Symbol) t(header, default: header.to_s.humanize) else header.to_s.dup end if @symphonia_modal_dialog ActiveSupport::Deprecation.warn "@symphonia_modal_dialog is no used anymore !" @symphonia_modal_dialog.title ||= header_text '' else html_title(header_text.dup) header_text << "\n" + content_tag(:small, small, class: 'text-muted') if small.present? s = '' if [:back] && !request.xhr? back_url = [:back] unless [:back].is_a? TrueClass s << link_to_back(back_url) end s << capture(&block).to_s if block_given? header_tag = content_tag request.xhr? && :h5 || :h1, id: 'page_header', class: s.present? && "col-6" || nil do header_text.html_safe end return header_tag if s.blank? content_tag :div, class: "row" do header_tag + content_tag(:div, s.html_safe, class: "col-6 text-right") end end end |
#will_paginate(collection_or_options = nil, options = {}) ⇒ Object
change the default link renderer for will_paginate
205 206 207 208 209 210 211 212 213 214 |
# File 'app/helpers/symphonia/application_helper.rb', line 205 def will_paginate( = nil, = {}) if .is_a? Hash , = , nil end unless [:renderer] = .merge renderer: Symphonia::BootstrapLinkRender end [:query] ||= @query if @query super *[, ].compact end |