Skip to content

Instantly share code, notes, and snippets.

@evanpurkhiser
Created April 20, 2012 15:54
Show Gist options
  • Save evanpurkhiser/2429869 to your computer and use it in GitHub Desktop.
Save evanpurkhiser/2429869 to your computer and use it in GitHub Desktop.
Build files to generate diagram images on yuml.me from the source text

yuml.me diagram build script

The included bash script and Makefile can be used to generate diagram images (in the PNG format) from the "source code" of the diagram.

Usage of the getdiagram.sh script

To use the build script simply pass the type of diagram you want to compile (valid types are class, usecase, and activity), and then pass it the file pattern to compile.

./getdiagram.sh [class|usecase|activity] filepattern

Usage of the Makefile

The included Makefile is a convenient way to generate a set of diagram images. You will have to customize this Makefile to work with your directory structure.

If you are unfamiliar with Makefiles you can read a quick introduction here.


Written by Evan Purkhiser

#!/bin/bash
#
# Download the usecase image from yuml.me
# Requires PERL and wget
#
# Usage: getdiagram [type] [sourcepattern]
#
if [[ $# < 2 ]]
then
echo "Usage: getdiagram [type] [sourcepattern]"
exit 1
fi
# For all of the diagram sources, download the images
find "${2}" | while read FILE_NAME
do
# Read the diagram from the file
CONTENTS="$(cat "${FILE_NAME}" | sed '/^$/d' | tr '\n' ',')"
# URL encode the diagram text
URL_STRING="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "${CONTENTS}")"
# Download the diagram image
wget -O "${FILE_NAME}.png" "http://yuml.me/diagram/plain;/${1}/${URL_STRING}"
done
# yuml.me diagram makefile
# generate the class diagram images as pngs
#
all: UsecaseDiagram/diagram.txt.png Iteration1/ClassDiagram/diagram.txt.png Iteration2/ClassDiagram/diagram.txt.png Iteration3/ClassDiagram/diagram.txt.png
clean:
rm Iteration1/ClassDiagram/diagram.txt.png
rm Iteration2/ClassDiagram/diagram.txt.png
rm Iteration3/ClassDiagram/diagram.txt.png
rm UsecaseDiagram/diagram.txt.png
Iteration%/ClassDiagram/diagram.txt.png: Iteration%/ClassDiagram/diagram.txt
./getdiagram.sh class Iteration$*/ClassDiagram/diagram.txt
UsecaseDiagram/diagram.txt.png: UsecaseDiagram/diagram.txt
./getdiagram.sh usecase UsecaseDiagram/diagram.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment