sintaxi / harp

Static Web Server/Generator/Bundler
http://harpjs.com
5k stars 343 forks source link

Access to file system #499

Closed cfjedimaster closed 5 years ago

cfjedimaster commented 9 years ago

Would it be possible to expose access to the file system, perhaps by making fs available to templates?

rwxrob commented 9 years ago

+1 can't seem to read in javascript files for example that I would like to inline in a <script> tags. I have tried partials (which I also learned are not supported in Jade; includes, which ignore anything with a .js extension or most anything else for that matter. My last hope was actually using JavaScript to read in the file into a variable.

omichelsen commented 9 years ago

@robmuh I'm doing this with Jade to inline javascript and it works fine:

script
  include ../scripts/echo.js
rwxrob commented 9 years ago

Well that is definitely working in 0.19 (wasn't in 0.14) and is something, but I was hoping to be able to loop through all the .js files or all files in js directory and include them with something like the following, which does not seem to work still:

doctype
html
  body
    script
      - for f in public._contents
        - if (f.slice(f.length-3,f.length) == '.js')
          != partial(f)

This throws no error and works if you use if for non .js files. It still doesn't minify, etc, but at least it would be one way to automatically inline all the JavaScript without touching the Jade for every new file created.

By the way, this makes Phaser.io game development so much nicer than the alternatives.

cfjedimaster commented 9 years ago

You can loop through all files. It is in the public scope I believe. See the Cookbook as they have an example of this.

On Wed, Oct 21, 2015 at 9:26 AM, Rob Muhlestein notifications@github.com wrote:

Well that is definitely working in 0.19 (wasn't in 0.14) and is something, but I was hoping to be able to loop through all the .js files or all files in js directory and include them with something like the following, which does not seem to work still:

doctypehtml body script - for f in public._contents - if (f.slice(f.length-3,f.length) == '.js') != partial(f)

This throws no error and works if you use if for non .js files. It still doesn't minify, etc, but at least it would be one way to automatically inline all the JavaScript without touching the Jade for every new file created.

By the way, this makes Phaser.io game development so much nicer than the alternatives.

— Reply to this email directly or view it on GitHub https://github.com/sintaxi/harp/issues/499#issuecomment-149912364.

Raymond Camden, Developer Advocate for MobileFirst at IBM

Email : raymondcamden@gmail.com Blog : www.raymondcamden.com Twitter: raymondcamden

rwxrob commented 9 years ago

Yes this loop works perfectly and I can print the name of the file in the html, the problem seems to be with the partial, it will not load the content of the file. It is a pretty simple test if anyone would like to confirm it. Just place main.js and blah.js in the same public with index.jade to recreate.