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, 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
# File 'lib/locomotive/mounter/models/snippet.rb', line 20

def source
  @source ||= {}

  source = if self.template.respond_to?(:source)
    # liquid or haml file
    self.template.source
  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



38
39
40
41
42
43
44
45
# File 'lib/locomotive/mounter/models/snippet.rb', line 38

def to_params
  params = self.filter_attributes %w(name slug)

  # raw_template
  params[:template] = self.source rescue nil

  params
end

#to_sObject



47
48
49
# File 'lib/locomotive/mounter/models/snippet.rb', line 47

def to_s
  self.name
end