Module: DynamicContentHelper
- Defined in:
- app/helpers/dynamic_content_helper.rb
Instance Method Summary collapse
- #c(section, content, *args) ⇒ Object
- #c_image_path(section, content, *args) ⇒ Object
- #c_image_tag(section, content, *args) ⇒ Object
- #link_to_edit(section, content) ⇒ Object
Instance Method Details
#c(section, content, *args) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/dynamic_content_helper.rb', line 41 def c section, content, *args = {default: '', preend: '', append: '', size: '', show: :content, only_numbers: false} = .merge(args.first) if args.count > 0 data = @dynamic_content # options[:append] += link_to_edit(section, content) if current_admin_user && !options[:only_numbers] if data.nil? raise DynamicContent::NoDataLoadedError, 'No Dynamic Content data loaded, try to include `before_action :load_dynamic_content` on your controller.' end if data.has_key?(section.to_sym) && data[section.to_sym].has_key?(content.to_sym) result = data[section.to_sym][content.to_sym] result = Dragonfly.app.fetch(result[:uid]).thumb([:size]).url if result.kind_of?(Hash) && result.has_key?(:uid) && ![:size].blank? result = result[[:show].to_sym] if result.kind_of?(Hash) result = [:default] if result.blank? result = result.scan(/\d/).join if [:only_numbers] else Rails.logger.warn('WARNING: Dynamic content data for '+section.to_s+':'+content.to_s+' was not found on database.') result = [:default] end return result.kind_of?(String) ? (result.blank? ? '' : ([:preend].html_safe + result + [:append].html_safe)) : result end |
#c_image_path(section, content, *args) ⇒ Object
34 35 36 37 38 39 |
# File 'app/helpers/dynamic_content_helper.rb', line 34 def c_image_path section, content, *args = { only_path: true } = .merge(args.first) if args.count > 0 return c_image_tag(section, content, ) end |
#c_image_tag(section, content, *args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/dynamic_content_helper.rb', line 5 def c_image_tag section, content, *args image, data, = '', @dynamic_content, { alt: nil, size: '' } = .merge(args.first) if args.count > 0 if data.nil? raise DynamicContent::NoDataLoadedError, 'No Dynamic Content data loaded, try to include `before_action :load_dynamic_content` on your controller.' end if data.has_key?(section.to_sym) && data[section.to_sym].has_key?(content.to_sym) data = data[section.to_sym][content.to_sym] begin [:alt] = data[:alt] if [:alt].blank? image = data[:content] if data[:data_type] == 'image' && ![:size].blank? && data[:uid].split('.').last != 'svg' image = Dragonfly.app.fetch(data[:uid]).thumb([:size]).url end rescue Rails.logger.warn('WARNING: Error to load dynamic image '+section.to_s+':'+content.to_s+'.') end else Rails.logger.warn('WARNING: Dynamic image data for '+section.to_s+':'+content.to_s+' was not found on database.') end .delete(:size) return [:only_path] ? image : image_tag(image, ) end |
#link_to_edit(section, content) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/helpers/dynamic_content_helper.rb', line 66 def link_to_edit section, content if @page.has_key?(section.to_sym) && @page[section.to_sym].has_key?(content.to_sym) id = @page[:id] elsif @application.has_key?(section.to_sym) && @application[section.to_sym].has_key?(content.to_sym) id = @application[:id] else return '' end return (' ' + link_to('', edit_admin_page_path(id)+'#'+section.to_s+'-'+content.to_s, class: 'admin-edit', data: {section: section, content: content, page: id}, title: 'Editar', target: '_blank')) end |