Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2 from awmcclain/master

Here you go!
  • Loading branch information...
commit 583c294b3cccc47528e1952194cb0e89e0706e1d 2 parents f7c98bf + ed50266
@stenson authored
Showing with 32 additions and 16 deletions.
  1. +6 −1 lib/commands.js
  2. +12 −6 lib/inca.js
  3. +14 −9 lib/tern.js
View
7 lib/commands.js
@@ -22,5 +22,10 @@ module.exports = {
bootstrap: function() {
exec("curl http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css > public/bootstrap.min.css");
+ },
+
+ host: function() {
+ console.log("~~~ Running inca in hosting mode ~~~".blue);
+ this.run({hosting: true});
}
-};
+};
View
18 lib/inca.js
@@ -23,11 +23,16 @@ var pages = {
standard: function(req, res, next) {
var url = req.params[0].split(".");
+ var ps = url[0].slice(1).split("/");
+
if (url[1]) { // has a file extension, not capable of changing prefix
+ if (path.existsSync(ps[0])) {
+ // Running inca outside of a project directory, let's remove the prefix
+ var newUrl = '/' + ps.slice(1).join("/") + '.' + url[1];
+ req.url = newUrl;
+ }
next();
} else {
- var ps = url[0].slice(1).split("/");
-
(path.existsSync(ps[0]))
? pages.dynamic(ps.slice(1).join("/"), req, res, ps[0]+"/")
: pages.dynamic(ps.join("/"), req, res, "");
@@ -57,13 +62,14 @@ function mustacheError() {
);
}
-function run() {
- if (!path.existsSync("mustaches")) return mustacheError();
-
+function run(options) {
+ options = options || {};
+ if (!options.hosting && !path.existsSync("mustaches")) return mustacheError();
// stop
app = express.createServer();
app.set("view engine", "mustache");
app.register(".mustache", tern);
+ app.helpers({ getPrefix: function() { return prefix; }});
setResourcePaths();
// look
@@ -87,4 +93,4 @@ module.exports = {
var cmd = args[2];
commands[cmd] ? commands[cmd]() : commands.run();
}
-};
+};
View
23 lib/tern.js
@@ -8,7 +8,8 @@ var tern = {}
// globals
, jsons = {}
, randoms = {}
- , keys = [];
+ , keys = []
+ , root;
var linkifiedText = function() {
var usernameOpts = {
@@ -53,17 +54,19 @@ var loadHelpers = function() {
}
};
-var loadJson = function() {
+var loadJson = function(prefix) {
if (path.existsSync("../json")) {
fs.readdirSync("../json").forEach(function(file) {
jsons[file.split(".")[0]] = JSON.parse(fs.readFileSync("../json/"+file, "utf-8"));
});
}
- fs.readdirSync("json").forEach(function(file) {
+ var jsonPath = path.existsSync(path.join(prefix, "json")) ? path.join(prefix, "json") : "json";
+ //console.log("reading json from ", jsonPath);
+ fs.readdirSync(jsonPath).forEach(function(file) {
if (file !== "urls.txt") {
try {
- jsons[file.split(".")[0]] = JSON.parse(fs.readFileSync("json/"+file, "utf-8"));
+ jsons[file.split(".")[0]] = JSON.parse(fs.readFileSync(path.join(jsonPath, file), "utf-8"));
} catch(e) {
console.log("couldn't parse json from ", file, "; no big deal though");
}
@@ -121,7 +124,7 @@ var rewriteDotSyntax = function(line) {
var inlinePartials = function(line) {
return line.replace(partialsRegex, function(match, operator, name) {
if (operator == '>') {
- var partial = "mustaches/" + name + ".mustache";
+ var partial = path.join(root, name + ".mustache");
return path.existsSync(partial) ? fs.readFileSync(partial, "utf-8") : "";
}
return match;
@@ -153,16 +156,18 @@ module.exports = {
randoms = {};
return function(options) {
+ root = options.root || ""; // Save off for inlinePartials
if (options.body) options.yield = options.body;
- loadJson();
+ loadJson(options.getPrefix());
jsons.settings = extend(jsons.settings, options.settings);
keys = Object.keys(jsons);
+
options = extend(options, jsons);
var template = rewrite(source);
- //console.log(template);
- return mustache.to_html(template, options, {});
+ var rendered_html = mustache.to_html(template, options, {});
+ return rendered_html;
}
}
-};
+};
Please sign in to comment.
Something went wrong with that request. Please try again.