zen 0.2.4.1 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +42 -33
- data/README.md +14 -27
- data/ROADMAP.md +20 -2
- data/{Thorfile → Rakefile} +2 -3
- data/bin/zen +27 -5
- data/lib/zen.rb +70 -52
- data/lib/zen/asset.rb +258 -0
- data/lib/zen/bin/app.rb +42 -0
- data/lib/zen/controller/admin_controller.rb +53 -36
- data/lib/zen/controller/base_controller.rb +13 -8
- data/lib/zen/controller/frontend_controller.rb +4 -3
- data/lib/zen/controller/main_controller.rb +17 -33
- data/lib/zen/error/validation_error.rb +10 -0
- data/lib/zen/ext/string.rb +185 -0
- data/lib/zen/helper/acl.rb +120 -92
- data/lib/zen/helper/common.rb +1 -3
- data/lib/zen/helper/theme.rb +73 -0
- data/lib/zen/language.rb +66 -57
- data/lib/zen/layout/admin.xhtml +5 -48
- data/lib/zen/layout/login.xhtml +4 -44
- data/lib/zen/model/methods.rb +1 -1
- data/lib/zen/model/settings.rb +0 -3
- data/lib/zen/package.rb +101 -83
- data/lib/zen/package/base.rb +62 -0
- data/lib/zen/package/categories/lib/categories.rb +29 -10
- data/lib/zen/package/categories/lib/categories/controller/categories.rb +4 -5
- data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +4 -5
- data/lib/zen/package/categories/lib/categories/language/en/category_groups.yml +4 -3
- data/lib/zen/package/categories/lib/categories/model/category.rb +2 -2
- data/lib/zen/package/categories/lib/categories/model/category_group.rb +3 -3
- data/lib/zen/package/categories/lib/categories/plugin/categories.rb +130 -0
- data/lib/zen/package/categories/lib/categories/view/admin/categories/form.xhtml +1 -1
- data/lib/zen/package/categories/lib/categories/view/admin/categories/index.xhtml +2 -2
- data/lib/zen/package/categories/lib/categories/view/admin/category-groups/index.xhtml +11 -6
- data/lib/zen/package/comments/lib/comments.rb +23 -13
- data/lib/zen/package/comments/lib/comments/controller/comments.rb +4 -5
- data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +7 -8
- data/lib/zen/package/comments/lib/comments/model/comment.rb +4 -4
- data/lib/zen/package/comments/lib/comments/plugin/comments.rb +111 -0
- data/lib/zen/package/comments/lib/comments/view/admin/comments/form.xhtml +2 -2
- data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields.rb +18 -11
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +4 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +4 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +2 -2
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/index.xhtml +9 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/form.xhtml +1 -1
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/index.xhtml +3 -3
- data/lib/zen/package/menus/lib/menus.rb +25 -43
- data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +5 -6
- data/lib/zen/package/menus/lib/menus/controller/menus.rb +9 -5
- data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +4 -4
- data/lib/zen/package/menus/lib/menus/model/menu.rb +2 -2
- data/lib/zen/package/menus/lib/menus/model/menu_item.rb +4 -1
- data/lib/zen/package/menus/lib/menus/plugin/menus.rb +152 -0
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/form.xhtml +1 -1
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/index.xhtml +3 -3
- data/lib/zen/package/menus/lib/menus/view/admin/menus/index.xhtml +7 -7
- data/lib/zen/package/sections/lib/sections.rb +32 -16
- data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +9 -18
- data/lib/zen/package/sections/lib/sections/controller/sections.rb +8 -9
- data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +1 -1
- data/lib/zen/package/sections/lib/sections/model/section.rb +4 -4
- data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -10
- data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +224 -0
- data/lib/zen/package/sections/lib/sections/plugin/sections.rb +85 -0
- data/lib/zen/package/sections/lib/sections/view/admin/form.xhtml +1 -1
- data/lib/zen/package/sections/lib/sections/view/admin/index.xhtml +9 -5
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +2 -2
- data/lib/zen/package/settings/lib/settings.rb +145 -10
- data/lib/zen/package/settings/lib/settings/controller/settings.rb +28 -24
- data/lib/zen/package/settings/lib/settings/language/en/settings.yml +10 -0
- data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -64
- data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +40 -0
- data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +76 -0
- data/lib/zen/package/settings/lib/settings/plugin/settings.rb +236 -0
- data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +20 -49
- data/lib/zen/package/settings/migrations/1295597111_create_schema.rb +0 -12
- data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +31 -0
- data/lib/zen/package/users/lib/users.rb +18 -15
- data/lib/zen/package/users/lib/users/controller/access_rules.rb +44 -8
- data/lib/zen/package/users/lib/users/controller/user_groups.rb +4 -5
- data/lib/zen/package/users/lib/users/controller/users.rb +5 -6
- data/lib/zen/package/users/lib/users/language/en/access_rules.yml +11 -9
- data/lib/zen/package/users/lib/users/model/access_rule.rb +7 -6
- data/lib/zen/package/users/lib/users/model/user.rb +4 -4
- data/lib/zen/package/users/lib/users/model/user_group.rb +3 -3
- data/lib/zen/package/users/lib/users/public/admin/js/users/access_rules.js +50 -0
- data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +32 -29
- data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +8 -6
- data/lib/zen/package/users/lib/users/view/admin/user-groups/index.xhtml +3 -3
- data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +2 -2
- data/lib/zen/package/users/migrations/1303510943_class_rules.rb +13 -0
- data/lib/zen/plugin.rb +110 -104
- data/lib/zen/plugin/base.rb +46 -0
- data/lib/zen/{liquid/controller_behavior.rb → plugin/controller.rb} +9 -7
- data/lib/zen/plugin/helper.rb +47 -0
- data/lib/zen/plugin/markup/lib/markup.rb +14 -0
- data/lib/zen/plugin/markup/lib/markup/language/en/markup.yml +6 -0
- data/lib/zen/plugin/markup/lib/markup/markup.rb +154 -0
- data/lib/zen/public/admin/css/forms.css +4 -0
- data/lib/zen/public/admin/css/general.css +15 -15
- data/lib/zen/public/admin/css/layout.css +10 -10
- data/lib/zen/public/admin/css/reset.css +123 -0
- data/lib/zen/public/admin/images/icons/accept.png +0 -0
- data/lib/zen/public/admin/images/icons/add.png +0 -0
- data/lib/zen/public/admin/images/icons/back.png +0 -0
- data/lib/zen/public/admin/images/icons/bold.png +0 -0
- data/lib/zen/public/admin/images/icons/close.png +0 -0
- data/lib/zen/public/admin/images/icons/delete.png +0 -0
- data/lib/zen/public/admin/images/icons/edit.png +0 -0
- data/lib/zen/public/admin/images/icons/error.png +0 -0
- data/lib/zen/public/admin/images/icons/help.png +0 -0
- data/lib/zen/public/admin/images/icons/info.png +0 -0
- data/lib/zen/public/admin/images/icons/italic.png +0 -0
- data/lib/zen/public/admin/images/icons/large/error.png +0 -0
- data/lib/zen/public/admin/images/icons/large/notice.png +0 -0
- data/lib/zen/public/admin/images/icons/large/success.png +0 -0
- data/lib/zen/public/admin/images/icons/link.png +0 -0
- data/lib/zen/public/admin/images/icons/logout.png +0 -0
- data/lib/zen/public/admin/images/icons/ol.png +0 -0
- data/lib/zen/public/admin/images/icons/pdf.png +0 -0
- data/lib/zen/public/admin/images/icons/ul.png +0 -0
- data/lib/zen/public/admin/images/icons/user.png +0 -0
- data/lib/zen/public/admin/images/icons/view.png +0 -0
- data/lib/zen/public/admin/js/mootools/core.js +384 -333
- data/lib/zen/public/admin/js/mootools/more.js +256 -231
- data/lib/zen/public/admin/js/vendor/{datepicker/Picker.Date.js → datepicker.js} +447 -0
- data/lib/zen/public/admin/js/vendor/yepnope.js +1 -0
- data/lib/zen/public/admin/js/zen/editor/base.js +8 -1
- data/lib/zen/public/admin/js/zen/init.js +89 -26
- data/lib/zen/public/favicon.ico +0 -0
- data/lib/zen/task.rb +7 -0
- data/lib/zen/task/build.rake +60 -0
- data/lib/zen/task/clean.rake +27 -0
- data/lib/zen/task/db.rake +111 -0
- data/lib/zen/task/package.rake +67 -0
- data/lib/zen/task/plugin.rake +24 -0
- data/lib/zen/task/proto.rake +95 -0
- data/lib/zen/task/theme.rake +68 -0
- data/lib/zen/theme.rb +28 -55
- data/lib/zen/theme/base.rb +64 -0
- data/lib/zen/validation.rb +149 -0
- data/lib/zen/version.rb +1 -1
- data/lib/zen/view/bottom.xhtml +6 -0
- data/lib/zen/view/main.xhtml +32 -0
- data/proto/app/Rakefile +12 -0
- data/proto/app/app.rb +6 -6
- data/proto/app/config/config.rb +7 -14
- data/proto/app/config/database.rb +0 -20
- data/proto/app/start.rb +0 -1
- data/proto/app/{vendor/themes → task}/.gitkeep +0 -0
- data/proto/app/vendor/theme/.gitkeep +0 -0
- data/proto/package/lib/package.rb +8 -17
- data/proto/package/lib/package/controller/controllers.rb +4 -4
- data/proto/package/lib/package/language/en/languages.yml +3 -3
- data/proto/package/lib/package/model/model.rb +1 -1
- metadata +73 -73
- data/lib/zen/bin/base.rb +0 -109
- data/lib/zen/helper/asset.rb +0 -106
- data/lib/zen/liquid/general.rb +0 -94
- data/lib/zen/liquid/redirect.rb +0 -70
- data/lib/zen/liquid/strip.rb +0 -60
- data/lib/zen/package/categories/lib/categories/liquid/categories.rb +0 -16
- data/lib/zen/package/comments/lib/comments/liquid/comment_form.rb +0 -127
- data/lib/zen/package/comments/lib/comments/liquid/comments.rb +0 -115
- data/lib/zen/package/menus/lib/menus/liquid/menus.rb +0 -152
- data/lib/zen/package/sections/lib/sections/liquid/section_entries.rb +0 -228
- data/lib/zen/package/sections/lib/sections/liquid/sections.rb +0 -77
- data/lib/zen/package/settings/lib/settings/liquid/setting.rb +0 -58
- data/lib/zen/package/users/lib/users/liquid/user.rb +0 -77
- data/lib/zen/package/users/lib/users/liquid/users.rb +0 -82
- data/lib/zen/plugin/markup.rb +0 -30
- data/lib/zen/public/admin/css/boilerplate.css +0 -176
- data/lib/zen/public/admin/images/general/noise.jpg +0 -0
- data/lib/zen/public/admin/js/vendor/datepicker/Picker.Attach.js +0 -137
- data/lib/zen/public/admin/js/vendor/datepicker/Picker.js +0 -291
- data/lib/zen/public/admin/js/vendor/datepicker/README.md +0 -325
- data/lib/zen/public/admin/js/vendor/datepicker/locale.js +0 -16
- data/lib/zen/strict_struct.rb +0 -36
- data/lib/zen/task/build.rb +0 -123
- data/lib/zen/task/clean.rb +0 -46
- data/lib/zen/task/db.rb +0 -130
- data/lib/zen/task/package.rb +0 -87
- data/lib/zen/task/proto.rb +0 -116
- data/lib/zen/task/theme.rb +0 -88
- data/proto/app/Thorfile +0 -4
@@ -0,0 +1,62 @@
|
|
1
|
+
#:nodoc:
|
2
|
+
module Zen
|
3
|
+
#:nodoc:
|
4
|
+
module Package
|
5
|
+
##
|
6
|
+
# Base class used to store the data about packages such as the name, directory, 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 package
|
15
|
+
attr_accessor :name
|
16
|
+
|
17
|
+
# The author of the package
|
18
|
+
attr_accessor :author
|
19
|
+
|
20
|
+
# A small description about the package
|
21
|
+
attr_accessor :about
|
22
|
+
|
23
|
+
# The URL to the website of the package
|
24
|
+
attr_accessor :url
|
25
|
+
|
26
|
+
# The root directory of the package
|
27
|
+
attr_accessor :directory
|
28
|
+
|
29
|
+
# Array containing the navigation items for the package
|
30
|
+
attr_accessor :menu
|
31
|
+
|
32
|
+
# Path to the directory containing all migrations
|
33
|
+
attr_accessor :migration_dir
|
34
|
+
|
35
|
+
# Array containing all controllers for the package. These classes will be used
|
36
|
+
# by the ACL system.
|
37
|
+
attr_accessor :controllers
|
38
|
+
|
39
|
+
##
|
40
|
+
# Validates all the attributes.
|
41
|
+
#
|
42
|
+
# @author Yorick Peterse
|
43
|
+
# @since 0.2.5
|
44
|
+
#
|
45
|
+
def validate
|
46
|
+
validates_presence([:name, :author, :about, :directory, :controllers])
|
47
|
+
validates_format(:name, /[a-z0-9_\-]+/)
|
48
|
+
validates_filepath(:directory)
|
49
|
+
|
50
|
+
if !migration_dir.nil?
|
51
|
+
validates_filepath(:migration_dir)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Check if the package hasn't been registered yet
|
55
|
+
if ::Zen::Package::Registered.key?(name.to_sym)
|
56
|
+
raise(::Zen::ValidationError, "The package #{name} already exists.")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -1,23 +1,42 @@
|
|
1
|
+
require __DIR__('categories/model/category_group')
|
2
|
+
require __DIR__('categories/model/category')
|
3
|
+
require __DIR__('categories/controller/category_groups')
|
4
|
+
require __DIR__('categories/controller/categories')
|
5
|
+
require __DIR__('categories/plugin/categories')
|
1
6
|
|
2
|
-
# Load
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require __DIR__ 'categories/controller/category_groups'
|
7
|
-
require __DIR__ 'categories/controller/categories'
|
7
|
+
# Load the language pack manually so it can be used in the block below
|
8
|
+
Zen::Language.options.paths.push(__DIR__('categories'))
|
9
|
+
Zen::Language.load('categories')
|
10
|
+
Zen::Language.load('category_groups')
|
8
11
|
|
9
12
|
# Describe what this package is all about
|
10
13
|
Zen::Package.add do |p|
|
11
|
-
p.name = '
|
14
|
+
p.name = 'categories'
|
12
15
|
p.author = 'Yorick Peterse'
|
13
16
|
p.url = 'http://yorickpeterse.com/'
|
14
|
-
p.about = "Module for managing categories. Categories can be used to organize
|
15
|
-
|
17
|
+
p.about = "Module for managing categories. Categories can be used to organize
|
18
|
+
section entries."
|
19
|
+
|
16
20
|
p.directory = __DIR__('categories')
|
17
21
|
p.migration_dir = __DIR__('../migrations')
|
18
22
|
|
19
23
|
p.menu = [{
|
20
|
-
:title =>
|
24
|
+
:title => lang('categories.titles.index'),
|
21
25
|
:url => "admin/category-groups"
|
22
26
|
}]
|
27
|
+
|
28
|
+
# Register all controllers
|
29
|
+
p.controllers = {
|
30
|
+
lang('categories.titles.index') => Categories::Controller::Categories,
|
31
|
+
lang('category_groups.titles.index') => Categories::Controller::CategoryGroups
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# Register our plugins
|
36
|
+
Zen::Plugin.add do |p|
|
37
|
+
p.name = 'categories'
|
38
|
+
p.author = 'Yorick Peterse'
|
39
|
+
p.url = 'http://yorickpeterse.com/'
|
40
|
+
p.about = 'Plugin that makes it easier to retrieve categories and category groups.'
|
41
|
+
p.plugin = Categories::Plugin::Categories
|
23
42
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Categories
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
##
|
6
6
|
# Categories can be seen as "tags" for your section entries. They describe the
|
7
7
|
# type of entry just like tags except that categories generally cover larger elements.
|
@@ -11,11 +11,10 @@ module Categories
|
|
11
11
|
# @author Yorick Peterse
|
12
12
|
# @since 0.1
|
13
13
|
#
|
14
|
-
class Categories < Zen::
|
15
|
-
include ::Categories::
|
14
|
+
class Categories < Zen::Controller::AdminController
|
15
|
+
include ::Categories::Model
|
16
16
|
|
17
|
-
map
|
18
|
-
trait :extension_identifier => 'com.zen.categories'
|
17
|
+
map('/admin/categories')
|
19
18
|
|
20
19
|
before_all do
|
21
20
|
csrf_protection(:save, :delete) do
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Categories
|
2
|
-
module
|
2
|
+
module Controller
|
3
3
|
##
|
4
4
|
# Category groups can be used to group a number of categories into a single container.
|
5
5
|
# These groups are assigned to a section (rather than individual categories). It's
|
@@ -9,11 +9,10 @@ module Categories
|
|
9
9
|
# @author Yorick Peterse
|
10
10
|
# @since 0.1
|
11
11
|
#
|
12
|
-
class CategoryGroups < Zen::
|
13
|
-
include ::Categories::
|
12
|
+
class CategoryGroups < Zen::Controller::AdminController
|
13
|
+
include ::Categories::Model
|
14
14
|
|
15
|
-
map
|
16
|
-
trait :extension_identifier => 'com.zen.categories'
|
15
|
+
map('/admin/category-groups')
|
17
16
|
|
18
17
|
before_all do
|
19
18
|
csrf_protection(:save, :delete) do
|
@@ -22,9 +22,10 @@ success:
|
|
22
22
|
delete : 'The category group has been deleted.'
|
23
23
|
|
24
24
|
errors:
|
25
|
-
new
|
26
|
-
save
|
27
|
-
delete
|
25
|
+
new : 'Failed to add a new category group.'
|
26
|
+
save : 'Failed to modify the category group.'
|
27
|
+
delete : 'Failed to delete the category group with ID #%s.'
|
28
|
+
no_delete: 'You need to specify at least one group to delete.'
|
28
29
|
|
29
30
|
buttons:
|
30
31
|
new : 'Add group'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Categories
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Model
|
5
5
|
##
|
6
6
|
# Model that represents a single category. This model has the following relations:
|
7
7
|
#
|
@@ -21,7 +21,7 @@ module Categories
|
|
21
21
|
# @since 0.1
|
22
22
|
#
|
23
23
|
class Category < Sequel::Model
|
24
|
-
many_to_one :category_group , :class => "Categories::
|
24
|
+
many_to_one :category_group , :class => "Categories::Model::CategoryGroup"
|
25
25
|
many_to_one :parent , :class => self
|
26
26
|
|
27
27
|
plugin :sluggable, :source => :name, :frozen => false
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Categories
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Model
|
5
5
|
##
|
6
6
|
# Model that represents a single category group. Each category group
|
7
7
|
# has the following relations to other models:
|
@@ -13,8 +13,8 @@ module Categories
|
|
13
13
|
# and should be no longer than 255 characters.
|
14
14
|
#
|
15
15
|
class CategoryGroup < Sequel::Model
|
16
|
-
one_to_many :categories, :class => "Categories::
|
17
|
-
many_to_many :sections , :class => "Sections::
|
16
|
+
one_to_many :categories, :class => "Categories::Model::Category"
|
17
|
+
many_to_many :sections , :class => "Sections::Model::Section"
|
18
18
|
|
19
19
|
##
|
20
20
|
# Validation rules for our model.
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#:nodoc
|
2
|
+
module Categories
|
3
|
+
#:nodoc
|
4
|
+
module Plugin
|
5
|
+
##
|
6
|
+
# The Categories plugin can be used to display a list of categories
|
7
|
+
#
|
8
|
+
# ## Usage
|
9
|
+
#
|
10
|
+
# A basic example of how to use this plugin looks like the following:
|
11
|
+
#
|
12
|
+
# plugin(:categories, :group => 'blog').each do |category|
|
13
|
+
# puts category[:name]
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# For more information about the available options see
|
17
|
+
# Zen::Plugin::Categories#initialize().
|
18
|
+
#
|
19
|
+
# @author Yorick Peterse
|
20
|
+
# @since 0.2.5
|
21
|
+
#
|
22
|
+
class Categories
|
23
|
+
include ::Categories::Model
|
24
|
+
include ::Zen::Plugin::Helper
|
25
|
+
|
26
|
+
##
|
27
|
+
# Creates a new instance of the plugin and stores the configuration options.
|
28
|
+
#
|
29
|
+
# @author Yorick Peterse
|
30
|
+
# @since 0.2.5
|
31
|
+
# @param [Hash] options Hash containing a set of options used to determine how the
|
32
|
+
# categories should be retrieved and which one should be retrieved.
|
33
|
+
# @option options [Integer] :limit The maximum amount of categories to retrieve.
|
34
|
+
# @option options [Integer] :offset The row offset, useful for pagination systems.
|
35
|
+
# @option options [String/Integer] :group The name or ID of the category group for
|
36
|
+
# which to retrieve all categories.
|
37
|
+
# @option options [String/Integer] :category The slug or ID of the category to
|
38
|
+
# retrieve. Setting this option will cause the plugin to ignore the offset and
|
39
|
+
# limit options.
|
40
|
+
#
|
41
|
+
def initialize(options = {})
|
42
|
+
@options = {
|
43
|
+
:limit => 20,
|
44
|
+
:offset => 0,
|
45
|
+
:group => nil,
|
46
|
+
:category => nil
|
47
|
+
}.merge(options)
|
48
|
+
|
49
|
+
# Validate the specified options
|
50
|
+
if @options[:group].nil? and @options[:category].nil?
|
51
|
+
raise(ArgumentError, "You need to specify either a category or category group.")
|
52
|
+
end
|
53
|
+
|
54
|
+
if !@options[:group].nil? and !@options[:category].nil?
|
55
|
+
raise(ArgumentError, "You can't specify both a category and a category group.")
|
56
|
+
end
|
57
|
+
|
58
|
+
group_class = @options[:group].class
|
59
|
+
cat_class = @options[:category].class
|
60
|
+
allowed = [Integer, String, Fixnum]
|
61
|
+
|
62
|
+
# Validate the types
|
63
|
+
if !@options[:group].nil?
|
64
|
+
validate_type(@options[:group], :group, allowed)
|
65
|
+
end
|
66
|
+
|
67
|
+
if !@options[:category].nil?
|
68
|
+
validate_type(@options[:category], :category, allowed)
|
69
|
+
end
|
70
|
+
|
71
|
+
validate_type(@options[:limit] , :limit , [Fixnum, Integer])
|
72
|
+
validate_type(@options[:offset], :offset, [Fixnum, Integer])
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Retrieves all categories based on the given configuration options.
|
77
|
+
#
|
78
|
+
# @author Yorick Peterse
|
79
|
+
# @since 0.2.5
|
80
|
+
# @return [Array] A list of all categories.
|
81
|
+
#
|
82
|
+
def call
|
83
|
+
categories = []
|
84
|
+
|
85
|
+
# Retrieve the categories for a given group]]
|
86
|
+
if !@options[:group].nil?
|
87
|
+
# Get the group for an ID or a name
|
88
|
+
if @options[:group].class == Integer or @options[:group].class == Fixnum
|
89
|
+
category_group = CategoryGroup[@options[:group]]
|
90
|
+
else
|
91
|
+
category_group = CategoryGroup[:name => @options[:group]]
|
92
|
+
end
|
93
|
+
|
94
|
+
# Since we require a group in this case we'll raise an error if the group
|
95
|
+
# doesn't exist. If we were to return an empty value this may confuse the
|
96
|
+
# developer.
|
97
|
+
if category_group.nil?
|
98
|
+
raise("No category group could be found for \"#{@options[:group]}\"")
|
99
|
+
end
|
100
|
+
|
101
|
+
# Get all the categories according to our specified configuration options
|
102
|
+
# and the category group that was retrieved earlier on.
|
103
|
+
categories = Category.filter(:category_group_id => category_group.id)
|
104
|
+
.limit(@options[:limit], @options[:offset])
|
105
|
+
.all
|
106
|
+
|
107
|
+
# Retrieve the category for the specified ID or slug
|
108
|
+
else
|
109
|
+
if @options[:category].class == Integer or @options[:category].class == Fixnum
|
110
|
+
categories = Category[@options[:category]]
|
111
|
+
else
|
112
|
+
categories = Category[:slug => @options[:category]]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Convert all categories to a hash
|
117
|
+
if categories.class == Array
|
118
|
+
categories.each_with_index do |cat, index|
|
119
|
+
categories[index] = cat.values
|
120
|
+
end
|
121
|
+
else
|
122
|
+
categories = categories.values
|
123
|
+
end
|
124
|
+
|
125
|
+
return categories
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -24,7 +24,7 @@ form_for(
|
|
24
24
|
|
25
25
|
# Generate the dropdown that contains all possible parent categories
|
26
26
|
parent_categories = {}
|
27
|
-
Categories::
|
27
|
+
Categories::Model::CategoryGroup[@category_group_id].categories.each do |c|
|
28
28
|
if c.id != @category.id
|
29
29
|
parent_categories[c.id] = c.name
|
30
30
|
end
|
@@ -39,7 +39,7 @@
|
|
39
39
|
<td>
|
40
40
|
#{anchor_to(
|
41
41
|
category.name,
|
42
|
-
Categories::
|
42
|
+
Categories::Controller::Categories.r(:edit, @category_group_id, category.id)
|
43
43
|
)}
|
44
44
|
</td>
|
45
45
|
<?r else ?>
|
@@ -62,7 +62,7 @@
|
|
62
62
|
<div class="button">
|
63
63
|
#{anchor_to(
|
64
64
|
lang('categories.buttons.new'),
|
65
|
-
Categories::
|
65
|
+
Categories::Controller::Categories.r(:new, @category_group_id)
|
66
66
|
)}
|
67
67
|
</div>
|
68
68
|
<?r end ?>
|
@@ -20,7 +20,9 @@
|
|
20
20
|
<th>#{lang('category_groups.labels.id')}</th>
|
21
21
|
<th>#{lang('category_groups.labels.name')}</th>
|
22
22
|
|
23
|
-
<?r if user_authorized?(
|
23
|
+
<?r if user_authorized?(
|
24
|
+
[:read], true, 'Categories::Controller::Categories'
|
25
|
+
) ?>
|
24
26
|
<th></th>
|
25
27
|
<?r end ?>
|
26
28
|
</tr>
|
@@ -30,7 +32,8 @@
|
|
30
32
|
<tr>
|
31
33
|
<?r if user_authorized?([:delete]) ?>
|
32
34
|
<td>
|
33
|
-
<input type="checkbox" name="category_group_ids[]"
|
35
|
+
<input type="checkbox" name="category_group_ids[]"
|
36
|
+
value="#{group.id}" />
|
34
37
|
</td>
|
35
38
|
<?r end ?>
|
36
39
|
|
@@ -40,18 +43,20 @@
|
|
40
43
|
<td>
|
41
44
|
#{anchor_to(
|
42
45
|
group.name,
|
43
|
-
Categories::
|
46
|
+
Categories::Controller::CategoryGroups.r(:edit, group.id)
|
44
47
|
)}
|
45
48
|
</td>
|
46
49
|
<?r else ?>
|
47
50
|
<td>#{group.name}</td>
|
48
51
|
<?r end ?>
|
49
52
|
|
50
|
-
<?r if user_authorized?(
|
53
|
+
<?r if user_authorized?(
|
54
|
+
[:read], true, 'Categories::Controller::Categories'
|
55
|
+
) ?>
|
51
56
|
<td>
|
52
57
|
#{anchor_to(
|
53
58
|
lang('category_groups.labels.manage'),
|
54
|
-
Categories::
|
59
|
+
Categories::Controller::Categories.r(:index, group.id)
|
55
60
|
)}
|
56
61
|
</td>
|
57
62
|
<?r end ?>
|
@@ -70,7 +75,7 @@
|
|
70
75
|
<div class="button">
|
71
76
|
#{anchor_to(
|
72
77
|
lang('category_groups.buttons.new'),
|
73
|
-
Categories::
|
78
|
+
Categories::Controller::CategoryGroups.r(:new)
|
74
79
|
)}
|
75
80
|
</div>
|
76
81
|
<?r end ?>
|
@@ -1,25 +1,35 @@
|
|
1
|
+
require __DIR__('comments/model/comment.rb')
|
2
|
+
require __DIR__('comments/controller/comments')
|
3
|
+
require __DIR__('comments/controller/comments_form')
|
4
|
+
require __DIR__('comments/plugin/comments')
|
1
5
|
|
2
|
-
|
3
|
-
|
4
|
-
require __DIR__ 'comments/controller/comments'
|
5
|
-
require __DIR__ 'comments/controller/comments_form'
|
6
|
-
require __DIR__ 'comments/liquid/comments'
|
7
|
-
require __DIR__ 'comments/liquid/comment_form'
|
8
|
-
|
9
|
-
Liquid::Template.register_tag('comments' , Comments::Liquid::Comments)
|
10
|
-
Liquid::Template.register_tag('comment_form', Comments::Liquid::CommentForm)
|
6
|
+
Zen::Language.options.paths.push(__DIR__('comments'))
|
7
|
+
Zen::Language.load('comments')
|
11
8
|
|
12
9
|
Zen::Package.add do |p|
|
13
|
-
p.name = '
|
10
|
+
p.name = 'comments'
|
14
11
|
p.author = 'Yorick Peterse'
|
15
12
|
p.url = 'http://yorickpeterse.com/'
|
16
|
-
p.about = "Allow users to post comments on any given section entry (as long as
|
17
|
-
|
13
|
+
p.about = "Allow users to post comments on any given section entry (as long as
|
14
|
+
the section allows it)."
|
15
|
+
|
18
16
|
p.directory = __DIR__('comments')
|
19
17
|
p.migration_dir = __DIR__('../migrations')
|
20
18
|
|
21
19
|
p.menu = [{
|
22
|
-
:title =>
|
20
|
+
:title => lang('comments.titles.index'),
|
23
21
|
:url => "admin/comments"
|
24
22
|
}]
|
23
|
+
|
24
|
+
p.controllers = {
|
25
|
+
lang('comments.titles.index') => Comments::Controller::Comments
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
Zen::Plugin.add do |p|
|
30
|
+
p.name = 'comments'
|
31
|
+
p.author = 'Yorick Peterse'
|
32
|
+
p.url = 'http://yorickpeterse.com/'
|
33
|
+
p.about = 'Plugin that can be used to retrieve comments.'
|
34
|
+
p.plugin = Comments::Plugin::Comments
|
25
35
|
end
|