Class: Pageflow::Site

Inherits:
ApplicationRecord show all
Includes:
TranslatedAttributes
Defined in:
app/models/pageflow/site.rb

Overview

rubocop:todo Style/Documentation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TranslatedAttributes

#attribute_translations, #translated

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



94
95
96
# File 'app/models/pageflow/site.rb', line 94

def self.ransackable_associations(_auth_object = nil)
  %w[account]
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



90
91
92
# File 'app/models/pageflow/site.rb', line 90

def self.ransackable_attributes(_auth_object = nil)
  %w[name]
end

Instance Method Details



49
50
51
# File 'app/models/pageflow/site.rb', line 49

def build_root_permalink_directory
  permalink_directories.build(path: '')
end

#cname_domainObject



45
46
47
# File 'app/models/pageflow/site.rb', line 45

def cname_domain
  cname.split('.').pop(2).join('.')
end

#display_nameObject



29
30
31
# File 'app/models/pageflow/site.rb', line 29

def display_name
  name.presence || I18n.t('pageflow.admin.sites.default_name')
end

#display_titleObject



41
42
43
# File 'app/models/pageflow/site.rb', line 41

def display_title
  title.presence || cname_domain.presence
end

#existing_and_potential_entry_templatesObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/pageflow/site.rb', line 67

def existing_and_potential_entry_templates
  entry_type_names = Pageflow.config_for().entry_types.map(&:name)

  allowed_existing_entry_templates =
    entry_templates.where(entry_type_name: entry_type_names)

  free_type_names =
    entry_type_names - allowed_existing_entry_templates.map(&:entry_type_name)

  potential_entry_templates = free_type_names.map do |type_name|
    entry_templates.build(entry_type_name: type_name)
  end

  allowed_existing_entry_templates + potential_entry_templates
end

#first_paged_entry_templateObject



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

def first_paged_entry_template
  entry_templates.find_or_initialize_by(entry_type_name: 'paged')
end

#hostObject



37
38
39
# File 'app/models/pageflow/site.rb', line 37

def host
  Pageflow.config.site_url_options_for(self)&.dig(:host)
end


25
26
27
# File 'app/models/pageflow/site.rb', line 25

def legal_info(locale:)
  LegalInfo.new(self, locale)
end

#name_with_account_prefixObject



33
34
35
# File 'app/models/pageflow/site.rb', line 33

def 
  [.name, name].compact.join(' - ')
end

#root_entryObject



53
54
55
56
57
# File 'app/models/pageflow/site.rb', line 53

def root_entry
  return unless root_permalink_directory

  root_permalink_directory.permalinks.find_by_slug('')&.entry
end


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

def root_permalink_directory
  permalink_directories.find_by_path('')
end

#theme_nameObject

Deprecated.

Depending on what you need this for, consider

scoping your code to an entry type or look at a specific entry's theme name.



86
87
88
# File 'app/models/pageflow/site.rb', line 86

def theme_name
  first_paged_entry_template.theme_name
end