Class: Locomotive::Mounter::Models::Snippet
- Defined in:
- lib/locomotive/mounter/models/snippet.rb
Instance Attribute Summary
Attributes inherited from Base
#_id, #created_at, #mounting_point, #updated_at
Instance Method Summary collapse
-
#name ⇒ Object
fields ##.
-
#source ⇒ String
Return the Liquid template based on the template_filepath property of the snippet.
-
#to_params ⇒ Hash
Return the params used for the API.
- #to_s ⇒ Object
Methods inherited from Base
Methods included from Fields
#attributes, #attributes_with_translations, #initialize, #localized_field?, #to_hash, #to_yaml, #translated_in, #translated_in?, #write_attributes
Constructor Details
This class inherits a constructor from Locomotive::Mounter::Models::Base
Instance Method Details
#name ⇒ Object
fields ##
8 |
# File 'lib/locomotive/mounter/models/snippet.rb', line 8 field :name |
#source ⇒ String
Return the Liquid template based on the template_filepath property of the snippet. If the template is HAML or SLIM, then a pre-rendering to Liquid is done.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/locomotive/mounter/models/snippet.rb', line 20 def source @source ||= {} source = if self.template.respond_to?(:need_for_prerendering?) # must be a tilt template with or without prerendering self.template.need_for_prerendering? ? self.template.render : self.template.data elsif self.template.is_a?(Exception) # comes from the parsing # we do not know how to render the page so rethrow the exception raise self.template else # simple string self.template end @source[Locomotive::Mounter.locale] = source end |
#to_params ⇒ Hash
Return the params used for the API.
41 42 43 44 45 46 47 48 |
# File 'lib/locomotive/mounter/models/snippet.rb', line 41 def to_params params = self.filter_attributes %w(name slug) # raw_template params[:template] = self.source rescue nil params end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/locomotive/mounter/models/snippet.rb', line 50 def to_s self.name end |