Module: Fae::ViewHelper
- Defined in:
- app/helpers/fae/view_helper.rb
Instance Method Summary collapse
- #fae_avatar(user = current_user) ⇒ Object
- #fae_clone_button(item) ⇒ Object
- #fae_content_form(f, attribute, label: nil, hint: nil, helper_text: nil, markdown: nil, markdown_supported: nil, input_options: nil, show_form_manager: true) ⇒ Object
- #fae_date_format(datetime, timezone = @option.time_zone) ⇒ Object
- #fae_datetime_format(datetime, timezone = @option.time_zone) ⇒ Object
- #fae_delete_button(item, delete_path = nil, *custom_attrs) ⇒ Object
- #fae_file_form(f, file_name, label: nil, helper_text: nil, required: nil, show_form_manager: true) ⇒ Object
- #fae_filter_datepicker(attribute, options = {}) ⇒ Object
- #fae_filter_form(options = {}, &block) ⇒ Object
- #fae_filter_select(attribute, opts = {}) ⇒ Object
- #fae_image_form(f, image_name, label: nil, alt_label: nil, caption_label: nil, show_alt: nil, show_caption: nil, required: nil, helper_text: nil, alt_helper_text: nil, caption_helper_text: nil, attached_as: nil, show_form_manager: true) ⇒ Object
- #fae_index_image(image, path = nil) ⇒ Object
- #fae_paginate(items) ⇒ Object
- #fae_path ⇒ Object
- #fae_seo_set_form(f, seo_set_name) ⇒ Object
- #fae_sort_id(item) ⇒ Object
- #fae_toggle(item, column) ⇒ Object
Instance Method Details
#fae_avatar(user = current_user) ⇒ Object
135 136 137 138 |
# File 'app/helpers/fae/view_helper.rb', line 135 def fae_avatar(user = current_user) hash = Digest::MD5.hexdigest(user.email.downcase) "https://secure.gravatar.com/avatar/#{hash}?s=80&d=mm" end |
#fae_clone_button(item) ⇒ Object
54 55 56 57 58 59 |
# File 'app/helpers/fae/view_helper.rb', line 54 def (item) return if item.blank? link_to "#{@index_path}?from_existing=#{item.id}", method: :post, title: 'Clone', class: 'js-tooltip table-action', data: { confirm: t('fae.clone_confirmation') } do concat content_tag :i, nil, class: 'icon-copy' end end |
#fae_content_form(f, attribute, label: nil, hint: nil, helper_text: nil, markdown: nil, markdown_supported: nil, input_options: nil, show_form_manager: true) ⇒ Object
24 25 26 |
# File 'app/helpers/fae/view_helper.rb', line 24 def fae_content_form(f, attribute, label: nil, hint: nil, helper_text: nil, markdown: nil, markdown_supported: nil, input_options: nil, show_form_manager: true) render 'fae/application/content_form', f: f, attribute: attribute, label: label, hint: hint, helper_text: helper_text, markdown: markdown, markdown_supported: markdown_supported, input_options: , show_form_manager: show_form_manager end |
#fae_date_format(datetime, timezone = @option.time_zone) ⇒ Object
4 5 6 |
# File 'app/helpers/fae/view_helper.rb', line 4 def fae_date_format(datetime, timezone = @option.time_zone) datetime.in_time_zone(timezone).strftime('%m/%d/%y') if is_date_or_time?(datetime) end |
#fae_datetime_format(datetime, timezone = @option.time_zone) ⇒ Object
8 9 10 |
# File 'app/helpers/fae/view_helper.rb', line 8 def fae_datetime_format(datetime, timezone = @option.time_zone) datetime.in_time_zone(timezone).strftime("%b %-d, %Y %l:%M%P %Z") if is_date_or_time?(datetime) end |
#fae_delete_button(item, delete_path = nil, *custom_attrs) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/fae/view_helper.rb', line 61 def (item, delete_path = nil, *custom_attrs) return if item.blank? delete_path ||= polymorphic_path( [main_app, fae_scope.to_sym, item.try(:fae_parent), item] ) attrs = { method: :delete, title: 'Delete', class: 'js-tooltip table-action', data: { confirm: t('fae.delete_confirmation') } } attrs.deep_merge!(custom_attrs[0]) if custom_attrs.present? link_to delete_path, attrs do concat content_tag :i, nil, class: 'icon-trash' end end |
#fae_file_form(f, file_name, label: nil, helper_text: nil, required: nil, show_form_manager: true) ⇒ Object
20 21 22 |
# File 'app/helpers/fae/view_helper.rb', line 20 def fae_file_form(f, file_name, label: nil, helper_text: nil, required: nil, show_form_manager: true) render 'fae/application/file_uploader', f: f, file_name: file_name, label: label, required: required, helper_text: helper_text, show_form_manager: show_form_manager end |
#fae_filter_datepicker(attribute, options = {}) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'app/helpers/fae/view_helper.rb', line 126 def fae_filter_datepicker(attribute, ={}) [:label] ||= attribute.to_s.titleize [:placeholder] = [:label] if [:placeholder].nil? content_tag :div, class: 'table-filter-group text-input datepicker' do concat label_tag "filter[#{attribute}]", [:label] concat text_field_tag "filter[#{attribute}]", nil, placeholder: [:placeholder] end end |
#fae_filter_form(options = {}, &block) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/fae/view_helper.rb', line 81 def fae_filter_form( = {}, &block) = return if [:collection].blank? form_tag([:action], prepare_form_filter_hash()) do concat prepare_filter_header() if block_given? filter_group_wrapper = content_tag(:div, class: 'table-filter-group-wrapper') do link_tag = content_tag(:a, t('fae.reset_search'), class: 'js-reset-btn button -small hidden', href: '#') concat capture(&block) concat content_tag(:div, link_tag, class: 'table-filter-group') end end concat filter_group_wrapper # I know this `unless !` looks like it should be an `if` but it's definitely supposed to be `unless !` unless ![:search] concat submit_tag t('fae.apply_filters'), class: 'hidden' end end end |
#fae_filter_select(attribute, opts = {}) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/helpers/fae/view_helper.rb', line 108 def fae_filter_select(attribute, opts = {}) = (attribute, opts) # grouped_by takes priority over grouped_options if [:grouped_by].present? = filter_generate_select_group([:collection], [:grouped_by], [:label_method]) elsif [:grouped_options].present? = ([:grouped_options]) else = ([:collection], 'id', [:label_method]) = ([:options]) if [:options].present? end content_tag :div, class: 'table-filter-group' do concat label_tag "filter[#{attribute}]", [:label] concat select_tag "filter[#{attribute}]", , prompt: [:placeholder] end end |
#fae_image_form(f, image_name, label: nil, alt_label: nil, caption_label: nil, show_alt: nil, show_caption: nil, required: nil, helper_text: nil, alt_helper_text: nil, caption_helper_text: nil, attached_as: nil, show_form_manager: true) ⇒ Object
16 17 18 |
# File 'app/helpers/fae/view_helper.rb', line 16 def fae_image_form(f, image_name, label: nil, alt_label: nil, caption_label: nil, show_alt: nil, show_caption: nil, required: nil, helper_text: nil, alt_helper_text: nil, caption_helper_text: nil, attached_as: nil, show_form_manager: true) render 'fae/images/image_uploader', f: f, image_name: image_name, label: label, alt_label: alt_label, caption_label: caption_label, show_alt: show_alt, show_caption: show_caption, required: required, helper_text: helper_text, alt_helper_text: alt_helper_text, caption_helper_text: caption_helper_text, attached_as: attached_as, show_form_manager: show_form_manager end |
#fae_index_image(image, path = nil) ⇒ Object
32 33 34 35 36 37 |
# File 'app/helpers/fae/view_helper.rb', line 32 def fae_index_image(image, path = nil) return if image.blank? || image.asset.blank? || image.asset.thumb.blank? content_tag :div, class: 'image-mat' do link_to_if path.present?, image_tag(image.asset.thumb.url), path end end |
#fae_paginate(items) ⇒ Object
140 141 142 143 144 |
# File 'app/helpers/fae/view_helper.rb', line 140 def fae_paginate(items) content_tag :nav, class: 'pagination', data: { filter_path: "#{@index_path}/filter" } do paginate items, theme: 'fae' end end |
#fae_path ⇒ Object
12 13 14 |
# File 'app/helpers/fae/view_helper.rb', line 12 def fae_path Rails.application.routes.url_helpers.fae_path[1..-1] end |
#fae_seo_set_form(f, seo_set_name) ⇒ Object
28 29 30 |
# File 'app/helpers/fae/view_helper.rb', line 28 def fae_seo_set_form(f, seo_set_name) render 'fae/application/seo_set_form', f: f, seo_set_name: seo_set_name end |
#fae_sort_id(item) ⇒ Object
75 76 77 78 79 |
# File 'app/helpers/fae/view_helper.rb', line 75 def fae_sort_id(item) return if item.blank? klass = item.class.name.underscore.gsub('/','__') "#{klass}_#{item.id}" end |
#fae_toggle(item, column) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/fae/view_helper.rb', line 39 def fae_toggle(item, column) active = item.send(column) link_class = active ? 'slider-yes-selected' : '' model_name = item.class.to_s.gsub('::','__').underscore.pluralize url = fae.toggle_path(model_name, item.id.to_s, column) link_to url, class: "slider-wrapper #{link_class}", method: :post, remote: true do '<div class="slider-options"> <div class="slider-option slider-option-yes" aria-live="polite">Yes</div> <div class="slider-option-selector"></div> <div class="slider-option slider-option-no" aria-live="polite">No</div> </div>'.html_safe end end |