-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
wintersmith-browserify | ||
====================== | ||
|
||
browserify plugin for wintersmith | ||
[browserify](https://github.com/substack/node-browserify) plugin for [wintersmith](https://github.com/jnordberg/wintersmith) | ||
|
||
install: | ||
|
||
`npm install wintersmith-browserify -g` | ||
then add `wintersmith-browserify` to plugins in your wintersmith config | ||
|
||
![browserify!](http://substack.net/images/browserify/browserify.png) | ||
|
||
:-D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["./../"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"template": "index.jade" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello from message.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
exports.messages = [ | ||
'hello from bar.js', | ||
require('./baz') | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
module.exports = 'hello from baz.coffee' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
window.addEventListener('load', require('./test').main, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
bar = require './foo/bar' | ||
http = require 'http' | ||
url = require 'url' | ||
|
||
exports.main = -> | ||
log = (message) -> | ||
@el ?= document.getElementById 'log' | ||
@el.innerHTML += "#{ message }\n" | ||
|
||
# log messages comming from other files | ||
log message for message in bar.messages | ||
|
||
# setup a http request using browserify's http module (which works exactly like nodes) | ||
request = http.get | ||
path: '/message.txt' | ||
, (response) -> | ||
buffer = [] | ||
response.on 'data', (chunk) -> | ||
buffer.push chunk | ||
response.on 'end', () -> | ||
log buffer.join '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
!!! 5 | ||
html(lang='en') | ||
head | ||
meta(charset='utf-8') | ||
title Browserify! | ||
script(src='scripts/main.js') | ||
body | ||
pre#log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('coffee-script'); | ||
module.exports = require('./plugin'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "wintersmith-browserify", | ||
"version": "0.1.0", | ||
"author": "Johan Nordberg <its@johan-nordberg.com>", | ||
"description": "browserify for witnersmith", | ||
"license": "MIT", | ||
"dependencies": { | ||
"browserify": ">= 0.0.1", | ||
"coffee-script": ">= 1.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
browserify = require 'browserify' | ||
path = require 'path' | ||
|
||
module.exports = (wintersmith, callback) -> | ||
|
||
class BrowserifyPlugin extends wintersmith.ContentPlugin | ||
|
||
constructor: (@_filename, @_base) -> | ||
|
||
getFilename: -> | ||
@_filename | ||
|
||
render: (locals, contents, templates, callback) -> | ||
bundle = browserify | ||
cache: false | ||
watch: false | ||
|
||
bundle.addListener 'syntaxError', (error) -> | ||
callback error | ||
# unset callback so we don't call it twice | ||
callback = null | ||
|
||
# wrap in try catch since coffeescript parse errors will throw.. | ||
try | ||
bundle.addEntry path.join(@_base, @_filename) | ||
callback? null, new Buffer bundle.bundle() | ||
catch error | ||
callback? error | ||
|
||
BrowserifyPlugin.fromFile = (filename, base, callback) -> | ||
callback null, new BrowserifyPlugin filename, base | ||
|
||
wintersmith.registerContentPlugin 'scripts', '**/*.js', BrowserifyPlugin | ||
callback() |