fullstack-cms 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/app/models/setting.rb +17 -5
- data/fullstack-cms.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/app/models/setting.rb
CHANGED
@@ -48,21 +48,33 @@ class Setting < ActiveRecord::Base
|
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
|
-
def self.get(
|
51
|
+
def self.get(key, default = nil)
|
52
52
|
cached_settings = Rails.cache.read('fullstack-settings-cache')
|
53
53
|
|
54
54
|
unless cached_settings
|
55
55
|
cached_settings = {}
|
56
|
-
Setting.
|
57
|
-
|
56
|
+
Setting.all.each do |setting|
|
57
|
+
l = setting.locale
|
58
|
+
g = setting.group
|
58
59
|
k = [g, setting.key].compact.join('/')
|
59
|
-
cached_settings[
|
60
|
+
cached_settings[l] ||= {}
|
61
|
+
cached_settings[l][k] = setting.value if setting.value
|
60
62
|
end
|
61
63
|
|
62
64
|
Rails.cache.write('fullstack-settings-cache', cached_settings)
|
63
65
|
end
|
64
66
|
|
65
|
-
cached_settings.
|
67
|
+
localized_settings = cached_settings[I18n.locale.to_s] || {}
|
68
|
+
unlocalized_settings = cached_settings[nil] || {}
|
69
|
+
|
70
|
+
key_segments = key.to_s.split("/")
|
71
|
+
if key_segments.size == 1
|
72
|
+
key_segments.unshift("global")
|
73
|
+
end
|
74
|
+
|
75
|
+
key = key_segments.join("/")
|
76
|
+
|
77
|
+
localized_settings[key] || unlocalized_settings[key] || default
|
66
78
|
end
|
67
79
|
|
68
80
|
# using Setting.get is simpler, expecially if you don't want 'autocreate' feature
|
data/fullstack-cms.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fullstack-cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -294,7 +294,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
294
294
|
version: '0'
|
295
295
|
segments:
|
296
296
|
- 0
|
297
|
-
hash:
|
297
|
+
hash: -4405423992718841812
|
298
298
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
299
299
|
none: false
|
300
300
|
requirements:
|