2015-08-08 16:55:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- var getFrag = function(fileName, stylePatterns) {
|
2015-08-03 20:45:58 -04:00
|
|
|
- var frag = partial(fileName);
|
|
|
|
- if (frag == null) {
|
2015-08-08 16:55:53 -04:00
|
|
|
- return "BAD FILENAME: " + fileName + " Current path: " + current.path + " Fragment path: " + current.pathToFrags;
|
2015-08-03 20:45:58 -04:00
|
|
|
- } else {
|
|
|
|
- // ``` gets translated to <pre><code>.....</code></pre> and we need
|
|
|
|
- // to remove this from the fragment prefix is 11 long and suffix is 13 long
|
|
|
|
- var r = frag.substring(11, frag.length-13);
|
2015-08-08 16:55:53 -04:00
|
|
|
- if (stylePatterns) {
|
|
|
|
- for (var styleName in stylePatterns) {
|
|
|
|
- var rxs = stylePatterns[styleName];
|
|
|
|
- rxs = Array.isArray(rxs) ? rxs : [rxs];
|
|
|
|
- rxs.forEach(function(rx) {
|
|
|
|
- r = annotate(r, styleName, rx );
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
2015-08-03 20:45:58 -04:00
|
|
|
- return r;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
2015-08-08 16:55:53 -04:00
|
|
|
- var annotate = function(str, styleName, rx) {
|
|
|
|
- var repls = {};
|
|
|
|
- var matches;
|
|
|
|
- do {
|
|
|
|
- matches = rx.exec(str);
|
|
|
|
- if (matches) {
|
|
|
|
- matches.slice(1).forEach(function(match) {
|
|
|
|
- var repl = '<span class="' + styleName + '">' + match + '</span>';
|
|
|
|
- repls[match] = { repl: repl, isGlobal: rx.global };
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- } while (matches != null && rx.global );
|
|
|
|
- for (var match in repls) {
|
|
|
|
- var repl = repls[match];
|
|
|
|
- var rx2 = new RegExp(match, repl.isGlobal ? "g" : "");
|
|
|
|
- str = str.replace(rx2, repl.repl);
|
|
|
|
- };
|
|
|
|
- return str;
|
|
|
|
- }
|
|
|
|
|
2015-08-03 20:45:58 -04:00
|
|
|
- var getExtn = function(fileName) {
|
|
|
|
- var ix = fileName.lastIndexOf('.');
|
|
|
|
- return ix > 0 ? fileName.substr(ix+1) : "";
|
|
|
|
- }
|
|
|
|
|
2015-08-08 16:55:53 -04:00
|
|
|
- var getPathToFrags = function() {
|
|
|
|
- var currentPath = current.path;
|
|
|
|
- // simple way to only take as many '../' sections as we need to back up to the 'docs' dir
|
|
|
|
- // from the current document
|
|
|
|
- // we will almost certainly never go 10 or 11 deep but ...
|
|
|
|
- return current.pathToFrags || "../../../../../../../../../../../".substr(0, (currentPath.length-2)*3) + "_fragments/";
|
|
|
|
- }
|
|
|
|
|
|
|
|
mixin makeExample(path, fileName, title, stylePatterns)
|
2015-08-06 15:45:50 -04:00
|
|
|
|
2015-08-08 16:55:53 -04:00
|
|
|
- var language = attributes.language || getExtn(fileName);
|
|
|
|
- var format = attributes.format || "linenums";
|
|
|
|
- var extPath = getPathToFrags() + path + "/";
|
2015-08-03 20:45:58 -04:00
|
|
|
|
2015-08-08 21:08:07 -04:00
|
|
|
if (title)
|
|
|
|
.example-title #{title}
|
2015-08-08 16:55:53 -04:00
|
|
|
code-example(language="#{language}" format="#{format}")
|
|
|
|
!= getFrag(extPath + fileName + ".md", stylePatterns)
|
2015-08-08 21:08:07 -04:00
|
|
|
|
2015-08-08 16:55:53 -04:00
|
|
|
mixin makeTabs(path, fileNames, tabNames, stylePatterns)
|
2015-08-03 20:45:58 -04:00
|
|
|
- fileNames = fileNames.split(",");
|
|
|
|
- tabNames = tabNames.split(",")
|
|
|
|
// .p Length #{currentPath.length}
|
2015-08-08 16:55:53 -04:00
|
|
|
|
2015-08-03 20:45:58 -04:00
|
|
|
code-tabs
|
|
|
|
each fileName,index in fileNames
|
|
|
|
- var tabName = tabNames[index].trim();
|
|
|
|
- var fileName = fileNames[index].trim();
|
2015-08-08 16:55:53 -04:00
|
|
|
- var language = attributes.language || getExtn(fileName);
|
|
|
|
- var format = attributes.format || "linenums";
|
|
|
|
- var extPath = getPathToFrags() + path + "/";
|
|
|
|
- var sps = Array.isArray(stylePatterns) ? stylePatterns[index] : stylePatterns;
|
|
|
|
code-pane(language="#{language}" name="#{tabName}" format="#{format}")
|
|
|
|
!= getFrag(extPath + fileName + ".md", sps)
|