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
@@ -18,7 +18,8 @@
|
|
18
18
|
<?r end ?>
|
19
19
|
|
20
20
|
<th>#{lang('access_rules.labels.id')}</th>
|
21
|
-
<th>#{lang('access_rules.labels.
|
21
|
+
<th>#{lang('access_rules.labels.package')}</th>
|
22
|
+
<th>#{lang('access_rules.labels.controller')}</th>
|
22
23
|
<th>#{lang('access_rules.labels.create')}</th>
|
23
24
|
<th>#{lang('access_rules.labels.read')}</th>
|
24
25
|
<th>#{lang('access_rules.labels.update')}</th>
|
@@ -37,16 +38,17 @@
|
|
37
38
|
<?r end ?>
|
38
39
|
|
39
40
|
<td>#{rule.id}</td>
|
40
|
-
|
41
|
+
<td>#{rule.package}</td>
|
42
|
+
|
41
43
|
<?r if user_authorized?([:update]) ?>
|
42
44
|
<td>
|
43
45
|
#{anchor_to(
|
44
|
-
rule.
|
45
|
-
Users::
|
46
|
+
@form_controllers[rule.package].key(rule.controller),
|
47
|
+
Users::Controller::AccessRules.r(:edit, rule.id)
|
46
48
|
)}
|
47
49
|
</td>
|
48
50
|
<?r else ?>
|
49
|
-
<td>#{rule.
|
51
|
+
<td>#{@form_controllers[rule.package].key(rule.controller)}</td>
|
50
52
|
<?r end ?>
|
51
53
|
|
52
54
|
<td>#{@boolean_hash.invert[rule.create_access]}</td>
|
@@ -78,7 +80,7 @@
|
|
78
80
|
<div class="button">
|
79
81
|
#{anchor_to(
|
80
82
|
lang('access_rules.buttons.new'),
|
81
|
-
Users::
|
83
|
+
Users::Controller::AccessRules.r(:new)
|
82
84
|
)}
|
83
85
|
</div>
|
84
86
|
<?r end ?>
|
@@ -37,7 +37,7 @@
|
|
37
37
|
<?r if user_authorized?([:update]) ?>
|
38
38
|
<td>
|
39
39
|
#{anchor_to(
|
40
|
-
group.name, Users::
|
40
|
+
group.name, Users::Controller::UserGroups.r(:edit, group.id)
|
41
41
|
)}
|
42
42
|
</td>
|
43
43
|
<?r else ?>
|
@@ -45,7 +45,7 @@
|
|
45
45
|
<?r end ?>
|
46
46
|
|
47
47
|
<td>#{group.slug}</td>
|
48
|
-
<td>#{@boolean_hash[group.super_group]}</td>
|
48
|
+
<td>#{@boolean_hash.invert[group.super_group]}</td>
|
49
49
|
</tr>
|
50
50
|
<?r end ?>
|
51
51
|
</tbody>
|
@@ -61,7 +61,7 @@
|
|
61
61
|
<div class="button">
|
62
62
|
#{anchor_to(
|
63
63
|
lang('user_groups.buttons.new'),
|
64
|
-
Users::
|
64
|
+
Users::Controller::UserGroups.r(:new)
|
65
65
|
)}
|
66
66
|
</div>
|
67
67
|
<?r end ?>
|
@@ -40,7 +40,7 @@
|
|
40
40
|
<td>
|
41
41
|
#{anchor_to(
|
42
42
|
user.email,
|
43
|
-
Users::
|
43
|
+
Users::Controller::Users.r(:edit, user.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('users.buttons.new'),
|
69
|
-
Users::
|
69
|
+
Users::Controller::Users.r(:new)
|
70
70
|
)}
|
71
71
|
</div>
|
72
72
|
<?r end ?>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
|
3
|
+
up do
|
4
|
+
rename_column(:access_rules, :extension, :package)
|
5
|
+
add_column(:access_rules, :controller, String, :null => false, :default => '*')
|
6
|
+
end
|
7
|
+
|
8
|
+
down do
|
9
|
+
rename_column(:access_rules, :package, :extension)
|
10
|
+
drop_column(:access_rules, :controller)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/lib/zen/plugin.rb
CHANGED
@@ -1,171 +1,177 @@
|
|
1
1
|
require __DIR__('error/plugin_error')
|
2
|
+
require __DIR__('plugin/base')
|
2
3
|
|
3
4
|
#:nodoc:
|
4
5
|
module Zen
|
5
6
|
##
|
6
7
|
# Plugins in Zen are quite similar to packages except for a few differences. The biggest
|
7
8
|
# difference is that plugins won't update any Ramaze root directories or language
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# addresses and so on.
|
9
|
+
# directories. This means that they can't have controllers, models and so on.
|
10
|
+
# Plugins are useful for supporting multiple markup formats (Markdown, Textile, etc)
|
11
|
+
# and other small tasks such as replacing Email addresses and so on.
|
12
12
|
#
|
13
13
|
# ## Creating Plugins
|
14
14
|
#
|
15
|
-
# Creating
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
15
|
+
# Creating a plugin happens in two steps. First you'll create your class and then you'll
|
16
|
+
# register it so that it can be used by the system. A plugin has a very simple layout,
|
17
|
+
# it's just a class with two methods: initialize and call. The most basic skeleton of a
|
18
|
+
# plugin looks like the following:
|
19
19
|
#
|
20
|
-
#
|
20
|
+
# class MyPlugin
|
21
|
+
# def initialize
|
21
22
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# def call
|
26
|
+
#
|
27
|
+
# end
|
28
|
+
# end
|
25
29
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
30
|
+
# When a plugin is called all specified arguments are sent to the construct method so if
|
31
|
+
# your plugin requires a number of arguments be sure to store them. An example of this
|
32
|
+
# looks like the following:
|
33
|
+
#
|
34
|
+
# class MyPlugin
|
35
|
+
# def initialize(name)
|
36
|
+
# @name = name
|
29
37
|
# end
|
30
|
-
# }
|
31
38
|
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# Because the actions method contains just a hash you can easily add functionality to
|
35
|
-
# existing plugins as following:
|
39
|
+
# def call
|
36
40
|
#
|
37
|
-
#
|
38
|
-
# plugin = Zen::Plugin['com.something.plugin.name']
|
39
|
-
# plugin.actions[:my_action] = lamda do
|
40
|
-
# # Do something....
|
41
|
+
# end
|
41
42
|
# end
|
42
43
|
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# Textile or HTML (it escapes all HTML) but by modifying the actions hash we can easily
|
46
|
-
# add new markup engines such as RDoc or even Latex.
|
44
|
+
# The call method is supposed to return some data. Say we want to capitalize a given
|
45
|
+
# name we'd modify the skeleton so that it looks like the following:
|
47
46
|
#
|
48
|
-
#
|
47
|
+
# class MyPlugin
|
48
|
+
# def initialize(name)
|
49
|
+
# @name = name
|
50
|
+
# end
|
49
51
|
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
52
|
+
# def call
|
53
|
+
# return @name.upcase
|
54
|
+
# end
|
55
|
+
# end
|
53
56
|
#
|
54
|
-
#
|
57
|
+
# ## Registering Plugins
|
55
58
|
#
|
56
|
-
#
|
59
|
+
# Now that the plugin is created it's time to tell Zen it actually is a plugin and not
|
60
|
+
# some random class that doesn't belong somewhere. This can be done by calling
|
61
|
+
# Zen::Plugin.add and specifying a block with the details of the plugin. Example:
|
57
62
|
#
|
58
|
-
#
|
63
|
+
# Zen::Plugin.add do |plugin|
|
64
|
+
# plugin.name = :my_plugin
|
65
|
+
# plugin.author = 'Your name goes in here'
|
66
|
+
# plugin.about = 'A simple plugin that capitalizes a given string/name'
|
67
|
+
# plugin.plugin = MyPlugin
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# The name and plugin setter are the most important. Names should always match the
|
71
|
+
# regular expression /[a-z0-9_\-]+/. This is done to ensure names are consistent and
|
72
|
+
# easy to remember. It's also used for calling plugins and making sure there are no
|
73
|
+
# duplicates.
|
74
|
+
#
|
75
|
+
# The second important part is the plugin setting. This setter takes the class constant
|
76
|
+
# of the plugin that was created earlier on. There's no need to call new(), this will
|
77
|
+
# be done by Zen whenever the plugin is actually used.
|
59
78
|
#
|
60
|
-
#
|
79
|
+
# ## Executing Plugins
|
61
80
|
#
|
62
|
-
#
|
81
|
+
# Executing plugins is very easy and can be done by using the global method plugin():
|
63
82
|
#
|
64
|
-
#
|
83
|
+
# plugin(:my_plugin, 'yorick') # => "YORICK"
|
84
|
+
#
|
85
|
+
# The first argument is the name of the plugin to call, all following arguments will be
|
86
|
+
# sent to the plugin's construct method.
|
65
87
|
#
|
66
88
|
# @author Yorick Peterse
|
67
89
|
# @since 0.2.4
|
68
|
-
# @attr_reader [Hash] plugins Hash containing all plugins.
|
69
90
|
#
|
70
91
|
module Plugin
|
71
|
-
class << self
|
72
|
-
attr_reader :plugins
|
73
|
-
end
|
74
92
|
|
75
93
|
##
|
76
|
-
#
|
94
|
+
# Hash containing all registered plugins. The keys are the names of the plugins and
|
95
|
+
# the values are instances of Zen::Plugin::Base.
|
77
96
|
#
|
78
|
-
# @
|
79
|
-
#
|
80
|
-
#
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
#
|
85
|
-
# end
|
86
|
-
# end
|
97
|
+
# @author Yorick Peterse
|
98
|
+
# @since 0.2.5
|
99
|
+
#
|
100
|
+
Registered = {}
|
101
|
+
|
102
|
+
##
|
103
|
+
# Adds a new plugin with the given details.
|
87
104
|
#
|
88
105
|
# @author Yorick Peterse
|
89
106
|
# @since 0.2.4
|
90
|
-
# @
|
91
|
-
#
|
92
|
-
# a certain setter.
|
107
|
+
# @raise [Zen::PluginError] Error raised whenever the plugin already exists or is
|
108
|
+
# missing a certain setter.
|
93
109
|
#
|
94
110
|
def self.add
|
95
|
-
|
96
|
-
required = [:name, :author, :about, :identifier, :actions]
|
97
|
-
plugin = Zen::StrictStruct.new(
|
98
|
-
:name, :author, :about, :url, :identifier, :actions
|
99
|
-
).new
|
111
|
+
plugin = Zen::Plugin::Base.new
|
100
112
|
|
101
113
|
yield plugin
|
102
114
|
|
103
|
-
#
|
104
|
-
plugin.validate
|
105
|
-
|
106
|
-
end
|
115
|
+
# Validate the plugin
|
116
|
+
plugin.validate
|
117
|
+
plugin.name = plugin.name.to_sym
|
107
118
|
|
108
|
-
|
109
|
-
if plugin.actions.class != Hash
|
110
|
-
raise(Zen::PluginError, "The actions setter/getter should be an instance of Hash.")
|
111
|
-
end
|
112
|
-
|
113
|
-
# Add our plugin
|
114
|
-
if !@plugins[plugin.identifier].nil?
|
115
|
-
raise(Zen::PluginError, "The plugin #{plugin.name} already exists.")
|
116
|
-
end
|
117
|
-
|
118
|
-
@plugins[plugin.identifier] = plugin
|
119
|
+
Registered[plugin.name] = plugin
|
119
120
|
end
|
120
121
|
|
121
122
|
##
|
122
|
-
# Returns a plugin for the given
|
123
|
+
# Returns a plugin for the given name.
|
123
124
|
#
|
124
125
|
# @example
|
125
|
-
# Zen::Plugin[
|
126
|
+
# Zen::Plugin[:markup]
|
126
127
|
#
|
127
128
|
# @author Yorick Peterse
|
128
129
|
# @since 0.2.4
|
129
|
-
# @param [String]
|
130
|
+
# @param [String] name The name of the plugin to retrieve.
|
130
131
|
# @raise Zen::PluginError Error that's raised when no plugins have been added yet or
|
131
132
|
# the specified plugin doesn't exist.
|
132
133
|
# @return [Struct] Instance of the plugin.
|
133
134
|
#
|
134
|
-
def self.[](
|
135
|
-
if
|
135
|
+
def self.[](name)
|
136
|
+
if name.class != Symbol
|
137
|
+
name = name.to_sym
|
138
|
+
end
|
139
|
+
|
140
|
+
if Registered.nil?
|
136
141
|
raise(Zen::PluginError, "No plugins have been added.")
|
137
142
|
end
|
138
143
|
|
139
|
-
if
|
140
|
-
raise(Zen::PluginError, "The plugin #{
|
144
|
+
if !Registered[name]
|
145
|
+
raise(Zen::PluginError, "The plugin #{name} doesn't exist.")
|
141
146
|
end
|
142
147
|
|
143
|
-
return
|
148
|
+
return Registered[name]
|
144
149
|
end
|
145
150
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
151
|
+
#:nodoc:
|
152
|
+
module SingletonMethods
|
153
|
+
##
|
154
|
+
# Retrieves the given plugin and executes it. All specified parameters will be sent
|
155
|
+
# to the plugin as well.
|
156
|
+
#
|
157
|
+
# @example
|
158
|
+
# plugin(:settings, :get, :language)
|
159
|
+
#
|
160
|
+
# @author Yorick Peterse
|
161
|
+
# @since 0.2.5
|
162
|
+
# @param [String/Symbol] name The name of the plugin to call.
|
163
|
+
# @param [Array] data Any data to pass to the plugin's action (a lambda).
|
164
|
+
# @param [Proc] block A block that should be passed to the plugin instead of this
|
165
|
+
# method.
|
166
|
+
# @return [Mixed]
|
167
|
+
#
|
168
|
+
def plugin(name, *data, &block)
|
169
|
+
if name.class != Symbol
|
170
|
+
name = name.to_sym
|
171
|
+
end
|
162
172
|
|
163
|
-
|
164
|
-
raise(Zen::PluginError, "The action #{action} doesn't exist for #{ident}.")
|
173
|
+
return ::Zen::Plugin[name].plugin.new(*data, &block).call
|
165
174
|
end
|
166
|
-
|
167
|
-
# Call the plugin and return it's value
|
168
|
-
return plugin.actions[action].call(*data)
|
169
175
|
end
|
170
176
|
|
171
177
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#:nodoc:
|
2
|
+
module Zen
|
3
|
+
#:nodoc:
|
4
|
+
module Plugin
|
5
|
+
##
|
6
|
+
# Base class used to store the data about plugins such as the name, plugin class, etc.
|
7
|
+
#
|
8
|
+
# @author Yorick Peterse
|
9
|
+
# @since 0.2.5
|
10
|
+
#
|
11
|
+
class Base
|
12
|
+
include ::Zen::Validation
|
13
|
+
|
14
|
+
# The name of the plugin
|
15
|
+
attr_accessor :name
|
16
|
+
|
17
|
+
# The author of the plugin
|
18
|
+
attr_accessor :author
|
19
|
+
|
20
|
+
# A small description of the plugin
|
21
|
+
attr_accessor :about
|
22
|
+
|
23
|
+
# The URL to the plugin's website
|
24
|
+
attr_accessor :url
|
25
|
+
|
26
|
+
# The class of the plugin
|
27
|
+
attr_accessor :plugin
|
28
|
+
|
29
|
+
##
|
30
|
+
# Validates all the attributes.
|
31
|
+
#
|
32
|
+
# @author Yorick Peterse
|
33
|
+
# @since 0.2.5
|
34
|
+
#
|
35
|
+
def validate
|
36
|
+
validates_presence([:name, :author, :about, :plugin])
|
37
|
+
validates_format(:name, /[a-z0-9_\-]+/)
|
38
|
+
|
39
|
+
# Check if the theme doesn't exist
|
40
|
+
if ::Zen::Plugin::Registered.key?(name.to_sym)
|
41
|
+
raise(::Zen::ValidationError, "The plugin #{name} already exists.")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Zen
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Plugin
|
5
5
|
##
|
6
|
-
# Module that can be used to
|
6
|
+
# Module that can be used to allows plugins to use data that would otherwise
|
7
7
|
# only be available to controllers. Including this module gives your tags access to
|
8
8
|
# the following methods:
|
9
9
|
#
|
@@ -12,9 +12,9 @@ module Zen
|
|
12
12
|
# * session
|
13
13
|
#
|
14
14
|
# @author Yorick Peterse
|
15
|
-
# @since 0.
|
15
|
+
# @since 0.2.5
|
16
16
|
#
|
17
|
-
module
|
17
|
+
module Controller
|
18
18
|
include ::Ramaze::Trinity
|
19
19
|
|
20
20
|
##
|
@@ -22,7 +22,7 @@ module Zen
|
|
22
22
|
# session() method not being available outside controllers.
|
23
23
|
#
|
24
24
|
# @author Yorick Peterse
|
25
|
-
# @since 0.
|
25
|
+
# @since 0.2.5
|
26
26
|
# @return [Object]
|
27
27
|
#
|
28
28
|
def session
|
@@ -34,7 +34,7 @@ module Zen
|
|
34
34
|
# request() method not being available outside controllers.
|
35
35
|
#
|
36
36
|
# @author Yorick Peterse
|
37
|
-
# @since 0.
|
37
|
+
# @since 0.2.5
|
38
38
|
# @return [Object]
|
39
39
|
#
|
40
40
|
def request
|
@@ -46,12 +46,14 @@ module Zen
|
|
46
46
|
# response() method not being available outside controllers.
|
47
47
|
#
|
48
48
|
# @author Yorick Peterse
|
49
|
-
# @since 0.
|
49
|
+
# @since 0.2.5
|
50
50
|
# @return [Object]
|
51
51
|
#
|
52
52
|
def response
|
53
53
|
return action.node.response
|
54
54
|
end
|
55
|
+
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
59
|
+
|