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,127 +0,0 @@
|
|
1
|
-
require 'ramaze/gestalt'
|
2
|
-
|
3
|
-
#:nodoc:
|
4
|
-
module Comments
|
5
|
-
#:nodoc:
|
6
|
-
module Liquid
|
7
|
-
##
|
8
|
-
# Liquid tag that can be used to generate the required form elements for submitting
|
9
|
-
# comments. It's important to remember that you still need to define your own
|
10
|
-
# form fields such as those for the name and Email, this tag merely generates
|
11
|
-
# the form open/closing tags and a few hidden fields. The following field (names)
|
12
|
-
# are required when creating a comment form:
|
13
|
-
#
|
14
|
-
# * name
|
15
|
-
# * website
|
16
|
-
# * email
|
17
|
-
# * comment
|
18
|
-
#
|
19
|
-
# Basic usage of this tag is as following:
|
20
|
-
#
|
21
|
-
# {% comment_form section_entry="hello-world" %}
|
22
|
-
#
|
23
|
-
# <p>
|
24
|
-
# <label for="name">Name</label>
|
25
|
-
# <input type="text" name="name" id="name" />
|
26
|
-
# </p>
|
27
|
-
#
|
28
|
-
# <input type="submit" value="Submit comment" />
|
29
|
-
#
|
30
|
-
# {% endcomment_form %}
|
31
|
-
#
|
32
|
-
# The following arguments can be used:
|
33
|
-
#
|
34
|
-
# * section_entry: the slug of the entry
|
35
|
-
# * section_entry_id: the ID of the entry
|
36
|
-
#
|
37
|
-
# @author Yorick Peterse
|
38
|
-
# @since 0.1
|
39
|
-
#
|
40
|
-
class CommentForm < ::Liquid::Block
|
41
|
-
include ::Zen::Liquid::General
|
42
|
-
include ::Zen::Liquid::ControllerBehavior
|
43
|
-
include ::Ramaze::Helper::CSRF
|
44
|
-
include ::Ramaze::Helper::BlueForm
|
45
|
-
|
46
|
-
##
|
47
|
-
# Creates a new instance of the block and passes the tag name,
|
48
|
-
# all additional arguments and the HTML to the constructor method.
|
49
|
-
#
|
50
|
-
# @author Yorick Peterse
|
51
|
-
# @param [String] tag_name The name of the tag that was called.
|
52
|
-
# @param [String] arguments All additional arguments passed as a string.
|
53
|
-
# @param [String] html The HTML inside the block.
|
54
|
-
# @since 0.1
|
55
|
-
#
|
56
|
-
def initialize(tag_name = 'comments_form', arguments = '', html = '')
|
57
|
-
super
|
58
|
-
|
59
|
-
@arguments = parse_key_values(arguments)
|
60
|
-
@args_parsed = false
|
61
|
-
end
|
62
|
-
|
63
|
-
##
|
64
|
-
# Renders the tag block.
|
65
|
-
#
|
66
|
-
# @author Yorick Peterse
|
67
|
-
# @since 0.1
|
68
|
-
#
|
69
|
-
def render(context)
|
70
|
-
if @args_parsed == false
|
71
|
-
@arguments.each do |k, v|
|
72
|
-
v = v.to_s
|
73
|
-
|
74
|
-
if context.has_key?(v)
|
75
|
-
@arguments[k] = h(context[v])
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
@args_parsed = true
|
81
|
-
g = Ramaze::Gestalt.new
|
82
|
-
user_html = ''
|
83
|
-
|
84
|
-
super(context).each { |h| user_html += h }
|
85
|
-
|
86
|
-
# Get our section to which this form belongs
|
87
|
-
if @arguments.key?('section_entry')
|
88
|
-
section_entry = ::Sections::Models::SectionEntry[
|
89
|
-
:slug => @arguments['section_entry']
|
90
|
-
]
|
91
|
-
else
|
92
|
-
section_entry = ::Sections::Models::SectionEntry[
|
93
|
-
@arguments['section_entry_id'].to_i
|
94
|
-
]
|
95
|
-
end
|
96
|
-
|
97
|
-
# Get the section entry's ID
|
98
|
-
if !section_entry.nil?
|
99
|
-
section_entry_id = section_entry.id
|
100
|
-
else
|
101
|
-
section_entry_id = nil
|
102
|
-
end
|
103
|
-
|
104
|
-
# Get the user's ID if he/she is logged in
|
105
|
-
if !session[:user].nil?
|
106
|
-
user_id = session[:user].id
|
107
|
-
else
|
108
|
-
user_id = nil
|
109
|
-
end
|
110
|
-
|
111
|
-
g_html = form_for(
|
112
|
-
nil,
|
113
|
-
:method => :post,
|
114
|
-
:action => Comments::Controllers::CommentsForm.r(:save)
|
115
|
-
) do |f|
|
116
|
-
f.input_hidden(:csrf_token , get_csrf_token)
|
117
|
-
f.input_hidden(:section_entry, section_entry_id)
|
118
|
-
f.input_hidden(:user_id , user_id)
|
119
|
-
|
120
|
-
user_html
|
121
|
-
end
|
122
|
-
|
123
|
-
return g_html
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
#:nodoc:
|
2
|
-
module Comments
|
3
|
-
#:nodoc:
|
4
|
-
module Liquid
|
5
|
-
##
|
6
|
-
# Tag that can be used to display a number of comments based on the section entry ID
|
7
|
-
# or the slug of a section entry.
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# {% comments section_entry="hello-world" limit="10" %}
|
11
|
-
# {{comment}}
|
12
|
-
# {% endcomments %}
|
13
|
-
#
|
14
|
-
# The following arguments can be used for this tag:
|
15
|
-
#
|
16
|
-
# * section_entry: the slug of the section entry for which to retrieve all comments
|
17
|
-
# * limit: the amount of comments to retriee
|
18
|
-
# * offset: the offset from which to start retrieving comments
|
19
|
-
#
|
20
|
-
# @author Yorick Peterse
|
21
|
-
# @since 0.1
|
22
|
-
#
|
23
|
-
class Comments < ::Liquid::Block
|
24
|
-
include ::Ramaze::Helper::CGI
|
25
|
-
include ::Zen::Liquid::General
|
26
|
-
|
27
|
-
##
|
28
|
-
# Creates a new instance of the block and passes the tag name,
|
29
|
-
# all additional arguments and the HTML to the constructor method.
|
30
|
-
#
|
31
|
-
# @author Yorick Peterse
|
32
|
-
# @param [String] tag_name The name of the tag that was called.
|
33
|
-
# @param [String] arguments All additional arguments passed as a string.
|
34
|
-
# @param [String] html The HTML inside the block.
|
35
|
-
# @since 0.1
|
36
|
-
#
|
37
|
-
def initialize(tag_name = 'comments', arguments = '', html = '')
|
38
|
-
super
|
39
|
-
|
40
|
-
@arguments = {
|
41
|
-
'limit' => nil,
|
42
|
-
'offset' => nil
|
43
|
-
}.merge(parse_key_values(arguments))
|
44
|
-
|
45
|
-
@args_parsed = false
|
46
|
-
|
47
|
-
if !@arguments.key?('section_entry') or @arguments['section_entry'].empty?
|
48
|
-
raise(
|
49
|
-
ArgumentError,
|
50
|
-
"You need to specify a section entry's slug in order to retrieve a set of comments"
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
##
|
56
|
-
# Retrieves all comments and renders the tag block.
|
57
|
-
#
|
58
|
-
# @author Yorick Peterse
|
59
|
-
# @since 0.1
|
60
|
-
#
|
61
|
-
def render context
|
62
|
-
if @args_parsed == false
|
63
|
-
@arguments = merge_context(@arguments, context)
|
64
|
-
end
|
65
|
-
|
66
|
-
@args_parsed = true
|
67
|
-
result = []
|
68
|
-
filter_hash = {:status => 'open'}
|
69
|
-
comments = []
|
70
|
-
format = nil
|
71
|
-
|
72
|
-
if @arguments.key?('section_entry')
|
73
|
-
entry = ::Sections::Models::SectionEntry[:slug => @arguments['section_entry']]
|
74
|
-
|
75
|
-
return if entry.nil?
|
76
|
-
filter_hash[:section_entry_id] = entry.id
|
77
|
-
end
|
78
|
-
|
79
|
-
comments = ::Comments::Models::Comment
|
80
|
-
.eager(:user, :section_entry)
|
81
|
-
.filter(filter_hash)
|
82
|
-
.limit(@arguments['limit'], @arguments['offset'])
|
83
|
-
|
84
|
-
context['total_rows'] = comments.count
|
85
|
-
|
86
|
-
comments.each_with_index do |comment, index|
|
87
|
-
context['index'] = index
|
88
|
-
|
89
|
-
if format.nil?
|
90
|
-
section = comment.section_entry.section
|
91
|
-
format = section.comment_format
|
92
|
-
end
|
93
|
-
|
94
|
-
comment.values.each { |k, v| context[k.to_s] = v }
|
95
|
-
|
96
|
-
# Convert the comment body into HTML
|
97
|
-
context['comment'] = Zen::Plugin.call(
|
98
|
-
'com.zen.plugin.markup', format.to_sym, context['comment']
|
99
|
-
)
|
100
|
-
|
101
|
-
['email', 'name', 'website'].each do |c|
|
102
|
-
if context[c].nil? or context[c].empty?
|
103
|
-
context[c] = comment.user.send(c)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
result.push(render_all(@nodelist, context))
|
108
|
-
end
|
109
|
-
|
110
|
-
result.push(render_all(@nodelist, context)) if result.empty?
|
111
|
-
return result
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
require 'ramaze/gestalt'
|
2
|
-
|
3
|
-
#:nodoc:
|
4
|
-
module Menus
|
5
|
-
#:nodoc:
|
6
|
-
module Liquid
|
7
|
-
##
|
8
|
-
# The menus tag can be used to display all menu items for a given menu slug or ID.
|
9
|
-
# Basic usage of this tag is as following:
|
10
|
-
#
|
11
|
-
# {% menus slug="main" %}
|
12
|
-
#
|
13
|
-
# Given we had a menu of which the slug is "main" the output would look like the this:
|
14
|
-
#
|
15
|
-
# <ul>
|
16
|
-
# <li>
|
17
|
-
# <a href="http://zen-cms.com/" title="Zen CMS">Zen CMS</a>
|
18
|
-
# </li>
|
19
|
-
# </ul>
|
20
|
-
#
|
21
|
-
# This tag takes the following arguments:
|
22
|
-
#
|
23
|
-
# * slug: the slug of the menu for which to retrieve all items.
|
24
|
-
# * id: the ID of the menu for which to retrieve all items.
|
25
|
-
# * order: string (either "asc" or "desc") that will be used to order the menu items.
|
26
|
-
#
|
27
|
-
# If both the slug and ID are specified the ID will be used instead of the slug.
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# {% menus slug="main" order="asc" %}
|
31
|
-
#
|
32
|
-
# @author Yorick Peterse
|
33
|
-
# @since 0.2a
|
34
|
-
#
|
35
|
-
class Menus < ::Liquid::Tag
|
36
|
-
include ::Zen::Liquid::General
|
37
|
-
|
38
|
-
##
|
39
|
-
# Initializes the tag class and converts the arguments string into a key/value
|
40
|
-
# hash.
|
41
|
-
#
|
42
|
-
# @author Yorick Peterse
|
43
|
-
# @since 0.2a
|
44
|
-
# @param [String] tag_name The name of the tag ("menus").
|
45
|
-
# @param [String] arguments All arguments passed as key="value" combinations.
|
46
|
-
# @param [String] tokens All tokens passed to the tag.
|
47
|
-
#
|
48
|
-
def initialize(tag_name = 'menus', arguments = '', tokens = '')
|
49
|
-
super
|
50
|
-
|
51
|
-
@arguments = {
|
52
|
-
'order' => 'desc'
|
53
|
-
}.merge(parse_key_values(arguments))
|
54
|
-
|
55
|
-
@args_parsed = false
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# Retrieves the specified menu, generates the HTML and renders the Liquid template.
|
60
|
-
#
|
61
|
-
# @author Yorick Peterse
|
62
|
-
# @since 0.2a
|
63
|
-
# @param [Liquid::Context] context The current Liquid instance.
|
64
|
-
# @return [String] The HTML for the specified navigation menu.
|
65
|
-
#
|
66
|
-
def render(context)
|
67
|
-
if @args_parsed == false
|
68
|
-
@arguments = merge_context(@arguments, context)
|
69
|
-
end
|
70
|
-
|
71
|
-
@args_parsed = true
|
72
|
-
menu_items = []
|
73
|
-
|
74
|
-
if @arguments.key?('id')
|
75
|
-
menu = ::Menus::Models::Menu[@arguments['slug'].to_i]
|
76
|
-
|
77
|
-
elsif @arguments.key?('slug')
|
78
|
-
menu = ::Menus::Models::Menu[:slug => @arguments['slug']]
|
79
|
-
|
80
|
-
else
|
81
|
-
raise(
|
82
|
-
ArgumentError,
|
83
|
-
"You need to specify either the ID or the slug in order to retrieve a menu."
|
84
|
-
)
|
85
|
-
end
|
86
|
-
|
87
|
-
return if menu.nil?
|
88
|
-
|
89
|
-
menu_items = ::Menus::Models::MenuItem.filter(:menu_id => menu.id)
|
90
|
-
.order(:order.send(@arguments['order']))
|
91
|
-
|
92
|
-
# Build the navigation menu
|
93
|
-
@g = ::Ramaze::Gestalt.new
|
94
|
-
attributes = {}
|
95
|
-
attributes[:class] = menu.css_class if !menu.css_class.nil?
|
96
|
-
attributes[:id] = menu.css_id if !menu.css_id.nil?
|
97
|
-
|
98
|
-
# Organize all menu items in a parent/child hierachy
|
99
|
-
items_ordered = {}
|
100
|
-
|
101
|
-
@g.ul(attributes) do
|
102
|
-
menu_items.each do |item|
|
103
|
-
if item.parent_id.nil?
|
104
|
-
self.menu_item(item)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
return @g.to_s
|
110
|
-
end
|
111
|
-
|
112
|
-
##
|
113
|
-
# Helper method used for generating a <li> and <a> tag for the current navigation
|
114
|
-
# item. If the item has any sub items those will be generated as well.
|
115
|
-
#
|
116
|
-
# @author Yorick Peterse
|
117
|
-
# @since 0.2a
|
118
|
-
# @param [Object] item The current navigation item
|
119
|
-
#
|
120
|
-
def menu_item(item)
|
121
|
-
attributes = {}
|
122
|
-
|
123
|
-
if !item.css_class.nil? and !item.css_class.empty?
|
124
|
-
attributes[:class] = item.css_class
|
125
|
-
end
|
126
|
-
|
127
|
-
if !item.css_id.nil? and !item.css_id.empty?
|
128
|
-
attributes[:id] = item.css_id
|
129
|
-
end
|
130
|
-
|
131
|
-
children = item.children
|
132
|
-
|
133
|
-
@g.li(attributes) do
|
134
|
-
if !item.url.nil? and !item.url.empty?
|
135
|
-
@g.a(:href => item.url, :title => item.name) { item.name }
|
136
|
-
else
|
137
|
-
@g.span { item.name }
|
138
|
-
end
|
139
|
-
|
140
|
-
if !children.empty?
|
141
|
-
@g.ul(:class => :children) do
|
142
|
-
item.children.each do |i|
|
143
|
-
self.menu_item(i)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end # end of @g.li(attributes) do
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
@@ -1,228 +0,0 @@
|
|
1
|
-
#:nodoc:
|
2
|
-
module Sections
|
3
|
-
#:nodoc:
|
4
|
-
module Liquid
|
5
|
-
##
|
6
|
-
# The SectionEntries tag can be used to retrieve all section entries
|
7
|
-
# for the given section. A basic example of this looks like the following:
|
8
|
-
#
|
9
|
-
# {% section_entries section="blog" %}
|
10
|
-
# Do something in here
|
11
|
-
# {% endsection_entries %}
|
12
|
-
#
|
13
|
-
# When using this tag you can specify the following optionally arguments:
|
14
|
-
#
|
15
|
-
# * section: the slug of the section for which to retrieve all entries
|
16
|
-
# * limit: the amount of entries to retrieve
|
17
|
-
# * offset: the offset from which to start selecting entries
|
18
|
-
# * section_entry: the slug of the section entry to select
|
19
|
-
# * order: the sort order type
|
20
|
-
# * order_by: the name of the column to sort on
|
21
|
-
# * category: retrieves all entries that are using the specified category
|
22
|
-
#
|
23
|
-
# These arguments can be specified as following:
|
24
|
-
#
|
25
|
-
# {% section_entries section="blog" limit="10" offset="20" %}
|
26
|
-
# Do something in here
|
27
|
-
# {% endsection_entries %}
|
28
|
-
#
|
29
|
-
# Inside this block you can output the values of your custom fields by
|
30
|
-
# calling the variable tag containing the name of the custom field. For example,
|
31
|
-
# if you have a field called "body" you can output it for each entry as following:
|
32
|
-
#
|
33
|
-
# {% section_entries section="blog" limit="10" offset="20" %}
|
34
|
-
# {{body}}
|
35
|
-
# {% endsection_entries %}
|
36
|
-
#
|
37
|
-
# The following variables are available by default:
|
38
|
-
#
|
39
|
-
# * id: the ID of the section entry
|
40
|
-
# * title: the entry title
|
41
|
-
# * slug: the entry slug
|
42
|
-
# * status: the status of the entry
|
43
|
-
# * created_at
|
44
|
-
# * updated_at
|
45
|
-
# * section_id: the ID of the section to which this entry belongs
|
46
|
-
#
|
47
|
-
# @example
|
48
|
-
# {% section_entries section="blog" limit="10" offset="20" %}
|
49
|
-
# <article>
|
50
|
-
# <header>
|
51
|
-
# <h1>{{title}}</h1>
|
52
|
-
# </header>
|
53
|
-
#
|
54
|
-
# {{body}}
|
55
|
-
# </article>
|
56
|
-
# {% endsection_entries %}
|
57
|
-
#
|
58
|
-
# @author Yorick Peterse
|
59
|
-
# @since 0.1
|
60
|
-
#
|
61
|
-
class SectionEntries < ::Liquid::Block
|
62
|
-
include ::Ramaze::Helper::CGI
|
63
|
-
include ::Zen::Liquid::General
|
64
|
-
|
65
|
-
##
|
66
|
-
# Creates a new instance of the block and passes the tag name,
|
67
|
-
# all additional arguments and the HTML to the constructor method.
|
68
|
-
#
|
69
|
-
# @author Yorick Peterse
|
70
|
-
# @since 0.1
|
71
|
-
# @param [String] tag_name The name of the tag that was called.
|
72
|
-
# @param [String] arguments All additional arguments passed as a string.
|
73
|
-
# @param [String] html The HTML inside the block.
|
74
|
-
#
|
75
|
-
def initialize(tag_name ='section_entries', arguments = '', html = '')
|
76
|
-
super
|
77
|
-
|
78
|
-
@arguments = {
|
79
|
-
'limit' => 10,
|
80
|
-
'offset' => 0,
|
81
|
-
'section' => '',
|
82
|
-
'order' => 'desc',
|
83
|
-
'order_by' => 'id',
|
84
|
-
'category' => ''
|
85
|
-
}.merge(parse_key_values(arguments))
|
86
|
-
|
87
|
-
@args_parsed = false
|
88
|
-
end
|
89
|
-
|
90
|
-
##
|
91
|
-
# Processes the arguments set in the constructor, retrieves all data and renders
|
92
|
-
# the tag block. When outputting data inside the tag block you can always use the
|
93
|
-
# following variables regardless on whether there are any section entries:
|
94
|
-
#
|
95
|
-
# * total_rows: the amount of rows retrieved
|
96
|
-
# * index: the current index
|
97
|
-
#
|
98
|
-
# Depending on whether you have any entries or not you can use the following
|
99
|
-
# values as well:
|
100
|
-
#
|
101
|
-
# * comments: array containing all comments for each entry
|
102
|
-
# * categories: array of all categories for each entry
|
103
|
-
# * user: data about the author of each entry
|
104
|
-
#
|
105
|
-
# On top of that you can of course also use your own custom values. Each value
|
106
|
-
# can be accessed by it's slug.
|
107
|
-
#
|
108
|
-
# @author Yorick Peterse
|
109
|
-
# @since 0.1
|
110
|
-
#
|
111
|
-
def render(context)
|
112
|
-
@arguments = merge_context(@arguments, context) if @args_parsed == false
|
113
|
-
|
114
|
-
@args_parsed = true
|
115
|
-
result = []
|
116
|
-
entries = []
|
117
|
-
filter_hash = {:status => 'published'}
|
118
|
-
|
119
|
-
# ------
|
120
|
-
# Filter by a section entry's slug
|
121
|
-
if @arguments.key?('section_entry')
|
122
|
-
if @arguments['section_entry'].empty?
|
123
|
-
raise(ArgumentError, "You need to specify a section entry to retrieve")
|
124
|
-
end
|
125
|
-
|
126
|
-
filter_hash[:slug] = @arguments['section_entry']
|
127
|
-
|
128
|
-
# ------
|
129
|
-
# Filter by a category's slug
|
130
|
-
elsif @arguments.key?('category') and !@arguments['category'].empty?
|
131
|
-
category = ::Categories::Models::Category[:slug => @arguments['category']]
|
132
|
-
|
133
|
-
# Bail out of the category doesn't exist
|
134
|
-
return result if category.nil?
|
135
|
-
|
136
|
-
# Retrieve the category group
|
137
|
-
group = category.category_group
|
138
|
-
|
139
|
-
# Now it's time to retrieve all section IDs
|
140
|
-
filter_hash[:section_id] = group.sections.map { |s| s.id }
|
141
|
-
|
142
|
-
# ------
|
143
|
-
# Filter by a section's slug
|
144
|
-
else
|
145
|
-
if @arguments['section'].empty?
|
146
|
-
@arguments['section'] = ::Settings::Model::Setting.get_settings[:default_section]
|
147
|
-
end
|
148
|
-
|
149
|
-
section = ::Sections::Models::Section[:slug => @arguments['section']]
|
150
|
-
|
151
|
-
return result if section.nil?
|
152
|
-
|
153
|
-
filter_hash[:section_id] = section.id
|
154
|
-
end
|
155
|
-
|
156
|
-
entries = ::Sections::Models::SectionEntry
|
157
|
-
.eager(:custom_field_values, :categories, :comments, :section, :user)
|
158
|
-
.filter(filter_hash)
|
159
|
-
.order(@arguments['order_by'].to_sym.send(@arguments['order']))
|
160
|
-
.limit(@arguments['limit'], @arguments['offset'])
|
161
|
-
|
162
|
-
context['total_rows'] = entries.count
|
163
|
-
|
164
|
-
entries.each_with_index do |entry, index|
|
165
|
-
entry.values.each { |k, v| context[k.to_s] = v }
|
166
|
-
|
167
|
-
context['index'] = index
|
168
|
-
context['categories'] = []
|
169
|
-
context['comments'] = []
|
170
|
-
context['user'] = {}
|
171
|
-
|
172
|
-
# Retrieve all categories
|
173
|
-
entry.categories.each do |c|
|
174
|
-
values = {}
|
175
|
-
|
176
|
-
c.values.each { |k, v| values[k.to_s] = v }
|
177
|
-
context['categories'].push(values)
|
178
|
-
end
|
179
|
-
|
180
|
-
# Get the user for the current entry
|
181
|
-
if !entry.user.nil?
|
182
|
-
entry.user.values.each { |k, v| context['user'][k.to_s] = v }
|
183
|
-
end
|
184
|
-
|
185
|
-
# Retrieve all comments
|
186
|
-
entry.comments.each do |c|
|
187
|
-
values = {}
|
188
|
-
|
189
|
-
c.values.each { |k, v| values[k.to_s] = v }
|
190
|
-
|
191
|
-
# Pull the Email, name and website fields from the user table in case the comment
|
192
|
-
# was posted by somebody who was logged in to the backend.
|
193
|
-
['email', 'name', 'website'].each do |m|
|
194
|
-
if values[m].nil? or values[m].empty?
|
195
|
-
values[m] = c.user.send(m)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
values['comment'] = Zen::Plugin.call(
|
200
|
-
'com.zen.plugin.markup',
|
201
|
-
entry.section.comment_format.to_sym,
|
202
|
-
values['comment']
|
203
|
-
)
|
204
|
-
|
205
|
-
context['comments'].push(values)
|
206
|
-
end
|
207
|
-
|
208
|
-
# Get all our custom fields
|
209
|
-
entry.custom_field_values.each do |field_value|
|
210
|
-
field = field_value.custom_field
|
211
|
-
name = field.slug
|
212
|
-
value = ::Zen::Plugin.call(
|
213
|
-
'com.zen.plugin.markup', field.format.to_sym, field_value.value
|
214
|
-
)
|
215
|
-
|
216
|
-
context[name.to_s] = value
|
217
|
-
end
|
218
|
-
|
219
|
-
result.push(render_all(@nodelist, context))
|
220
|
-
end
|
221
|
-
|
222
|
-
result.push(render_all(@nodelist, context)) if result.empty?
|
223
|
-
|
224
|
-
return result
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|