Sha256: 1b2b4fdcccf883d79413e0c5b9c2e95a929666353f2c2e682e0d1b41d7586940
Contents?: true
Size: 1.84 KB
Versions: 15
Compression:
Stored size: 1.84 KB
Contents
module Locomotive module ContentTypesHelper # Renders the label of a content type entry. If no entry_template filled in the content type, # it just calls the _label method of the entry (based on the label_field_id). Otherwise, it # parses and renders the liquid template. # # @param [ ContentType ] content_type The content type for better performance # @param [ ContentEntry] entry The entry we want to display the label # # @return [ String ] The label of the content type entry # def entry_label(content_type, entry) link = edit_content_entry_path(current_site, content_type.slug, entry) if content_type.entry_template.blank? label = entry._label(content_type).presence || t(:untranslated, scope: 'locomotive.shared.list') link_to label, link # default one else assigns = { 'site' => current_site, 'entry' => entry.to_liquid(content_type), 'link' => link, 'today' => Date.today, 'now' => Time.zone.now } registers = { site: current_site, locale: ::Mongoid::Fields::I18n.locale.to_s, services: Locomotive::Steam::Services.build_instance } context = ::Liquid::Context.new({}, assigns, registers) content_type.render_entry_template(context).html_safe end end # List the fields which could be used to filter the content entries # in the back-office. # Not all the types are included. Only: string, text, integer, float, email # # @param [ ContentType ] content_type The content type owning the fields # # @return [ Array ] Used as it by the select_tag method # def options_for_filter_fields(content_type) allowed_types = %w(string text integer float email) fields = content_type.entries_custom_fields.where(:type.in => allowed_types) fields.map { |field| [field.label, field._id] } end end end
Version data entries
15 entries across 15 versions & 1 rubygems