Module: Locomotive::ContentEntriesHelper
- Defined in:
- app/helpers/locomotive/content_entries_helper.rb
Instance Method Summary collapse
-
#label_for_custom_field(content_entry, field) ⇒ String
Display the label related to a field of a content entry.
- #options_for_belongs_to_custom_field(class_name) ⇒ Object
-
#push_has_many_form(field) ⇒ Object
Keep track of the form used to create / edit content entries from a has_many custom field.
-
#render_has_many_forms ⇒ String
Render all the forms used to create / edit content entries from a has_many custom field.
Instance Method Details
#label_for_custom_field(content_entry, field) ⇒ String
Display the label related to a field of a content entry. If the field is not localized, we just display the label. If the field is localized, then we display a nice flag icon to let the end-user know about it.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/locomotive/content_entries_helper.rb', line 50 def label_for_custom_field(content_entry, field) if field.localized? translated_css = content_entry.translated_field?(field) ? '' : 'untranslated' icon = content_tag(:i, '', class: 'icon-flag') tag = content_tag(:span, icon, class: "localized-icon #{translated_css}") "#{tag}#{field.label}" else field.label end end |
#options_for_belongs_to_custom_field(class_name) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/locomotive/content_entries_helper.rb', line 30 def (class_name) content_type = Locomotive::ContentType.class_name_to_content_type(class_name, current_site) if content_type content_type.ordered_entries.map { |entry| [entry_label(content_type, entry), entry._id] } else [] # unknown content type end end |
#push_has_many_form(field) ⇒ Object
Keep track of the form used to create / edit content entries from a has_many custom field. Because of formtastic which does not work with embedded forms, we have to render them once we are done with our main form.
11 12 13 |
# File 'app/helpers/locomotive/content_entries_helper.rb', line 11 def push_has_many_form(field) (@has_many_forms ||= []) << field end |
#render_has_many_forms ⇒ String
Render all the forms used to create / edit content entries from a has_many custom field. Because of formtastic which does not work with embedded forms, we have to render them once we are done with our main form.
22 23 24 25 26 27 28 |
# File 'app/helpers/locomotive/content_entries_helper.rb', line 22 def render_has_many_forms return unless @has_many_forms @has_many_forms.map do |field| render 'locomotive/custom_fields/types/has_many_form', field: field end.join("\n").html_safe end |