Skip to content

Commit 93267e5

Browse files
committed
Add yuml gimmick
1 parent 1bb6a0f commit 93267e5

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ module.exports = function(grunt) {
5050
// 'js/gimmicks/leaflet.js',
5151
'js/gimmicks/themechooser.js',
5252
'js/gimmicks/twitter.js',
53-
'js/gimmicks/youtube_embed.js'
53+
'js/gimmicks/youtube_embed.js',
54+
'js/gimmicks/yuml.js'
5455
],
5556

5657
// files that we always inline (stuff not available on CDN)

js/gimmicks/yuml.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* # YUML GIMMICK
2+
*
3+
* Create diagrams in no time with [yUML][yUML].
4+
*
5+
* ## Usage
6+
*
7+
* [gimmick:yuml]( [HttpContext]uses -.->[Response] )
8+
*
9+
* [gimmick:yuml (style: 'scruffy', dir: 'TB') ]( [Customer]->[Billing Address] )
10+
*
11+
* [gimmick:yuml (diag: 'activity', style: 'plain') ]( `Make Coffee´->`want more coffee´ )
12+
*
13+
* [gimmick:yuml (diag: 'usecase', scale: 200) ]( [Customer]-`Sign In´, [Customer]-`Buy Products´ )
14+
*
15+
* ## Options
16+
*
17+
* * **diag**: `class`, `activity`, `usecase`
18+
* * **style**: `plain`, `scruffy`
19+
* * **dir**: `LR`, `TB`, `RL`
20+
* * **scale**: number (original size: 100)
21+
*
22+
* ## Author
23+
*
24+
* Copyright 2014 Guillermo Calvo
25+
*
26+
* <https://github.com/guillermocalvo/>
27+
*
28+
* ## License
29+
*
30+
* Licensed under the [GNU Lesser General Public License][LGPL].
31+
*
32+
* [yUML]: http://www.yuml.me/
33+
* [LGPL]: http://www.gnu.org/copyleft/lesser.html
34+
*/
35+
(function($) {
36+
'use strict';
37+
function yuml($link, opt, text) {
38+
var default_options = {
39+
type: 'class', /* { class, activity, usecase } */
40+
style: 'plain', /* { plain, scruffy } */
41+
direction: 'LR', /* LR, TB, RL */
42+
scale: '100'
43+
};
44+
var options = $.extend ({}, default_options, opt);
45+
46+
return $link.each(function(i,e) {
47+
48+
var $this = $(e);
49+
var url = 'http://yuml.me/diagram/';
50+
var data = $this.attr('href');
51+
var title = $this.attr('title');
52+
53+
title = (title ? title : '');
54+
55+
/* `FOOBAR´ => (FOOBAR) */
56+
data = data.replace( new RegExp('`', 'g'), '(' ).replace( new RegExp('´', 'g'), ')' );
57+
58+
url += options.style + ';dir:' + options.direction + ';scale:' + options.scale + '/' + options.type + '/' + data;
59+
60+
var $img = $('<img src="' + url + '" title="' + title + '" alt="' + title + '">');
61+
62+
$this.replaceWith($img);
63+
});
64+
}
65+
var yumlGimmick = {
66+
name: 'yuml',
67+
version: $.md.version,
68+
once: function() {
69+
$.md.linkGimmick(this, 'yuml', yuml);
70+
$.md.registerScript(this, '', {
71+
license: 'LGPL',
72+
loadstage: 'postgimmick',
73+
finishstage: 'all_ready'
74+
});
75+
}
76+
};
77+
$.md.registerGimmick(yumlGimmick);
78+
79+
}(jQuery));

0 commit comments

Comments
 (0)