Class: Locomotive::Mounter::MountingPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/mounter/mounting_point.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



55
56
57
# File 'lib/locomotive/mounter/mounting_point.rb', line 55

def method_missing(name, *args, &block)
  (self.resources || {})[name.to_sym] || super
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/locomotive/mounter/mounting_point.rb', line 6

def path
  @path
end

#resourcesObject

Returns the value of attribute resources.



6
7
8
# File 'lib/locomotive/mounter/mounting_point.rb', line 6

def resources
  @resources
end

#root_pageObject

Returns the value of attribute root_page.



6
7
8
# File 'lib/locomotive/mounter/mounting_point.rb', line 6

def root_page
  @root_page
end

Instance Method Details

#default_localeSymbol

Return the default locale which is the first locale defined for a site. If none, then use the current I18n locale.

Returns:

  • (Symbol)

    The default locale



33
34
35
# File 'lib/locomotive/mounter/mounting_point.rb', line 33

def default_locale
  (self.locales.first || Locomotive::Mounter.locale).to_sym
end

#inspectObject



59
60
61
# File 'lib/locomotive/mounter/mounting_point.rb', line 59

def inspect
  "[MountingPoint] #{(self.resources || {}).keys.inspect}"
end

#localesArray

Return all the locales defined by the site related to that mounting point.

Returns:

  • (Array)

    The list of the locales



24
25
26
# File 'lib/locomotive/mounter/mounting_point.rb', line 24

def locales
  self.site.locales || []
end

#register_resource(name, elements) ⇒ Object

Register a resource (site, pages, content types, …etc) and its elements. It makes sure that all the elements get a pointer to that mounting point. The elements can be either an array, hash or even a single object (ex: site). For instance, for a page, it will be a hash whose key is the fullpath.

Parameters:

  • name (Symbol)

    Name of the resource

  • elements (Object)

    Element(s) related to the resource



45
46
47
48
49
50
51
52
53
# File 'lib/locomotive/mounter/mounting_point.rb', line 45

def register_resource(name, elements)
  self.resources ||= {}

  (elements.respond_to?(:values) ? elements.values : [*elements]).each do |element|
    element.mounting_point = self
  end

  self.resources[name.to_sym] = elements
end