Class: Locomotive::Site

Instance Method Summary collapse

Methods included from Concerns::Site::Metafields

#any_localized_metafield?, #find_metafield, #has_metafields?

Methods included from Concerns::Site::UrlRedirections

#add_or_update_url_redirection, #remove_url_redirection, #url_redirections=, #url_redirections_plain_text, #url_redirections_with_information

Methods included from Concerns::Site::Cache

#last_modified_at

Methods included from Concerns::Site::Timezone

#timezone

Methods included from Concerns::Site::Locales

#default_locale, #default_locale_was, #each_locale, #is_default_locale?, #locale_fallbacks, #locales=, #localized?, #prefix_default_locale?, #with_default_locale

Methods included from Concerns::Site::AccessPoints

#asset_host=, #domains=, #handle=, #main_domain, #to_param

Instance Method Details

#accountsObject


63
64
65
# File 'app/models/locomotive/site.rb', line 63

def accounts
  Account.criteria.in(_id: self.memberships.map(&:account_id))
end

#admin_membershipsObject


71
72
73
# File 'app/models/locomotive/site.rb', line 71

def admin_memberships
  self.memberships.find_all { |m| m.admin? }
end

#created_byObject

associations ##


25
# File 'app/models/locomotive/site.rb', line 25

belongs_to  :created_by,      class_name: 'Locomotive::Account', optional: true

#is_admin?(account) ⇒ Boolean

Returns:


75
76
77
# File 'app/models/locomotive/site.rb', line 75

def is_admin?()
  self.memberships.detect { |m| m.admin? && m. == ._id }
end

#localized_content_typesObject


59
60
61
# File 'app/models/locomotive/site.rb', line 59

def localized_content_types
  self.content_types.localized
end

#membership_for(account) ⇒ Object


67
68
69
# File 'app/models/locomotive/site.rb', line 67

def membership_for()
  self.memberships.where(account_id: ._id).first
end

#membershipsObject

behaviours ##


45
# File 'app/models/locomotive/site.rb', line 45

accepts_nested_attributes_for :memberships, allow_destroy: true

#nameObject

validations ##


19
# File 'app/models/locomotive/site.rb', line 19

field :name

#ordered_pages(conditions = {}) ⇒ Criteria

Get all the pages in the right order: depth and position, both ASC.

Parameters:

  • conditions (Hash) (defaults to: {})

    Extra conditions passed to the Mongoid criteria

Returns:

  • (Criteria)

    a Mongoid criteria


55
56
57
# File 'app/models/locomotive/site.rb', line 55

def ordered_pages(conditions = {})
  self.pages.unscoped.where(conditions || {}).order_by_depth_and_position
end

#to_liquidObject


84
85
86
# File 'app/models/locomotive/site.rb', line 84

def to_liquid
  to_steam.to_liquid
end

#to_steamObject


79
80
81
82
# File 'app/models/locomotive/site.rb', line 79

def to_steam
  repository = Locomotive::Steam::Services.build_instance.repositories.site
  repository.build(self.attributes.dup)
end