How can I get @coffee to pull in CoffeeScript from a separate file?

27 views
Skip to first unread message

Zak

unread,
Jun 8, 2013, 1:30:24 PM6/8/13
to zap...@googlegroups.com
Instead of stuffing all my coffeescript in an inline string, how can I reference a local file? I want to do something like this:

    @coffee '/app.js' : __dirname + '/public/js/app.coffee'

step...@shimaore.net

unread,
Jun 8, 2013, 5:23:26 PM6/8/13
to zap...@googlegroups.com
Hello,

> Instead of stuffing all my coffeescript in an inline string,

One option is to not stuff it in a string but to keep it in a function,
this

@coffee '/app.js': ->
($ 'body').html 'hello'

should work.

I guess this

@coffee '/app.js': require './app.coffee'

should work as well (as long as app.coffee `exports` the desired code and
sticks to what is doable client-side).

But have a look at the example for connect-assets,

https://github.com/zappajs/zappajs/blob/master/examples/connect-assets.coffee

which references .coffee files in

https://github.com/zappajs/zappajs/tree/master/examples/public/js

but serves them as .js (which is closest to what you wanted I presume).

I seem to remember @scien mentioned he's now using something better than
connect-assets but I can't remember the name.
S.

--
St�phane Alnet -- Telecom Artisan. OpenSource Advocate.
Development and integration for FreeSwitch, OpenSIPS, CouchDB, Node.js.
Mobile: +33643482771 - http://shimaore.net/ - https://github.com/shimaore/

Bryant Williams

unread,
Jun 9, 2013, 11:30:07 AM6/9/13
to zap...@googlegroups.com
https://github.com/scien/asset-wrap/blob/master/examples/zappa-with-middleware.coffee

require('zappajs') ->
  wrap = require 'asset-wrap'
  assets = new wrap.Assets [
    new wrap.Snockets {
      src: 'src/app.coffee'
      dst: '/app.js'
    }
  ], (err) ->
    throw err if err
    @use assets.middleware

    @get '/': ->
      @render index: {
        assets: assets
      }

    @view index: ->
      head ->
        text @assets.tag '/app.js'
      body ->
        a href: @assets.url '/app.js', ->
          'View Javascript'

On Saturday, June 8, 2013 5:23:26 PM UTC-4, Stephane wrote:
Hello,

> Instead of stuffing all my coffeescript in an inline string,

One option is to not stuff it in a string but to keep it in a function,
this

    @coffee '/app.js': ->
      ($ 'body').html 'hello'

should work.

I guess this

    @coffee '/app.js': require './app.coffee'

should work as well (as long as app.coffee `exports` the desired code and
sticks to what is doable client-side).

But have a look at the example for connect-assets,

  https://github.com/zappajs/zappajs/blob/master/examples/connect-assets.coffee

which references .coffee files in

  https://github.com/zappajs/zappajs/tree/master/examples/public/js

but serves them as .js (which is closest to what you wanted I presume).

I seem to remember @scien mentioned he's now using something better than
connect-assets but I can't remember the name.
S.

--
St�phane Alnet -- Telecom Artisan. OpenSource Advocate.
Reply all
Reply to author
Forward
0 new messages