Method: CmsPage.load_from_file

Defined in:
app/models/cms_page.rb

.load_from_file(site, path) ⇒ Object

Attempting to initialize page object from yaml file that is found in config.seed_data_path This file defines all attributes of the page plus all the block information



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

def self.load_from_file(site, path)
  return nil if LucyCms.config.seed_data_path.blank?
  path = (path == '/')? '/index' : path.to_s.chomp('/')
  file_path = "#{LucyCms.config.seed_data_path}/#{site.hostname}/pages#{path}.yml"
  return nil unless File.exists?(file_path)
  attributes              = YAML.load_file(file_path).symbolize_keys!
  attributes[:cms_layout] = CmsLayout.load_from_file(site, attributes[:cms_layout])
  attributes[:parent]     = CmsPage.load_from_file(site, attributes[:parent])
  attributes[:cms_site]   = site
  new(attributes)
rescue
  raise "Failed to load from #{file_path}"
end