zen 0.2.4.1 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +42 -33
- data/README.md +14 -27
- data/ROADMAP.md +20 -2
- data/{Thorfile → Rakefile} +2 -3
- data/bin/zen +27 -5
- data/lib/zen.rb +70 -52
- data/lib/zen/asset.rb +258 -0
- data/lib/zen/bin/app.rb +42 -0
- data/lib/zen/controller/admin_controller.rb +53 -36
- data/lib/zen/controller/base_controller.rb +13 -8
- data/lib/zen/controller/frontend_controller.rb +4 -3
- data/lib/zen/controller/main_controller.rb +17 -33
- data/lib/zen/error/validation_error.rb +10 -0
- data/lib/zen/ext/string.rb +185 -0
- data/lib/zen/helper/acl.rb +120 -92
- data/lib/zen/helper/common.rb +1 -3
- data/lib/zen/helper/theme.rb +73 -0
- data/lib/zen/language.rb +66 -57
- data/lib/zen/layout/admin.xhtml +5 -48
- data/lib/zen/layout/login.xhtml +4 -44
- data/lib/zen/model/methods.rb +1 -1
- data/lib/zen/model/settings.rb +0 -3
- data/lib/zen/package.rb +101 -83
- data/lib/zen/package/base.rb +62 -0
- data/lib/zen/package/categories/lib/categories.rb +29 -10
- data/lib/zen/package/categories/lib/categories/controller/categories.rb +4 -5
- data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +4 -5
- data/lib/zen/package/categories/lib/categories/language/en/category_groups.yml +4 -3
- data/lib/zen/package/categories/lib/categories/model/category.rb +2 -2
- data/lib/zen/package/categories/lib/categories/model/category_group.rb +3 -3
- data/lib/zen/package/categories/lib/categories/plugin/categories.rb +130 -0
- data/lib/zen/package/categories/lib/categories/view/admin/categories/form.xhtml +1 -1
- data/lib/zen/package/categories/lib/categories/view/admin/categories/index.xhtml +2 -2
- data/lib/zen/package/categories/lib/categories/view/admin/category-groups/index.xhtml +11 -6
- data/lib/zen/package/comments/lib/comments.rb +23 -13
- data/lib/zen/package/comments/lib/comments/controller/comments.rb +4 -5
- data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +7 -8
- data/lib/zen/package/comments/lib/comments/model/comment.rb +4 -4
- data/lib/zen/package/comments/lib/comments/plugin/comments.rb +111 -0
- data/lib/zen/package/comments/lib/comments/view/admin/comments/form.xhtml +2 -2
- data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields.rb +18 -11
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +4 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +4 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +2 -2
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/index.xhtml +9 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/form.xhtml +1 -1
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/index.xhtml +3 -3
- data/lib/zen/package/menus/lib/menus.rb +25 -43
- data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +5 -6
- data/lib/zen/package/menus/lib/menus/controller/menus.rb +9 -5
- data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +4 -4
- data/lib/zen/package/menus/lib/menus/model/menu.rb +2 -2
- data/lib/zen/package/menus/lib/menus/model/menu_item.rb +4 -1
- data/lib/zen/package/menus/lib/menus/plugin/menus.rb +152 -0
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/form.xhtml +1 -1
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/index.xhtml +3 -3
- data/lib/zen/package/menus/lib/menus/view/admin/menus/index.xhtml +7 -7
- data/lib/zen/package/sections/lib/sections.rb +32 -16
- data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +9 -18
- data/lib/zen/package/sections/lib/sections/controller/sections.rb +8 -9
- data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +1 -1
- data/lib/zen/package/sections/lib/sections/model/section.rb +4 -4
- data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -10
- data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +224 -0
- data/lib/zen/package/sections/lib/sections/plugin/sections.rb +85 -0
- data/lib/zen/package/sections/lib/sections/view/admin/form.xhtml +1 -1
- data/lib/zen/package/sections/lib/sections/view/admin/index.xhtml +9 -5
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +2 -2
- data/lib/zen/package/settings/lib/settings.rb +145 -10
- data/lib/zen/package/settings/lib/settings/controller/settings.rb +28 -24
- data/lib/zen/package/settings/lib/settings/language/en/settings.yml +10 -0
- data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -64
- data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +40 -0
- data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +76 -0
- data/lib/zen/package/settings/lib/settings/plugin/settings.rb +236 -0
- data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +20 -49
- data/lib/zen/package/settings/migrations/1295597111_create_schema.rb +0 -12
- data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +31 -0
- data/lib/zen/package/users/lib/users.rb +18 -15
- data/lib/zen/package/users/lib/users/controller/access_rules.rb +44 -8
- data/lib/zen/package/users/lib/users/controller/user_groups.rb +4 -5
- data/lib/zen/package/users/lib/users/controller/users.rb +5 -6
- data/lib/zen/package/users/lib/users/language/en/access_rules.yml +11 -9
- data/lib/zen/package/users/lib/users/model/access_rule.rb +7 -6
- data/lib/zen/package/users/lib/users/model/user.rb +4 -4
- data/lib/zen/package/users/lib/users/model/user_group.rb +3 -3
- data/lib/zen/package/users/lib/users/public/admin/js/users/access_rules.js +50 -0
- data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +32 -29
- data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +8 -6
- data/lib/zen/package/users/lib/users/view/admin/user-groups/index.xhtml +3 -3
- data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +2 -2
- data/lib/zen/package/users/migrations/1303510943_class_rules.rb +13 -0
- data/lib/zen/plugin.rb +110 -104
- data/lib/zen/plugin/base.rb +46 -0
- data/lib/zen/{liquid/controller_behavior.rb → plugin/controller.rb} +9 -7
- data/lib/zen/plugin/helper.rb +47 -0
- data/lib/zen/plugin/markup/lib/markup.rb +14 -0
- data/lib/zen/plugin/markup/lib/markup/language/en/markup.yml +6 -0
- data/lib/zen/plugin/markup/lib/markup/markup.rb +154 -0
- data/lib/zen/public/admin/css/forms.css +4 -0
- data/lib/zen/public/admin/css/general.css +15 -15
- data/lib/zen/public/admin/css/layout.css +10 -10
- data/lib/zen/public/admin/css/reset.css +123 -0
- data/lib/zen/public/admin/images/icons/accept.png +0 -0
- data/lib/zen/public/admin/images/icons/add.png +0 -0
- data/lib/zen/public/admin/images/icons/back.png +0 -0
- data/lib/zen/public/admin/images/icons/bold.png +0 -0
- data/lib/zen/public/admin/images/icons/close.png +0 -0
- data/lib/zen/public/admin/images/icons/delete.png +0 -0
- data/lib/zen/public/admin/images/icons/edit.png +0 -0
- data/lib/zen/public/admin/images/icons/error.png +0 -0
- data/lib/zen/public/admin/images/icons/help.png +0 -0
- data/lib/zen/public/admin/images/icons/info.png +0 -0
- data/lib/zen/public/admin/images/icons/italic.png +0 -0
- data/lib/zen/public/admin/images/icons/large/error.png +0 -0
- data/lib/zen/public/admin/images/icons/large/notice.png +0 -0
- data/lib/zen/public/admin/images/icons/large/success.png +0 -0
- data/lib/zen/public/admin/images/icons/link.png +0 -0
- data/lib/zen/public/admin/images/icons/logout.png +0 -0
- data/lib/zen/public/admin/images/icons/ol.png +0 -0
- data/lib/zen/public/admin/images/icons/pdf.png +0 -0
- data/lib/zen/public/admin/images/icons/ul.png +0 -0
- data/lib/zen/public/admin/images/icons/user.png +0 -0
- data/lib/zen/public/admin/images/icons/view.png +0 -0
- data/lib/zen/public/admin/js/mootools/core.js +384 -333
- data/lib/zen/public/admin/js/mootools/more.js +256 -231
- data/lib/zen/public/admin/js/vendor/{datepicker/Picker.Date.js → datepicker.js} +447 -0
- data/lib/zen/public/admin/js/vendor/yepnope.js +1 -0
- data/lib/zen/public/admin/js/zen/editor/base.js +8 -1
- data/lib/zen/public/admin/js/zen/init.js +89 -26
- data/lib/zen/public/favicon.ico +0 -0
- data/lib/zen/task.rb +7 -0
- data/lib/zen/task/build.rake +60 -0
- data/lib/zen/task/clean.rake +27 -0
- data/lib/zen/task/db.rake +111 -0
- data/lib/zen/task/package.rake +67 -0
- data/lib/zen/task/plugin.rake +24 -0
- data/lib/zen/task/proto.rake +95 -0
- data/lib/zen/task/theme.rake +68 -0
- data/lib/zen/theme.rb +28 -55
- data/lib/zen/theme/base.rb +64 -0
- data/lib/zen/validation.rb +149 -0
- data/lib/zen/version.rb +1 -1
- data/lib/zen/view/bottom.xhtml +6 -0
- data/lib/zen/view/main.xhtml +32 -0
- data/proto/app/Rakefile +12 -0
- data/proto/app/app.rb +6 -6
- data/proto/app/config/config.rb +7 -14
- data/proto/app/config/database.rb +0 -20
- data/proto/app/start.rb +0 -1
- data/proto/app/{vendor/themes → task}/.gitkeep +0 -0
- data/proto/app/vendor/theme/.gitkeep +0 -0
- data/proto/package/lib/package.rb +8 -17
- data/proto/package/lib/package/controller/controllers.rb +4 -4
- data/proto/package/lib/package/language/en/languages.yml +3 -3
- data/proto/package/lib/package/model/model.rb +1 -1
- metadata +73 -73
- data/lib/zen/bin/base.rb +0 -109
- data/lib/zen/helper/asset.rb +0 -106
- data/lib/zen/liquid/general.rb +0 -94
- data/lib/zen/liquid/redirect.rb +0 -70
- data/lib/zen/liquid/strip.rb +0 -60
- data/lib/zen/package/categories/lib/categories/liquid/categories.rb +0 -16
- data/lib/zen/package/comments/lib/comments/liquid/comment_form.rb +0 -127
- data/lib/zen/package/comments/lib/comments/liquid/comments.rb +0 -115
- data/lib/zen/package/menus/lib/menus/liquid/menus.rb +0 -152
- data/lib/zen/package/sections/lib/sections/liquid/section_entries.rb +0 -228
- data/lib/zen/package/sections/lib/sections/liquid/sections.rb +0 -77
- data/lib/zen/package/settings/lib/settings/liquid/setting.rb +0 -58
- data/lib/zen/package/users/lib/users/liquid/user.rb +0 -77
- data/lib/zen/package/users/lib/users/liquid/users.rb +0 -82
- data/lib/zen/plugin/markup.rb +0 -30
- data/lib/zen/public/admin/css/boilerplate.css +0 -176
- data/lib/zen/public/admin/images/general/noise.jpg +0 -0
- data/lib/zen/public/admin/js/vendor/datepicker/Picker.Attach.js +0 -137
- data/lib/zen/public/admin/js/vendor/datepicker/Picker.js +0 -291
- data/lib/zen/public/admin/js/vendor/datepicker/README.md +0 -325
- data/lib/zen/public/admin/js/vendor/datepicker/locale.js +0 -16
- data/lib/zen/strict_struct.rb +0 -36
- data/lib/zen/task/build.rb +0 -123
- data/lib/zen/task/clean.rb +0 -46
- data/lib/zen/task/db.rb +0 -130
- data/lib/zen/task/package.rb +0 -87
- data/lib/zen/task/proto.rb +0 -116
- data/lib/zen/task/theme.rb +0 -88
- data/proto/app/Thorfile +0 -4
@@ -0,0 +1,85 @@
|
|
1
|
+
#:nodoc:
|
2
|
+
module Sections
|
3
|
+
#:nodoc:
|
4
|
+
module Plugin
|
5
|
+
##
|
6
|
+
# Plugin that can be used to display sections and their details. If you want to
|
7
|
+
# display section entries instead you should use the plugin
|
8
|
+
# Sections::Plugin::SectionEntries.
|
9
|
+
#
|
10
|
+
# ## Usage
|
11
|
+
#
|
12
|
+
# section = plugin(:sections, :section => 10)
|
13
|
+
# section.name # => "My Section"
|
14
|
+
#
|
15
|
+
# @author Yorick Peterse
|
16
|
+
# @since 0.2.5
|
17
|
+
#
|
18
|
+
class Sections
|
19
|
+
include ::Zen::Plugin::Helper
|
20
|
+
include ::Sections::Model
|
21
|
+
|
22
|
+
##
|
23
|
+
# Creates a new instance of the plugin and saves/validates the given configuration
|
24
|
+
# options.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# plugin = Sections::Plugin::Sections.new(:section => 10)
|
28
|
+
#
|
29
|
+
# @author Yorick Peterse
|
30
|
+
# @since 0.2.5
|
31
|
+
# @param [Hash] options Hash with a set of configuration files to use.
|
32
|
+
#
|
33
|
+
def initialize(options = {})
|
34
|
+
@options = {
|
35
|
+
:limit => 20,
|
36
|
+
:offset => 0,
|
37
|
+
:section => nil
|
38
|
+
}.merge(options)
|
39
|
+
|
40
|
+
validate_type(@options[:limit] , :limit , [Fixnum, Integer])
|
41
|
+
validate_type(@options[:offset] , :offset , [Fixnum, Integer])
|
42
|
+
validate_type(@options[:section], :section, [NilClass, Integer, Fixnum, String])
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Retrieves the section(s) based on the given configuration options. When multiple
|
47
|
+
# sections are retrieved they're returned as an array, otherwise a single instance
|
48
|
+
# of Sections::Model::Sections will be returned.
|
49
|
+
#
|
50
|
+
# @author Yorick Peterse
|
51
|
+
# @since 0.2.5
|
52
|
+
# @return [Array/Sections::Model::Section] List of all sections that were retrieved
|
53
|
+
# or an instance of Sections::Model::Section in case a specific section was retrieved
|
54
|
+
# from the database.
|
55
|
+
#
|
56
|
+
def call
|
57
|
+
# Retrieve a single section
|
58
|
+
if !@options[:section].nil?
|
59
|
+
# Retrieve a section by it's slug
|
60
|
+
if @options[:section].class == String
|
61
|
+
sections = Section[:slug => @options[:section]]
|
62
|
+
# Retrieve a section by it's ID
|
63
|
+
else
|
64
|
+
sections = Section[@options[:section]]
|
65
|
+
end
|
66
|
+
# Retrieve mutliple sections
|
67
|
+
else
|
68
|
+
sections = Section.limit(@options[:limit], @options[:offset]).all
|
69
|
+
end
|
70
|
+
|
71
|
+
# Convert every section to a hash
|
72
|
+
if sections.class == Array
|
73
|
+
sections.each_with_index do |section, index|
|
74
|
+
sections[index] = section.values
|
75
|
+
end
|
76
|
+
else
|
77
|
+
sections = sections.values
|
78
|
+
end
|
79
|
+
|
80
|
+
return sections
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -70,7 +70,7 @@ form_for(@section, :method => 'post', :action => @form_save_url, :id => :section
|
|
70
70
|
f.select(
|
71
71
|
lang('sections.labels.comment_format'),
|
72
72
|
:comment_format,
|
73
|
-
:values =>
|
73
|
+
:values => Zen::Plugin::Markup::Engines,
|
74
74
|
:selected => @section.comment_format,
|
75
75
|
:size => 1
|
76
76
|
)
|
@@ -22,7 +22,9 @@
|
|
22
22
|
<th>#{lang('sections.labels.slug')}</th>
|
23
23
|
<th>#{lang('sections.labels.comment_allow')}</th>
|
24
24
|
|
25
|
-
<?r if user_authorized?(
|
25
|
+
<?r if user_authorized?(
|
26
|
+
[:read], true, 'Sections::Controller::SectionEntries'
|
27
|
+
) ?>
|
26
28
|
<th></th>
|
27
29
|
<?r end ?>
|
28
30
|
</tr>
|
@@ -42,7 +44,7 @@
|
|
42
44
|
<td>
|
43
45
|
#{anchor_to(
|
44
46
|
section.name,
|
45
|
-
Sections::
|
47
|
+
Sections::Controller::Sections.r(:edit, section.id),
|
46
48
|
:title => section.name
|
47
49
|
)}
|
48
50
|
</td>
|
@@ -55,11 +57,13 @@
|
|
55
57
|
#{@boolean_hash.invert[section.comment_allow]}
|
56
58
|
</td>
|
57
59
|
|
58
|
-
<?r if user_authorized?(
|
60
|
+
<?r if user_authorized?(
|
61
|
+
[:read], true, 'Sections::Controller::SectionEntries'
|
62
|
+
) ?>
|
59
63
|
<td>
|
60
64
|
#{anchor_to(
|
61
65
|
lang('sections.labels.manage_entries'),
|
62
|
-
Sections::
|
66
|
+
Sections::Controller::SectionEntries.r(:index, section.id)
|
63
67
|
)}
|
64
68
|
</td>
|
65
69
|
<?r end ?>
|
@@ -77,7 +81,7 @@
|
|
77
81
|
<div class="button">
|
78
82
|
#{anchor_to(
|
79
83
|
lang('sections.buttons.new'),
|
80
|
-
Sections::
|
84
|
+
Sections::Controller::Sections.r(:new)
|
81
85
|
)}
|
82
86
|
</div>
|
83
87
|
<?r end ?>
|
@@ -40,7 +40,7 @@
|
|
40
40
|
<td>
|
41
41
|
#{anchor_to(
|
42
42
|
entry.title,
|
43
|
-
Sections::
|
43
|
+
Sections::Controller::SectionEntries.r(:edit, @section_id, entry.id)
|
44
44
|
)}
|
45
45
|
</td>
|
46
46
|
<?r else ?>
|
@@ -66,7 +66,7 @@
|
|
66
66
|
<div class="button">
|
67
67
|
#{anchor_to(
|
68
68
|
lang('section_entries.buttons.new'),
|
69
|
-
Sections::
|
69
|
+
Sections::Controller::SectionEntries.r(:new, @section_id)
|
70
70
|
)}
|
71
71
|
</div>
|
72
72
|
<?r end ?>
|
@@ -1,21 +1,156 @@
|
|
1
|
+
require __DIR__('settings/model/setting')
|
2
|
+
require __DIR__('settings/controller/settings')
|
3
|
+
require __DIR__('settings/plugin/settings')
|
1
4
|
|
2
|
-
|
3
|
-
|
4
|
-
require __DIR__ 'settings/liquid/setting'
|
5
|
-
|
6
|
-
Liquid::Template.register_tag('setting', Settings::Liquid::Setting)
|
5
|
+
Zen::Language.options.paths.push(__DIR__('settings'))
|
6
|
+
Zen::Language.load('settings')
|
7
7
|
|
8
|
+
# Register the package
|
8
9
|
Zen::Package.add do |p|
|
9
|
-
p.name = '
|
10
|
+
p.name = 'settings'
|
10
11
|
p.author = 'Yorick Peterse'
|
11
12
|
p.url = 'http://yorickpeterse.com/'
|
12
|
-
p.about = 'Module for managing settings such as the default module, whether or
|
13
|
-
|
13
|
+
p.about = 'Module for managing settings such as the default module, whether or
|
14
|
+
not to allow registration, etc.'
|
15
|
+
|
14
16
|
p.directory = __DIR__('settings')
|
15
17
|
p.migration_dir = __DIR__('../migrations')
|
16
18
|
|
17
19
|
p.menu = [{
|
18
|
-
:title =>
|
19
|
-
:url =>
|
20
|
+
:title => lang('settings.titles.index'),
|
21
|
+
:url => 'admin/settings'
|
20
22
|
}]
|
23
|
+
|
24
|
+
p.controllers = {
|
25
|
+
lang('settings.titles.index') => Settings::Controller::Settings
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Create all variables required for the settings
|
30
|
+
section_hash = {}
|
31
|
+
theme_hash = {}
|
32
|
+
|
33
|
+
begin
|
34
|
+
Sections::Model::Section.select(:name, :slug).each do |s|
|
35
|
+
section_hash[s.slug] = s.name
|
36
|
+
end
|
37
|
+
rescue => e
|
38
|
+
Ramaze::Log.warn("The settings plugin failed to retrieve all sections: #{e.message}")
|
39
|
+
end
|
40
|
+
|
41
|
+
Zen::Theme::Registered.each do |name, theme|
|
42
|
+
name = name.to_s
|
43
|
+
theme_hash[name] = name
|
44
|
+
end
|
45
|
+
|
46
|
+
# ------
|
47
|
+
|
48
|
+
# Register the plugin
|
49
|
+
Zen::Plugin.add do |plugin|
|
50
|
+
plugin.name = 'settings'
|
51
|
+
plugin.author = 'Yorick Peterse'
|
52
|
+
plugin.url = 'http://yorickpeterse.com/'
|
53
|
+
plugin.about = 'Plugin that can be used to register, retrieve and migrate settings.'
|
54
|
+
plugin.plugin = Settings::Plugin::Settings
|
55
|
+
end
|
56
|
+
|
57
|
+
# Register all setting groups
|
58
|
+
plugin(:settings, :register_group) do |group|
|
59
|
+
group.title = 'General'
|
60
|
+
group.name = 'general'
|
61
|
+
end
|
62
|
+
|
63
|
+
plugin(:settings, :register_group) do |group|
|
64
|
+
group.title = 'Security'
|
65
|
+
group.name = 'security'
|
66
|
+
end
|
67
|
+
|
68
|
+
# Register all settings
|
69
|
+
plugin(:settings, :register) do |setting|
|
70
|
+
setting.title = lang('settings.labels.website_name')
|
71
|
+
setting.description = lang('settings.placeholders.website_name')
|
72
|
+
setting.name = 'website_name'
|
73
|
+
setting.group = 'general'
|
74
|
+
setting.default = 'Zen'
|
75
|
+
setting.type = 'textbox'
|
76
|
+
end
|
77
|
+
|
78
|
+
plugin(:settings, :register) do |setting|
|
79
|
+
setting.title = lang('settings.labels.website_description')
|
80
|
+
setting.description = lang('settings.placeholders.website_description')
|
81
|
+
setting.name = 'website_description'
|
82
|
+
setting.group = 'general'
|
83
|
+
setting.type = 'textarea'
|
84
|
+
end
|
85
|
+
|
86
|
+
plugin(:settings, :register) do |setting|
|
87
|
+
setting.title = lang('settings.labels.website_enabled')
|
88
|
+
setting.description = lang('settings.placeholders.website_enabled')
|
89
|
+
setting.name = 'website_enabled'
|
90
|
+
setting.group = 'general'
|
91
|
+
setting.type = 'radio'
|
92
|
+
setting.default = '1'
|
93
|
+
setting.values = {
|
94
|
+
lang('zen_general.special.boolean_hash.true') => '1',
|
95
|
+
lang('zen_general.special.boolean_hash.false') => '0'
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
plugin(:settings, :register) do |setting|
|
100
|
+
setting.title = lang('settings.labels.language')
|
101
|
+
setting.description = lang('settings.placeholders.language')
|
102
|
+
setting.name = 'language'
|
103
|
+
setting.group = 'general'
|
104
|
+
setting.default = 'en'
|
105
|
+
setting.type = 'select'
|
106
|
+
setting.values = {
|
107
|
+
'en' => lang('zen_general.special.language_hash.en')
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
plugin(:settings, :register) do |setting|
|
112
|
+
setting.title = lang('settings.labels.default_section')
|
113
|
+
setting.description = lang('settings.placeholders.default_section')
|
114
|
+
setting.name = 'default_section'
|
115
|
+
setting.group = 'general'
|
116
|
+
setting.type = 'select'
|
117
|
+
setting.values = section_hash
|
118
|
+
end
|
119
|
+
|
120
|
+
plugin(:settings, :register) do |setting|
|
121
|
+
setting.title = lang('settings.labels.theme')
|
122
|
+
setting.description = lang('settings.placeholders.theme')
|
123
|
+
setting.name = 'theme'
|
124
|
+
setting.group = 'general'
|
125
|
+
setting.type = 'select'
|
126
|
+
setting.values = theme_hash
|
127
|
+
end
|
128
|
+
|
129
|
+
plugin(:settings, :register) do |setting|
|
130
|
+
setting.title = lang('settings.labels.enable_antispam')
|
131
|
+
setting.description = lang('settings.placeholders.enable_antispam')
|
132
|
+
setting.name = 'enable_antispam'
|
133
|
+
setting.group = 'security'
|
134
|
+
setting.type = 'radio'
|
135
|
+
setting.values = {
|
136
|
+
lang('zen_general.special.boolean_hash.true') => '1',
|
137
|
+
lang('zen_general.special.boolean_hash.false') => '0'
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
plugin(:settings, :register) do |setting|
|
142
|
+
setting.title = lang('settings.labels.defensio_key')
|
143
|
+
setting.description = lang('settings.placeholders.defensio_key')
|
144
|
+
setting.name = 'defensio_key'
|
145
|
+
setting.group = 'security'
|
146
|
+
setting.type = 'textbox'
|
147
|
+
end
|
148
|
+
|
149
|
+
# Migrate all settings
|
150
|
+
begin
|
151
|
+
plugin(:settings, :migrate)
|
152
|
+
rescue
|
153
|
+
Ramaze::Log.warn(
|
154
|
+
"Failed to migrate the current settings, make sure the database table is up to date."
|
155
|
+
)
|
21
156
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Settings
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
##
|
6
6
|
# Controller for managing settings. Each setting is saved as a separate
|
7
7
|
# row in the database, making management and retrieving them easier.
|
@@ -9,11 +9,10 @@ module Settings
|
|
9
9
|
# @author Yorick Peterse
|
10
10
|
# @since 0.1
|
11
11
|
#
|
12
|
-
class Settings < Zen::
|
13
|
-
include ::Settings::
|
12
|
+
class Settings < Zen::Controller::AdminController
|
13
|
+
include ::Settings::Model
|
14
14
|
|
15
|
-
map
|
16
|
-
trait :extension_identifier => 'com.zen.settings'
|
15
|
+
map('/admin/settings')
|
17
16
|
|
18
17
|
before_all do
|
19
18
|
csrf_protection(:save, :delete) do
|
@@ -36,8 +35,6 @@ module Settings
|
|
36
35
|
|
37
36
|
@form_save_url = Settings.r(:save)
|
38
37
|
|
39
|
-
Zen::Language.load('settings')
|
40
|
-
|
41
38
|
# Set the page title
|
42
39
|
if !action.method.nil?
|
43
40
|
method = action.method.to_sym
|
@@ -66,17 +63,17 @@ module Settings
|
|
66
63
|
|
67
64
|
set_breadcrumbs(lang('settings.titles.index'))
|
68
65
|
|
69
|
-
|
70
|
-
@
|
66
|
+
@settings_ordered = {}
|
67
|
+
@groups = ::Settings::Plugin::Settings::Registered[:groups]
|
71
68
|
|
72
69
|
# Organize the settings so that each item is a child
|
73
70
|
# item of it's group.
|
74
|
-
settings.each do |
|
75
|
-
if !@
|
76
|
-
@
|
71
|
+
::Settings::Plugin::Settings::Registered[:settings].each do |name, setting|
|
72
|
+
if !@settings_ordered.key?(setting.group)
|
73
|
+
@settings_ordered[setting.group] = []
|
77
74
|
end
|
78
75
|
|
79
|
-
@
|
76
|
+
@settings_ordered[setting.group].push(setting)
|
80
77
|
end
|
81
78
|
end
|
82
79
|
|
@@ -102,19 +99,26 @@ module Settings
|
|
102
99
|
|
103
100
|
flash_success = lang('settings.success.save')
|
104
101
|
flash_error = lang('settings.errors.save')
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
102
|
+
|
103
|
+
# Update all settings
|
104
|
+
post.each do |key, value|
|
105
|
+
setting = Setting[:name => key]
|
106
|
+
|
107
|
+
begin
|
108
|
+
# Update the DB record
|
109
|
+
setting.update(:value => value)
|
110
|
+
notification(:success, lang('settings.titles.index'), flash_success)
|
111
|
+
|
112
|
+
# Update the internal settings
|
113
|
+
if ::Zen::Settings[key.to_sym] != value
|
114
|
+
::Zen::Settings[key.to_sym] = value
|
115
|
+
end
|
116
|
+
rescue
|
117
|
+
notification(:error, lang('settings.titles.index'), flash_error)
|
118
|
+
flash[:form_errors] = setting.errors
|
109
119
|
end
|
110
|
-
|
111
|
-
notification(:success, lang('settings.titles.index'), flash_success)
|
112
|
-
rescue
|
113
|
-
notification(:error, lang('settings.titles.index'), flash_error)
|
114
|
-
|
115
|
-
flash[:form_errors] = @setting.errors
|
116
120
|
end
|
117
|
-
|
121
|
+
|
118
122
|
redirect_referrer
|
119
123
|
end
|
120
124
|
end
|
@@ -12,6 +12,16 @@ labels:
|
|
12
12
|
enable_antispam : 'Enable anti-spam'
|
13
13
|
defensio_key : 'Defensio API key'
|
14
14
|
|
15
|
+
placeholders:
|
16
|
+
website_name : 'The name of the website.'
|
17
|
+
website_description : 'The description of the website.'
|
18
|
+
website_enabled : 'Whether or not the website is available to non admins.'
|
19
|
+
language : 'The language to use for the system.'
|
20
|
+
default_section : 'The default section to use on the homepage.'
|
21
|
+
theme : 'The frontend theme to use.'
|
22
|
+
enable_antispam : "Whether or not Defensio's anti-spam system should be used."
|
23
|
+
defensio_key : 'The API key to use for the Defensio anti-spam system.'
|
24
|
+
|
15
25
|
tabs:
|
16
26
|
general : 'General'
|
17
27
|
security : 'Security'
|
@@ -1,12 +1,12 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Settings
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Model
|
5
5
|
##
|
6
6
|
# Model that represents a single setting. This model is also used to retrieve
|
7
7
|
# all possible values for a certain settngs. This is done by calling a method
|
8
8
|
# that matches the format get_SETTING-NAME_values. For example, a setting named "theme"
|
9
|
-
# would result in a call to Settings::
|
9
|
+
# would result in a call to Settings::Model::Setting#get_theme_values.
|
10
10
|
#
|
11
11
|
# In order to add new method you'll have to monkey patch this model as following:
|
12
12
|
#
|
@@ -23,7 +23,6 @@ module Settings
|
|
23
23
|
# idea to refactor this and put it in it's own class/plugin/whatever.
|
24
24
|
#
|
25
25
|
class Setting < Sequel::Model
|
26
|
-
include ::Zen::Language
|
27
26
|
|
28
27
|
##
|
29
28
|
# Retrieves all settings and returns them as a key/value hash.
|
@@ -42,72 +41,12 @@ module Settings
|
|
42
41
|
value = s.value
|
43
42
|
end
|
44
43
|
|
45
|
-
settings[s.
|
44
|
+
settings[s.name.to_sym] = value
|
46
45
|
end
|
47
46
|
|
48
47
|
return settings
|
49
48
|
end
|
50
49
|
|
51
|
-
##
|
52
|
-
# Generates the possible values for the setting "website_enabled".
|
53
|
-
#
|
54
|
-
# @author Yorick Peterse
|
55
|
-
# @since 0.2
|
56
|
-
# @return [Hash]
|
57
|
-
#
|
58
|
-
def self.get_website_enabled_values
|
59
|
-
hash = {
|
60
|
-
lang('zen_general.special.boolean_hash.true') => '1',
|
61
|
-
lang('zen_general.special.boolean_hash.false') => '0'
|
62
|
-
}
|
63
|
-
|
64
|
-
return hash
|
65
|
-
end
|
66
|
-
|
67
|
-
##
|
68
|
-
# Generates the possible values for the setting "language".
|
69
|
-
#
|
70
|
-
# @author Yorick Peterse
|
71
|
-
# @since 0.2
|
72
|
-
# @return [Hash]
|
73
|
-
#
|
74
|
-
def self.get_language_values
|
75
|
-
return ::Zen.languages
|
76
|
-
end
|
77
|
-
|
78
|
-
##
|
79
|
-
# Generates the possible values for the setting "default_section".
|
80
|
-
#
|
81
|
-
# @author Yorick Peterse
|
82
|
-
# @since 0.2
|
83
|
-
# @return [Hash]
|
84
|
-
#
|
85
|
-
def self.get_default_section_values
|
86
|
-
section_hash = {}
|
87
|
-
|
88
|
-
::Sections::Models::Section.select(:name, :slug).each do |s|
|
89
|
-
section_hash[s.slug] = s.name
|
90
|
-
end
|
91
|
-
|
92
|
-
return section_hash
|
93
|
-
end
|
94
|
-
|
95
|
-
##
|
96
|
-
# Generates the possible values for the setting "theme".
|
97
|
-
#
|
98
|
-
# @author Yorick Peterse
|
99
|
-
# @since 0.2
|
100
|
-
# @return [Hash]
|
101
|
-
#
|
102
|
-
def self.get_theme_values
|
103
|
-
theme_hash = {}
|
104
|
-
|
105
|
-
Zen::Theme.themes.each do |ident, theme|
|
106
|
-
theme_hash[ident] = theme.name
|
107
|
-
end
|
108
|
-
|
109
|
-
return theme_hash
|
110
|
-
end
|
111
50
|
end
|
112
51
|
end
|
113
52
|
end
|