Class: Alchemy::Language

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Code
Defined in:
app/models/alchemy/language.rb

Defined Under Namespace

Modules: Code

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Code

#code, #code=

Class Method Details

.currentObject

Current language from current thread or default.



65
66
67
# File 'app/models/alchemy/language.rb', line 65

def current
  RequestStore.store[:alchemy_current_language] || default
end

.current=(v) ⇒ Object

Store the current language in the current thread.



60
61
62
# File 'app/models/alchemy/language.rb', line 60

def current=(v)
  RequestStore.store[:alchemy_current_language] = v
end

.current_root_pageObject

The root page of the current language.



70
71
72
# File 'app/models/alchemy/language.rb', line 70

def current_root_page
  current.pages.language_roots.first
end

.defaultObject Also known as: get_default

Default language



75
76
77
# File 'app/models/alchemy/language.rb', line 75

def default
  find_by(default: true)
end

Instance Method Details

#label(attrib) ⇒ Object



81
82
83
84
85
86
87
# File 'app/models/alchemy/language.rb', line 81

def label(attrib)
  if attrib.to_sym == :code
    self.code
  else
    I18n.t(self.code, default: self.name)
  end
end

#layout_root_pageObject

Layout root page



97
98
99
# File 'app/models/alchemy/language.rb', line 97

def layout_root_page
  @layout_root_page ||= Page.layout_root_for(id)
end

#root_pageObject

Root page



92
93
94
# File 'app/models/alchemy/language.rb', line 92

def root_page
  @root_page ||= pages.language_roots.first
end