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
@@ -41,7 +41,7 @@
41
41
  <td>
42
42
  #{anchor_to(
43
43
  field.name,
44
- CustomFields::Controllers::CustomFields.r(:edit, @custom_field_group_id, field.id),
44
+ CustomFields::Controller::CustomFields.r(:edit, @custom_field_group_id, field.id),
45
45
  :title => field.name
46
46
  )}
47
47
  </td>
@@ -51,7 +51,7 @@
51
51
 
52
52
  <td>#{field.slug}</td>
53
53
  <td>#{lang("custom_fields.special.type_hash.#{field.type}")}</td>
54
- <td>#{@format_hash[field.format]}</td>
54
+ <td>#{Zen::Plugin::Markup::Engines[field.format]}</td>
55
55
  </tr>
56
56
  <?r end ?>
57
57
  </tbody>
@@ -68,7 +68,7 @@
68
68
  <div class="button">
69
69
  #{anchor_to(
70
70
  lang('custom_fields.buttons.new'),
71
- CustomFields::Controllers::CustomFields.r(:new, @custom_field_group_id)
71
+ CustomFields::Controller::CustomFields.r(:new, @custom_field_group_id)
72
72
  )}
73
73
  </div>
74
74
  <?r end ?>
@@ -1,58 +1,40 @@
1
+ Ramaze::HelpersHelper.options.paths.push(__DIR__('menus'))
1
2
 
2
- # Update the list of helper paths
3
- Ramaze::HelpersHelper.options.paths << __DIR__('menus')
4
-
5
- # Load all our models
6
3
  require __DIR__('menus/model/menu')
7
4
  require __DIR__('menus/model/menu_item')
8
-
9
- # Load all controllers
10
5
  require __DIR__('menus/controller/menus')
11
6
  require __DIR__('menus/controller/menu_items')
7
+ require __DIR__('menus/plugin/menus')
12
8
 
13
- # Load all Liquid tags and register them
14
- require __DIR__('menus/liquid/menus')
15
-
16
- Liquid::Template.register_tag('menus', Menus::Liquid::Menus)
9
+ Zen::Language.options.paths.push(__DIR__('menus'))
10
+ Zen::Language.load('menus')
11
+ Zen::Language.load('menu_items')
17
12
 
18
- # Describe the package
19
13
  Zen::Package.add do |p|
20
- # The name of the package
21
- p.name = 'Menus'
22
-
23
- # The person/company that made the package
24
- p.author = 'Yorick Peterse'
25
-
26
- # A URL to a page about the package
27
- p.url = 'http://zen-cms.com/userguide/menus'
28
-
29
- # Describe what your theme or extension does.
30
- p.about = 'The Menus extension allows you to easily create navigation menus
14
+ p.name = 'menus'
15
+ p.author = 'Yorick Peterse'
16
+ p.url = 'http://zen-cms.com/userguide/menus'
17
+ p.about = 'The Menus extension allows you to easily create navigation menus
31
18
  for the frontend.'
32
19
 
33
- ##
34
- # An identifier is a unique string for your package in the following format:
35
- #
36
- # * com.AUTHOR.NAME for extensions
37
- # * com.AUTHOR.themes.NAME for themes
38
- #
39
- # An example of this would be "com.zen.sections" or "com.zen.themes.zen_website".
40
- #
41
- p.identifier = 'com.zen.menus'
42
-
43
- ##
44
- # Path to the directory containing the controllers, models, etc.
45
- #
46
- p.directory = __DIR__('menus')
47
-
48
- ##
49
- # Path to the directory containing all migrations for this package.
50
- #
20
+ p.directory = __DIR__('menus')
51
21
  p.migration_dir = __DIR__('../migrations')
52
-
53
- # Note that themes can not have menu items (they'll be ignored).
22
+
54
23
  p.menu = [{
55
- :title => "Menus",
24
+ :title => lang('menus.titles.index'),
56
25
  :url => "/admin/menus"
57
26
  }]
27
+
28
+ p.controllers = {
29
+ lang('menus.titles.index') => Menus::Controller::Menus,
30
+ lang('menu_items.titles.index') => Menus::Controller::MenuItems
31
+ }
32
+ end
33
+
34
+ Zen::Plugin.add do |p|
35
+ p.name = 'menus'
36
+ p.author = 'Yorick Peterse'
37
+ p.url = 'http://yorickpeterse.com/'
38
+ p.about = 'Plugin that can be used to display a navigation menu.'
39
+ p.plugin = Menus::Plugin::Menus
58
40
  end
@@ -1,19 +1,18 @@
1
1
  #:nodoc:
2
2
  module Menus
3
3
  #:nodoc:
4
- module Controllers
4
+ module Controller
5
5
  ##
6
6
  # Controller for managing individual navigation items that belong to a menu.
7
7
  #
8
8
  # @author Yorick Peterse
9
9
  # @since 0.2a
10
10
  #
11
- class MenuItems < ::Zen::Controllers::AdminController
12
- include ::Menus::Models
11
+ class MenuItems < ::Zen::Controller::AdminController
12
+ include ::Menus::Model
13
13
 
14
- map '/admin/menu-items'
15
- trait :extension_identifier => 'com.zen.menus'
16
- helper :menu_item
14
+ map('/admin/menu-items')
15
+ helper(:menu_item)
17
16
 
18
17
  before_all do
19
18
  csrf_protection(:save, :delete) do
@@ -1,7 +1,7 @@
1
1
  #:nodoc:
2
2
  module Menus
3
3
  #:nodoc:
4
- module Controllers
4
+ module Controller
5
5
  ##
6
6
  # Controller for managing menu groups. Individual navigation items are managed using
7
7
  # the menu items controller, simply named "menu_items".
@@ -9,11 +9,10 @@ module Menus
9
9
  # @author Yorick Peterse
10
10
  # @since 0.2a
11
11
  #
12
- class Menus < Zen::Controllers::AdminController
13
- include ::Menus::Models
12
+ class Menus < Zen::Controller::AdminController
13
+ include ::Menus::Model
14
14
 
15
- map '/admin/menus'
16
- trait :extension_identifier => 'com.zen.menus'
15
+ map('/admin/menus')
17
16
 
18
17
  before_all do
19
18
  csrf_protection(:save, :delete) do
@@ -154,6 +153,11 @@ module Menus
154
153
  else
155
154
  @menu = Menu.new
156
155
  save_action = :new
156
+
157
+ # Delete the slug if it's empty
158
+ if post['slug'].empty?
159
+ post.delete('slug')
160
+ end
157
161
  end
158
162
 
159
163
  # Set our notifications
@@ -19,14 +19,14 @@ module Ramaze
19
19
  # @param [Integer] menu_id The ID of the menu to validate.
20
20
  #
21
21
  def validate_menu(menu_id = nil)
22
- if !menu_id or ::Menus::Models::Menu[menu_id].nil?
22
+ if !menu_id or ::Menus::Model::Menu[menu_id].nil?
23
23
  notification(
24
24
  :error,
25
25
  @menu_items_lang.titles[:index],
26
26
  @menu_items_lang.errors[:invalid_menu]
27
27
  )
28
28
 
29
- redirect(::Menus::Controllers::Menus.r(:index))
29
+ redirect(::Menus::Controller::Menus.r(:index))
30
30
  end
31
31
  end
32
32
 
@@ -48,7 +48,7 @@ module Ramaze
48
48
  # @return [Hash]
49
49
  #
50
50
  def menu_item_tree(menu_id)
51
- menu_items = ::Menus::Models::MenuItem.filter(
51
+ menu_items = ::Menus::Model::MenuItem.filter(
52
52
  :menu_id => menu_id,
53
53
  :parent_id => nil
54
54
  )
@@ -71,7 +71,7 @@ module Ramaze
71
71
  #
72
72
  # @author Yorick Peterse
73
73
  # @since 0.2a
74
- # @param [Menus::Models::MenuItem] item A MenuItem instance
74
+ # @param [Menus::Model::MenuItem] item A MenuItem instance
75
75
  # @param [Integer] spaces The amount of unbreakable spaces to use.
76
76
  #
77
77
  def descendant_items(item, spaces)
@@ -1,7 +1,7 @@
1
1
  #:nodoc:
2
2
  module Menus
3
3
  #:nodoc:
4
- module Models
4
+ module Model
5
5
  ##
6
6
  # Model used for managing groups of menu items. This model uses the following
7
7
  # Sequel plugins:
@@ -15,7 +15,7 @@ module Menus
15
15
  plugin :sluggable, :source => :name, :freeze => false
16
16
 
17
17
  # Define our relations
18
- one_to_many :menu_items, :class => "Menus::Models::MenuItem"
18
+ one_to_many :menu_items, :class => "Menus::Model::MenuItem"
19
19
 
20
20
  ##
21
21
  # Specifies all validates rules used when creating or updating a menu.
@@ -1,7 +1,7 @@
1
1
  #:nodoc:
2
2
  module Menus
3
3
  #:nodoc:
4
- module Models
4
+ module Model
5
5
  ##
6
6
  # Model used for managing individual menu items in a group.
7
7
  # This model uses the following plugins:
@@ -14,6 +14,9 @@ module Menus
14
14
  class MenuItem < Sequel::Model
15
15
  plugin :tree, :order => :order
16
16
 
17
+ many_to_one :menu , :class => 'Menus::Model::Menu'
18
+ many_to_one :parent, :class => self
19
+
17
20
  ##
18
21
  # Specifies all validation rules that will be used when creating or updating a
19
22
  # menu item.
@@ -0,0 +1,152 @@
1
+ require 'ramaze/gestalt'
2
+
3
+ #:nodoc:
4
+ module Menus
5
+ #:nodoc:
6
+ module Plugin
7
+ ##
8
+ # Plugin for displaying navigation menus. This plugin will take care of recursively
9
+ # displaying all sub items and various other tasks, you merely have to set a few
10
+ # options and then you can sit back and enjoy.
11
+ #
12
+ # ## Usage
13
+ #
14
+ # menu = plugin(:menus, :menu => 'userguide', :sub => true)
15
+ #
16
+ # Calling this plugin will result in a string with HTML being returned. If you were
17
+ # to use this plugin in an Etanni template you'd have to wrap the call in #{} in order
18
+ # to actually display the menu.
19
+ #
20
+ # For more information about all the available options see
21
+ # Menus::Plugin::Menus#initialize().
22
+ #
23
+ # @author Yorick Peterse
24
+ # @since 0.2.5
25
+ #
26
+ class Menus
27
+ include ::Zen::Plugin::Helper
28
+ include ::Menus::Model
29
+
30
+ ##
31
+ # Creates a new instance of the plugin and saves the configuration options.
32
+ #
33
+ # @example
34
+ # plugin = Menus::Plugin::Menus.new(:limit => 10, :offset => 0, :sub => false)
35
+ #
36
+ # @author Yorick Peterse
37
+ # @since 0.2.5
38
+ # @param [Hash] options Hash with configuration options.
39
+ # @option options [Integer/Fixnum] :limit The maximum amount of root items to
40
+ # retrieve.
41
+ # @option options [Integer/Fixnum] :offset The row offset for all root elements.
42
+ # @option options [Fixnum/Integer/String] :menu The ID or slug of the menu for which
43
+ # to retrieve all menu items.
44
+ # @option options [Boolean] :sub When set to false sub items will be ignored. This
45
+ # option is set to true by default.
46
+ #
47
+ def initialize(options = {})
48
+ @options = {
49
+ :limit => 20,
50
+ :offset => 0,
51
+ :menu => nil,
52
+ :sub => true
53
+ }.merge(options)
54
+
55
+ validate_type(@options[:limit] , :limit , [Integer, Fixnum])
56
+ validate_type(@options[:offset], :offset, [Integer, Fixnum])
57
+ validate_type(@options[:menu] , :menu , [String, Integer, Fixnum])
58
+ end
59
+
60
+ ##
61
+ # Renders the navigation menu based on the given configuration options.
62
+ #
63
+ # @author Yorick Peterse
64
+ # @since 0.2.5
65
+ # @return [String] The HTML for the navigation menu.
66
+ #
67
+ def call
68
+ # Retrieve the menu
69
+ if @options[:menu].class == String
70
+ menu = Menu[:slug => @options[:menu]]
71
+ else
72
+ menu = Menu[@options[:menu]]
73
+ end
74
+
75
+ return if !menu
76
+
77
+ # Get all menu items
78
+ menu_items = MenuItem.filter(:menu_id => menu.id, :parent_id => nil)
79
+ .limit(@options[:limit], @options[:offset])
80
+ .all
81
+
82
+ @g = Ramaze::Gestalt.new
83
+ attributes = {}
84
+ items_tree = {}
85
+
86
+ # Set the attributes for the main <ul> elements
87
+ if !menu.css_class.nil?
88
+ attributes[:class] = menu.css_class
89
+ end
90
+
91
+ if !menu.css_id.nil?
92
+ attributes[:id] = menu.css_id
93
+ end
94
+
95
+ # Time to build the HTML
96
+ @g.ul(attributes) do
97
+ menu_items.each do |item|
98
+ if item.parent_id.nil?
99
+ generate_item(item)
100
+ end
101
+ end
102
+ end
103
+
104
+ return @g.to_s
105
+ end
106
+
107
+ private
108
+
109
+ ##
110
+ # Generates the HTML for a single <li> element and all sub elements.
111
+ #
112
+ # @author Yorick Peterse
113
+ # @since 0.2.5
114
+ # @param [Object] item An instance of the MenuItem model as returned by Sequel.
115
+ #
116
+ def generate_item(item)
117
+ attributes = {}
118
+
119
+ if !item.css_class.nil?
120
+ attributes[:class] = item.css_class
121
+ end
122
+
123
+ if !item.css_id.nil?
124
+ attributes[:id] = item.css_id
125
+ end
126
+
127
+ # Get all child elements
128
+ children = item.children
129
+
130
+ # Render the <li> tag
131
+ @g.li(attributes) do
132
+ # Do we have a URL?
133
+ if !item.url.nil? and !item.url.empty?
134
+ @g.a(:href => item.url, :title => item.name) { item.name }
135
+ else
136
+ @g.span { item.name }
137
+ end
138
+
139
+ # Generate all the sub elements
140
+ if !children.empty? and @options[:sub] === true
141
+ @g.ul(:class => :children) do
142
+ children.each do |child|
143
+ generate_item(child)
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+
150
+ end
151
+ end
152
+ end
@@ -27,7 +27,7 @@ form_for(
27
27
 
28
28
  # Generate the dropdown that contains all possible parent menu items
29
29
  parent_items = {}
30
- Menus::Models::Menu[@menu_id.to_i].menu_items.each do |i|
30
+ Menus::Model::Menu[@menu_id.to_i].menu_items.each do |i|
31
31
  if i.id != @menu_item.id
32
32
  parent_items[i.id] = i.name
33
33
  end
@@ -37,11 +37,11 @@
37
37
 
38
38
  <td>#{item.id}</td>
39
39
 
40
- <?r if user_authorized?([:edit]) ?>
40
+ <?r if user_authorized?([:update]) ?>
41
41
  <td>
42
42
  #{anchor_to(
43
43
  item.name,
44
- Menus::Controllers::MenuItems.r(:edit, @menu_id, item.id)
44
+ Menus::Controller::MenuItems.r(:edit, @menu_id, item.id)
45
45
  )}
46
46
  </td>
47
47
  <?r else ?>
@@ -68,7 +68,7 @@
68
68
  <div class="button">
69
69
  #{anchor_to(
70
70
  lang('menu_items.buttons.new'),
71
- Menus::Controllers::MenuItems.r(:new, @menu_id)
71
+ Menus::Controller::MenuItems.r(:new, @menu_id)
72
72
  )}
73
73
  </div>
74
74
  <?r end ?>
@@ -23,7 +23,7 @@
23
23
  <th>#{lang('menus.labels.css_class')}</th>
24
24
  <th>#{lang('menus.labels.css_id')}</th>
25
25
 
26
- <?r if user_authorized?([:create, :read]) ?>
26
+ <?r if user_authorized?([:read], true, 'Menus::Controller::MenuItems') ?>
27
27
  <th></th>
28
28
  <?r end ?>
29
29
  </tr>
@@ -39,12 +39,12 @@
39
39
  <?r end ?>
40
40
 
41
41
  <td>#{menu.id}</td>
42
-
43
- <?r if user_authorized?([:edit]) ?>
42
+
43
+ <?r if user_authorized?([:update]) ?>
44
44
  <td>
45
45
  #{anchor_to(
46
46
  menu.name,
47
- Menus::Controllers::Menus.r(:edit, menu.id)
47
+ Menus::Controller::Menus.r(:edit, menu.id)
48
48
  )}
49
49
  </td>
50
50
  <?r else ?>
@@ -55,11 +55,11 @@
55
55
  <td>#{menu.css_class}</td>
56
56
  <td>#{menu.css_id}</td>
57
57
 
58
- <?r if user_authorized?([:create, :read]) ?>
58
+ <?r if user_authorized?([:read], true, 'Menus::Controller::MenuItems') ?>
59
59
  <td>
60
60
  #{anchor_to(
61
61
  lang('menus.labels.manage_items'),
62
- Menus::Controllers::MenuItems.r(:index, menu.id)
62
+ Menus::Controller::MenuItems.r(:index, menu.id)
63
63
  )}
64
64
  </td>
65
65
  <?r end ?>
@@ -78,7 +78,7 @@
78
78
  <div class="button">
79
79
  #{anchor_to(
80
80
  lang('menus.buttons.new'),
81
- Menus::Controllers::Menus.r(:new)
81
+ Menus::Controller::Menus.r(:new)
82
82
  )}
83
83
  </div>
84
84
  <?r end ?>