Module: TbCore::ApplicationHelper
- Included in:
- Spud::ApplicationController
- Defined in:
- app/helpers/tb_core/application_helper.rb
Instance Method Summary collapse
- #cache_key_for_spud_collection(collection, key: 'view', cache_params: [], for_user: false) ⇒ Object
- #current_site_name ⇒ Object
- #tb_form_error_field(record, attribute) ⇒ Object
- #tb_form_error_header(record) ⇒ Object
- #tb_form_errors(record, *fields_to_display) ⇒ Object
- #tb_form_field(attribute) ⇒ Object
- #tb_form_for(record, options = {}, &block) ⇒ Object
- #tb_page_title ⇒ Object
Instance Method Details
#cache_key_for_spud_collection(collection, key: 'view', cache_params: [], for_user: false) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/tb_core/application_helper.rb', line 70 def cache_key_for_spud_collection(collection, key:'view', cache_params:[], for_user:false) cache_keys = [controller_name, action_name, key] cache_keys << collection.collect(&:updated_at).max().try(:utc).try(:to_i) if for_user cache_keys << current_user_id end if cache_params.any? cache_keys += cache_params.collect{ |cache_param| params[cache_param] || 'nil' } end cache_keys += collection.collect(&:id) cache_key = cache_keys.join('/') if cache_key.length > 250 return Digest::SHA1.hexdigest(cache_key) else return cache_key end end |
#current_site_name ⇒ Object
66 67 68 |
# File 'app/helpers/tb_core/application_helper.rb', line 66 def current_site_name return Spud::Core.config.site_name end |
#tb_form_error_field(record, attribute) ⇒ Object
39 40 41 42 43 44 |
# File 'app/helpers/tb_core/application_helper.rb', line 39 def tb_form_error_field(record, attribute) = record.errors[attribute].first if return content_tag :p, , :class => 'help-block form-field-error' end end |
#tb_form_error_header(record) ⇒ Object
32 33 34 35 36 37 |
# File 'app/helpers/tb_core/application_helper.rb', line 32 def tb_form_error_header(record) if record.errors.any? = "Please correct the following #{'error'.pluralize(record.errors.size)}:" return content_tag :h4, , :class => 'form-field-error' end end |
#tb_form_errors(record, *fields_to_display) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/tb_core/application_helper.rb', line 16 def tb_form_errors(record, *fields_to_display) if record.errors.any? content_tag :div, :class => 'form-errors' do concat(tb_form_error_header(record)) concat(raw "<ul>") if fields_to_display.any? = fields_to_display.collect{ |field| record.errors.(field) }.flatten() else = record.errors. end concat(raw .collect{ |msg| "<li>#{msg}</li>" }.join()) concat(raw "</ul>") end end end |
#tb_form_field(attribute) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/helpers/tb_core/application_helper.rb', line 46 def tb_form_field(attribute) content_tag :div, :class => 'form-group' do concat label_tag attribute, attribute, :class => 'col-sm-2 control-label' concat(content_tag(:div, :class => 'col-sm-10') do text_field_tag attribute, :placeholder => attribute, :class => 'form-control' end) end end |
#tb_form_for(record, options = {}, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/tb_core/application_helper.rb', line 3 def tb_form_for(record, = {}, &block) [:builder] = TbCore::FormBuilder [:html] ||= {} if [:html][:class] [:html][:class] += ' form-horizontal' else [:html][:class] = 'form-horizontal' end return form_for(record, , &block) end |
#tb_page_title ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/tb_core/application_helper.rb', line 55 def tb_page_title if content_for?(:title) title = content_for(:title) + ' | ' + Spud::Core.site_name elsif @page_title title = @page_title + ' | ' + Spud::Core.site_name else title = Spud::Core.site_name end return content_tag :title, title end |