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.
Files changed (189) hide show
  1. data/MANIFEST +42 -33
  2. data/README.md +14 -27
  3. data/ROADMAP.md +20 -2
  4. data/{Thorfile → Rakefile} +2 -3
  5. data/bin/zen +27 -5
  6. data/lib/zen.rb +70 -52
  7. data/lib/zen/asset.rb +258 -0
  8. data/lib/zen/bin/app.rb +42 -0
  9. data/lib/zen/controller/admin_controller.rb +53 -36
  10. data/lib/zen/controller/base_controller.rb +13 -8
  11. data/lib/zen/controller/frontend_controller.rb +4 -3
  12. data/lib/zen/controller/main_controller.rb +17 -33
  13. data/lib/zen/error/validation_error.rb +10 -0
  14. data/lib/zen/ext/string.rb +185 -0
  15. data/lib/zen/helper/acl.rb +120 -92
  16. data/lib/zen/helper/common.rb +1 -3
  17. data/lib/zen/helper/theme.rb +73 -0
  18. data/lib/zen/language.rb +66 -57
  19. data/lib/zen/layout/admin.xhtml +5 -48
  20. data/lib/zen/layout/login.xhtml +4 -44
  21. data/lib/zen/model/methods.rb +1 -1
  22. data/lib/zen/model/settings.rb +0 -3
  23. data/lib/zen/package.rb +101 -83
  24. data/lib/zen/package/base.rb +62 -0
  25. data/lib/zen/package/categories/lib/categories.rb +29 -10
  26. data/lib/zen/package/categories/lib/categories/controller/categories.rb +4 -5
  27. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +4 -5
  28. data/lib/zen/package/categories/lib/categories/language/en/category_groups.yml +4 -3
  29. data/lib/zen/package/categories/lib/categories/model/category.rb +2 -2
  30. data/lib/zen/package/categories/lib/categories/model/category_group.rb +3 -3
  31. data/lib/zen/package/categories/lib/categories/plugin/categories.rb +130 -0
  32. data/lib/zen/package/categories/lib/categories/view/admin/categories/form.xhtml +1 -1
  33. data/lib/zen/package/categories/lib/categories/view/admin/categories/index.xhtml +2 -2
  34. data/lib/zen/package/categories/lib/categories/view/admin/category-groups/index.xhtml +11 -6
  35. data/lib/zen/package/comments/lib/comments.rb +23 -13
  36. data/lib/zen/package/comments/lib/comments/controller/comments.rb +4 -5
  37. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +7 -8
  38. data/lib/zen/package/comments/lib/comments/model/comment.rb +4 -4
  39. data/lib/zen/package/comments/lib/comments/plugin/comments.rb +111 -0
  40. data/lib/zen/package/comments/lib/comments/view/admin/comments/form.xhtml +2 -2
  41. data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +3 -3
  42. data/lib/zen/package/custom_fields/lib/custom_fields.rb +18 -11
  43. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +4 -5
  44. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +4 -5
  45. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +2 -2
  46. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +3 -3
  47. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
  48. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/index.xhtml +9 -5
  49. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/form.xhtml +1 -1
  50. data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/index.xhtml +3 -3
  51. data/lib/zen/package/menus/lib/menus.rb +25 -43
  52. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +5 -6
  53. data/lib/zen/package/menus/lib/menus/controller/menus.rb +9 -5
  54. data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +4 -4
  55. data/lib/zen/package/menus/lib/menus/model/menu.rb +2 -2
  56. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +4 -1
  57. data/lib/zen/package/menus/lib/menus/plugin/menus.rb +152 -0
  58. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/form.xhtml +1 -1
  59. data/lib/zen/package/menus/lib/menus/view/admin/menu-items/index.xhtml +3 -3
  60. data/lib/zen/package/menus/lib/menus/view/admin/menus/index.xhtml +7 -7
  61. data/lib/zen/package/sections/lib/sections.rb +32 -16
  62. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +9 -18
  63. data/lib/zen/package/sections/lib/sections/controller/sections.rb +8 -9
  64. data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +1 -1
  65. data/lib/zen/package/sections/lib/sections/model/section.rb +4 -4
  66. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -10
  67. data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +224 -0
  68. data/lib/zen/package/sections/lib/sections/plugin/sections.rb +85 -0
  69. data/lib/zen/package/sections/lib/sections/view/admin/form.xhtml +1 -1
  70. data/lib/zen/package/sections/lib/sections/view/admin/index.xhtml +9 -5
  71. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +2 -2
  72. data/lib/zen/package/settings/lib/settings.rb +145 -10
  73. data/lib/zen/package/settings/lib/settings/controller/settings.rb +28 -24
  74. data/lib/zen/package/settings/lib/settings/language/en/settings.yml +10 -0
  75. data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -64
  76. data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +40 -0
  77. data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +76 -0
  78. data/lib/zen/package/settings/lib/settings/plugin/settings.rb +236 -0
  79. data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +20 -49
  80. data/lib/zen/package/settings/migrations/1295597111_create_schema.rb +0 -12
  81. data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +31 -0
  82. data/lib/zen/package/users/lib/users.rb +18 -15
  83. data/lib/zen/package/users/lib/users/controller/access_rules.rb +44 -8
  84. data/lib/zen/package/users/lib/users/controller/user_groups.rb +4 -5
  85. data/lib/zen/package/users/lib/users/controller/users.rb +5 -6
  86. data/lib/zen/package/users/lib/users/language/en/access_rules.yml +11 -9
  87. data/lib/zen/package/users/lib/users/model/access_rule.rb +7 -6
  88. data/lib/zen/package/users/lib/users/model/user.rb +4 -4
  89. data/lib/zen/package/users/lib/users/model/user_group.rb +3 -3
  90. data/lib/zen/package/users/lib/users/public/admin/js/users/access_rules.js +50 -0
  91. data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +32 -29
  92. data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +8 -6
  93. data/lib/zen/package/users/lib/users/view/admin/user-groups/index.xhtml +3 -3
  94. data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +2 -2
  95. data/lib/zen/package/users/migrations/1303510943_class_rules.rb +13 -0
  96. data/lib/zen/plugin.rb +110 -104
  97. data/lib/zen/plugin/base.rb +46 -0
  98. data/lib/zen/{liquid/controller_behavior.rb → plugin/controller.rb} +9 -7
  99. data/lib/zen/plugin/helper.rb +47 -0
  100. data/lib/zen/plugin/markup/lib/markup.rb +14 -0
  101. data/lib/zen/plugin/markup/lib/markup/language/en/markup.yml +6 -0
  102. data/lib/zen/plugin/markup/lib/markup/markup.rb +154 -0
  103. data/lib/zen/public/admin/css/forms.css +4 -0
  104. data/lib/zen/public/admin/css/general.css +15 -15
  105. data/lib/zen/public/admin/css/layout.css +10 -10
  106. data/lib/zen/public/admin/css/reset.css +123 -0
  107. data/lib/zen/public/admin/images/icons/accept.png +0 -0
  108. data/lib/zen/public/admin/images/icons/add.png +0 -0
  109. data/lib/zen/public/admin/images/icons/back.png +0 -0
  110. data/lib/zen/public/admin/images/icons/bold.png +0 -0
  111. data/lib/zen/public/admin/images/icons/close.png +0 -0
  112. data/lib/zen/public/admin/images/icons/delete.png +0 -0
  113. data/lib/zen/public/admin/images/icons/edit.png +0 -0
  114. data/lib/zen/public/admin/images/icons/error.png +0 -0
  115. data/lib/zen/public/admin/images/icons/help.png +0 -0
  116. data/lib/zen/public/admin/images/icons/info.png +0 -0
  117. data/lib/zen/public/admin/images/icons/italic.png +0 -0
  118. data/lib/zen/public/admin/images/icons/large/error.png +0 -0
  119. data/lib/zen/public/admin/images/icons/large/notice.png +0 -0
  120. data/lib/zen/public/admin/images/icons/large/success.png +0 -0
  121. data/lib/zen/public/admin/images/icons/link.png +0 -0
  122. data/lib/zen/public/admin/images/icons/logout.png +0 -0
  123. data/lib/zen/public/admin/images/icons/ol.png +0 -0
  124. data/lib/zen/public/admin/images/icons/pdf.png +0 -0
  125. data/lib/zen/public/admin/images/icons/ul.png +0 -0
  126. data/lib/zen/public/admin/images/icons/user.png +0 -0
  127. data/lib/zen/public/admin/images/icons/view.png +0 -0
  128. data/lib/zen/public/admin/js/mootools/core.js +384 -333
  129. data/lib/zen/public/admin/js/mootools/more.js +256 -231
  130. data/lib/zen/public/admin/js/vendor/{datepicker/Picker.Date.js → datepicker.js} +447 -0
  131. data/lib/zen/public/admin/js/vendor/yepnope.js +1 -0
  132. data/lib/zen/public/admin/js/zen/editor/base.js +8 -1
  133. data/lib/zen/public/admin/js/zen/init.js +89 -26
  134. data/lib/zen/public/favicon.ico +0 -0
  135. data/lib/zen/task.rb +7 -0
  136. data/lib/zen/task/build.rake +60 -0
  137. data/lib/zen/task/clean.rake +27 -0
  138. data/lib/zen/task/db.rake +111 -0
  139. data/lib/zen/task/package.rake +67 -0
  140. data/lib/zen/task/plugin.rake +24 -0
  141. data/lib/zen/task/proto.rake +95 -0
  142. data/lib/zen/task/theme.rake +68 -0
  143. data/lib/zen/theme.rb +28 -55
  144. data/lib/zen/theme/base.rb +64 -0
  145. data/lib/zen/validation.rb +149 -0
  146. data/lib/zen/version.rb +1 -1
  147. data/lib/zen/view/bottom.xhtml +6 -0
  148. data/lib/zen/view/main.xhtml +32 -0
  149. data/proto/app/Rakefile +12 -0
  150. data/proto/app/app.rb +6 -6
  151. data/proto/app/config/config.rb +7 -14
  152. data/proto/app/config/database.rb +0 -20
  153. data/proto/app/start.rb +0 -1
  154. data/proto/app/{vendor/themes → task}/.gitkeep +0 -0
  155. data/proto/app/vendor/theme/.gitkeep +0 -0
  156. data/proto/package/lib/package.rb +8 -17
  157. data/proto/package/lib/package/controller/controllers.rb +4 -4
  158. data/proto/package/lib/package/language/en/languages.yml +3 -3
  159. data/proto/package/lib/package/model/model.rb +1 -1
  160. metadata +73 -73
  161. data/lib/zen/bin/base.rb +0 -109
  162. data/lib/zen/helper/asset.rb +0 -106
  163. data/lib/zen/liquid/general.rb +0 -94
  164. data/lib/zen/liquid/redirect.rb +0 -70
  165. data/lib/zen/liquid/strip.rb +0 -60
  166. data/lib/zen/package/categories/lib/categories/liquid/categories.rb +0 -16
  167. data/lib/zen/package/comments/lib/comments/liquid/comment_form.rb +0 -127
  168. data/lib/zen/package/comments/lib/comments/liquid/comments.rb +0 -115
  169. data/lib/zen/package/menus/lib/menus/liquid/menus.rb +0 -152
  170. data/lib/zen/package/sections/lib/sections/liquid/section_entries.rb +0 -228
  171. data/lib/zen/package/sections/lib/sections/liquid/sections.rb +0 -77
  172. data/lib/zen/package/settings/lib/settings/liquid/setting.rb +0 -58
  173. data/lib/zen/package/users/lib/users/liquid/user.rb +0 -77
  174. data/lib/zen/package/users/lib/users/liquid/users.rb +0 -82
  175. data/lib/zen/plugin/markup.rb +0 -30
  176. data/lib/zen/public/admin/css/boilerplate.css +0 -176
  177. data/lib/zen/public/admin/images/general/noise.jpg +0 -0
  178. data/lib/zen/public/admin/js/vendor/datepicker/Picker.Attach.js +0 -137
  179. data/lib/zen/public/admin/js/vendor/datepicker/Picker.js +0 -291
  180. data/lib/zen/public/admin/js/vendor/datepicker/README.md +0 -325
  181. data/lib/zen/public/admin/js/vendor/datepicker/locale.js +0 -16
  182. data/lib/zen/strict_struct.rb +0 -36
  183. data/lib/zen/task/build.rb +0 -123
  184. data/lib/zen/task/clean.rb +0 -46
  185. data/lib/zen/task/db.rb +0 -130
  186. data/lib/zen/task/package.rb +0 -87
  187. data/lib/zen/task/proto.rb +0 -116
  188. data/lib/zen/task/theme.rb +0 -88
  189. 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.extension')}</th>
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.extension,
45
- Users::Controllers::AccessRules.r(:edit, rule.id)
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.extension}</td>
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::Controllers::AccessRules.r(:new)
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::Controllers::UserGroups.r(:edit, group.id)
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::Controllers::UserGroups.r(:new)
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::Controllers::Users.r(:edit, user.id)
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::Controllers::Users.r(:new)
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
@@ -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
- # direactories. This means that they can't have controllers, models and so on. On top
9
- # of that they're nothing more than lambda's. Plugins are useful for supporting multiple
10
- # markup formats (Markdown, Textile, etc) and other small tasks such as replacing Email
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 plugins works in a similar way as creating packages. Plugins are added by
16
- # calling Zen::Plugin#add and passing a block to it with details such as the name of
17
- # the plugin, the author, the identifier and a list of actions. The last two are very
18
- # important as the plugin won't work without them.
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
- # ### Actions
20
+ # class MyPlugin
21
+ # def initialize
21
22
  #
22
- # Each plugin has a getter/setter called "actions", this is just a simple key/value
23
- # hash where the keys are the names of the actions and the values lambda's. The keys
24
- # should always be symbols. Example:
23
+ # end
24
+ #
25
+ # def call
26
+ #
27
+ # end
28
+ # end
25
29
  #
26
- # actions = {
27
- # :downcase => lambda do |string|
28
- # string.downcase
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
- # Note that you don't *have to* use lambda's, anything that responds to call() will do.
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
- # # First retrieve our plugin
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
- # This can be very useful for extending plugins such as the markup plugin that's used to
44
- # convert Markdown or Textile to HTML. By default this plugin only converts Markdown and
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
- # ## Calling Plugins
47
+ # class MyPlugin
48
+ # def initialize(name)
49
+ # @name = name
50
+ # end
49
51
  #
50
- # Plugins can be called using Zen::Plugin#call, this method requires you to specify the
51
- # plugin identifier, the action to call and optionally any data to send to the plugin.
52
- # An example of calling a plugin would look like the following:
52
+ # def call
53
+ # return @name.upcase
54
+ # end
55
+ # end
53
56
  #
54
- # Zen::Plugin.call('com.zen.plugin.markup', :markdown, 'hello **world**')
57
+ # ## Registering Plugins
55
58
  #
56
- # ## Identifiers
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
- # Plugin identifiers should always have the following format:
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
- # com.VENDOR.plugin.NAME
79
+ # ## Executing Plugins
61
80
  #
62
- # For example:
81
+ # Executing plugins is very easy and can be done by using the global method plugin():
63
82
  #
64
- # com.zen.plugin.markup
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
- # Adds a new plugin with the given details.
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
- # @example
79
- # Zen::Plugin.add do |p|
80
- # p.name = 'Markup'
81
- # p.author = 'Yorick Peterse'
82
- # p.actions = {
83
- # :markdown => lambda do |markup|
84
- # RDiscount.new(markup).to_html
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
- # @yield [plugin] Struct object containing all the details of a plugin.
91
- # @raise [Zen::PluginError] Error raised whenever the plugin already exists or is missing
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
- @plugins ||= {}
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
- # Check if all the required keys have been set
104
- plugin.validate(required) do |k|
105
- raise(Zen::PluginError, "The following plugin key is missing: #{k}")
106
- end
115
+ # Validate the plugin
116
+ plugin.validate
117
+ plugin.name = plugin.name.to_sym
107
118
 
108
- # The actions getter should be a hash
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 identifier.
123
+ # Returns a plugin for the given name.
123
124
  #
124
125
  # @example
125
- # Zen::Plugin['com.zen.plugin.markup']
126
+ # Zen::Plugin[:markup]
126
127
  #
127
128
  # @author Yorick Peterse
128
129
  # @since 0.2.4
129
- # @param [String] ident The plugin identifier.
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.[](ident)
135
- if @plugins.nil?
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 !@plugins[ident]
140
- raise(Zen::PluginError, "The plugin #{ident} doesn't exist.")
144
+ if !Registered[name]
145
+ raise(Zen::PluginError, "The plugin #{name} doesn't exist.")
141
146
  end
142
147
 
143
- return @plugins[ident]
148
+ return Registered[name]
144
149
  end
145
150
 
146
- ##
147
- # Calls the plugin for the given identifier and executes the action.
148
- #
149
- # @example
150
- # Zen::Plugin.call('com.zen.foobar', :markdown, 'hello **world**')
151
- #
152
- # @author Yorick Peterse
153
- # @since 0.2.4
154
- # @param [String] ident The plugin identifier.
155
- # @param [Symbol] action The plugin action to call.
156
- # @param [Array] data Any data to pass to the plugin's action (a lambda).
157
- # @return [Mixed]
158
- #
159
- def self.call(ident, action, *data)
160
- plugin = self[ident]
161
- action = action.to_sym
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
- if !plugin.actions[action]
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 Liquid
4
+ module Plugin
5
5
  ##
6
- # Module that can be used to allow Liquid tags to use data that would otherwise
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.1
15
+ # @since 0.2.5
16
16
  #
17
- module ControllerBehavior
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.1
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.1
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.1
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
+