Permalink
Browse files

Make FBP parser run in the browser

  • Loading branch information...
1 parent 2e0397c commit 2fc0716b3faa90e23184a6da170dcc51aa9244f3 @bergie bergie committed May 30, 2013
Showing with 84 additions and 5 deletions.
  1. +2 −0 .gitignore
  2. +39 −2 Gruntfile.coffee
  3. +9 −0 component.json
  4. +5 −1 package.json
  5. +5 −2 spec/fbp.coffee
  6. +24 −0 spec/runner.html
View
@@ -1,2 +1,4 @@
/node_modules/
.DS_Store
+/browser/
+/spec/*.js
View
@@ -3,11 +3,28 @@ module.exports = ->
@initConfig
pkg: @file.readJSON 'package.json'
+ # Generate library from Peg grammar
peg:
fbp:
grammar: 'grammar/fbp.peg'
outputFile: 'lib/fbp.js'
+ # Build the browser Component
+ component_build:
+ 'fbp':
+ output: './browser/'
+ config: './component.json'
+ scripts: true
+ styles: false
+
+ # JavaScript minification for the browser
+ uglify:
+ options:
+ report: 'min'
+ noflo:
+ files:
+ './browser/fbp.min.js': ['./browser/fbp.js']
+
# Automated recompilation and testing when developing
watch:
files: ['spec/*.coffee', 'grammar/*.peg']
@@ -18,12 +35,32 @@ module.exports = ->
nodejs:
src: ['spec/*.coffee']
+ # CoffeeScript compilation
+ coffee:
+ spec:
+ options:
+ bare: true
+ expand: true
+ cwd: 'spec'
+ src: ['**.coffee']
+ dest: 'spec'
+ ext: '.js'
+
+ # BDD tests on browser
+ mocha_phantomjs:
+ all: ['spec/runner.html']
+
+ # Grunt plugins used for building
@loadNpmTasks 'grunt-peg'
+ @loadNpmTasks 'grunt-component-build'
+ @loadNpmTasks 'grunt-contrib-uglify'
# Grunt plugins used for testing
@loadNpmTasks 'grunt-cafe-mocha'
+ @loadNpmTasks 'grunt-contrib-coffee'
+ @loadNpmTasks 'grunt-mocha-phantomjs'
@loadNpmTasks 'grunt-contrib-watch'
- @registerTask 'build', ['peg']
- @registerTask 'test', ['build', 'cafemocha']
+ @registerTask 'build', ['peg', 'component_build', 'uglify']
+ @registerTask 'test', ['build', 'coffee', 'cafemocha', 'mocha_phantomjs']
@registerTask 'default', ['build']
View
@@ -0,0 +1,9 @@
+{
+ "name": "fbp",
+ "description": "Parser for the .fbp flow definition language",
+ "version": "1.0.0",
+ "scripts": [
+ "lib/fbp.js"
+ ],
+ "main": "lib/fbp.js"
+}
View
@@ -18,7 +18,11 @@
"chai": "~1.5.0",
"mocha": "~1.9.0",
"grunt-contrib-watch": "~0.3.1",
- "grunt-peg": "~0.1.0"
+ "grunt-peg": "~0.1.0",
+ "grunt-component-build": "~0.2.7",
+ "grunt-mocha-phantomjs": "~0.2.8",
+ "grunt-contrib-uglify": "~0.2.1",
+ "grunt-contrib-coffee": "~0.7.0"
},
"keywords": [],
"scripts": {
View
@@ -1,5 +1,8 @@
-chai = require 'chai' unless chai
-parser = require '../lib/fbp'
+if typeof process is 'object' and process.title is 'node'
+ chai = require 'chai' unless chai
+ parser = require '../lib/fbp'
+else
+ parser = require 'fbp'
describe 'FBP parser', ->
it 'should provide a parse method', ->
View
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>FBP in browser</title>
+ <link rel="stylesheet" href="../node_modules/mocha/mocha.css">
+ </head>
+ <body>
+ <div id="mocha"></div>
+ <script src="../browser/fbp.js"></script>
+ <script src="http://chaijs.com/chai.js"></script>
+ <script src="../node_modules/mocha/mocha.js"></script>
+ <script>mocha.setup('bdd');</script>
+ <script src="./fbp.js"></script>
+ <script>
+ if (window.mochaPhantomJS) {
+ mochaPhantomJS.run();
+ } else {
+ mocha.checkLeaks();
+ mocha.run();
+ }
+ </script>
+ </body>
+</html>

0 comments on commit 2fc0716

Please sign in to comment.