zen 0.2.6 → 0.2.6.1

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.
@@ -1,14 +1,22 @@
1
- 0.2.6 May 29 2011
1
+ ## 0.2.6.1 - June 1st, 2011
2
+
3
+ * Dropped Zen.settings and modified the settings plugin so that it works properly when
4
+ using a multi-process based environment such as Unicorn.
5
+
6
+ ## 0.2.6 - May 29th, 2011
2
7
 
3
8
  * Zen is now using RVM for gem management and such.
4
9
  * Began working on making Zen compatible with at least JRuby. Rubinius isn't worth the
5
- effort at this time.
10
+ effort at this time.
6
11
  * Removed Ramaze::Helper::Common.notification in favor of Ramaze::Helper::Message.
7
12
  * Dropped Zen::Database, Zen::Settings and most of the options in favor of instance
8
- variables set in the main Zen module. See commit d40ee1c2e518a323b2983e1bcfb7a0d863bf3b2f
9
- for more information.
13
+ variables set in the main Zen module. See commit
14
+ [d40ee1c2e518a323b2983e1bcfb7a0d863bf3b2f][d40ee1c2e518a323b2983e1bcfb7a0d863bf3b2f]
15
+ for more information.
10
16
  * Translated Zen to Dutch.
11
17
  * Re-organized the application prototypes to make them easier to use/understand.
12
18
  * Implemented the anti-spam system as a plugin and added a decent XSS protection system
13
- using Loofah.
19
+ using Loofah.
14
20
  * Various changes to the Javascript classes.
21
+
22
+ [d40ee1c2e518a323b2983e1bcfb7a0d863bf3b2f]: https://github.com/zen-cms/Zen-Core/commit/d40ee1c2e518a323b2983e1bcfb7a0d863bf3b2f
data/MANIFEST CHANGED
@@ -1,7 +1,7 @@
1
1
  .gems
2
2
  .travis.yml
3
3
  AUTHORS
4
- CHANGELOG
4
+ CHANGELOG.md
5
5
  LICENSE
6
6
  MANIFEST
7
7
  README.md
data/lib/zen.rb CHANGED
@@ -28,14 +28,6 @@ module Zen
28
28
  #
29
29
  attr_accessor :database
30
30
 
31
- ##
32
- # Hash containing all system settings.
33
- #
34
- # @author Yorick Peterse
35
- # @since 0.2.6
36
- #
37
- attr_accessor :settings
38
-
39
31
  ##
40
32
  # String containing the path to the root directory of the Zen application.
41
33
  #
@@ -47,12 +39,10 @@ module Zen
47
39
  ##
48
40
  # Loads the database and the required models.
49
41
  #
50
- # @author Yorick Peterse
42
+ # @author Yorick Peterse
51
43
  # @since 0.1
52
44
  #
53
45
  def init
54
- @settings ||= {}
55
-
56
46
  # Initialize the database
57
47
  Zen::Language.load('zen_general')
58
48
 
@@ -95,17 +85,6 @@ module Zen
95
85
  "Failed to migrate the settings, make sure the database table is up to date"
96
86
  )
97
87
  end
98
-
99
- begin
100
- ::Settings::Model::Setting.get_settings.each do |k, v|
101
- Zen.settings[k] = v
102
- end
103
- rescue => e
104
- Ramaze::Log.warn(
105
- "Failed to retrieve the settings, are you sure the database is migrated?\n" +
106
- "Error: #{e.message}"
107
- )
108
- end
109
88
  end
110
89
  end # class << self
111
90
  end # Zen
@@ -138,3 +117,8 @@ require __DIR__('zen/controller/frontend_controller')
138
117
  require __DIR__('zen/controller/admin_controller')
139
118
  require __DIR__('zen/controller/main_controller')
140
119
  require __DIR__('zen/controller/preview')
120
+
121
+ # Load the cache for the settings. This has to be done outside any of the init methods as
122
+ # that would make it impossible to set a custom cache.
123
+ Ramaze::Cache.options.names.push(:settings)
124
+ Ramaze::Cache.options.settings = Ramaze::Cache::LRU
@@ -26,12 +26,13 @@ module Zen
26
26
  #
27
27
  def index(*uri)
28
28
  @request_uri = []
29
+ theme = plugin(:settings, :get, :theme).value
29
30
 
30
31
  # Clean the URI of nasty input
31
32
  uri.each { |v| @request_uri.push(h(v)) }
32
33
 
33
34
  if !@request_uri[0] or @request_uri[0].empty?
34
- @request_uri[0] = ::Zen.settings[:default_section]
35
+ @request_uri[0] = plugin(:settings, :get, :default_section).value
35
36
  end
36
37
 
37
38
  if !@request_uri[1] or @request_uri[1].empty?
@@ -39,11 +40,11 @@ module Zen
39
40
  end
40
41
 
41
42
  # A theme is always required
42
- if ::Zen.settings[:theme].nil? or ::Zen.settings[:theme].empty?
43
+ if theme.nil? or theme.empty?
43
44
  respond(lang('zen_general.errors.no_theme'))
44
45
  end
45
46
 
46
- theme = ::Zen::Theme[::Zen.settings[:theme]]
47
+ theme = ::Zen::Theme[theme]
47
48
  group = @request_uri[0]
48
49
  template = @request_uri[1]
49
50
 
@@ -53,7 +54,7 @@ module Zen
53
54
  template_path = File.join(theme_path, group, "#{template}.xhtml")
54
55
 
55
56
  # Is the website down?
56
- if ::Zen.settings[:website_enabled] == '0'
57
+ if plugin(:settings, :get, :website_enabled).value === '0'
57
58
  offline_path = File.join(theme_path, 'offline.xhtml')
58
59
 
59
60
  if File.exist?(offline_path)
@@ -12,7 +12,6 @@ module Ramaze
12
12
  # @since 0.2.5
13
13
  #
14
14
  module Theme
15
-
16
15
  ##
17
16
  # Renders a partial from the current theme's partial directory. The first argument
18
17
  # is the name of the partial (without an extension) to render. The second argument
@@ -29,7 +28,8 @@ module Ramaze
29
28
  # the partial.
30
29
  #
31
30
  def partial(file, variables = {})
32
- theme = ::Zen::Theme[::Zen.settings[:theme]]
31
+ theme = plugin(:settings, :get, :theme).value
32
+ theme = Zen::Theme[theme]
33
33
 
34
34
  if !theme.respond_to?(:partial_dir) or theme.partial_dir.nil?
35
35
  raise(::Zen::ThemeError, "The theme #{theme.name} has no partial directory set.")
@@ -59,7 +59,7 @@ module Ramaze
59
59
  # @param [Hash] variables Hash with variables to pass to the 404 template.
60
60
  #
61
61
  def show_404(variables = {})
62
- theme = ::Zen::Theme[::Zen.settings[:theme]]
62
+ theme = ::Zen::Theme[plugin(:settings, :get, :theme).value]
63
63
  template = "#{theme.template_dir}/404.xhtml"
64
64
 
65
65
  # Render the template and replace the current buffer with it's output
@@ -67,7 +67,6 @@ module Ramaze
67
67
 
68
68
  respond(template, 404)
69
69
  end
70
-
71
- end
72
- end
73
- end
70
+ end # Theme
71
+ end # Helper
72
+ end # Ramaze
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html lang="#{::Zen.settings[:language]}">
2
+ <html lang="#{plugin(:settings, :get, :language).value}">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
 
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html lang="#{::Zen.settings[:language]}">
2
+ <html lang="#{plugin(:settings, :get, :language).value}">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
 
@@ -84,8 +84,8 @@ module Comments
84
84
  end
85
85
 
86
86
  # Require anti-spam validation?
87
- if ::Zen.settings[:enable_antispam] == '1'
88
- engine = ::Zen.settings[:anti_spam_system].to_sym
87
+ if plugin(:settings, :get, :enable_antispam).value === '1'
88
+ engine = plugin(:settings, :get, :anti_spam_system).value.to_sym
89
89
  spam = plugin(:anti_spam, engine, nil, nil, nil, post['comment'])
90
90
 
91
91
  # Time to validate the Defensio response
@@ -114,13 +114,8 @@ module Comments
114
114
  # @return [TrueClass/FalseClass]
115
115
  #
116
116
  def defensio
117
- spam = true
118
-
119
- if !::Zen.settings.key?(:defensio_key)
120
- raise(::Zen::PluginError, "The setting \"defensio_key\" is missing")
121
- end
122
-
123
- api_key = ::Zen.settings[:defensio_key]
117
+ spam = true
118
+ api_key = plugin(:settings, :get, :defensio_key).value
124
119
 
125
120
  if api_key.nil? or api_key.empty?
126
121
  raise(
@@ -107,15 +107,8 @@ module Settings
107
107
 
108
108
  # Update all settings
109
109
  post.each do |key, value|
110
- setting = Setting[:name => key]
111
-
112
110
  begin
113
- setting.update(:value => value)
114
-
115
- # Update the internal settings
116
- if ::Zen.settings[key.to_sym] != value
117
- ::Zen.settings[key.to_sym] = value
118
- end
111
+ plugin(:settings, :get, key).value = value
119
112
  rescue => e
120
113
  Ramaze::Log.error(e.inspect)
121
114
  message(:error, flash_error)
@@ -69,6 +69,48 @@ module Settings
69
69
  raise(::Zen::ValidationError, "The settings group #{group} doesn't exist.")
70
70
  end
71
71
  end
72
+
73
+ ##
74
+ # Updates the value of a setting both in the cache and the SQL database.
75
+ #
76
+ # @author Yorick Peterse
77
+ # @since 0.2.6.1
78
+ # @param [String] value The value to set the setting to.
79
+ #
80
+ def value=(value)
81
+ # First we'll update the SQL database
82
+ ::Settings::Model::Setting[:name => name].update(:value => value)
83
+
84
+ # Sync the cache
85
+ ::Ramaze::Cache.settings.store(name, value)
86
+ end
87
+
88
+ ##
89
+ # Retrieves the setting. If it exists in the cache the cache's value is used,
90
+ # otherwise it will be retrieved from the SQL database and cached.
91
+ #
92
+ # @author Yorick Peterse
93
+ # @since 0.2.6.1
94
+ #
95
+ def value
96
+ val = ::Ramaze::Cache.settings.fetch(name)
97
+
98
+ # Get the setting from the database
99
+ if val.nil?
100
+ setting = ::Settings::Model::Setting[:name => name]
101
+
102
+ # If the value is also nil we'll use the default value
103
+ if setting.value.nil? or setting.value.empty?
104
+ val = setting.default
105
+ else
106
+ val = setting.value
107
+ end
108
+
109
+ ::Ramaze::Cache.settings.store(name, val)
110
+ end
111
+
112
+ return val
113
+ end
72
114
  end # SettingBase
73
115
  end # Plugin
74
116
  end # Settings
@@ -181,7 +181,9 @@ module Settings
181
181
  # @return [Zen::StrictStruct]
182
182
  #
183
183
  def get(name)
184
- validate_type(name, :name, [String])
184
+ validate_type(name, :name, [String, Symbol])
185
+
186
+ name = name.to_s
185
187
 
186
188
  if !Registered[:settings].key?(name)
187
189
  raise(ArgumentError, "The setting #{name} doesn't exist.")
@@ -20,12 +20,7 @@
20
20
  @settings_ordered.each do |group, items|
21
21
  f.g.div(:id => "group_#{group}") do
22
22
  items.each do |s|
23
- # Get the value from either the value or default getter
24
- if ::Zen.settings[s.name.to_sym].nil?
25
- value = s.default
26
- else
27
- value = ::Zen.settings[s.name.to_sym]
28
- end
23
+ value = plugin(:settings, :get, s.name).value
29
24
 
30
25
  case s.type
31
26
  when 'textbox'
@@ -42,24 +42,26 @@ module Users
42
42
  # @param [Hash] creds The specified credentials
43
43
  # @return [Object/Boolean] new instance of the given user.
44
44
  #
45
- def self.authenticate creds
45
+ def self.authenticate(creds)
46
46
  email = creds['email']
47
47
  password = creds['password']
48
48
 
49
- if email.nil? or password.nil?
50
- return false
51
- end
49
+ return false if email.nil? or password.nil?
52
50
 
53
51
  user = self[:email => email]
54
52
 
55
53
  if !user.nil? and user.password == password and user.status == 'open'
56
54
  # Overwrite all the global settings with the user specific ones
57
- ::Zen.settings.each do |k, v|
58
- if user.respond_to?(k)
59
- got = user.send(k)
55
+ [:language, :frontend_language, :date_format].each do |setting|
56
+ # "plugin" is already defined by Sequel so we'll have to call the plugin
57
+ # manually.
58
+ value = ::Zen::Plugin[:settings].plugin.new(:get, setting).call.value
59
+
60
+ if user.respond_to?(setting)
61
+ got = user.send(setting)
60
62
 
61
63
  if got.nil? or got.empty?
62
- user.send("#{k}=", v)
64
+ user.send("#{setting}=", value)
63
65
  end
64
66
  end
65
67
  end
data/lib/zen/version.rb CHANGED
@@ -7,5 +7,5 @@ module Zen
7
7
  # @author Yorick Peterse
8
8
  # @since 0.1
9
9
  #
10
- Version = '0.2.6'
10
+ Version = '0.2.6.1'
11
11
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: zen
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.6
5
+ version: 0.2.6.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Yorick Peterse
@@ -203,7 +203,7 @@ files:
203
203
  - .gems
204
204
  - .travis.yml
205
205
  - AUTHORS
206
- - CHANGELOG
206
+ - CHANGELOG.md
207
207
  - LICENSE
208
208
  - MANIFEST
209
209
  - README.md