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
@@ -162,7 +162,14 @@ Zen.Editor.Base = new Class(
162
162
  {
163
163
  this.setOptions(options);
164
164
 
165
- this.elements = $$(css_selector);
165
+ if ( typeof css_selector === 'string' )
166
+ {
167
+ this.elements = $$(css_selector);
168
+ }
169
+ else
170
+ {
171
+ this.elements = [css_selector];
172
+ }
166
173
 
167
174
  // Load our driver
168
175
  var driver = this.options.format.capitalize().camelCase();
@@ -1,15 +1,8 @@
1
1
  window.addEvent('domready', function()
2
2
  {
3
3
  /**
4
- * Create a new instance of the Tabs class.
5
- * This will create a regular tab system for
6
- * the CSS selector "div.tabs ul".
7
- */
8
- new Zen.Tabs('div.tabs ul');
9
-
10
- /**
11
- * Show a notification whenever we find an error, success
12
- * or notice hash in the Zen.Flash object.
4
+ * Show a notification whenever we find an error, success or notice hash in the
5
+ * Zen.Flash object.
13
6
  */
14
7
  if ( Zen.Flash.notification )
15
8
  {
@@ -23,9 +16,8 @@ window.addEvent('domready', function()
23
16
  }
24
17
 
25
18
  /**
26
- * Enable the automatic checking of all checkboxes in a table with a class
27
- * of "table". Perhaps I'll use a class for this in the future but for now
28
- * this is good enough.
19
+ * Enable the automatic checking of all checkboxes in a table with a class of "table".
20
+ * Perhaps I'll use a class for this in the future but for now this is good enough.
29
21
  */
30
22
  var tables = $$('.table');
31
23
 
@@ -33,39 +25,110 @@ window.addEvent('domready', function()
33
25
  {
34
26
  tables.each(function(table)
35
27
  {
36
- var check_all = table.getElement('thead tr th:first-child input[type=checkbox]');
28
+ var check_all = table.getElement(
29
+ 'thead tr th:first-child input[type=checkbox]'
30
+ );
37
31
 
38
32
  check_all.addEvent('click', function()
39
33
  {
40
34
  var check_all_status = check_all.get('checked');
41
35
 
42
- tables.getElements('tbody tr td:first-child input[type=checkbox]').each(function(c)
36
+ tables.getElements(
37
+ 'tbody tr td:first-child input[type=checkbox]'
38
+ ).each(function(c)
43
39
  {
44
40
  c.set('checked', check_all_status);
45
41
  });
46
42
  });
47
43
  });
48
44
  }
45
+
46
+ /**
47
+ * Create a new instance of the Tabs class. This will create a regular tab system for
48
+ * the CSS selector "div.tabs ul".
49
+ */
50
+ var tab_selector = 'div.tabs ul';
51
+ var tab_elements = $$(tab_selector).length;
52
+
53
+ yepnope(
54
+ {
55
+ test: !Zen.Tabs && tab_elements > 0,
56
+ yep: ['/admin/css/tabs.css', '/admin/js/zen/tabs.js'],
57
+ complete: function()
58
+ {
59
+ // Double check there are any elements
60
+ if ( tab_elements > 0 )
61
+ {
62
+ new Zen.Tabs(tab_selector);
63
+ }
64
+ }
65
+ });
49
66
 
50
67
  /**
51
- * Initialize our editor for all elements with a class of "visual_editor" and retrieve
52
- * the editor format from the attribute "data-format".
68
+ * Initialize our editor for all elements with a class of "visual_editor" and
69
+ * retrieve the editor format from the attribute "data-format".
53
70
  */
54
- new Zen.Editor.Base('.visual_editor[data-format="html"]' , { format: 'html' }).display();
55
- new Zen.Editor.Base('.visual_editor[data-format="textile"]' , { format: 'textile' }).display();
56
- new Zen.Editor.Base('.visual_editor[data-format="markdown"]', { format: 'markdown' }).display();
71
+ var editor_elements = $$('.visual_editor');
72
+
73
+ if ( editor_elements.length > 0 )
74
+ {
75
+ var editor_files = ['/admin/css/editor.css', '/admin/js/zen/editor/base.js'];
76
+
77
+ // Determine what drivers to load
78
+ editor_elements.each(function(editor)
79
+ {
80
+ var driver = editor.get('data-format');
81
+
82
+ // Screw you, you should've set the attribute!
83
+ if ( !driver )
84
+ {
85
+ return console.error(
86
+ "Missing attribute data-format for the editor with ID "
87
+ + editor.get('id')
88
+ );
89
+ }
90
+
91
+ editor_files.include('/admin/js/zen/editor/drivers/' + driver + '.js');
92
+ });
93
+
94
+ // Load all the files we need
95
+ yepnope(
96
+ {
97
+ test: Zen.Editor,
98
+ nope: editor_files,
99
+ complete: function()
100
+ {
101
+ editor_elements.each(function(editor)
102
+ {
103
+ new Zen.Editor.Base(
104
+ editor, {format: editor.get('data-format')}
105
+ ).display();
106
+ });
107
+ }
108
+ });
109
+ }
57
110
 
58
111
  /**
59
- * Initializes a datepicker object whenever it's loaded and the correct element was found.
112
+ * Initializes a datepicker object whenever it's loaded and the correct element was
113
+ * found.
60
114
  */
61
- if ( typeof Picker != "undefined" && typeof Picker.Date != "undefined" )
115
+ var date_elements = $$('input[type="text"].date');
116
+
117
+ if ( date_elements.length > 0 )
62
118
  {
63
- new Picker.Date($$('form input[type="text"].date'),
119
+ yepnope(
64
120
  {
65
- timePicker: true,
66
- pickerClass: 'datepicker',
67
- format: '%Y-%m-%d %H:%M:%S',
68
- draggable: true
121
+ test : typeof Picker === 'undefined',
122
+ yep : ['/admin/css/datepicker.css', '/admin/js/vendor/datepicker.js'],
123
+ complete: function()
124
+ {
125
+ new Picker.Date(date_elements,
126
+ {
127
+ timePicker: true,
128
+ pickerClass: 'datepicker',
129
+ format: '%Y-%m-%d %H:%M:%S'
130
+ });
131
+ }
69
132
  });
70
133
  }
71
134
  });
@@ -0,0 +1,7 @@
1
+ require 'rake'
2
+
3
+ import __DIR__('task/db.rake')
4
+ import __DIR__('task/package.rake')
5
+ import __DIR__('task/plugin.rake')
6
+ import __DIR__('task/proto.rake')
7
+ import __DIR__('task/theme.rake')
@@ -0,0 +1,60 @@
1
+ ##
2
+ # Task group used for building various elements such as the Gem and the documentation.
3
+ #
4
+ # @author Yorick Peterse
5
+ # @since 0.2.5
6
+ #
7
+ namespace :build do
8
+
9
+ desc 'Builds the documentation using YARD'
10
+ task :doc do
11
+ zen_path = File.expand_path('../../../../', __FILE__)
12
+ command = "yard doc #{zen_path}/lib -m markdown -M rdiscount -o #{zen_path}/doc "
13
+ command += "-r #{zen_path}/README.md --private --protected "
14
+ command += "--files #{zen_path}/license.txt,#{zen_path}/CHANGELOG.md,"
15
+ command += "#{zen_path}/ROADMAP.md"
16
+
17
+ sh(command)
18
+ end
19
+
20
+ desc 'Builds a new Gem'
21
+ task :gem do
22
+ zen_path = File.expand_path('../../../../', __FILE__)
23
+
24
+ # Build and install the gem
25
+ sh("gem build #{zen_path}/zen.gemspec")
26
+ sh("mv #{zen_path}/zen-#{Zen::Version}.gem #{zen_path}/pkg")
27
+ sh("gem install #{zen_path}/pkg/zen-#{Zen::Version}.gem")
28
+ end
29
+
30
+ desc 'Builds the MANIFEST file'
31
+ task :manifest do
32
+ zen_path = File.expand_path('../../../../', __FILE__)
33
+ ignore_exts = ['.gem', '.gemspec']
34
+ ignore_files = ['.DS_Store', '.gitignore']
35
+ ignore_dirs = ['.git', '.yardoc', 'spec', 'pkg', 'doc']
36
+ files = ''
37
+
38
+ Find.find(zen_path) do |f|
39
+ f[zen_path] = ''
40
+ f.gsub!(/^\//, '')
41
+
42
+ # Ignore directories
43
+ if !File.directory?(f) and !ignore_exts.include?(File.extname(f)) and !ignore_files.include?(File.basename(f))
44
+ files += "#{f}\n"
45
+ else
46
+ Find.prune if ignore_dirs.include?(f)
47
+ end
48
+ end
49
+
50
+ # Time to write the MANIFEST file
51
+ begin
52
+ handle = File.open 'MANIFEST', 'w'
53
+ handle.write files.strip
54
+ puts "The MANIFEST file has been updated."
55
+ rescue
56
+ abort "The MANIFEST file could not be written."
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,27 @@
1
+ require 'fileutils'
2
+
3
+ ##
4
+ # Task group used to remove various files that aren't needed when releasing gems and such.
5
+ #
6
+ # @author Yorick Peterse
7
+ # @since 0.2.5
8
+ #
9
+ namespace :clean do
10
+
11
+ desc 'Removes all log files'
12
+ task :log do
13
+ zen_path = File.expand_path('../../../../', __FILE__)
14
+
15
+ log_files = Dir.glob("#{zen_path}/spec/log/**/*.log")
16
+ log_files.each { |file| File.unlink(file) }
17
+ end
18
+
19
+ desc 'Removes all YARD files'
20
+ task :yard do
21
+ zen_path = File.expand_path('../../../../', __FILE__)
22
+
23
+ FileUtils.rm_rf("#{zen_path}/doc")
24
+ FileUtils.rm_rf("#{zen_path}/.yardoc")
25
+ end
26
+
27
+ end
@@ -0,0 +1,111 @@
1
+ Sequel.extension(:migration)
2
+
3
+ ##
4
+ # Task group for database related tasks such as migrating and removing the database.
5
+ #
6
+ # @author Yorick Peterse
7
+ # @since 0.2.5
8
+ #
9
+ namespace :db do
10
+
11
+ desc 'Migrates the database to the newest version'
12
+ task :migrate do
13
+ if Zen::Package::Registered.empty?
14
+ abort "No packages have been registered."
15
+ end
16
+
17
+ # Get the details required to run a migration
18
+ Zen::Package::Registered.each do |name, pkg|
19
+ # Get the migration directory
20
+ if pkg.respond_to?(:migration_dir) and !pkg.migration_dir.nil?
21
+ dir = pkg.migration_dir
22
+ else
23
+ dir = pkg.directory + '/../../migrations'
24
+ end
25
+
26
+ if !File.directory?(dir)
27
+ abort "The migration directory #{dir} doesn't exist."
28
+ end
29
+
30
+ table = 'migrations_package_' + pkg.name.to_s
31
+
32
+ # Migration time
33
+ Zen::Database.handle.transaction do
34
+ Sequel::Migrator.run(Zen::Database.handle, dir, :table => table)
35
+ puts "Successfully migrated \"#{pkg.name}\""
36
+ end
37
+ end
38
+ end
39
+
40
+ desc 'Deletes the entire database'
41
+ task :delete do
42
+ if Zen::Package::Registered.empty?
43
+ abort "No packages have been registered."
44
+ end
45
+
46
+ packages = Zen::Package::Registered.map { |name, pkg| [name, pkg] }.reverse
47
+
48
+ # Get the details required to run a migration
49
+ packages.each do |name, pkg|
50
+ # Get the migration directory
51
+ if pkg.respond_to?(:migration_dir) and !pkg.migration_dir.nil?
52
+ dir = pkg.migration_dir
53
+ else
54
+ dir = pkg.directory + '/../../migrations'
55
+ end
56
+
57
+ if !File.directory?(dir)
58
+ abort "The migration directory #{dir} doesn't exist."
59
+ end
60
+
61
+ table = 'migrations_package_' + pkg.name.to_s
62
+
63
+ # Migration time
64
+ Zen::Database.handle.transaction do
65
+ Sequel::Migrator.run(Zen::Database.handle, dir, :table => table, :target => 0)
66
+ Zen::Database.handle.drop_table(table)
67
+
68
+ puts "Successfully uninstalled \"#{pkg.name}\""
69
+ end
70
+ end
71
+ end
72
+
73
+ desc 'Creates a default administrator with a random password'
74
+ task :user do
75
+ password = (0..12).map do
76
+ letter = ('a'..'z').to_a[rand(26)]
77
+ number = (0..9).to_a[rand(26)]
78
+ letter + number.to_s
79
+ end.join
80
+
81
+ # Only insert the user if it isn't there yet.
82
+ user = Users::Model::User[:email => 'admin@website.tld']
83
+ group = Users::Model::UserGroup[:slug => 'administrators']
84
+
85
+ if group.nil?
86
+ group = Users::Model::UserGroup.new(
87
+ :name => 'Administrators',
88
+ :slug => 'administrators', :super_group => true
89
+ ).save
90
+ end
91
+
92
+ if !user.nil?
93
+ abort "The default user has already been inserted."
94
+ end
95
+
96
+ user = Users::Model::User.new(
97
+ :email => 'admin@website.tld', :name => 'Administrator',
98
+ :password => password, :status => 'open'
99
+ ).save
100
+
101
+ user.user_group_pks = [group.id]
102
+
103
+ puts "Default administrator account has been created.
104
+
105
+ Email: admin@website.tld
106
+ Passowrd: #{password}
107
+
108
+ You can login by going to http://domain.tld/admin/users/login/
109
+ "
110
+ end
111
+ end
@@ -0,0 +1,67 @@
1
+ ##
2
+ # Task group for managing packages.
3
+ #
4
+ # @author Yorick Peterse
5
+ # @since 0.2.5
6
+ #
7
+ namespace :package do
8
+
9
+ desc 'Lists all installed packages'
10
+ task :list do
11
+ Zen::Package::Registered.each do |name, pkg|
12
+ message = <<-MSG
13
+ --------------------------
14
+ Name: #{name}
15
+ Author: #{pkg.author}
16
+
17
+ #{pkg.about}
18
+ MSG
19
+
20
+ puts message
21
+ end
22
+ end
23
+
24
+ desc 'Migrates a package to a certain version'
25
+ task :migrate, :name, :version do |task, args|
26
+ if !args[:name]
27
+ abort "You need to specify the name of a package to migrate"
28
+ end
29
+
30
+ if !args[:version]
31
+ version = nil
32
+ else
33
+ version = args[:version].to_i
34
+ end
35
+
36
+ # Validate the package name
37
+ if !Zen::Packages::Registered[args[:name].to_sym]
38
+ abort "The package name \"#{args[:name]}\" is invalid."
39
+ end
40
+
41
+ package = Zen::Packages::Registered[args[:name].to_sym]
42
+
43
+ # Get the migrations directory
44
+ if package.respond_to?(:migration_dir) and !package.migration_dir.nil?
45
+ dir = package.migration_dir
46
+ else
47
+ dir = package.directory + '/../../migrations'
48
+ end
49
+
50
+ # Validate the directory
51
+ if !File.directory?(dir)
52
+ abort "The directory #{dir} does not exist."
53
+ end
54
+
55
+ table = 'migrations_package_' + package.name.to_s
56
+
57
+ puts "Migrating package..."
58
+
59
+ # Run all migrations
60
+ Zen::Database.handle.transaction do
61
+ Sequel.migrator.run(
62
+ Zen::Database.handle, dir, :table => table, :target => version
63
+ )
64
+ end
65
+ end
66
+
67
+ end