Permalink
Browse files

more browser compile options

  • Loading branch information...
1 parent 038adad commit 3c0eb36312356075a96cc855831a8109450f9914 @malgorithms committed Sep 5, 2012
View
@@ -1,7 +1,8 @@
-{spawn, exec} = require 'child_process'
-fs = require 'fs'
-jison = require 'jison'
-path = require 'path'
+{spawn, exec} = require 'child_process'
+fs = require 'fs'
+jison = require 'jison'
+path = require 'path'
+{getCommonHeadersJs} = require './lib/view'
task 'build', 'build the whole jam', (cb) ->
console.log "Building"
@@ -11,9 +12,10 @@ task 'build', 'build the whole jam', (cb) ->
buildParser ->
runCoffee ['-c', '-o', 'lib/'].concat(files), ->
runCoffee ['-c', 'index.coffee'], ->
- generateExpressTest ->
- console.log "Done building."
- cb() if typeof cb is 'function'
+ buildCommonHeaders ->
+ generateExpressTest ->
+ console.log "Done building."
+ cb() if typeof cb is 'function'
runCoffee = (args, cb) ->
proc = spawn 'coffee', args
@@ -40,23 +42,32 @@ buildParser = (cb) ->
fs.writeFileSync "./lib/#{file_name}", source
cb()
+buildCommonHeaders = (cb) ->
+ headers = getCommonHeadersJs true, true
+ fs.writeFileSync "./toffee.js", headers, "utf8"
+ cb()
+
generateExpressTest = (cb) ->
# generate the JS file bundling all the tests
- proc = spawn 'coffee', ['./src/command_line.coffee', '-m', './test/cases', '-o', './test/express3/public/javascripts/test_cases.js']
+ proc = spawn 'coffee', ['./src/command_line.coffee', '-n', '-m', './test/cases', '-o', './test/express3/public/javascripts/test_cases.js']
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
proc.stdout.on 'data', (buffer) -> console.log buffer.toString()
proc.on 'exit', (status) ->
process.exit(1) if status isnt 0
cb() if typeof cb is 'function'
+ headers = getCommonHeadersJs true, true
+ fs.writeFileSync "./test/express3/public/javascripts/toffee.js", headers, "utf8"
+
# generate an index page that tests them all
test_page = """
<html>
<head>
<title>Test Toffee in the browser</title>
+ <script type="text/javascript" src="/javascripts/toffee.js"></script>
<script type="text/javascript" src="/javascripts/test_cases.js"></script>
<style>
.test_case {font-size:10px; font-family:courier new;}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,7 +1,7 @@
{
"name": "toffee",
"description": "An Express 3.x and 2.x templating language based on CoffeeScript with slicker tokens and syntax. Built with love at OkCupid.",
- "version": "0.0.41",
+ "version": "0.0.42",
"directories": {
"lib": "./lib"
},
View
@@ -33,23 +33,33 @@ program.on '--help', ->
"
program.version(getVersionNumber())
- .option('-o, --output [path]', 'output file')
- .option('-p, --print', 'print output to stdout')
- .option('-m, --minimize', 'minimize output (ugly, smaller file)')
- .option('-c, --coffee', 'output to CoffeeScript (not JS)')
+ .option('-o, --output [path]', 'output to single file')
+ .option('-p, --print', 'print output to stdout')
+ .option('-m, --minimize', 'minimize output (ugly, smaller file)')
+ .option('-c, --coffee', 'output to CoffeeScript (not JS)')
+ .option('-b, --bundle_path [path]', 'bundle_path (instead of "/") for templates')
+ .option('-n, --no_headers', 'exclude boilerplate toffee (requires toffee.js included separately)')
.parse process.argv
# -----------------------------------------------------------------------------
-compile = (start_path, path) ->
+compile = (start_path, full_path) ->
###
e.g., if start_path is /foo/bar
and path is /foo/bar/car/thing.toffee
###
- source = fs.readFileSync path, 'utf8'
- bundle_path = path[start_path.length...]
+ source = fs.readFileSync full_path, 'utf8'
+ bundle_path = full_path[start_path.length...]
+
+ if start_path is full_path
+ bundle_path = "/" + path.basename full_path
+
+ if program.bundle_path
+ bundle_path = path.normalize "#{program.bundle_path}/#{bundle_path}"
+
+
v = new view source,
- fileName: path
+ fileName: full_path
bundlePath: bundle_path
browserMode: true
minimize: program.minimize? and program.minimize
@@ -81,6 +91,8 @@ recurseRun = (start_path, curr_path, out_text) ->
return out_text
+# -----------------------------------------------------------------------------
+
run = exports.run = ->
if program.args.length isnt 1
@@ -95,11 +107,14 @@ run = exports.run = ->
process.exit 1
start_path = path.normalize start_path
template_out = recurseRun start_path, start_path, ''
- header_out = getCommonHeadersJs true, true
+ if program.no_headers
+ header_out = ""
+ else
+ header_out = getCommonHeadersJs true, true
if program.coffee
out_text = "`#{header_out}`\n#{template_out}"
else
- out_text = "#{header_out}\n;\n#{template_out}"
+ out_text = "#{header_out}#{template_out}"
if program.print
console.log out_text

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,6 +1,7 @@
<html>
<head>
<title>Test Toffee in the browser</title>
+ <script type="text/javascript" src="/javascripts/toffee.js"></script>
<script type="text/javascript" src="/javascripts/test_cases.js"></script>
<style>
.test_case {font-size:10px; font-family:courier new;}

0 comments on commit 3c0eb36

Please sign in to comment.