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
@@ -148,9 +148,7 @@ module Ramaze
148
148
  # @return [String]
149
149
  #
150
150
  def cycle(*args)
151
- if @@cycle_counter.nil?
152
- @@cycle_counter = 0
153
- end
151
+ @@cycle_counter ||= 0
154
152
 
155
153
  # Check the current counter and reset it if it matches the total amount of arguments
156
154
  if @@cycle_counter >= args.count
@@ -0,0 +1,73 @@
1
+ require __DIR__('../error/theme_error')
2
+
3
+ #:nodoc:
4
+ module Ramaze
5
+ #:nodoc:
6
+ module Helper
7
+ ##
8
+ # Helper that provides a few methods that make certain tasks easier when creating
9
+ # themes and templates.
10
+ #
11
+ # @author Yorick Peterse
12
+ # @since 0.2.5
13
+ #
14
+ module Theme
15
+
16
+ ##
17
+ # Renders a partial from the current theme's partial directory. The first argument
18
+ # is the name of the partial (without an extension) to render. The second argument
19
+ # is a hash with variables that should be made available to the partial.
20
+ #
21
+ # @example
22
+ # partial(:header) # => partials/header.xhtml
23
+ # partial(:header, :username => "YorickPeterse")
24
+ #
25
+ # @author Yorick Peterse
26
+ # @since 0.2.5
27
+ # @param [Symbol] file The name of the partial to render.
28
+ # @param [Hash] variables A hash with variables that should be made available for
29
+ # the partial.
30
+ #
31
+ def partial(file, variables = {})
32
+ theme = ::Zen::Theme[::Zen::Settings[:theme]]
33
+
34
+ if !theme.respond_to?(:partial_dir) or theme.partial_dir.nil?
35
+ raise(::Zen::ThemeError, "The theme #{theme.name} has no partial directory set.")
36
+ end
37
+
38
+ template = "#{theme.partial_dir}/#{file}.xhtml"
39
+
40
+ if !File.exist?(template)
41
+ raise(::Zen::ThemeError, "The template #{template} doesn't exist.")
42
+ end
43
+
44
+ # All done captain!
45
+ render_file(template, variables)
46
+ end
47
+
48
+ ##
49
+ # Renders the 404 template for the current theme (clearing the current buffer) and
50
+ # sets the HTTP response code to 404. Optionally you can pass a set of variables to
51
+ # the 404 template by setting this method's first argument to a hash.
52
+ #
53
+ # @example
54
+ # show_404
55
+ # show_404(:uri => @request_uri)
56
+ #
57
+ # @author Yorick Peterse
58
+ # @since 0.2.5
59
+ # @param [Hash] variables Hash with variables to pass to the 404 template.
60
+ #
61
+ def show_404(variables = {})
62
+ theme = ::Zen::Theme[::Zen::Settings[:theme]]
63
+ template = "#{theme.template_dir}/404.xhtml"
64
+
65
+ # Render the template and replace the current buffer with it's output
66
+ template = render_file(template, variables)
67
+
68
+ respond(template, 404)
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -54,7 +54,9 @@ module Zen
54
54
  # ## Options
55
55
  #
56
56
  # * language: Small string that defines the current language (e.g. "en").
57
- # * paths: Array of paths to look for a language file
57
+ # * paths: Array of paths to look for a language directory. Note that this should be
58
+ # the parent directory of the directory called "language", not the actual directory
59
+ # itself.
58
60
  #
59
61
  # @author Yorick Peterse
60
62
  # @since 0.2
@@ -62,13 +64,17 @@ module Zen
62
64
  module Language
63
65
  include Ramaze::Optioned
64
66
 
67
+ ##
68
+ # Hash containing all loaded translation files.
69
+ #
70
+ # @author Yorick Peterse
71
+ # @since 0.2.5
72
+ #
73
+ Registered = {}
74
+
65
75
  options.dsl do
66
76
  o 'Small string that defines the current language (e.g. "en").', :language, 'en'
67
- o 'Array of paths to look for a language file' , :paths , []
68
- end
69
-
70
- class << self
71
- attr_reader :translations
77
+ o 'Array of paths to look for the language files' , :paths , []
72
78
  end
73
79
 
74
80
  ##
@@ -83,10 +89,9 @@ module Zen
83
89
  # @param [String] lang_name The name of the language file to load.
84
90
  #
85
91
  def self.load(lang_name)
86
- @translations ||= {}
87
- @translations[self.options.language.to_s] ||= {}
92
+ Registered[self.options.language.to_s] ||= {}
88
93
 
89
- if @translations[self.options.language.to_s][lang_name.to_s]
94
+ if Registered[self.options.language.to_s][lang_name.to_s]
90
95
  return
91
96
  end
92
97
 
@@ -101,8 +106,8 @@ module Zen
101
106
  # would result in {'person.age' => 18}.
102
107
  translation = self.to_dotted_hash({lang_name.to_s => translation})
103
108
 
104
- @translations[self.options.language.to_s] ||= {}
105
- @translations[self.options.language.to_s].merge!(translation)
109
+ Registered[self.options.language.to_s] ||= {}
110
+ Registered[self.options.language.to_s].merge!(translation)
106
111
 
107
112
  # Prevents the exception from being raised
108
113
  return
@@ -112,52 +117,6 @@ module Zen
112
117
  raise(Zen::LanguageError, "No language file could be found for \"#{lang_name}\"")
113
118
  end
114
119
 
115
- ##
116
- # Method for retrieving the correct language item based on the given string.
117
- # If you want to retrieve sub-items you can separate each level with a dot:
118
- #
119
- # lang('tutorial.main.sub')
120
- #
121
- # This would require our YAML file to look something like the following:
122
- #
123
- # ---
124
- # main:
125
- # sub: "Something!"
126
- #
127
- # It's important to remember that your key should always include the name of the
128
- # language file since once a file is loaded it will be kept in memory to reduce
129
- # disk usage.
130
- #
131
- # @example
132
- # lang('username')
133
- #
134
- # @author Yorick Peterse
135
- # @since 0.2
136
- # @param [String] key The language key to select.
137
- # @return [Mixed]
138
- #
139
- def lang(key)
140
- lang = ::Zen::Language.options.language.to_s
141
- groups = []
142
- translations = ::Zen::Language.translations
143
-
144
- if !translations or !translations.key?(lang)
145
- raise(
146
- Zen::LanguageError,
147
- "No translation files have been added for the language code \"#{lang}\""
148
- )
149
- end
150
-
151
- if translations[lang][key]
152
- return translations[lang][key]
153
- end
154
-
155
- raise(
156
- Zen::LanguageError,
157
- "The specified language item \"#{key}\" does not exist"
158
- )
159
- end
160
-
161
120
  private
162
121
 
163
122
  ##
@@ -218,5 +177,55 @@ module Zen
218
177
 
219
178
  return target
220
179
  end
180
+
181
+ #:nodoc:
182
+ module SingletonMethods
183
+ ##
184
+ # Method for retrieving the correct language item based on the given string.
185
+ # If you want to retrieve sub-items you can separate each level with a dot:
186
+ #
187
+ # lang('tutorial.main.sub')
188
+ #
189
+ # This would require our YAML file to look something like the following:
190
+ #
191
+ # ---
192
+ # main:
193
+ # sub: "Something!"
194
+ #
195
+ # It's important to remember that your key should always include the name of the
196
+ # language file since once a file is loaded it will be kept in memory to reduce
197
+ # disk usage.
198
+ #
199
+ # @example
200
+ # lang('username')
201
+ #
202
+ # @author Yorick Peterse
203
+ # @since 0.2
204
+ # @param [String] key The language key to select.
205
+ # @return [Mixed]
206
+ #
207
+ def lang(key)
208
+ lang = ::Zen::Language.options.language.to_s
209
+ groups = []
210
+ translations = ::Zen::Language::Registered
211
+
212
+ if !translations or !translations.key?(lang)
213
+ raise(
214
+ Zen::LanguageError,
215
+ "No translation files have been added for the language code \"#{lang}\""
216
+ )
217
+ end
218
+
219
+ if translations[lang][key]
220
+ return translations[lang][key]
221
+ end
222
+
223
+ raise(
224
+ Zen::LanguageError,
225
+ "The specified language item \"#{key}\" does not exist"
226
+ )
227
+ end
228
+ end
229
+
221
230
  end
222
231
  end
@@ -1,10 +1,10 @@
1
1
  <!DOCTYPE html>
2
- <html lang="#{@settings[:language]}">
2
+ <html lang="#{::Zen::Settings[:language]}">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
 
6
6
  <!-- Load all stylesheets -->
7
- #{build_css}
7
+ #{::Zen::Asset.build(:stylesheet)}
8
8
 
9
9
  <title>#{@page_title}</title>
10
10
  </head>
@@ -17,10 +17,7 @@
17
17
  doesn't have the required permissions for the extension that created it.
18
18
  -->
19
19
  <nav id="main_nav" class="grid_12">
20
- #{
21
- perms = extension_permissions
22
- Zen::Package.build_menu("left", perms[0], perms[1])
23
- }
20
+ #{Zen::Package.build_menu("left", extension_permissions)}
24
21
 
25
22
  <ul class="right clearfix">
26
23
  <li>
@@ -43,47 +40,7 @@
43
40
  </header>
44
41
  </div>
45
42
 
46
- <!--
47
- Main area of the admin panel. The content stretches across the entire screen and there
48
- are no silly sidebars.
49
- -->
50
- <div id="container" class="container">
51
- <div id="content" class="grid_12">
52
- #{@content}
53
- </div>
54
- </div>
55
-
56
- <footer id="main_footer" class="container">
57
- <div class="grid_12">
58
- <p>#{lang('zen_general.labels.zen_version') % Zen::Version}</p>
59
- <ul class="clearfix">
60
- <li>
61
- <a href="http://zen-cms.com/">
62
- #{lang('zen_general.labels.zen_website')}
63
- </a>
64
- </li>
65
- <li>
66
- <a href="http://zen-cms.com/documentation">
67
- #{lang('zen_general.labels.zen_docs')}
68
- </a>
69
- </li>
70
- <li>
71
- <a href="https://github.com/zen-cms/">
72
- #{lang('zen_general.labels.zen_github')}
73
- </a>
74
- </li>
75
- </ul>
76
- </div>
77
- </footer>
78
-
79
- <script src="/admin/js/mootools/core.js"></script>
80
- <script src="/admin/js/mootools/more.js"></script>
81
-
82
- <script>
83
- Zen = {};
84
- Zen.Flash = #{flash.combined.to_json};
85
- </script>
86
-
87
- #{build_js}
43
+ #{render_file(__DIR__('../view/main.xhtml'))}
44
+ #{render_file(__DIR__('../view/bottom.xhtml'))}
88
45
  </body>
89
46
  </html>
@@ -1,56 +1,16 @@
1
1
  <!DOCTYPE html>
2
- <html lang="#{@settings[:language]}">
2
+ <html lang="#{::Zen::Settings[:language]}">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
 
6
6
  <!-- Load all stylesheets -->
7
- #{build_css}
7
+ #{::Zen::Asset.build(:stylesheet)}
8
8
 
9
9
  <title>#{@page_title}</title>
10
10
  </head>
11
11
 
12
12
  <body id="login">
13
- <!--
14
- Main area of the admin panel. The content stretches across the entire screen and there
15
- are no silly sidebars.
16
- -->
17
- <div id="container" class="container">
18
- <div id="content" class="grid_12">
19
- #{@content}
20
- </div>
21
- </div>
22
-
23
- <footer id="main_footer" class="container">
24
- <div class="grid_12">
25
- <p>#{lang('zen_general.labels.zen_version') % Zen::Version}</p>
26
- <ul class="clearfix">
27
- <li>
28
- <a href="http://zen-cms.com/">
29
- #{lang('zen_general.labels.zen_website')}
30
- </a>
31
- </li>
32
- <li>
33
- <a href="http://zen-cms.com/documentation">
34
- #{lang('zen_general.labels.zen_docs')}
35
- </a>
36
- </li>
37
- <li>
38
- <a href="https://github.com/zen-cms/">
39
- #{lang('zen_general.labels.zen_github')}
40
- </a>
41
- </li>
42
- </ul>
43
- </div>
44
- </footer>
45
-
46
- <script src="/admin/js/mootools/core.js"></script>
47
- <script src="/admin/js/mootools/more.js"></script>
48
-
49
- <script>
50
- Zen = {};
51
- Zen.Flash = #{flash.combined.to_json};
52
- </script>
53
-
54
- #{build_js}
13
+ #{render_file(__DIR__('../view/main.xhtml'))}
14
+ #{render_file(__DIR__('../view/bottom.xhtml'))}
55
15
  </body>
56
16
  </html>
@@ -9,7 +9,7 @@ module Sequel
9
9
  # elements using the BlueForm helper.
10
10
  #
11
11
  # @example
12
- # Sections::Models::Section.pk_hash(:name) # => {1 => 'Blog', 2 => 'General'}
12
+ # Sections::Model::Section.pk_hash(:name) # => {1 => 'Blog', 2 => 'General'}
13
13
  #
14
14
  # @author Yorick Peterse
15
15
  # @param [Symbol] column The name of the optional column to select.
@@ -1,5 +1,3 @@
1
- include Zen::Language
2
-
3
1
  Zen::Language.load('zen_models')
4
2
 
5
3
  # When passing a hash to update() or create() we'll ignore any keys that don't belong
@@ -10,7 +8,6 @@ Sequel::Model.strict_param_setting = false
10
8
  # Load all the required plugins
11
9
  Sequel::Model.plugin :validation_helpers
12
10
  Sequel::Model.plugin :association_pks
13
- Sequel::Model.plugin :schema
14
11
 
15
12
  Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS.merge!(
16
13
  {
@@ -1,7 +1,6 @@
1
1
  require 'ramaze/gestalt'
2
- require __DIR__('helper/acl')
3
- require __DIR__('liquid/controller_behavior')
4
2
  require __DIR__('error/package_error')
3
+ require __DIR__('package/base')
5
4
 
6
5
  #:nodoc:
7
6
  module Zen
@@ -20,16 +19,29 @@ module Zen
20
19
  #
21
20
  # When using this block you're required to set the following attributes:
22
21
  #
23
- # * name: the name of the package
24
- # * author: the name of the person who made the package
25
- # * about: a small description of the package
26
- # * url: the URL to the package's website
27
- # * identifier: unique identifier for the package. The format is com.AUTHOR.NAME for
28
- # extensions and com.AUTHOR.themes.NAME for themes.
29
- # * directory: the root directory of the package, set this using __DIR__('path')
22
+ # * name: the name of the package in lowercased letters and/or numbers.
23
+ # * author: the name of the person who made the package.
24
+ # * about: a small description of the package.
25
+ # * url: the URL to the package's website.
26
+ # * directory: the root directory of the package, set this using __DIR__('path').
30
27
  #
31
28
  # Optionally you can also specify the attribute "menu" (more on that later).
32
29
  #
30
+ # ## ACL
31
+ #
32
+ # Packages allow developers to register controllers for the ACL system that ships with
33
+ # Zen. Doing this means a user can set controller specific rules in the backend without
34
+ # having to write any code. In order to register a set of controllers you'll need to
35
+ # set the "controllers" attribute in the package block to a hash. The keys of this hash
36
+ # should be a human readable name of the controller and the values the full namespace
37
+ # of the controller as either a string or a constants:
38
+ #
39
+ # Zen::Package.add do |pkg|
40
+ # pkg.controllers = {
41
+ # 'Test Controller' => Test::Controller::TestController
42
+ # }
43
+ # end
44
+ #
33
45
  # ## Menu Items
34
46
  #
35
47
  # The package system easily allows modules to add navigation/sub-navigation elements
@@ -60,41 +72,43 @@ module Zen
60
72
  #
61
73
  # If your package uses it's own database tables it's best to use migrations as these make
62
74
  # it very easy to install/uninstall the extension. Migrations should be put in the root
63
- # directory of your extension. For example, if your extension is in "foobar" the migrations
64
- # should be located in "foobar/migrations", the lib directory in "foobar/lib", etc.
75
+ # directory of your extension. For example, if your extension is in "foobar" the
76
+ # migrations should be located in "foobar/migrations", the lib directory in "foobar/lib",
77
+ # etc.
65
78
  #
66
79
  # Migrations can be executed using the Thor task "package:migrate" or "db:migrate",
67
80
  # the latter will install all packages while the first one will only install the
68
81
  # specified packages. For more information on these tasks execute the following command:
69
82
  #
70
- # $ thor -T
71
- #
72
- # ## Identifiers
73
- #
74
- # Package identifiers should always have the following format:
75
- #
76
- # com.VENDOR.NAME
77
- #
78
- # For example:
79
- #
80
- # com.zen.sections
83
+ # $ rake -T
81
84
  #
82
85
  # @author Yorick Peterse
83
86
  # @since 0.1
84
- # @attr_reader [Array] packages Array containing the instances of all packages.
85
87
  #
86
88
  module Package
87
- class << self
88
- attr_reader :packages
89
- end
90
-
91
89
  ##
92
- # Adds a new package along with all it's details such as the name,
93
- # author, version and so on. Extensions can be added using a simple
94
- # block as following:
90
+ # Hash containing all the registered packages. The keys of this hash are the names
91
+ # of all packages and the values the instances of Zen::Package::Base.
92
+ #
93
+ # @author Yorick Peterse
94
+ # @since 0.2.5
95
+ #
96
+ Registered = {}
97
+
98
+ ##
99
+ # Array containing all controllers of all packages.
100
+ #
101
+ # @author Yorick Peterse
102
+ # @since 0.2.5
103
+ #
104
+ Controllers = []
105
+
106
+ ##
107
+ # Adds a new package along with all it's details such as the name, author, version
108
+ # and so on. Extensions can be added using a simple block as following:
95
109
  #
96
110
  # Zen::Package.add do |ext|
97
- # ext.name = "Name"
111
+ # ext.name = "name"
98
112
  # ext.author = "Author"
99
113
  # end
100
114
  #
@@ -105,7 +119,6 @@ module Zen
105
119
  # * version
106
120
  # * about
107
121
  # * url
108
- # * identifier
109
122
  # * directory
110
123
  #
111
124
  # You can also set "migration_dir" to a directory with all migrations. By default
@@ -116,17 +129,13 @@ module Zen
116
129
  # @yield [package] Object containing all setters and getters for each package.
117
130
  #
118
131
  def self.add
119
- package = Zen::StrictStruct.new(
120
- :name, :author, :about, :url, :identifier, :directory, :menu, :migration_dir
121
- ).new
122
-
123
- required = [:name, :author, :about, :identifier, :directory]
132
+ package = Zen::Package::Base.new
124
133
 
125
134
  yield package
126
-
127
- package.validate(required) do |k|
128
- raise(Zen::PackageError, "The following package key is missing: #{k}")
129
- end
135
+
136
+ # Validate the package
137
+ package.validate
138
+ package.name = package.name.to_sym
130
139
 
131
140
  # Update the root but prevent duplicates
132
141
  if !Ramaze.options.roots.include?(package.directory)
@@ -138,31 +147,37 @@ module Zen
138
147
  Zen::Language.options.paths.push(package.directory)
139
148
  end
140
149
 
141
- # Validate the directories
142
- [:directory, :migration_dir].each do |k|
143
- if package.respond_to?(k) and !package.send(k).nil?
144
- if !File.exist?(package.send(k))
145
- raise(PackageError, "The directory #{package.send(k)} does not exist.")
146
- end
150
+ package.controllers.each do |name, controller|
151
+ controller = controller.to_s
152
+
153
+ if !Controllers.include?(controller)
154
+ Controllers.push(controller)
147
155
  end
148
156
  end
149
157
 
150
- @packages = {} if @packages.nil?
151
- @packages[package.identifier.to_s] = package
158
+ Registered[package.name.to_sym] = package
152
159
  end
153
-
160
+
154
161
  ##
155
- # Shortcut method that can be used to retrieve an extension or theme based on the
156
- # given extension identifier.
162
+ # Retrieves the package for the given name.
157
163
  #
158
164
  # @author Yorick Peterse
159
- # @param [String] ident The package's identifier
160
- # @return [Object]
165
+ # @since 0.1
161
166
  #
162
- def self.[](ident)
163
- @packages[ident.to_s]
167
+ def self.[](name)
168
+ name = name.to_sym
169
+
170
+ if Registered.empty?
171
+ raise(PackageError, "No packages have been added yet.")
172
+ end
173
+
174
+ if !Registered.key?(name)
175
+ raise(PackageError, "The package \"#{name}\" doesn't exist.")
176
+ end
177
+
178
+ return Registered[name]
164
179
  end
165
-
180
+
166
181
  ##
167
182
  # Builds a navigation menu for all installed extensions.
168
183
  # Extensions can have an infinite amount of sub-navigation
@@ -170,32 +185,21 @@ module Zen
170
185
  # of which each list item can contain N sub items.
171
186
  #
172
187
  # @author Yorick Peterse
173
- # @param [String] css_class A string of CSS classes to apply to the main UL element.
174
- # @param [Hash] permissions Hash containing the permissions as returned by
175
- # Ramaze::Helper::ACL#extension_permissions
176
- # @param [Boolean] all When set to true all elements will be displayed opposed to
177
- # only those the user is allowed to see.
188
+ # @param [String] css_class A string of CSS classes to apply to the main UL element.
189
+ # @param [Hash] permissions Hash containing the permissions as returned by
190
+ # Ramaze::Helper::ACL.extension_permissions
178
191
  # @since 0.1
179
192
  #
180
- def self.build_menu(css_class = '', permissions = {}, all = false)
181
- @g = Ramaze::Gestalt.new
182
- menu_items = []
183
- identifiers = []
184
-
185
- # Build a list of all allowed extensions
186
- permissions.each do |ident, rules|
187
- if rules.include?(:read)
188
- identifiers.push(ident)
189
- end
190
- end
193
+ def self.build_menu(css_class = '', permissions = {})
194
+ @g = Ramaze::Gestalt.new
195
+ @permissions = permissions
196
+ menu_items = []
191
197
 
192
- @packages.each do |ident, ext|
198
+ Registered.each do |name, pkg|
193
199
  # Got a menu for us?
194
- if !ext.menu.nil?
195
- if identifiers.include?(ext.identifier) or all == true
196
- ext.menu.each do |m|
197
- menu_items.push(m)
198
- end
200
+ if !pkg.menu.nil?
201
+ pkg.menu.each do |m|
202
+ menu_items.push(m)
199
203
  end
200
204
  end
201
205
  end
@@ -226,12 +230,26 @@ module Zen
226
230
  # @param [Hash] menu Hash containing the navigation items (url, title, etc)
227
231
  # @since 0.1
228
232
  #
229
- def self.nav_list menu
233
+ def self.nav_list(menu)
234
+ if menu[:url][0] != '/'
235
+ menu[:url] = '/' + menu[:url]
236
+ end
237
+
238
+ # Get the controller for the current item
239
+ controller = Ramaze::AppMap.at('/').url_map.at(menu[:url]).to_s
240
+ read_access = @permissions[controller].include?(:read)
241
+
242
+ # Ignore the menu item alltogether
243
+ if !read_access and !menu.key?(:children)
244
+ return
245
+ end
246
+
230
247
  @g.li do
231
- if menu[:url][0] != '/'
232
- menu[:url] = '/' + menu[:url]
248
+ # Easy way of disabling an item and not fucking up the menu
249
+ if !read_access
250
+ menu[:url] = '#'
233
251
  end
234
-
252
+
235
253
  @g.a :href => menu[:url], :title => menu[:title] do
236
254
  menu[:title]
237
255
  end