Edgewall Software

Changes between Version 1 and Version 2 of WikiMacros


Ignore:
Timestamp:
Mar 21, 2004, 8:12:37 AM (20 years ago)
Author:
daniel
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • WikiMacros

    v1 v2  
    1 =  Wiki Macros - Plugins =
     1=  Wiki Macros =
     2Trac macros are plugins to extend the Trac engine with custom 'functions' written in Python. They allow insertion of custom dynamic HTML data in any module supporting WikiFormatting.
    23
    3 Wiki macros is an experimental feature to use custom "plugin" modules to extend the wiki and the WikiFormatting syntax.
     4Another kind of macros are WikiProcessors. They typically deal with alternate markup formats and representation of larger blocks of information (like source code highlighting). See also: WikiProcessors.
    45
    5 JonasBorgstrom commited initial support for it in [167].
     6== Available Macros ==
     7As of 0.6, macros are still a new feature in Trac, and the list of available (and distributed) macros is
     8admittedly not very impressive. In future Trac releases, we hope to build a library of useful macros, and will of course happily include contributed macros (see below).
    69
    7 '''For now, macros are considered dangerous and the consequences are unexplored''' - on the other hand, that makes it just '''so''' much more interesting, doesn't it?
     10 * '''!HelloWorld''' -- An example macro, useful for learning how to write macros.
     11 * '''Timestamp''' -- Insert the current date and time.
     12
     13=== Examples ===
     14!HelloWorld:
     15 [[HelloWorld(Testing)]]
     16
     17Timestamp:
     18 [[Timestamp]]
     19
    820
    921----
    1022
    11 Using a macro, we could pretty easily add support for RestructuredText in Trac. -- DanielLundin
     23
     24== Macros from around the world ==
     25The [http://projects.edgewall.com/trac/ Trac Project] has a section dedicated to user-contributed macros, [http://projects.edgewall.com/trac/wiki/MacroBazaar MacroBazaar]. If you're looking for new macros, or have written new ones to share with the world, don't hesitate adding it to the [http://projects.edgewall.com/trac/wiki/MacroBazaar MacroBazaar] wiki page.
     26
     27  http://projects.edgewall.com/trac/wiki/MacroBazaar
     28
     29
     30----
     31
     32
     33== Developing New Macros ==
     34Macros, like Trac itself, are written in the [http://www.python.org/ Python programming language]. They are very simple modules, identified by the filename and should contain a single ''entry point'' function. Trac will display the returned data inserted into the HTML where the macro was called.
     35
     36It's easiest to learn from an example:
     37{{{
     38# MyMacro.py -- The world's simplest macro
     39
     40def execute(hdf, args):
     41    return "Hello World called with args: %s" % args
     42}}}
     43
     44=== Advanced Topics: Template-enabled Macros ===
     45For advanced uses, macros can also render structured output in HDF, to be rendered to HTML using clearsilver templates - like most Trac output. In short, this allows more generic and well-designed advanced macros.
     46
     47Macros gain direct access to the main HDF tree, and are free to manipulate it.
     48
     49Example:
     50{{{
     51def execute(hdf, args):
     52    # Currently hdf is set only when the macro is called
     53    # From a wiki page
     54    if hdf:
     55        hdf.setValue('wiki.macro.greeting', 'Hello World')
     56       
     57    # args will be null if the macro is called without parentesis.
     58    args = args or 'No arguments'
     59    return 'Hello World, args = ' + args
     60}}}
     61
     62
     63
     64----
     65See also:  WikiProcessors, WikiFormatting, TracGuide