Class: Pageflow::Site

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

Overview

rubocop:todo Style/Documentation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



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

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

.ransackable_attributes(_auth_object = nil) ⇒ Object



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

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

Instance Method Details



39
40
41
# File 'app/models/pageflow/site.rb', line 39

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

#cname_domainObject



35
36
37
# File 'app/models/pageflow/site.rb', line 35

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

#display_nameObject



19
20
21
# File 'app/models/pageflow/site.rb', line 19

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

#display_titleObject



31
32
33
# File 'app/models/pageflow/site.rb', line 31

def display_title
  title.presence || cname_domain.presence
end

#existing_and_potential_entry_templatesObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/pageflow/site.rb', line 57

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



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

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

#hostObject



27
28
29
# File 'app/models/pageflow/site.rb', line 27

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

#name_with_account_prefixObject



23
24
25
# File 'app/models/pageflow/site.rb', line 23

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

#root_entryObject



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

def root_entry
  return unless root_permalink_directory

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


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

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.



76
77
78
# File 'app/models/pageflow/site.rb', line 76

def theme_name
  first_paged_entry_template.theme_name
end