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
@@ -1,32 +1,48 @@
|
|
1
|
+
require __DIR__('sections/model/section')
|
2
|
+
require __DIR__('sections/model/section_entry')
|
3
|
+
require __DIR__('sections/controller/sections')
|
4
|
+
require __DIR__('sections/controller/section_entries')
|
5
|
+
require __DIR__('sections/plugin/sections')
|
6
|
+
require __DIR__('sections/plugin/section_entries')
|
1
7
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require __DIR__ 'sections/controller/sections'
|
6
|
-
require __DIR__ 'sections/controller/section_entries'
|
8
|
+
Zen::Language.options.paths.push(__DIR__('sections'))
|
9
|
+
Zen::Language.load('sections')
|
10
|
+
Zen::Language.load('section_entries')
|
7
11
|
|
8
|
-
# Load and register all our liquid tags
|
9
|
-
require __DIR__ 'sections/liquid/section_entries'
|
10
|
-
require __DIR__ 'sections/liquid/sections'
|
11
|
-
|
12
|
-
Liquid::Template.register_tag('sections', Sections::Liquid::Sections)
|
13
|
-
Liquid::Template.register_tag('section_entries', Sections::Liquid::SectionEntries)
|
14
|
-
|
15
|
-
# Describe what this extension is all about
|
16
12
|
Zen::Package.add do |p|
|
17
|
-
p.name = '
|
13
|
+
p.name = 'sections'
|
18
14
|
p.author = 'Yorick Peterse'
|
19
15
|
p.url = 'http://yorickpeterse.com/'
|
20
16
|
p.about = "The sections module allows users to create and manage sections.
|
21
17
|
Sections can be seen as small web applications that live inside the CMS.
|
22
18
|
For example, you could have a section for your blog and for your pages."
|
23
19
|
|
24
|
-
p.identifier = 'com.zen.sections'
|
25
20
|
p.directory = __DIR__('sections')
|
26
21
|
p.migration_dir = __DIR__('../migrations')
|
27
22
|
|
28
23
|
p.menu = [{
|
29
|
-
:title =>
|
24
|
+
:title => lang('sections.titles.index'),
|
30
25
|
:url => "admin"
|
31
26
|
}]
|
27
|
+
|
28
|
+
p.controllers = {
|
29
|
+
lang('sections.titles.index') => Sections::Controller::Sections,
|
30
|
+
lang('section_entries.titles.index') => Sections::Controller::SectionEntries
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
Zen::Plugin.add do |p|
|
35
|
+
p.name = 'sections'
|
36
|
+
p.author = 'Yorick Peterse'
|
37
|
+
p.about = 'Plugin for retrieving multiple or individual sections.'
|
38
|
+
p.url = 'http://yorickpeterse.com/'
|
39
|
+
p.plugin = Sections::Plugin::Sections
|
40
|
+
end
|
41
|
+
|
42
|
+
Zen::Plugin.add do |p|
|
43
|
+
p.name = 'section_entries'
|
44
|
+
p.author = 'Yorick Peterse'
|
45
|
+
p.about = 'Plugin for retrieving multiple or individual section entries.'
|
46
|
+
p.url = 'http://yorickpeterse.com/'
|
47
|
+
p.plugin = Sections::Plugin::SectionEntries
|
32
48
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Sections
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
##
|
6
6
|
# Section entries can be seen as blog entries, products, all sorts of things.
|
7
7
|
# Each section belongs to a section and can't be created without one.
|
@@ -9,12 +9,11 @@ module Sections
|
|
9
9
|
# @author Yorick Peterse
|
10
10
|
# @since 0.1
|
11
11
|
#
|
12
|
-
class SectionEntries < Zen::
|
13
|
-
include ::Sections::
|
14
|
-
|
15
|
-
map '/admin/section-entries'
|
16
|
-
trait :extension_identifier => 'com.zen.sections'
|
12
|
+
class SectionEntries < Zen::Controller::AdminController
|
13
|
+
include ::Sections::Model
|
17
14
|
|
15
|
+
map('/admin/section-entries')
|
16
|
+
|
18
17
|
before_all do
|
19
18
|
csrf_protection(:save, :delete) do
|
20
19
|
respond(lang('zen_general.errors.csrf'), 403)
|
@@ -49,14 +48,6 @@ module Sections
|
|
49
48
|
@page_title = lang("section_entries.titles.#{method}") rescue nil
|
50
49
|
end
|
51
50
|
|
52
|
-
# Load our datepicker that ships with Zen itself
|
53
|
-
require_js(
|
54
|
-
'vendor/datepicker/Picker', 'vendor/datepicker/Picker.Attach',
|
55
|
-
'vendor/datepicker/Picker.Date', 'vendor/datepicker/locale'
|
56
|
-
)
|
57
|
-
|
58
|
-
require_css('datepicker')
|
59
|
-
|
60
51
|
@status_hash = {
|
61
52
|
'draft' => lang('section_entries.special.status_hash.draft'),
|
62
53
|
'published' => lang('section_entries.special.status_hash.published')
|
@@ -123,7 +114,7 @@ module Sections
|
|
123
114
|
|
124
115
|
@users_hash = {}
|
125
116
|
|
126
|
-
Users::
|
117
|
+
Users::Model::User.each { |u| @users_hash[u.id] = u.name }
|
127
118
|
end
|
128
119
|
|
129
120
|
##
|
@@ -153,7 +144,7 @@ module Sections
|
|
153
144
|
@entry = SectionEntry.new(:section_id => @section_id)
|
154
145
|
@users_hash = {}
|
155
146
|
|
156
|
-
Users::
|
147
|
+
Users::Model::User.each { |u| @users_hash[u.id] = u.name }
|
157
148
|
end
|
158
149
|
|
159
150
|
##
|
@@ -172,7 +163,7 @@ module Sections
|
|
172
163
|
# patches as it executes quite a few queries. I'll keep it as it is for now.
|
173
164
|
#
|
174
165
|
def save
|
175
|
-
if !user_authorized?([:create, :
|
166
|
+
if !user_authorized?([:create, :update])
|
176
167
|
respond(lang('zen_general.errors.not_authorized'), 403)
|
177
168
|
end
|
178
169
|
|
@@ -214,7 +205,7 @@ module Sections
|
|
214
205
|
|
215
206
|
# Update the field values
|
216
207
|
field_values.each do |field_id, value|
|
217
|
-
field_value = CustomFields::
|
208
|
+
field_value = CustomFields::Model::CustomFieldValue[
|
218
209
|
:custom_field_id => field_id,
|
219
210
|
:section_entry_id => @entry.id
|
220
211
|
]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Sections
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
##
|
6
6
|
# Sections can be seen as mini applications inside your website.
|
7
7
|
# Examples of sections can be a blog, pages, a products listing, etc.
|
@@ -14,11 +14,10 @@ module Sections
|
|
14
14
|
# @author Yorick Peterse
|
15
15
|
# @since 0.1
|
16
16
|
#
|
17
|
-
class Sections < Zen::
|
18
|
-
include ::Sections::
|
17
|
+
class Sections < Zen::Controller::AdminController
|
18
|
+
include ::Sections::Model
|
19
19
|
|
20
|
-
map
|
21
|
-
trait :extension_identifier => 'com.zen.sections'
|
20
|
+
map('/admin')
|
22
21
|
|
23
22
|
before_all do
|
24
23
|
csrf_protection(:save, :delete) do
|
@@ -95,8 +94,8 @@ module Sections
|
|
95
94
|
@page_title
|
96
95
|
)
|
97
96
|
|
98
|
-
@custom_field_group_pk_hash = CustomFields::
|
99
|
-
@category_group_pk_hash = Categories::
|
97
|
+
@custom_field_group_pk_hash = CustomFields::Model::CustomFieldGroup.pk_hash(:name)
|
98
|
+
@category_group_pk_hash = Categories::Model::CategoryGroup.pk_hash(:name)
|
100
99
|
|
101
100
|
if flash[:form_data]
|
102
101
|
@section = flash[:form_data]
|
@@ -126,8 +125,8 @@ module Sections
|
|
126
125
|
@page_title
|
127
126
|
)
|
128
127
|
|
129
|
-
@custom_field_group_pk_hash = CustomFields::
|
130
|
-
@category_group_pk_hash = Categories::
|
128
|
+
@custom_field_group_pk_hash = CustomFields::Model::CustomFieldGroup.pk_hash(:name)
|
129
|
+
@category_group_pk_hash = Categories::Model::CategoryGroup.pk_hash(:name)
|
131
130
|
@section = Section.new
|
132
131
|
end
|
133
132
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Sections
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Model
|
5
5
|
##
|
6
6
|
# Model that represents a single section. This model has the following
|
7
7
|
# relations:
|
@@ -20,18 +20,18 @@ module Sections
|
|
20
20
|
class Section < Sequel::Model
|
21
21
|
one_to_many(
|
22
22
|
:section_entries,
|
23
|
-
:class => "Sections::
|
23
|
+
:class => "Sections::Model::SectionEntry",
|
24
24
|
:eager => [:custom_field_values]
|
25
25
|
)
|
26
26
|
|
27
27
|
many_to_many(
|
28
28
|
:custom_field_groups,
|
29
|
-
:class => "CustomFields::
|
29
|
+
:class => "CustomFields::Model::CustomFieldGroup"
|
30
30
|
)
|
31
31
|
|
32
32
|
many_to_many(
|
33
33
|
:category_groups,
|
34
|
-
:class => "Categories::
|
34
|
+
:class => "Categories::Model::CategoryGroup"
|
35
35
|
)
|
36
36
|
|
37
37
|
plugin(:sluggable, :source => :name, :freeze => false)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Sections
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Model
|
5
5
|
##
|
6
6
|
# Model that represents a singe section entry. This model has the following
|
7
7
|
# relations:
|
@@ -19,21 +19,19 @@ module Sections
|
|
19
19
|
# @author Yorick Peterse
|
20
20
|
# @since 0.1
|
21
21
|
#
|
22
|
-
class SectionEntry < Sequel::Model
|
23
|
-
|
24
|
-
|
25
|
-
:class => "Comments::Models::Comment"
|
26
|
-
)
|
22
|
+
class SectionEntry < Sequel::Model
|
23
|
+
|
24
|
+
one_to_many(:comments, :class => "Comments::Model::Comment")
|
27
25
|
|
28
26
|
one_to_many(
|
29
27
|
:custom_field_values,
|
30
|
-
:class => "CustomFields::
|
28
|
+
:class => "CustomFields::Model::CustomFieldValue",
|
31
29
|
:eager => [:custom_field]
|
32
30
|
)
|
33
31
|
|
34
|
-
many_to_one(:user , :class => "Users::
|
35
|
-
many_to_many(:categories, :class => "Categories::
|
36
|
-
many_to_one(:section , :class => "Sections::
|
32
|
+
many_to_one(:user , :class => "Users::Model::User")
|
33
|
+
many_to_many(:categories, :class => "Categories::Model::Category")
|
34
|
+
many_to_one(:section , :class => "Sections::Model::Section")
|
37
35
|
|
38
36
|
plugin(:sluggable , :source => :title , :freeze => false)
|
39
37
|
plugin(:timestamps, :create => :created_at, :update => false)
|
@@ -48,6 +46,7 @@ module Sections
|
|
48
46
|
validates_presence([:title, :status, :user_id])
|
49
47
|
validates_presence(:slug) unless new?
|
50
48
|
end
|
49
|
+
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
#:nodoc:
|
2
|
+
module Sections
|
3
|
+
#:nodoc:
|
4
|
+
module Plugin
|
5
|
+
##
|
6
|
+
# The SectionEntries plugin can be used to retrieve section entries as well as the
|
7
|
+
# associated comments and user data. This allows you to relatively easily build a list
|
8
|
+
# of entries (e.g. blog articles) without having to retrieve and process the
|
9
|
+
# associated data manually.
|
10
|
+
#
|
11
|
+
# ## Usage
|
12
|
+
#
|
13
|
+
# Basic usage is as following:
|
14
|
+
#
|
15
|
+
# entries = plugin(:section_entries, :limit => 10, :section => 'blog')
|
16
|
+
# entries.each do |e|
|
17
|
+
# puts e[:title]
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# The values of custom fields are stored under the key :fields. This key contains a
|
21
|
+
# hash where the keys are the slugs of the custom fields and the values the values for
|
22
|
+
# the current entry.
|
23
|
+
#
|
24
|
+
# entries.each do |e|
|
25
|
+
# e[:fields][:thumbnail]
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# User data can be found in the key :user:
|
29
|
+
#
|
30
|
+
# entries.each do |e|
|
31
|
+
# e[:user][:name]
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Last but not least, comments can be found under the key :comments:
|
35
|
+
#
|
36
|
+
# entries.each do |e|
|
37
|
+
# e[:comments].each do |c|
|
38
|
+
# c[:comment]
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# For a full list of available options see Sections::Plugin::SectionEntries.initialize.
|
43
|
+
#
|
44
|
+
# @author Yorick Peterse
|
45
|
+
# @since 0.2.5
|
46
|
+
#
|
47
|
+
class SectionEntries
|
48
|
+
include ::Zen::Plugin::Helper
|
49
|
+
include ::Sections::Model
|
50
|
+
|
51
|
+
##
|
52
|
+
# Creates a new instance of the plugin and validates/stores the given configuration
|
53
|
+
# options. Please note that you always need to either specify a section from which
|
54
|
+
# to retrieve all entries or a single entry in order to use this plugin. You can
|
55
|
+
# retrieve a list of entries (or just a single one) by specifying the ID or the
|
56
|
+
# slug:
|
57
|
+
#
|
58
|
+
# plugin(:section_entries, :section => 'blog')
|
59
|
+
# plugin(:section_entries, :section => 10)
|
60
|
+
#
|
61
|
+
# @author Yorick Peterse
|
62
|
+
# @since 0.2.5
|
63
|
+
# @param [Hash] options Hash with a collection of custom configuration options that
|
64
|
+
# determine how and what entries should be retrieved.
|
65
|
+
# @option options [Fixnum/Integer] :limit
|
66
|
+
# @option options [Fixnum/Integer] :offset
|
67
|
+
# @option options [NilClass/String/Integer/Fixnum] :section
|
68
|
+
# @option options [NilClass/String/Integer/Fixnum] :entry
|
69
|
+
# @option options [TrueClass] :markup When set to true the markup of all entries will
|
70
|
+
# be converted to the desired output (usually this is HTML).
|
71
|
+
# @option options [TrueClass] :comments When set to true all comments for each entry
|
72
|
+
# will be retrieved.
|
73
|
+
# @option options [TrueClass] :comment_markup When set to true the markup of comments
|
74
|
+
# will be converted to the desired output.
|
75
|
+
# @option options [TrueClass] :categories When set to true all categories for each
|
76
|
+
# entry will be retrieved as well.
|
77
|
+
#
|
78
|
+
def initialize(options = {})
|
79
|
+
@options = {
|
80
|
+
:limit => 20,
|
81
|
+
:offset => 0,
|
82
|
+
:section => nil,
|
83
|
+
:entry => nil,
|
84
|
+
:markup => true,
|
85
|
+
:comments => true,
|
86
|
+
:comment_markup => true,
|
87
|
+
:categories => true
|
88
|
+
}.merge(options)
|
89
|
+
|
90
|
+
validate_type(@options[:limit] , :limit , [Fixnum, Integer])
|
91
|
+
validate_type(@options[:offset] , :limit , [Fixnum, Integer])
|
92
|
+
validate_type(@options[:section] , :section , [NilClass, String, Integer, Fixnum])
|
93
|
+
validate_type(@options[:entry] , :entry , [NilClass, String, Integer, Fixnum])
|
94
|
+
validate_type(@options[:markup] , :markup , [TrueClass, FalseClass])
|
95
|
+
validate_type(@options[:comments], :comments, [TrueClass, FalseClass])
|
96
|
+
|
97
|
+
if @options[:section].nil? and @options[:entry].nil?
|
98
|
+
raise(
|
99
|
+
ArgumentError,
|
100
|
+
"You need to specify either an entry or a section to retrieve."
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# Fetches all the data and converts everything to a hash. Once this is done either
|
107
|
+
# an array of entries or a single entry hash will be returned.
|
108
|
+
#
|
109
|
+
# @author Yorick Peterse
|
110
|
+
# @since 0.2.5
|
111
|
+
# @return [Array/Hash]
|
112
|
+
#
|
113
|
+
def call
|
114
|
+
# Create the list with models to load using eager()
|
115
|
+
eager_models = [:custom_field_values, :categories, :section, :user]
|
116
|
+
filter_hash = {}
|
117
|
+
|
118
|
+
if @options[:comments] === true
|
119
|
+
eager_models.push(:comments)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Retrieve multiple entries
|
123
|
+
if !@options[:section].nil?
|
124
|
+
# Retrieve the section by it's slug
|
125
|
+
if @options[:section].class == String
|
126
|
+
section_id = Section[:slug => @options[:section]].id
|
127
|
+
else
|
128
|
+
section_id = @options[:section]
|
129
|
+
end
|
130
|
+
|
131
|
+
filter_hash[:section_id] = section_id
|
132
|
+
end
|
133
|
+
|
134
|
+
# Retrieve a specific entry
|
135
|
+
if !@options[:entry].nil?
|
136
|
+
# Retrieve it by it's slug
|
137
|
+
if @options[:entry].class == String
|
138
|
+
filter_hash[:slug] = @options[:entry]
|
139
|
+
# Retrieve the entry by it's ID
|
140
|
+
else
|
141
|
+
filter_hash[:id] = @options[:entry]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Get the entries
|
146
|
+
entries = SectionEntry.filter(filter_hash)
|
147
|
+
.eager(*eager_models)
|
148
|
+
.limit(@options[:limit], @options[:offset])
|
149
|
+
.all
|
150
|
+
|
151
|
+
comment_format = nil
|
152
|
+
|
153
|
+
# Loop through all entries so we can process our custom field values
|
154
|
+
entries.each_with_index do |entry, index|
|
155
|
+
if comment_format.nil?
|
156
|
+
comment_format = entry.section.comment_format
|
157
|
+
end
|
158
|
+
|
159
|
+
field_values = {}
|
160
|
+
user = {}
|
161
|
+
comments = []
|
162
|
+
categories = []
|
163
|
+
|
164
|
+
# Store all the custom field values
|
165
|
+
entry.custom_field_values.each do |v|
|
166
|
+
name = v.custom_field.slug.to_sym
|
167
|
+
value = v.value
|
168
|
+
|
169
|
+
# Convert the markup
|
170
|
+
if @options[:markup] === true
|
171
|
+
value = plugin(:markup, v.custom_field.format, value)
|
172
|
+
end
|
173
|
+
|
174
|
+
field_values[name] = value
|
175
|
+
end
|
176
|
+
|
177
|
+
# Get all the comments if the developer wants them
|
178
|
+
if @options[:comments] === true
|
179
|
+
entry.comments.each do |c|
|
180
|
+
comment = c.values
|
181
|
+
|
182
|
+
if c.user
|
183
|
+
comment[:user] = c.user.values
|
184
|
+
end
|
185
|
+
|
186
|
+
# Convert the comment's markup
|
187
|
+
if @options[:comment_markup]
|
188
|
+
comment[:comment] = plugin(:markup, comment_format, comment[:comment])
|
189
|
+
end
|
190
|
+
|
191
|
+
comments.push(comment)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Get the user data
|
196
|
+
if !entry.user.nil?
|
197
|
+
user = entry.user.values
|
198
|
+
end
|
199
|
+
|
200
|
+
# Get all categories
|
201
|
+
categories = entry.categories.map do |cat|
|
202
|
+
cat.values
|
203
|
+
end
|
204
|
+
|
205
|
+
# Convert the entry to a hash and re-assign all data
|
206
|
+
entry = entry.values
|
207
|
+
entry[:fields] = field_values
|
208
|
+
entry[:user] = user
|
209
|
+
entry[:comments] = comments
|
210
|
+
entry[:categories] = categories
|
211
|
+
entries[index] = entry
|
212
|
+
end
|
213
|
+
|
214
|
+
# Do we only want a single entry?
|
215
|
+
if !@options[:entry].nil?
|
216
|
+
entries = entries[0]
|
217
|
+
end
|
218
|
+
|
219
|
+
return entries
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|