Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for git file versions in snippets #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/wheat/data.js
Expand Up @@ -23,36 +23,43 @@ function preProcessMarkdown(markdown) {

// Look for snippet placeholders
var unique = props.uniqueSnippets = {};
props.snippets = (markdown.match(/\n<[^<>:\s]+\.[a-z]{2,4}(\*|[#].+)?>\n/g) || []).map(
props.snippets = (markdown.match(/\n<[^<>:\s]+\.[a-z]{2,4}(\*|[#|\:].+)?>\n/g) || []).map(
function (original) {
// nuke the leading and trailing /n< and >/n
var path = original.substr(2, original.length - 4);

var filename = path;
execute = path[path.length - 1] === "*";
if (execute) {
filename = filename.substr(0, filename.length - 1);
}
base = path.substr(path.indexOf('/') + 1).replace(/[#*].*$/, '');
base = path.substr(path.indexOf('/') + 1).replace(/[(#|\:)*].*$/, '');
var match = filename.match(/#(.+)$/);
var name;
if (match) {
name = match[1];
filename = path.substr(0, match.index);
}
var version = 'fs';
match = filename.match(/\:(.+)$/);
if (match) {
version = match[1];
filename = path.substr(0, match.index);
}
return unique[base] = {
original: original,
filename: filename,
execute: execute,
base: base,
name: name
name: name,
version: version
};
}
);
if (props.snippets.length === 0) {
props.uniqueSnippets = false;
}


return props;
}

Expand Down Expand Up @@ -123,7 +130,7 @@ function activateSnippets(version, snippets, canExecute, callback) {
}
var group = this.group();
snippets.forEach(function (snippet) {
Git.readFile(version, "articles/" + snippet.filename, group());
Git.readFile(snippet.version, "articles/" + snippet.filename, group());
});
},
function (err, files) {
Expand Down