Class: Locomotive::Mounter::Models::Snippet

Inherits:
Base
  • Object
show all
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

Methods inherited from Base

#initialize, #persisted?

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

#nameObject

fields ##



8
# File 'lib/locomotive/mounter/models/snippet.rb', line 8

field :name

#sourceString

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.

Returns:

  • (String)

    The liquid template



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_paramsHash

Return the params used for the API.

Returns:

  • (Hash)

    The params



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_sObject



50
51
52
# File 'lib/locomotive/mounter/models/snippet.rb', line 50

def to_s
  self.name
end