Class: Fullstack::Cms::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/fullstack/cms/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#linkablesObject



18
19
20
# File 'lib/fullstack/cms/configuration.rb', line 18

def linkables
  @linkables || []
end

#localizedObject Also known as: localize, localized?



11
12
13
# File 'lib/fullstack/cms/configuration.rb', line 11

def localized
  @localized.nil? ? true : @localized
end

Instance Method Details

#default_localeObject



7
8
9
# File 'lib/fullstack/cms/configuration.rb', line 7

def default_locale
  "#{I18n.default_locale}" || "en"
end

config.menu( ‘main’, :localized => true )

… menu( ‘main’, :locale => I18n.locale ) menu_items( ‘main’, :locale => I18n.locale )



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fullstack/cms/configuration.rb', line 34

def menu(uid, options = {})
  return nil unless Menu.table_exists?
  options = options.reverse_merge({:localized => localized?})
  localized_menu = options.delete(:localized)
  
  if localized_menu && localized? # ignores the option if CMS is not localized
    I18n.available_locales.each do |locale|
      m = Menu.find_or_create_by_uid_and_locale(uid.to_s, locale.to_s)
      raise m.errors.full_messages.join("\n") if m.errors.any?
        
    end
  else
    m = Menu.find_or_create_by_uid(uid.to_s)
    raise m.errors.full_messages.join("\n") if m.errors.any?
    
  end
end

#resources(&block) ⇒ Object



22
23
24
# File 'lib/fullstack/cms/configuration.rb', line 22

def resources(&block)
  Fullstack::Admin.resources(&block)
end

#setting(key, options = {}) ⇒ Object

config.setting(‘description’, :kind => :text, :localized => true, :group => group) setting(‘website/description’, :locale => I18n.locale)



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fullstack/cms/configuration.rb', line 55

def setting(key, options = {})
  return nil unless Setting.table_exists?

  options = options.reverse_merge({ :localized => localized? }).merge({ :autocreate => true })
  localized_setting = options.delete(:localized)

  if localized_setting && localized? # ignores the option if CMS is not localized
    I18n.available_locales.each do |locale|
      Setting.global(key.to_s, options.merge(:locale => locale.to_s))
    end
  else
    Setting.global(key.to_s, options)
  end


end