Giter Site home page Giter Site logo

Comments (4)

jperville avatar jperville commented on August 23, 2024

I integrated ditaa with this plugin quite easily. The main difficulty was to convince ditaa to work in "pipe" mode instead of creating files on the filesystem. To achieve that I wrote the following python wrapper:

#!/usr/bin/python

"Wraps the ditaa diagram rendering tool to work in piped mode." 

from tempfile import mkdtemp
from shutil import rmtree
from os.path import join
from os import system
from sys import stdin, exit

if __name__ == "__main__":
    tmpdir, ret = mkdtemp(prefix='ditaa'), 1
    try:
        infile, outfile = join(tmpdir, "in.ditaa"), join(tmpdir, "out.png")
        f = open(infile, "wb")
        f.write(stdin.read())
        f.close()
        ret = system("/usr/bin/ditaa %s %s 1>&2" % (infile, outfile))
        if ret == 0:
            print open(outfile, "rb").read()
    finally:
        rmtree(tmpdir)
    exit(ret)

Save the above program as /usr/local/bin/ditaa-pipe and make it executable.
Now edit the global config/wiki_external_filter.yml file to declare a ditaa macro in your environment.

  ditaa:
    description: "Constructs diagram image from its textual description in ditaa language, see http://ditaa.sourceforge.net/"
    template: image
    outputs:
      - command: "/usr/local/bin/ditaa-pipe"
        content_type: "image/png"

Restart redmine and enjoy!

To test, simply invoke the "ditaa" macro with the ditaa source as macro argument, like this:

{{ditaa(
/----\ /----\
|c33F| |cC02|
|    | |    |
\----/ \----/

/----\ /----\
|c1FF| |c1AB|
|    | |    |
\----/ \----/
)}}

Feel free to reuse my source (or better: integrate it into the official plugin).

from wiki_external_filter.

ebrahim avatar ebrahim commented on August 23, 2024

Good job. Just a tiny bug: ditaa-pipe may fail if it is run twice simultaneously, because of similar output file name of out.png shared between two Ditaa processes. Here is my own ditaa-pipe shell script:

#!/bin/bash

base=`mktemp`
cat >"$base.ditaa"
ditaa "$base.ditaa" "$base.png" >/dev/null
cat "$base.png"
rm -f "$base.ditaa" "$base.png"

from wiki_external_filter.

jperville avatar jperville commented on August 23, 2024

Hello ebrahim and thank you for your contribution.
I used "mkdtemp" in my script to be sure that my work files are safe ; even if the basenames are fixed all files are created in a protected directory. Happy diagramming with ditaa in redmine!

from wiki_external_filter.

ebrahim avatar ebrahim commented on August 23, 2024

Oops! You're right.

from wiki_external_filter.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.