Skip to content

Commit

Permalink
Fix bug, add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Feb 24, 2014
1 parent 49dff7e commit 96bc3fa
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
5 changes: 5 additions & 0 deletions HELP.md
@@ -0,0 +1,5 @@
Turn a markdown file into a presentation. Same rules as
biggie. `-o` opens a browser.

biggie < file.md
biggie file.md
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -5,6 +5,18 @@ biggie is the last mile of [big](https://github.com/tmcw/big). It turns
and slides into a website, and even posts it online for you with the magic of
[bl.ocks.org](http://bl.ocks.org/) and [Gist](http://gist.github.com).

## cli

You can use biggie basically from the command line as an npm module:

```
npm install -g biggie
echo "# hi" | biggie > index.html
```

Pipe it into [browser](https://gist.github.com/defunkt/318247) or [bcat](http://rtomayko.github.io/bcat/)
to just view it in a browser immediately.

## develop

git@github.com:tmcw/biggie.git
Expand Down
29 changes: 29 additions & 0 deletions cli.js
@@ -0,0 +1,29 @@
#!/usr/bin/env node

var concat = require('concat-stream'),
fs = require('fs'),
mustache = require('mustache'),
argv = require('minimist')(process.argv.slice(2)),
marked = require('marked');

if (process.stdin.isTTY && !argv._[0]) {
process.stdout.write(fs.readFileSync(__dirname + '/HELP.md'));
process.exit(1);
}

(argv._.length ? fs.createReadStream(argv._[0]) : process.stdin).pipe(concat(convert));

function convert(data) {
var divs = data.toString().split('---').filter(function(v) {
return v.replace(/\s/g, '');
}).map(function(v) {
return '<div>' + marked(v) + '</div>';
}).join('\n');

process.stdout.write(mustache.render(
fs.readFileSync(__dirname + '/js/template.hbs', 'utf8'), {
title: 'Foo',
slides: divs,
style: fs.readFileSync(argv.style || (__dirname + '/js/style/classic.hbs'))
}));
}
2 changes: 1 addition & 1 deletion js/site.js
Expand Up @@ -673,7 +673,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
if (helper = helpers.style) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.style); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n</style>\n<script type='text/javascript'>\nwindow.onload = function() {\n var s = document.getElementsByTagName('div'), cur = 0, ti;\n if (!s) return;\n function go(n) {\n cur = n;\n var i = 1e3, e = s[n], t;\n for (var k = 0; k < s.length; k++) s[k].style.display = 'none';\n e.style.display = 'inline';\n e.style.fontSize = i + 'px';\n if (e.firstChild.nodeName === 'IMG') {\n document.body.style.backgroundImage = 'url(' + e.firstChild.src + ')';\n e.firstChild.style.display = 'none';\n if ('classList' in e) e.classList.add('imageText');\n } else {\n document.body.style.backgroundImage = '';\n document.body.style.backgroundColor = e.style.backgroundColor;\n }\n if (ti !== undefined) window.clearInterval(ti);\n t = parseInt(e.getAttribute('time-to-next') || 0, 10);\n if (t > 0) ti = window.setTimeout(fwd, (t * 1000));\n while (\n e.offsetWidth > window.innerWidth ||\n e.offsetHeight > window.innerHeight) {\n e.style.fontSize = (i -= i * 0.05) + 'px';\n if (i < 0) break;\n }\n e.style.marginTop = ((window.innerHeight - e.offsetHeight) / 2) + 'px';\n if (window.location.hash !== n) window.location.hash = n;\n document.title = e.textContent || e.innerText;\n }\n document.onclick = function() { go(++cur % (s.length)); };\n function fwd() { go(Math.min(s.length - 1, ++cur)); }\n function rev() { go(Math.max(0, --cur)); }\n document.onkeydown = function(e) {\n if (e.which === 39) fwd();\n if (e.which === 37) rev();\n };\n document.ontouchstart = function(e) {\n var x0 = e.changedTouches[0].pageX;\n document.ontouchend = function(e) {\n var x1 = e.changedTouches[0].pageX;\n if (x1 - x0 < 0) fwd();\n if (x1 - x0 > 0) rev();\n };\n };\n function parse_hash() {\n return Math.max(Math.min(\n s.length - 1,\n parseInt(window.location.hash.substring(1), 10)), 0);\n }\n if (window.location.hash) cur = parse_hash() || cur;\n window.onhashchange = function() {\n var c = parse_hash();\n if (c !== cur) go(c);\n };\n\n go(cur);\n};\n</script></head><body>\n";
buffer += "\n</style>\n<script type='text/javascript'>\nwindow.onload = function() {\n var s = document.getElementsByTagName('div'), cur = 0, ti;\n if (!s) return;\n function go(n) {\n cur = n;\n var i = 1e3, e = s[n], t;\n for (var k = 0; k < s.length; k++) s[k].style.display = 'none';\n e.style.display = 'inline';\n e.style.fontSize = i + 'px';\n if (e.firstChild.nodeName === 'IMG') {\n document.body.style.backgroundImage = 'url(' + e.firstChild.src + ')';\n e.firstChild.style.display = 'none';\n if ('classList' in e) e.classList.add('imageText');\n } else {\n document.body.style.backgroundImage = '';\n document.body.style.backgroundColor = e.style.backgroundColor;\n }\n if (ti !== undefined) window.clearInterval(ti);\n t = parseInt(e.getAttribute('time-to-next') || 0, 10);\n if (t > 0) ti = window.setTimeout(fwd, (t * 1000));\n while (\n e.offsetWidth > window.innerWidth ||\n e.offsetHeight > window.innerHeight) {\n e.style.fontSize = (i -= 5) + 'px';\n if (i < 0) break;\n }\n e.style.marginTop = ((window.innerHeight - e.offsetHeight) / 2) + 'px';\n if (window.location.hash !== n) window.location.hash = n;\n document.title = e.textContent || e.innerText;\n }\n document.onclick = function() { go(++cur % (s.length)); };\n function fwd() { go(Math.min(s.length - 1, ++cur)); }\n function rev() { go(Math.max(0, --cur)); }\n document.onkeydown = function(e) {\n if (e.which === 39) fwd();\n if (e.which === 37) rev();\n };\n document.ontouchstart = function(e) {\n var x0 = e.changedTouches[0].pageX;\n document.ontouchend = function(e) {\n var x1 = e.changedTouches[0].pageX;\n if (x1 - x0 < 0) fwd();\n if (x1 - x0 > 0) rev();\n };\n };\n function parse_hash() {\n return Math.max(Math.min(\n s.length - 1,\n parseInt(window.location.hash.substring(1), 10)), 0);\n }\n if (window.location.hash) cur = parse_hash() || cur;\n window.onhashchange = function() {\n var c = parse_hash();\n if (c !== cur) go(c);\n };\n\n go(cur);\n};\n</script></head><body>\n";
if (helper = helpers.slides) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.slides); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
if(stack1 || stack1 === 0) { buffer += stack1; }
Expand Down
2 changes: 1 addition & 1 deletion js/template.hbs
Expand Up @@ -31,7 +31,7 @@ window.onload = function() {
while (
e.offsetWidth > window.innerWidth ||
e.offsetHeight > window.innerHeight) {
e.style.fontSize = (i -= i * 0.05) + 'px';
e.style.fontSize = (i -= 5) + 'px';
if (i < 0) break;
}
e.style.marginTop = ((window.innerHeight - e.offsetHeight) / 2) + 'px';
Expand Down
14 changes: 12 additions & 2 deletions package.json
Expand Up @@ -7,10 +7,16 @@
"start": "beefy js/index.js:js/site.js -o",
"make": "browserify js/index.js > js/site.js"
},
"bin": {
"biggie": "cli.js"
},
"dependencies": {
"codemirror": "https://github.com/tmcw/CodeMirror/archive/module-export.tar.gz",
"marked": "~0.3.1",
"underscore": "~1.6.0"
"underscore": "~1.6.0",
"concat-stream": "~1.4.1",
"mustache": "~0.8.1",
"minimist": "0.0.8"
},
"repository": "git@github.com:tmcw/biggie.git",
"author": "Tom MacWright <tom@macwright.org>",
Expand All @@ -19,5 +25,9 @@
"beefy": "~1.1.0",
"hbsfy": "~1.3.2"
},
"browserify": { "transform": [ "hbsfy" ] }
"browserify": {
"transform": [
"hbsfy"
]
}
}

0 comments on commit 96bc3fa

Please sign in to comment.