diff --git a/lib/helpers/raw.js b/lib/helpers/raw.js index d323ae977..34669054d 100644 --- a/lib/helpers/raw.js +++ b/lib/helpers/raw.js @@ -281,14 +281,15 @@ exports.getCurrent = function(sourcePath){ // this could be a tad smarter var namespace = sourcePath.split(".")[0].split("/") - + var base = ''; + namespace.slice(0, namespace.length - 1) ? namespace.slice(0, namespace.length - 1).forEach(function() { base += '../' }) : '' return { source: namespace[namespace.length -1], - path: namespace + path: namespace, + base: base } } - /** * * Source Type diff --git a/test/current.js b/test/current.js new file mode 100644 index 000000000..51a687860 --- /dev/null +++ b/test/current.js @@ -0,0 +1,97 @@ +var should = require('should') +var polymer = require('../') + +describe("current", function(){ + + describe("base", function(){ + var root = __dirname + "/fixtures/current/base" + var poly = polymer.root(root) + + it("should use a relative path in the root", function(done){ + poly.render("index.jade", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("

Matthew Carter

") + body.should.include("") + done() + }) + }) + + it("should use a relative path when nested", function(done){ + poly.render("georgia/verdana/helvetica/index.ejs", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("

Matthew Carter

") + body.should.include("") + done() + }) + }) + + }) + + describe("path", function(){ + var root = __dirname + "/fixtures/current/path" + var poly = polymer.root(root) + + it("should provide current path", function(done){ + poly.render("index.jade", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("

index

") + done() + }) + }) + + it("should provide current path in to an index page in a subdirectory", function(done){ + poly.render("one/two/index.jade", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("
  • one") + body.should.include("
  • two") + body.should.include("
  • index") + done() + }) + }) + + + it("should provide current path to a non-index page in a subdirectory", function(done){ + poly.render("one/two/three/about.jade", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("
  • one") + body.should.include("
  • two") + body.should.include("
  • three") + body.should.include("
  • about") + body.should.not.include("index") + done() + }) + }) + + it("should provide a portion of the current path", function(done){ + poly.render("contact/index.ejs", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("contact") + done() + }) + }) + + + }) + + describe("source", function(){ + var root = __dirname + "/fixtures/current/source" + var poly = polymer.root(root) + + it("should provide the current source", function(done){ + poly.render("about.jade", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("About") + done() + }) + }) + + }) + +}) \ No newline at end of file diff --git a/test/fixtures/current/path/contact/index.ejs b/test/fixtures/current/path/contact/index.ejs new file mode 100644 index 000000000..fd8374a08 --- /dev/null +++ b/test/fixtures/current/path/contact/index.ejs @@ -0,0 +1,8 @@ + + + + <%= current.path[0] %> + + + + \ No newline at end of file diff --git a/test/fixtures/current/path/index.jade b/test/fixtures/current/path/index.jade new file mode 100644 index 000000000..39b3d6d46 --- /dev/null +++ b/test/fixtures/current/path/index.jade @@ -0,0 +1,6 @@ +doctype +html + head + title Home + body + h1= current.path \ No newline at end of file diff --git a/test/fixtures/current/path/one/two/index.jade b/test/fixtures/current/path/one/two/index.jade new file mode 100644 index 000000000..0615fb554 --- /dev/null +++ b/test/fixtures/current/path/one/two/index.jade @@ -0,0 +1,9 @@ +doctype +html + head + title Two + body + h1 Where am I? + ul + each item in current.path + li: a(href="#")= item \ No newline at end of file diff --git a/test/fixtures/current/path/one/two/three/about.jade b/test/fixtures/current/path/one/two/three/about.jade new file mode 100644 index 000000000..23834bb74 --- /dev/null +++ b/test/fixtures/current/path/one/two/three/about.jade @@ -0,0 +1,9 @@ +doctype +html + head + title About + body + h1 Where am I? + ul + each item in current.path + li: a(href="#")= item \ No newline at end of file diff --git a/test/fixtures/current/source/about.jade b/test/fixtures/current/source/about.jade new file mode 100644 index 000000000..94c965334 --- /dev/null +++ b/test/fixtures/current/source/about.jade @@ -0,0 +1,8 @@ +doctype +html + head + title About + body + nav + a(href="/") Home + a(href="about" class="#{ current.source == 'about' ? 'active' : 'inactive' }") About