Permalink
Browse files

Add static releases, improve getting started docs

  • Loading branch information...
1 parent b37a7ad commit 9c42957ad7fa8afc924ea8c197ec9c82a51d8ed7 Christian Johansen committed Feb 24, 2012
View
@@ -2,6 +2,8 @@
rm -fr static
echo "Indexing docs site at http://localhost:8090"
+mkdir static
+cp -r public/* static/.
wget --convert-links --page-requisites --recursive --level=inf -U WGET --html-extension --no-host-directories --directory-prefix=static http://localhost:8090/
find static -name "*.html" | xargs sed -i s/\"index.html/"\"\/"/
find static -name "*.html" | xargs sed -i s/index.html//
@@ -0,0 +1,12 @@
+var config = exports; // Vanity
+
+config["Browser tests"] = {
+ environment: "browser",
+ sources: ["strftime.js"],
+ tests: ["strftime-test.js"]
+};
+
+config["Server tests"] = {
+ extends: "Browser tests",
+ environment: "node"
+};
@@ -0,0 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <title>strftime</title>
+ </head>
+ <body>
+ <script type="text/javascript" src="/releases/latest/buster-test.js"></script>
+ <script type="text/javascript" src="strftime.js"></script>
+ <script type="text/javascript" src="strftime-test.js"></script>
+ </body>
+</html>
@@ -0,0 +1,43 @@
+if (typeof require == "function" && typeof module == "object") {
+ buster = require("buster");
+ require("./strftime");
+}
+
+var assert = buster.assert;
+
+buster.testCase("Date strftime tests", {
+ setUp: function () {
+ this.date = new Date(2009, 11, 5);
+ },
+
+ "%Y": {
+ setUp: function () {
+ this.year = this.date.strftime("%Y");
+ },
+
+ "should return full year": function () {
+ assert.equals(this.year, "2009");
+ },
+
+ "should return a string": function () {
+ assert.equals(typeof this.year, "string");
+ }
+ },
+
+ "%y should return two digit year": function () {
+ assert.equals(this.date.strftime("%y"), "09");
+ },
+
+ "%m should return month": function () {
+ assert.equals(this.date.strftime("%m"), "12");
+ },
+
+ "%d should return date": function () {
+ assert.equals(this.date.strftime("%d"), "05");
+ },
+
+ "//%j should return the day of the year": function () {
+ var date = new Date(2011, 0, 1);
+ assert.equals(date.strftime("%j"), 1);
+ }
+});
@@ -0,0 +1,57 @@
+// This is unfinished demo code
+
+Date.prototype.strftime = (function () {
+ function strftime(format) {
+ var date = this;
+
+ return (format + "").replace(/%([a-zA-Z])/g, function (m, f) {
+ var formatter = Date.formats && Date.formats[f];
+
+ if (typeof formatter == "function") {
+ return formatter.call(Date.formats, date);
+ } else if (typeof formatter == "string") {
+ return date.strftime(formatter);
+ }
+
+ return "%" + f;
+ });
+ }
+
+ // Internal helper
+ function zeroPad(num) {
+ return (+num < 10 ? "0" : "") + num;
+ }
+
+ Date.formats = {
+ // Formatting methods
+ d: function (date) {
+ return zeroPad(date.getDate());
+ },
+
+ m: function (date) {
+ return zeroPad(date.getMonth() + 1);
+ },
+
+ y: function (date) {
+ return zeroPad(date.getYear() % 100);
+ },
+
+ Y: function (date) {
+ return date.getFullYear();
+ },
+
+ j: function (date) {
+ var jan1 = new Date(date.getFullYear(), 0, 1);
+ var diff = date.getTime() - jan1.getTime();
+
+ // 86400000 == 60 * 60 * 24 * 1000
+ return Math.ceil(diff / 86400000);
+ },
+
+ // Format shorthands
+ F: "%Y-%m-%d",
+ D: "%m/%d/%y"
+ };
+
+ return strftime;
+}());

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 9c42957

Please sign in to comment.