NewWikiPageButton: refactored
@@ -1,3 +0,0 @@ | ||
1 | -[trac.plugins] | |
2 | -NewWikiPageButton = newwikipagebutton | |
3 | - |
@@ -1 +0,0 @@ | ||
1 | - |
@@ -1,8 +0,0 @@ | ||
1 | -setup.py | |
2 | -NewWikiPageButton.egg-info/PKG-INFO | |
3 | -NewWikiPageButton.egg-info/SOURCES.txt | |
4 | -NewWikiPageButton.egg-info/dependency_links.txt | |
5 | -NewWikiPageButton.egg-info/entry_points.txt | |
6 | -NewWikiPageButton.egg-info/top_level.txt | |
7 | -newwikipagebutton/__init__.py | |
8 | -newwikipagebutton/newwikipagebutton.py | |
\ No newline at end of file |
@@ -1 +0,0 @@ | ||
1 | -newwikipagebutton |
@@ -3,15 +3,18 @@ | ||
3 | 3 | from setuptools import setup |
4 | 4 | |
5 | 5 | PACKAGE = 'NewWikiPageButton' |
6 | -VERSION = '1.01' | |
6 | +VERSION = '1.1.0' | |
7 | 7 | |
8 | -setup(name=PACKAGE, | |
9 | -version=VERSION, | |
10 | -packages=['newwikipagebutton'], | |
11 | -entry_points={'trac.plugins': '%s = newwikipagebutton' % PACKAGE}, | |
12 | -package_data={'newwikipagebutton': [ 'htdocs/*.js','htdocs/*.css','htdocs/*.png','htdocs/images/*.png','htdocs/images/*.gif','templates/*.js']}, | |
13 | -author = "Tomohito Ozaki", | |
14 | -author_email = "ozaki@yuroyoro.com", | |
15 | -description = "", | |
16 | -url = "http://d.hatena.ne.jp/yuroyoro/", | |
8 | +setup( | |
9 | + name = PACKAGE, | |
10 | + version = VERSION, | |
11 | + packages = ['newwikipagebutton'], | |
12 | + entry_points = {'trac.plugins': ['newwikipagebutton = newwikipagebutton']}, | |
13 | + package_data = { | |
14 | + 'newwikipagebutton': ['htdocs/*.js'], | |
15 | + }, | |
16 | + author = "Tomohito Ozaki", | |
17 | + author_email = "ozaki@yuroyoro.com", | |
18 | + description = "", | |
19 | + url = "http://d.hatena.ne.jp/yuroyoro/", | |
17 | 20 | ) |
@@ -1,17 +0,0 @@ | ||
1 | - | |
2 | -$(document).ready(function(){ | |
3 | - | |
4 | - html = '<form><input type="button" value="新しいページを作成する" name="newwikipagebutton" id = "newwikipagebutton"/></form>' | |
5 | - | |
6 | - $("form#attachfile").after(html); | |
7 | - $("input#newwikipagebutton").click(function(){ | |
8 | - ret = prompt("新しいページ名", ""); | |
9 | - url = location.href.replace(/\/$/,""); | |
10 | - if (url.match(/\/wiki/) == null){ | |
11 | - url = url + "/wiki"; | |
12 | - } | |
13 | - if( ret){ | |
14 | - location.href= url + "/" + ret; | |
15 | - } | |
16 | - }); | |
17 | -}); |
@@ -0,0 +1,17 @@ | ||
1 | +jQuery(document).ready(function($) { | |
2 | + var html = $('<form onsubmit="return false">' + | |
3 | + '<input type="submit" value="新しいページを作成する" name="newwikipagebutton" />' + | |
4 | + '</form>'); | |
5 | + $("form#attachfile").after(html); | |
6 | + html.click(function(){ | |
7 | + var ret = prompt("新しいページ名", ""); | |
8 | + if (ret) { | |
9 | + var url = location.href.replace(/\/$/,""); | |
10 | + if (url.match(/\/wiki/) == null){ | |
11 | + url = url + "/wiki"; | |
12 | + } | |
13 | + location.href = url + "/" + ret; | |
14 | + } | |
15 | + return false; | |
16 | + }); | |
17 | +}); |
@@ -1,57 +1,31 @@ | ||
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # NewWikiPageButton plugin |
3 | -import re | |
4 | - | |
5 | -from trac.core import * | |
6 | -from trac.web.chrome import ITemplateProvider, add_stylesheet, add_script | |
7 | -from trac.web.api import IRequestFilter, IRequestHandler | |
8 | -from trac.util import escape, Markup | |
9 | -from trac.perm import IPermissionRequestor | |
10 | 3 | |
11 | 4 | from pkg_resources import resource_filename |
12 | 5 | |
6 | +from trac.core import Component, implements | |
7 | +from trac.web.api import IRequestFilter | |
8 | +from trac.web.chrome import ITemplateProvider, add_script | |
13 | 9 | |
10 | + | |
14 | 11 | class NewWikiPageButtonPlugin(Component): |
15 | - implements( IRequestHandler ,ITemplateProvider ,IRequestFilter) | |
16 | 12 | |
13 | + implements(ITemplateProvider, IRequestFilter) | |
14 | + | |
17 | 15 | # ITemplateProvider methods |
18 | 16 | |
19 | 17 | def get_templates_dirs(self): |
20 | - yield resource_filename(__name__, 'templates') | |
18 | + return () | |
21 | 19 | |
22 | 20 | def get_htdocs_dirs(self): |
23 | 21 | yield 'newwikipagebutton', resource_filename(__name__, 'htdocs') |
24 | - | |
25 | 22 | |
26 | - # IRequestHandler methods | |
27 | - | |
28 | - def match_request(self, req): | |
29 | - return re.match(r'^/NewWikiPageButton/newwikipagebutton.js', req.path_info) is not None | |
30 | - | |
31 | - def process_request(self, req): | |
32 | - | |
33 | - if re.match(r'^/NewWikiPageButton/newwikipagebutton.js',req.path_info) : | |
34 | - if 'WIKI_CREATE' in req.perm('wiki') or 'WIKI_ADMIN' in req.perm('wiki'): | |
35 | - | |
36 | - return 'newwikipagebutton.js',{},'text/plain' | |
37 | - | |
38 | - | |
39 | 23 | # IRequestFilter methods |
40 | - | |
41 | - def post_process_request(self, req, template, data, content_type): | |
42 | - path = req.path_info | |
43 | - | |
44 | - def uses_newwikipagebutton(req): | |
45 | - if template == 'wiki_view.html' : | |
46 | - return True | |
47 | - return False | |
48 | - | |
49 | - if uses_newwikipagebutton(req) : | |
50 | - if 'WIKI_CREATE' in req.perm('wiki') or 'WIKI_ADMIN' in req.perm('wiki'): | |
51 | - add_script(req, '/NewWikiPageButton/newwikipagebutton.js') | |
52 | 24 | |
53 | - return template, data, content_type | |
54 | - | |
55 | 25 | def pre_process_request(self, req, handler): |
56 | 26 | return handler |
57 | 27 | |
28 | + def post_process_request(self, req, template, data, content_type): | |
29 | + if template == 'wiki_view.html' and 'WIKI_CREATE' in req.perm('wiki'): | |
30 | + add_script(req, 'newwikipagebutton/newwikipagebutton.js') | |
31 | + return template, data, content_type |