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



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

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

#prepend_locale_to_pathObject



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

def prepend_locale_to_path
  @prepend_locale_to_path.nil? ? true : @prepend_locale_to_path
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 )



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

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



25
26
27
# File 'lib/fullstack/cms/configuration.rb', line 25

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)



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

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