Skip to content

Commit

Permalink
Initial commit of Trac TopMacro
Browse files Browse the repository at this point in the history
  • Loading branch information
dwclifton committed Dec 21, 2008
0 parents commit 6648394
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
71 changes: 71 additions & 0 deletions 0.11/README
@@ -0,0 +1,71 @@
= !TopMacro =

TopMacro is exceedingly simple, like all good software ;-). In a nutshell, it
does exactly what you think it would, inserts a "top of page" link in your Wiki
page. The only option is a string that is inserted into the content of the markup.
This defaults to a single circumflex "!^" character (more commonly known as a caret),
surrounded by square brackets. The anchor element returned includes a "Top of Page"
title attribute so the user knows its purpose, and a "topofpage" class so the Wiki
author may style it in any way they please.

{{{
[[Top]] becomes:

[<a href="#" class="topofpage" title="Top of page">^</a>]
}}}

You could of course achieve the same effect by doing this:

{{{
{{{
#!html
[<a href="#" class="topofpage" title="Top of page">^</a>]
}}}
}}}

Resulting in this:

{{{
#!html
[<a href="#" class="topofpage" title="Top of page">^</a>]
}}}

But who wants to do all that typing? That's what [http://en.wikipedia.org/wiki/Macro_(computer_science) macros]
are for after all. Note that the brackets do not form part of the anchor itself.
That is a personal preference. If you pass a string to the macro they are ommited.

== Installation ==

{{{
python setup.py bdist_egg
cp dist/*.egg /trac/env/Project/plugins
}}}

== Configuration ==

Enable the macro in:

/trac/env/Project/conf/trac.ini:

{{{
[components]
top.* = enabled
}}}

Then restart you Web server.

== Examples ==

{{{
[[Top]]
[[Top(top)]]
[[Top(Top of page)]]
}}}

== Source ==

Browse the source at: [http://github.com/dwclifton/tracinigetmacro/tree/master GitHub][[BR]]
Public clone URL:
{{{
git clone git://github.com/dwclifton/topmacro.git
}}}
22 changes: 22 additions & 0 deletions 0.11/setup.py
@@ -0,0 +1,22 @@
#!/usr/bin/env python

import os.path
from setuptools import setup

setup(
name = 'TracTopMacro',
packages = ['top'],
version = '0.11.0',

author = 'Douglas Clifton',
author_email = 'dwclifton@gmail.com',
description = 'Top of page Macro',
long_description = open(os.path.join(os.path.dirname(__file__), 'README')).read(),
keywords = '0.11 dwclifton macro wiki',
url = 'http://trac-hacks.org/wiki/TopMacro',
license = 'BSD',

entry_points = { 'trac.plugins': [ 'top.macro = top.macro' ],
classifiers = ['Framework :: Trac'],
install_requires = ['Trac']
)
2 changes: 2 additions & 0 deletions 0.11/top/__init__.py
@@ -0,0 +1,2 @@
# __init__.py
from top import *
42 changes: 42 additions & 0 deletions 0.11/top/macro.py
@@ -0,0 +1,42 @@
""" @package TopMacro
@file macro.py
@brief The TopMacro class
Return a top of page anchor element.
@author Douglas Clifton <dwclifton@gmail.com>
@date December, 2008
@version 0.11.0
"""

from trac.core import *
from trac.wiki.macros import WikiMacroBase
from trac.wiki.api import parse_args
from genshi.builder import tag

__all__ = ['TopMacro']

class TopMacro(WikiMacroBase):

def expand_macro(self, formatter, name, args):
""" Return a top of page anchor element."""

prefix = '['
content = '^'
suffix = ']'

args, kw = parse_args(args)

if args:
content = args.pop(0).strip()
prefix = suffix = ''

# class is a python reserved identifier

class_ = 'topofpage'
title = 'Top of page'

return tag.span(prefix,
tag.a(content, href='#', title='%s' % title),
suffix,
class_='%s' % class_)

0 comments on commit 6648394

Please sign in to comment.