olelo 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/Rakefile +6 -12
- data/bin/olelo +13 -8
- data/config.ru +21 -15
- data/config/aspects.rb +45 -32
- data/config/config.yml.default +1 -0
- data/config/initializers/00-mime_types.rb +22 -17
- data/config/initializers/01-slim.rb +2 -2
- data/lib/olelo.rb +1 -8
- data/lib/olelo/application.rb +33 -34
- data/lib/olelo/attributes.rb +4 -4
- data/lib/olelo/extensions.rb +0 -7
- data/lib/olelo/helper.rb +13 -25
- data/lib/olelo/html_safe.rb +0 -4
- data/lib/olelo/locale.yml +6 -3
- data/lib/olelo/menu.rb +1 -1
- data/lib/olelo/page.rb +21 -18
- data/lib/olelo/version.rb +1 -1
- data/olelo.gemspec +5 -3
- data/plugins/aspects/changelog.rb +5 -5
- data/plugins/aspects/documentbrowser.rb +5 -5
- data/plugins/{gallery → aspects/gallery}/gallery.css +0 -0
- data/plugins/{gallery → aspects/gallery}/gallery.scss +0 -0
- data/plugins/{gallery → aspects/gallery}/main.rb +3 -3
- data/plugins/aspects/highlight.rb +1 -1
- data/plugins/aspects/image.rb +1 -1
- data/plugins/aspects/imageinfo.rb +3 -3
- data/plugins/aspects/main.rb +21 -21
- data/plugins/aspects/pageinfo.rb +2 -2
- data/plugins/aspects/source.rb +1 -1
- data/plugins/aspects/subpages.rb +7 -7
- data/plugins/aspects/text.rb +1 -1
- data/plugins/authentication/portal.rb +2 -2
- data/plugins/authentication/yamlfile.rb +1 -1
- data/plugins/blog/main.rb +10 -10
- data/plugins/editor/preview.rb +3 -3
- data/plugins/filters/creole.rb +1 -1
- data/plugins/filters/editsection.rb +2 -2
- data/plugins/filters/html2xml.rb +6 -0
- data/plugins/filters/main.rb +1 -1
- data/plugins/filters/remind/main.rb +15 -0
- data/plugins/filters/remind/rem2html +562 -0
- data/plugins/filters/s5/main.rb +1 -1
- data/plugins/login/persistent.rb +1 -1
- data/plugins/misc/system.rb +4 -0
- data/plugins/misc/variables.rb +1 -1
- data/plugins/misc/webdav.rb +10 -10
- data/plugins/repositories/git_grep.rb +2 -2
- data/plugins/repositories/gitrb_repository.rb +10 -10
- data/plugins/repositories/rugged_repository.rb +7 -7
- data/plugins/tags/code.rb +1 -1
- data/plugins/tags/footnotes.rb +4 -3
- data/plugins/tags/gist.rb +2 -2
- data/plugins/tags/html.rb +11 -11
- data/plugins/tags/include.rb +6 -6
- data/plugins/tags/main.rb +10 -10
- data/plugins/tags/math.rb +2 -2
- data/plugins/tags/redirect.rb +3 -3
- data/plugins/tags/scripting.rb +12 -12
- data/plugins/tags/sort.rb +1 -1
- data/plugins/tags/tabs.rb +1 -1
- data/plugins/treeview/main.rb +3 -3
- data/plugins/treeview/script.js +5 -5
- data/plugins/treeview/script/00-jquery.treeview.js +6 -6
- data/plugins/treeview/script/init.js +1 -1
- data/plugins/utils/assets.rb +4 -4
- data/plugins/utils/cache.rb +10 -6
- data/plugins/utils/store.rb +4 -4
- data/static/script.js +124 -126
- data/static/script/{02-jquery.js → 01-jquery.js} +0 -0
- data/static/script/02-olelo.storage.js +54 -0
- data/static/script/10-olelo.historytable.js +2 -2
- data/static/script/13-olelo.tabwidget.js +2 -2
- data/test/helper.rb +5 -4
- data/test/page_test.rb +1 -1
- data/test/request_test.rb +42 -38
- data/test/string_extensions_test.rb +0 -6
- data/test/templates_test.rb +1 -1
- data/test/util_test.rb +1 -1
- data/views/changes.slim +2 -2
- data/views/compare.slim +4 -4
- data/views/delete.slim +2 -2
- data/views/deleted.slim +1 -1
- data/views/edit.slim +31 -26
- data/views/history.slim +5 -5
- data/views/layout.slim +1 -1
- data/views/login.slim +30 -32
- data/views/move.slim +3 -3
- data/views/profile.slim +2 -2
- data/views/show.slim +1 -1
- metadata +43 -104
- data/static/script/01-jstorage.js +0 -217
data/plugins/filters/s5/main.rb
CHANGED
data/plugins/login/persistent.rb
CHANGED
@@ -23,7 +23,7 @@ class ::Olelo::Application
|
|
23
23
|
if path == '/login'
|
24
24
|
if User.logged_in? && params[:persistent]
|
25
25
|
token = "#{sha256(User.current.name + Config['rack.session_secret'])}-#{User.current.name}"
|
26
|
-
response.set_cookie(TOKEN_NAME, :
|
26
|
+
response.set_cookie(TOKEN_NAME, value: token, expires: Time.now + TOKEN_LIFETIME)
|
27
27
|
end
|
28
28
|
elsif path == '/logout'
|
29
29
|
response.delete_cookie(TOKEN_NAME)
|
data/plugins/misc/system.rb
CHANGED
data/plugins/misc/variables.rb
CHANGED
@@ -26,5 +26,5 @@ end
|
|
26
26
|
Application.hook :head, 1 do
|
27
27
|
vars = page ? params.merge(PLUGIN.exported_variables(page)) : params
|
28
28
|
vars = vars.merge('user_logged_in' => !User.logged_in?, 'user_name' => User.current.name)
|
29
|
-
%{<script type="text/javascript">Olelo = #{escape_javascript(vars
|
29
|
+
%{<script type="text/javascript">Olelo = #{escape_javascript MultiJson.dump(vars)};</script>}
|
30
30
|
end
|
data/plugins/misc/webdav.rb
CHANGED
@@ -7,7 +7,7 @@ class ::Olelo::Application
|
|
7
7
|
raise :reserved_path.t if self.class.reserved_path?(page.path)
|
8
8
|
page.content = request.body
|
9
9
|
page.save
|
10
|
-
Page.commit(:page_uploaded.t(:
|
10
|
+
Page.commit(:page_uploaded.t(page: page.title))
|
11
11
|
:created
|
12
12
|
end
|
13
13
|
rescue NotFound => ex
|
@@ -18,7 +18,7 @@ class ::Olelo::Application
|
|
18
18
|
:bad_request
|
19
19
|
end
|
20
20
|
|
21
|
-
put '/(:path)', :
|
21
|
+
put '/(:path)', tail: true do
|
22
22
|
if request.form_data?
|
23
23
|
:not_implemented
|
24
24
|
else
|
@@ -26,7 +26,7 @@ class ::Olelo::Application
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
post '/(:path)', :
|
29
|
+
post '/(:path)', tail: true do
|
30
30
|
if request.form_data?
|
31
31
|
super()
|
32
32
|
else
|
@@ -35,11 +35,11 @@ class ::Olelo::Application
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# TODO: Implement more methods if needed
|
38
|
-
add_route('PROPFIND', '/(:path)', :
|
39
|
-
add_route('PROPPATCH', '/(:path)', :
|
40
|
-
add_route('MKCOL', '/(:path)', :
|
41
|
-
add_route('COPY', '/(:path)', :
|
42
|
-
add_route('MOVE', '/(:path)', :
|
43
|
-
add_route('LOCK', '/(:path)', :
|
44
|
-
add_route('UNLOCK', '/(:path)', :
|
38
|
+
add_route('PROPFIND', '/(:path)', tail: true) { :not_found }
|
39
|
+
add_route('PROPPATCH', '/(:path)', tail: true) { :not_implemented }
|
40
|
+
add_route('MKCOL', '/(:path)', tail: true) { :not_implemented }
|
41
|
+
add_route('COPY', '/(:path)', tail: true) { :not_implemented }
|
42
|
+
add_route('MOVE', '/(:path)', tail: true) { :not_implemented }
|
43
|
+
add_route('LOCK', '/(:path)', tail: true) { :not_implemented }
|
44
|
+
add_route('UNLOCK', '/(:path)', tail: true) { :not_implemented }
|
45
45
|
end
|
@@ -58,9 +58,9 @@ end
|
|
58
58
|
|
59
59
|
__END__
|
60
60
|
@@ grep.slim
|
61
|
-
- title :search_results.t(:
|
61
|
+
- title :search_results.t(pattern: params[:pattern])
|
62
62
|
h1= title
|
63
|
-
p= :match.t(:
|
63
|
+
p= :match.t(count: @matches.length)
|
64
64
|
.search
|
65
65
|
- @matches.each do |path, content|
|
66
66
|
.match
|
@@ -7,8 +7,8 @@ class GitrbRepository < Repository
|
|
7
7
|
|
8
8
|
def initialize(config)
|
9
9
|
Olelo.logger.info "Opening git repository: #{config[:path]}"
|
10
|
-
@git = Gitrb::Repository.new(:
|
11
|
-
:
|
10
|
+
@git = Gitrb::Repository.new(path: config[:path], create: true,
|
11
|
+
bare: config[:bare], logger: Olelo.logger)
|
12
12
|
end
|
13
13
|
|
14
14
|
# @override
|
@@ -36,15 +36,15 @@ class GitrbRepository < Repository
|
|
36
36
|
|
37
37
|
# @override
|
38
38
|
def get_history(path, skip, limit)
|
39
|
-
@git.log(:
|
40
|
-
:
|
39
|
+
@git.log(max_count: limit, skip: skip,
|
40
|
+
path: [path, path + ATTRIBUTE_EXT, path + CONTENT_EXT]).map do |c|
|
41
41
|
commit_to_version(c)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
# @override
|
46
46
|
def get_path_version(path, version)
|
47
|
-
commits = @git.log(:
|
47
|
+
commits = @git.log(max_count: 2, start: version, path: [path, path + ATTRIBUTE_EXT, path + CONTENT_EXT])
|
48
48
|
|
49
49
|
succ = nil
|
50
50
|
@git.git_rev_list('--reverse', '--remove-empty', "#{commits[0]}..", '--', path, path + ATTRIBUTE_EXT, path + CONTENT_EXT) do |io|
|
@@ -94,11 +94,11 @@ class GitrbRepository < Repository
|
|
94
94
|
if content.blank?
|
95
95
|
@git.root.delete(path + CONTENT_EXT)
|
96
96
|
else
|
97
|
-
@git.root[path + CONTENT_EXT] = Gitrb::Blob.new(:
|
97
|
+
@git.root[path + CONTENT_EXT] = Gitrb::Blob.new(data: content)
|
98
98
|
end
|
99
99
|
collapse_empty_tree(path)
|
100
100
|
else
|
101
|
-
@git.root[path] = Gitrb::Blob.new(:
|
101
|
+
@git.root[path] = Gitrb::Blob.new(data: content)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -108,7 +108,7 @@ class GitrbRepository < Repository
|
|
108
108
|
attributes = attributes.blank? ? nil : YAML.dump(attributes).sub(/\A\-\-\-\s*\n/s, '')
|
109
109
|
expand_tree(path)
|
110
110
|
if attributes
|
111
|
-
@git.root[path + ATTRIBUTE_EXT] = Gitrb::Blob.new(:
|
111
|
+
@git.root[path + ATTRIBUTE_EXT] = Gitrb::Blob.new(data: attributes)
|
112
112
|
else
|
113
113
|
@git.root.delete(path + ATTRIBUTE_EXT)
|
114
114
|
end
|
@@ -133,8 +133,8 @@ class GitrbRepository < Repository
|
|
133
133
|
|
134
134
|
# @override
|
135
135
|
def diff(path, from, to)
|
136
|
-
diff = @git.diff(:
|
137
|
-
:
|
136
|
+
diff = @git.diff(from: from && from.to_s, to: to.to_s,
|
137
|
+
path: [path, path + CONTENT_EXT, path + ATTRIBUTE_EXT], detect_renames: true)
|
138
138
|
Diff.new(commit_to_version(diff.from), commit_to_version(diff.to), diff.patch)
|
139
139
|
end
|
140
140
|
|
@@ -132,7 +132,7 @@ class RuggedRepository < Repository
|
|
132
132
|
return @oid if @oid
|
133
133
|
builder = Rugged::Tree::Builder.new
|
134
134
|
@entries.each do |name, entry|
|
135
|
-
builder << { :
|
135
|
+
builder << { type: entry.type, filemode: entry.filemode, oid: entry.save, name: name }
|
136
136
|
end
|
137
137
|
builder.write(@git)
|
138
138
|
end
|
@@ -151,13 +151,13 @@ class RuggedRepository < Repository
|
|
151
151
|
raise 'Concurrent transactions' if @head != current_head
|
152
152
|
|
153
153
|
user = User.current
|
154
|
-
author = {:
|
154
|
+
author = {email: user.email, name: user.name, time: Time.now }
|
155
155
|
commit = Rugged::Commit.create(@git,
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
160
|
-
:
|
156
|
+
author: author,
|
157
|
+
message: comment,
|
158
|
+
committer: author,
|
159
|
+
parents: [@head],
|
160
|
+
tree: @tree.save)
|
161
161
|
|
162
162
|
raise 'Concurrent transactions' if @head != current_head
|
163
163
|
if current_head
|
data/plugins/tags/code.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
description 'Code tag with syntax highlighting'
|
2
2
|
dependencies 'utils/pygments'
|
3
3
|
|
4
|
-
Tag.define :code, :
|
4
|
+
Tag.define :code, requires: 'lang' do |context, attrs, content|
|
5
5
|
Pygments.pygmentize(content, attrs['lang'])
|
6
6
|
end
|
data/plugins/tags/footnotes.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
description 'Footnote support'
|
2
3
|
|
3
|
-
Tag.define :ref, :
|
4
|
+
Tag.define :ref, optional: 'name', description: 'Create footnote' do |context, attrs, content|
|
4
5
|
footnotes = context[:footnotes] ||= []
|
5
6
|
hash = context[:footnotes_hash] ||= {}
|
6
7
|
name = attrs['name']
|
@@ -19,9 +20,9 @@ Tag.define :ref, :optional => 'name', :description => 'Create footnote' do |cont
|
|
19
20
|
%{<a class="ref" id="ref#{ref_id}" href="#note#{note_id}">[#{note_id}]</a>}
|
20
21
|
end
|
21
22
|
|
22
|
-
Tag.define :references, :
|
23
|
+
Tag.define :references, description: 'Print all footnotes' do |context, attrs|
|
23
24
|
footnotes = context[:footnotes]
|
24
|
-
render :footnotes, :
|
25
|
+
render :footnotes, locals: {footnotes: footnotes} if footnotes
|
25
26
|
end
|
26
27
|
|
27
28
|
__END__
|
data/plugins/tags/gist.rb
CHANGED
@@ -2,10 +2,10 @@ description 'Tag to embed github gist'
|
|
2
2
|
export_scripts 'gist-embed.css'
|
3
3
|
require 'open-uri'
|
4
4
|
|
5
|
-
Tag.define :gist, :
|
5
|
+
Tag.define :gist, requires: 'id' do |context, attrs|
|
6
6
|
if attrs['id'] =~ /^\d+$/
|
7
7
|
body = open("https://gist.github.com/#{attrs['id']}.json").read
|
8
|
-
gist =
|
8
|
+
gist = MultiJson.load(body)
|
9
9
|
gist['div'].gsub(' ', ' ')
|
10
10
|
else
|
11
11
|
raise ArgumentError, 'Invalid gist id'
|
data/plugins/tags/html.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
description 'Safe html tags'
|
2
2
|
|
3
3
|
HTML_TAGS = [
|
4
|
-
[:a, {:
|
5
|
-
[:img, {:
|
6
|
-
[:br, {:
|
4
|
+
[:a, {optional: %w(href title)}],
|
5
|
+
[:img, {autoclose: true, optional: %w(src alt title)}],
|
6
|
+
[:br, {autoclose: true}],
|
7
7
|
[:i],
|
8
8
|
[:u],
|
9
9
|
[:b],
|
10
10
|
[:pre],
|
11
11
|
[:kbd],
|
12
12
|
# provided by syntax highlighter
|
13
|
-
# [:code, :
|
13
|
+
# [:code, optional: %w(lang)]
|
14
14
|
[:cite],
|
15
15
|
[:strong],
|
16
16
|
[:em],
|
@@ -20,9 +20,9 @@ HTML_TAGS = [
|
|
20
20
|
[:del],
|
21
21
|
[:table],
|
22
22
|
[:tr],
|
23
|
-
[:td, {:
|
23
|
+
[:td, {optional: %w(colspan rowspan)}],
|
24
24
|
[:th],
|
25
|
-
[:ol, {:
|
25
|
+
[:ol, {optional: %w(start)}],
|
26
26
|
[:ul],
|
27
27
|
[:li],
|
28
28
|
[:p],
|
@@ -32,11 +32,11 @@ HTML_TAGS = [
|
|
32
32
|
[:h4],
|
33
33
|
[:h5],
|
34
34
|
[:h6],
|
35
|
-
[:blockquote, {:
|
36
|
-
[:div, {:
|
37
|
-
[:span, {:
|
38
|
-
[:video, {:
|
39
|
-
[:audio, {:
|
35
|
+
[:blockquote, {optional: %w(cite)}],
|
36
|
+
[:div, {optional: %w(style)}],
|
37
|
+
[:span, {optional: %w(style)}],
|
38
|
+
[:video, {optional: %w(autoplay controls height width loop preload src poster)}],
|
39
|
+
[:audio, {optional: %w(autoplay controls loop preload src)}]
|
40
40
|
]
|
41
41
|
|
42
42
|
HTML_TAGS.each do |name, options|
|
data/plugins/tags/include.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
description 'Include tags'
|
2
2
|
|
3
|
-
Tag.define :include, :
|
3
|
+
Tag.define :include, optional: '*', requires: 'page', limit: 10, description: 'Include page' do |context, attrs|
|
4
4
|
path = attrs['page']
|
5
5
|
path = context.page.path/'..'/path if !path.starts_with? '/'
|
6
6
|
if page = Page.find(path, context.page.tree_version)
|
7
|
-
Aspects::Aspect.find!(page, :
|
8
|
-
call(context.subcontext(:
|
7
|
+
Aspects::Aspect.find!(page, name: attrs['aspect'], layout: true).
|
8
|
+
call(context.subcontext(params: attrs.merge(included: true), page: page), page)
|
9
9
|
else
|
10
|
-
%{<a href="#{escape_html build_path(path, :
|
10
|
+
%{<a href="#{escape_html build_path(path, action: :new)}">#{escape_html :create_page.t(page: path)}</a>}
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
Tag.define :includeonly, :
|
14
|
+
Tag.define :includeonly, immediate: true, description: 'Text which is shown only if included' do |context, attrs, content|
|
15
15
|
nested_tags(context.subcontext, content) if context.params[:included]
|
16
16
|
end
|
17
17
|
|
18
|
-
Tag.define :noinclude, :
|
18
|
+
Tag.define :noinclude, immediate: true, description: 'Text which is not included' do |context, attrs, content|
|
19
19
|
nested_tags(context.subcontext, content) if !context.params[:included]
|
20
20
|
end
|
data/plugins/tags/main.rb
CHANGED
@@ -157,9 +157,9 @@ class Tag < Filters::NestingFilter
|
|
157
157
|
raise 'Tag must take two or three arguments' if block.arity != 2 && block.arity != 3
|
158
158
|
# Find the plugin which provided this tag.
|
159
159
|
plugin = Plugin.for(block)
|
160
|
-
options.merge!(:
|
161
|
-
:
|
162
|
-
:
|
160
|
+
options.merge!(name: name.to_s, plugin: plugin, autoclose: block.arity == 2,
|
161
|
+
optional: Set.new([*options[:optional]].compact.flatten),
|
162
|
+
requires: Set.new([*options[:requires]].compact.flatten))
|
163
163
|
options[:description] ||= plugin.description
|
164
164
|
options[:namespace] ||= plugin.path.split('/').last
|
165
165
|
tag = TagInfo.new(options)
|
@@ -184,7 +184,7 @@ class Tag < Filters::NestingFilter
|
|
184
184
|
# * :static - Execute dynamic tags only once
|
185
185
|
#
|
186
186
|
# Examples:
|
187
|
-
# :
|
187
|
+
# enable: %w(html:* include) Enables all tags in the html namespace and the include tag.
|
188
188
|
def configure(options)
|
189
189
|
super
|
190
190
|
list = @options[:enable] ? tag_list(*@options[:enable]) : @@tags.keys
|
@@ -288,7 +288,7 @@ class Tag < Filters::NestingFilter
|
|
288
288
|
"#{@protection_prefix}#{@protected_tags.length-1}#{@protection_suffix}"
|
289
289
|
end
|
290
290
|
rescue Exception => ex
|
291
|
-
Olelo.logger.
|
291
|
+
Olelo.logger.warn ex.message
|
292
292
|
"#{name} - #{ex.message}"
|
293
293
|
end
|
294
294
|
|
@@ -322,7 +322,7 @@ Application.hook :render, 2000 do |name, xml, layout|
|
|
322
322
|
name, attrs, content = Marshal.load(decode64($1))
|
323
323
|
raise 'Invalid dynamic tag' unless Hash === attrs && Tag.tags[name] && Tag.tags[name].dynamic
|
324
324
|
begin
|
325
|
-
context = Aspects::Context.new(:
|
325
|
+
context = Aspects::Context.new(page: page, params: params, request: request, response: response)
|
326
326
|
if content
|
327
327
|
raise 'Invalid dynamic tag' unless String === content
|
328
328
|
Tag.tags[name].dynamic.new.call(context, attrs, content).to_s
|
@@ -338,16 +338,16 @@ Application.hook :render, 2000 do |name, xml, layout|
|
|
338
338
|
''
|
339
339
|
end
|
340
340
|
end
|
341
|
-
cache_control(:
|
341
|
+
cache_control(no_cache: true) if no_cache
|
342
342
|
end
|
343
343
|
|
344
|
-
Filters::Filter.register :tag, Tag, :
|
344
|
+
Filters::Filter.register :tag, Tag, description: 'Process extension tags'
|
345
345
|
|
346
|
-
Tag.define :nowiki, :
|
346
|
+
Tag.define :nowiki, description: 'Disable tag and wikitext filtering' do |context, attrs, content|
|
347
347
|
escape_html(content)
|
348
348
|
end
|
349
349
|
|
350
|
-
Tag.define :notags, :
|
350
|
+
Tag.define :notags, description: 'Disable tag processing', immediate: true do |context, attrs, content|
|
351
351
|
content
|
352
352
|
end
|
353
353
|
|
data/plugins/tags/math.rb
CHANGED
@@ -92,7 +92,7 @@ class LaTeXRenderer < MathRenderer
|
|
92
92
|
register 'mathjax', LaTeXRenderer
|
93
93
|
end
|
94
94
|
|
95
|
-
Tag.define :math, :
|
95
|
+
Tag.define :math, optional: 'display' do |context, attrs, code|
|
96
96
|
raise('Limits exceeded') if code.size > 10240
|
97
97
|
MathRenderer.instance.render(code, attrs['display'] == 'block' ? 'block' : 'inline')
|
98
98
|
end
|
@@ -104,7 +104,7 @@ class ::Olelo::Application
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
get '/_/blahtex/:name', :
|
107
|
+
get '/_/blahtex/:name', name: /\w+\.\w+/ do
|
108
108
|
begin
|
109
109
|
file = Rack::File.new(nil)
|
110
110
|
file.path = File.join(Config['blahtex_directory'], params[:name])
|
data/plugins/tags/redirect.rb
CHANGED
@@ -3,19 +3,19 @@ description 'Tag to redirect to other pages'
|
|
3
3
|
Application.hook :render do |name, xml, layout|
|
4
4
|
if params[:redirect] && layout
|
5
5
|
links = [params[:redirect]].flatten.map do |link|
|
6
|
-
%{<a href="#{escape_html build_path(link, :
|
6
|
+
%{<a href="#{escape_html build_path(link, action: :edit)}">#{escape_html link}</a>}
|
7
7
|
end.join(' → ')
|
8
8
|
xml.sub!(/<div id="menu">.*?<\/ul>/m, "\\0Redirected from #{links} → ◎ ")
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
Tag.define :redirect, :
|
12
|
+
Tag.define :redirect, requires: 'to', dynamic: true do |context, attrs|
|
13
13
|
list = context.params[:redirect] || []
|
14
14
|
to = attrs['to']
|
15
15
|
if list.include?(to)
|
16
16
|
raise "Invalid redirect to #{to}"
|
17
17
|
else
|
18
18
|
list << context.page.path
|
19
|
-
throw :redirect, build_path(to, 'redirect[]' => list, :
|
19
|
+
throw :redirect, build_path(to, 'redirect[]' => list, version: !context.page.head? && context.page)
|
20
20
|
end
|
21
21
|
end
|
data/plugins/tags/scripting.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
description 'Wiki syntax tags for scripting'
|
2
2
|
require 'evaluator'
|
3
3
|
|
4
|
-
Tag.define :value, :
|
4
|
+
Tag.define :value, requires: 'of', immediate: true, description: 'Print value' do |context, attrs|
|
5
5
|
Evaluator.eval(attrs['of'], context.params)
|
6
6
|
end
|
7
7
|
|
8
|
-
Tag.define :def, :
|
9
|
-
:
|
8
|
+
Tag.define :def, optional: %w(value args), requires: 'name',
|
9
|
+
immediate: true, description: 'Define variable' do |context, attrs, content|
|
10
10
|
name = attrs['name'].downcase
|
11
11
|
if attrs['value']
|
12
12
|
context.params[name] = Evaluator.eval(attrs['value'], context.params)
|
@@ -17,7 +17,7 @@ Tag.define :def, :optional => %w(value args), :requires => 'name',
|
|
17
17
|
nil
|
18
18
|
end
|
19
19
|
|
20
|
-
Tag.define :call, :
|
20
|
+
Tag.define :call, optional: '*', requires: 'name', immediate: true, description: 'Call function' do |context, attrs|
|
21
21
|
name = attrs['name'].downcase
|
22
22
|
functions = context[:functions]
|
23
23
|
raise NameError, "Function #{name} not found" if !functions || !functions[name]
|
@@ -27,7 +27,7 @@ Tag.define :call, :optional => '*', :requires => 'name', :immediate => true, :de
|
|
27
27
|
hash[arg] = Evaluator.eval(attrs[arg], context.params)
|
28
28
|
hash
|
29
29
|
end
|
30
|
-
result = nested_tags(context.subcontext(:
|
30
|
+
result = nested_tags(context.subcontext(params: args), content)
|
31
31
|
if attrs['result']
|
32
32
|
context.params[attrs['result']] = result
|
33
33
|
nil
|
@@ -36,28 +36,28 @@ Tag.define :call, :optional => '*', :requires => 'name', :immediate => true, :de
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
Tag.define :for, :
|
40
|
-
:
|
39
|
+
Tag.define :for, optional: 'counter', requires: %w(from to),
|
40
|
+
immediate: true, limit: 50, description: 'For loop' do |context, attrs, content|
|
41
41
|
to = attrs['to'].to_i
|
42
42
|
from = attrs['from'].to_i
|
43
43
|
raise 'Limits exceeded' if to - from > 10
|
44
44
|
(from..to).map do |i|
|
45
45
|
params = attrs['counter'] ? {attrs['counter'] => i} : {}
|
46
|
-
nested_tags(context.subcontext(:
|
46
|
+
nested_tags(context.subcontext(params: params), content)
|
47
47
|
end.join
|
48
48
|
end
|
49
49
|
|
50
|
-
Tag.define :repeat, :
|
51
|
-
:
|
50
|
+
Tag.define :repeat, optional: 'counter', requires: 'times',
|
51
|
+
immediate: true, limit: 50, description: 'Repeat loop' do |context, attrs, content|
|
52
52
|
n = attrs['times'].to_i
|
53
53
|
raise 'Limits exceeded' if n > 10
|
54
54
|
(1..n).map do |i|
|
55
55
|
params = attrs['counter'] ? {attrs['counter'] => i} : {}
|
56
|
-
nested_tags(context.subcontext(:
|
56
|
+
nested_tags(context.subcontext(params: params), content)
|
57
57
|
end.join
|
58
58
|
end
|
59
59
|
|
60
|
-
Tag.define :if, :
|
60
|
+
Tag.define :if, requires: 'test', immediate: true, description: 'If statement' do |context, attrs, content|
|
61
61
|
if Evaluator.eval(attrs['test'], context.params)
|
62
62
|
nested_tags(context.subcontext, content)
|
63
63
|
end
|