46 lines
1.7 KiB
Plaintext
46 lines
1.7 KiB
Plaintext
- var getFrag = function(fileName) {
|
|
- var frag = partial(fileName);
|
|
- if (frag == null) {
|
|
- return "BAD FILENAME: " + fileName + " Current path: " + current.path;
|
|
- } 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);
|
|
- return r;
|
|
- }
|
|
- }
|
|
|
|
- var getExtn = function(fileName) {
|
|
- var ix = fileName.lastIndexOf('.');
|
|
- return ix > 0 ? fileName.substr(ix+1) : "";
|
|
- }
|
|
|
|
// HACK: to avoid having to include a path in makeTabs calls
|
|
- 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 ...
|
|
- var pathToFrags = "../../../../../../../../../../../".substr(0, (currentPath.length-2)*3) + "_fragments/";
|
|
|
|
mixin makeExample(path, fileName, title)
|
|
- var extn = getExtn(fileName);
|
|
- var extPath = pathToFrags + path + "/";
|
|
if (title)
|
|
.example-title #{title}
|
|
code-example(language="#{extn}" format="linenums")
|
|
!= getFrag(extPath + fileName + ".md")
|
|
|
|
mixin makeTabs(path, fileNames, tabNames)
|
|
- fileNames = fileNames.split(",");
|
|
- tabNames = tabNames.split(",")
|
|
// .p Length #{currentPath.length}
|
|
code-tabs
|
|
each fileName,index in fileNames
|
|
- var tabName = tabNames[index].trim();
|
|
- var fileName = fileNames[index].trim();
|
|
- var extn = getExtn(fileName);
|
|
- var extPath = pathToFrags + path + "/";
|
|
code-pane(language="#{extn}" name="#{tabName}" format="linenums")
|
|
!= getFrag(extPath + fileName + ".md")
|