Commit 8d7f6064 by benjaoming

Adding a help plugin and extra markdown extensions

parent 1b690611
...@@ -109,6 +109,7 @@ INSTALLED_APPS = ( ...@@ -109,6 +109,7 @@ INSTALLED_APPS = (
'sorl.thumbnail', 'sorl.thumbnail',
'wiki', 'wiki',
'wiki.plugins.images', 'wiki.plugins.images',
'wiki.plugins.help',
'wiki.plugins.attachments', 'wiki.plugins.attachments',
'wiki.plugins.notifications', 'wiki.plugins.notifications',
'mptt', 'mptt',
......
...@@ -13,6 +13,24 @@ WIKI_LANGUAGE = 'markdown' ...@@ -13,6 +13,24 @@ WIKI_LANGUAGE = 'markdown'
# extend the built-in editor and customize it.... # extend the built-in editor and customize it....
EDITOR = getattr(django_settings, 'WIKI_EDITOR', 'wiki.editors.markitup.MarkItUp') EDITOR = getattr(django_settings, 'WIKI_EDITOR', 'wiki.editors.markitup.MarkItUp')
# If you want to write an extension, you should use the plugin API as you
# will get an article model instance to play with. These are just the
# builtin markdown extensions
# Notice that this should be a callable which accepts the article as an argument
def get_extensions(article):
from wiki.models import URLPath
try:
urlpath = URLPath.objects.get(article=article)
url = reverse_lazy('wiki:get', kwargs={'path': urlpath.path})
except URLPath.DoesNotExist:
url = reverse_lazy('wiki:get', kwargs={'article_id': article.id})
return ['extra', 'wikilinks(base_url=%s)' % url, 'codehilite(force_linenos=True)', 'toc']
MARKDOWN_EXTENSIONS = getattr(
django_settings,
'WIKI_MARKDOWN_EXTENSIONS',
get_extensions
)
# This slug is used in URLPath if an article has been deleted. The children of the # This slug is used in URLPath if an article has been deleted. The children of the
# URLPath of that article are moved to lost and found. They keep their permissions # URLPath of that article are moved to lost and found. They keep their permissions
# and all their content. # and all their content.
......
...@@ -161,6 +161,7 @@ class Article(models.Model): ...@@ -161,6 +161,7 @@ class Article(models.Model):
else: else:
content = self.current_revision.content content = self.current_revision.content
extensions = plugin_registry.get_markdown_extensions() extensions = plugin_registry.get_markdown_extensions()
extensions += settings.MARKDOWN_EXTENSIONS(self)
return mark_safe(article_markdown(content, self, extensions=extensions)) return mark_safe(article_markdown(content, self, extensions=extensions))
......
from django.db import models
# Create your models here.
{% load i18n %}<h4>{% trans "Adding new articles" %}</h4>
<p>
{% trans "To create a new wiki article, create a link to it. Clicking the link gives you the creation page." %}
</p>
<pre>[Article Name](wiki:ArticleName)</pre>
<h4>{% trans "An external link" %}</h4>
<pre>[Link](http://google.com)</pre>
<h4>{% trans "Headers" %}</h4>
<p>{% trans "Use these codes for headers and to automatically generate Tables of Contents." %}</p>
<pre>Hugest header
===========
Huger header
------------
# Hugest Header
## Huger header
### Huge header
#### Small header
[[ TOC ]]
</pre>
<h4>{% trans "Typography" %}</h4>
<pre>*emphasis* or _emphasis_</pre>
<pre>**strong** or __strong__</pre>
<h4>{% trans "Lists" %}</h4>
<pre>- Unordered List
- Sub Item 1
- Sub Item 2</pre>
<pre>1. Ordered
2. List</pre>
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
# Create your views here.
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import patterns
from django.utils.translation import ugettext as _
from wiki.core.plugins import registry
from wiki.core.plugins.base import BasePlugin
class HelpPlugin(BasePlugin):
slug = 'help'
urlpatterns = patterns('',)
sidebar = {'headline': _('Help'),
'icon_class': 'icon-question-sign',
'template': 'wiki/plugins/help/sidebar.html',
'form_class': None,
'get_form_kwargs': (lambda a: {})}
markdown_extensions = []
def __init__(self):
pass
registry.register(HelpPlugin)
...@@ -10,13 +10,7 @@ from wiki.plugins.images.markdown_extensions import ImageExtension ...@@ -10,13 +10,7 @@ from wiki.plugins.images.markdown_extensions import ImageExtension
class ImagePlugin(BasePlugin): class ImagePlugin(BasePlugin):
#settings_form = 'wiki.plugins.notifications.forms.SubscriptionForm'
slug = settings.SLUG slug = settings.SLUG
urlpatterns = patterns('',
url('^$', views.ImageView.as_view(), name='images_index'),
)
sidebar = {'headline': _('Images'), sidebar = {'headline': _('Images'),
'icon_class': 'icon-picture', 'icon_class': 'icon-picture',
'template': 'wiki/plugins/images/sidebar.html', 'template': 'wiki/plugins/images/sidebar.html',
......
...@@ -27,6 +27,14 @@ ...@@ -27,6 +27,14 @@
#attachment_form #id_description #attachment_form #id_description
{ width: 95% } { width: 95% }
.wiki-article div.toc {
margin: 10px 0;
background: #f9f9f9;
padding: 10px;
width: 300px;
border: 1px solid #CCC;
}
input[type=file] {float: none; width: auto;} input[type=file] {float: none; width: auto;}
.asteriskField { font-size: 20px; margin-left: 5px;} .asteriskField { font-size: 20px; margin-left: 5px;}
......
...@@ -252,8 +252,11 @@ class Edit(FormView, ArticleMixin): ...@@ -252,8 +252,11 @@ class Edit(FormView, ArticleMixin):
# Generate sidebar forms # Generate sidebar forms
self.sidebar_forms = [] self.sidebar_forms = []
for form_id, Form in self.get_sidebar_form_classes().items(): for form_id, Form in self.get_sidebar_form_classes().items():
form = Form(self.article, self.request.user) if Form:
setattr(form, 'form_id', form_id) form = Form(self.article, self.request.user)
setattr(form, 'form_id', form_id)
else:
form = None
self.sidebar_forms.append(form) self.sidebar_forms.append(form)
return super(Edit, self).get(request, *args, **kwargs) return super(Edit, self).get(request, *args, **kwargs)
...@@ -261,21 +264,24 @@ class Edit(FormView, ArticleMixin): ...@@ -261,21 +264,24 @@ class Edit(FormView, ArticleMixin):
# Generate sidebar forms # Generate sidebar forms
self.sidebar_forms = [] self.sidebar_forms = []
for form_id, Form in self.get_sidebar_form_classes().items(): for form_id, Form in self.get_sidebar_form_classes().items():
if form_id == self.request.GET.get('f', None): if Form:
form = Form(self.article, self.request, data=self.request.POST, files=self.request.FILES) if form_id == self.request.GET.get('f', None):
if form.is_valid(): form = Form(self.article, self.request, data=self.request.POST, files=self.request.FILES)
form.save() if form.is_valid():
usermessage = form.get_usermessage() form.save()
if usermessage: usermessage = form.get_usermessage()
messages.success(self.request, usermessage) if usermessage:
else: messages.success(self.request, usermessage)
messages.success(self.request, _(u'Your changes were saved.')) else:
if self.urlpath: messages.success(self.request, _(u'Your changes were saved.'))
return redirect('wiki:edit', path=self.urlpath.path) if self.urlpath:
return redirect('wiki:edit', article_id=self.article.id) return redirect('wiki:edit', path=self.urlpath.path)
return redirect('wiki:edit', article_id=self.article.id)
else:
form = Form(self.article, self.request)
setattr(form, 'form_id', form_id)
else: else:
form = Form(self.article, self.request) form = None
setattr(form, 'form_id', form_id)
self.sidebar_forms.append(form) self.sidebar_forms.append(form)
return super(Edit, self).post(request, *args, **kwargs) return super(Edit, self).post(request, *args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment