Permalink
Browse files

Updated README.md and fixed a bug with processing embedded line.

  • Loading branch information...
1 parent b6427ac commit e4acefbcff8eaf5435bd4494dde49c8a9a132b64 @vail130 committed Jan 17, 2013
Showing with 312 additions and 317 deletions.
  1. +0 −19 LICENSE
  2. +7 −0 LICENSE-MIT
  3. +31 −41 README.md
  4. +223 −0 bin/wieldyjs
  5. +0 −219 bin/wieldymarkup
  6. +24 −24 lib/{wieldymarkup.js → wieldyjs.js}
  7. +20 −7 package.json
  8. +5 −5 src/{wieldymarkup.coffee → wieldyjs.coffee}
  9. +1 −1 test/test.js
  10. +1 −1 test_src/test.coffee
View
19 LICENSE
@@ -1,19 +0,0 @@
-Copyright (c) 2013 Vail Gold
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
View
@@ -0,0 +1,7 @@
+Copyright (c) 2013 Vail Gold
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,55 +1,46 @@
-# WieldyMarkup - Nicer than HTML
-
-## tl;dr
-
-WieldyMarkup is an HTML abstraction markup language, similar in many ways to [Jade](http://jade-lang.com/). However, WieldyMarkup does not do any interpolation (currently), and is meant to be part of the build & deploy process, not the page serving process. It's probably best for writing static HTML pages and templates that use Underscore or Mustache templating languages, as well.
+# WieldyMarkup - Template-agnostic markup that's clean and compiles to HTML
## Installation
```shell
-npm install wieldymarkup
+npm install wieldyjs -g
+wieldyjs
+
+WieldyJS: WieldyMarkup Compiler for Node
+
+ Usage:
+ wieldyjs [options]* [(file | dir)* | ((-m | --mirror) in-dir out-dir)]
+
+ Usage Syntax:
+ `[` and `]` denote optional groups
+ `(` and `)` denote semantic groups
+ `*` denotes 0 or more of the preceeding entity
+ `|` denotes OR relationship between preceeding and proceeding entities
+
+ Global Options:
+ -h OR --help Show this help message.
+ -v OR --verbose Display messages describing compiler behavior.
+ -c OR --compress Output HTML files without whitespace between tags.
+ -r OR --recursive Search recursively inside directories for .wml files.
+
```
## Terminal Usage
-Creates `.html` files with the same file name in the same directory as compiled `.wml` files. Add `-c` or `--compress` argument to remove whitespace between HTML tags.
-
-### Specific Files
-
-This will fail if any files do not have the `.wml` extension. Use `-f` or `--force` anywhere to fail silently.
-
-```shell
-./path/to/wieldymarkup /path/to/text_file_1.wml /path/to/text_file_2.wml
-```
-
-### In a Directory
-
-The directory should directly follow the `-d` argument. This will compile direct children with `.wml` extension and create `.html` files in the same directory.
-
-```shell
-./path/to/wieldymarkup -d example/
-```
-
-Use `-r` or `--recursive` to compile all `.wml` files, recursively.
+There are two main ways to use WieldyJS:
-```shell
-./path/to/wieldymarkup -r -d example/
-```
+1. List `.wml` files and directories containing `.wml` files, and WieldyJS will compile `.html` versions in the same location.
-Add a second directory argument to compile all `.wml` files into `.html` files in a separate file tree.
-
-```shell
-./path/to/wieldymarkup -r -d example-wml/ example-html/
-```
-
-Use `-v` or `--verbose` for more messages in the console.
+2. Use the `-m` or `--mirror` option and list an input directory and output directory, in that order. WieldyJS will find all `.wml` files in the input directory and compile them to `.html` files in the output directory.
## Node Usage
+This will fail if any files do not have the `.wml` extension. Use `-f` or `--force` anywhere to fail silently.
+
```javascript
var fs = require('fs');
-var Compiler = require('wieldymarkup');
+var Compiler = require('wieldyjs');
// Just a one-off
fs.readFile('/path/to/file', 'utf8', function(err, data) {
@@ -58,7 +49,7 @@ fs.readFile('/path/to/file', 'utf8', function(err, data) {
var compressed_html = new Compiler(data, true).output;
});
-# Or a little more flexible
+// Or a little more flexible
var c = new Compiler();
fs.readFile('/path/to/file', 'utf8', function(err, data) {
if (err) { return console.log(err); }
@@ -72,13 +63,12 @@ fs.readFile('/path/to/file', 'utf8', function(err, data) {
```shell
cd /path/to/wieldymarkup
-npm install mocha
mocha
```
-## Indicative Example
+## WieldyMarkup Syntax:
-### WieldyMarkup:
+### WML:
```
`<!DOCTYPE html>
@@ -104,7 +94,7 @@ html lang=en
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.>
```
-### Corresponding HTML Output:
+### HTML:
```html
<!DOCTYPE html>
View
@@ -0,0 +1,223 @@
+#!/usr/bin/env node
+
+var Compiler = require('../lib/wieldyjs').Compiler;
+var _ = require('underscore');
+var findit = require('findit');
+var fs = require('fs');
+
+var Commander = function(args) {
+
+ var getOutputFile = function(inputDir, outputDir, file) {
+ subTreeSections = path.split(file).slice(path.split(inputDir).length);
+ subTreeSections.pop();
+ subTree = path.join(subTreeSections);
+ fileBaseName = path.basename(file, '.wml');
+ return path.join(outputDir, subTree, fileBaseName + '.html');
+ };
+
+ var makeDirsForPath = function(path, verbose) {
+ var pathSections = path.split('/');
+ pathSections.pop();
+ if(pathSections[0] == '') {
+ pathSections.shift();
+ }
+ var tempPath, stats;
+ for(var i = 0; pathSections[i]; i++) {
+ tempPath = '/' + pathSections.slice(0, i+1).join('/');
+ if(!fs.existsSync(tempPath)) {
+ if(verbose) {
+ console.log("Creating directory " + tempPath);
+ }
+ fs.mkdirSync(tempPath);
+ }
+ }
+ };
+
+ var self = this;
+
+ this.init = function(args) {
+ this.verbose = false;
+ this.compress = false;
+ this.recursive = false;
+
+ var help = false;
+ var mirror = false;
+
+ if(args.indexOf("-h") + args.indexOf("--help") > -2) {
+ help = true;
+ }
+
+ if(args.indexOf("-v") + args.indexOf("--verbose") > -2) {
+ this.verbose = true;
+ }
+ if(args.indexOf("-c") + args.indexOf("--compress") > -2) {
+ this.compress = true;
+ if(this.verbose) {
+ console.log("Compression mode detected.");
+ }
+ }
+ if(args.indexOf("-r") + args.indexOf("--recursive") > -2) {
+ this.recursive = true;
+ if(this.verbose) {
+ console.log("Recursive mode detected.");
+ }
+ }
+ if(args.indexOf("-m") + args.indexOf("--mirror") > -2) {
+ var mirror = true;
+ if(this.verbose) {
+ console.log("Mirrored mode detected.");
+ }
+ }
+
+ filteredArgs = _.reject(args, function(arg) { return arg[0] === '-' });
+
+ if(help || filteredArgs.length === 0) {
+ this.showHelp();
+ } else if(mirror) {
+ if(filteredArgs.length !== 2) {
+ return console.log([
+ "There must be exactly two path arguments for mirrored mored. ",
+ "Exiting."
+ ].join(""));
+ } else {
+ this.processMirroredFileTree(filteredArgs);
+ }
+ } else {
+ this.processPathList(filteredArgs);
+ }
+ };
+
+ this.showHelp = function() {
+ console.log([
+ "",
+ "WieldyJS: WieldyMarkup Compiler for Node",
+ "",
+ "Usage:",
+ " wieldyjs [options]* [(file | dir)* | ((-m | --mirror) in-dir out-dir)]",
+ "",
+ "Usage Syntax:",
+ " `[` and `]` denote optional groups",
+ " `(` and `)` denote semantic groups",
+ " `*` denotes 0 or more of the preceeding entity",
+ " `|` denotes OR relationship between preceeding and proceeding entities",
+ "",
+ "Global Options:",
+ " -h OR --help Show this help message.",
+ " -v OR --verbose Display messages describing compiler behavior.",
+ " -c OR --compress Output HTML files without whitespace between tags.",
+ " -r OR --recursive Search recursively inside directories for .wml files.",
+ ""
+ ].join("\n "));
+ };
+
+ this.processPathList = function(args) {
+ if(this.verbose) {
+ console.log("Processing as path list.");
+ }
+
+ _.each(args, function(arg) {
+ if(!fs.existsSync(arg)) {
+ // TODO: Add verbose message
+ return;
+ }
+ if(fs.statSync(arg).isDirectory()) {
+ if(self.recursive) {
+ findit(arg).on('file', function (file) {
+ if(path.extname(file) !== '.wml') {
+ return;
+ }
+ self.compileFromPath(file, getOutputFile(arg, arg, file));
+ });
+
+ } else {
+ fs.readdir(arg, function (err, files) {
+ if (err) {
+ return console.log(err);
+ }
+ _.each(files, function(file) {
+ if(path.extname(file) !== '.wml') {
+ return;
+ }
+ self.compileFromPath(file, getOutputFile(arg, arg, file));
+ });
+ });
+ }
+ } else {
+ if(path.extname(arg) !== '.wml') {
+ return;
+ }
+ self.compileFromPath(arg, arg.substr(0, arg.length - 4) + '.html');
+ }
+ });
+ };
+
+ this.processMirroredFileTree = function(args) {
+ if(this.verbose) {
+ console.log("Processing as mirrored file tree.");
+ }
+
+ var inputDir = path.normalize(args[0]);
+ var outputDir = path.normalize(args[1]);
+ var cwd = process.cwd();
+
+ if(inputDir[0] !== '/' && inputDir.search(/^[a-zA-Z]:[\\\/]/) === 0) {
+ inputDir = path.join(cwd, inputDir);
+ }
+ if(!fs.existsSync(inputDir)) {
+ return console.log("Input directory does not exist. Exiting.");
+ }
+ if(!fs.statSync(inputDir).isDirectory()) {
+ return console.log("Input directory is not a directory. Exiting.");
+ }
+ if(this.verbose) {
+ console.log("Input directory confirmed.");
+ }
+
+ if(outputDir[0] !== '/' && outputDir.search(/^[a-zA-Z]:[\\\/]/) === 0) {
+ outputDir = path.join(cwd, outputDir);
+ }
+ if(this.verbose) {
+ console.log("Output directory confirmed.");
+ }
+
+ if(this.recursive) {
+ findit(inputDir).on('file', function (file) {
+ if(path.extname(file) !== '.wml') {
+ return;
+ }
+ self.compileFromPath(file, getOutputFile(inputDir, outputDir, file));
+ });
+
+ } else {
+ fs.readdir(inputDir, function (err, files) {
+ if (err) {
+ return console.log(err);
+ }
+ _.each(files, function(file) {
+ if(path.extname(file) !== '.wml') {
+ return;
+ }
+ self.compileFromPath(file, getOutputFile(inputDir, outputDir, file));
+ });
+ });
+ }
+ };
+
+ this.compileFromPath = function(file, output) {
+ fs.readFile(file, 'utf8', function(err, data) {
+ if (err) { return console.log(err); }
+
+ var html = new Compiler(data, self.compress).output;
+ makeDirsForPath(output, self.verbose);
+
+ if(self.verbose) {
+ console.log("Compiling " + output);
+ }
+ fs.writeFile(output, html);
+ });
+ };
+
+ this.init(args);
+}
+
+new Commander(process.argv.slice(2));
Oops, something went wrong.

0 comments on commit e4acefb

Please sign in to comment.