Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade template as a preprocessor for html

I will not be using node.js in production, but I like jades syntax, so I would like to compile jade template into html when developing.

Given this file structure:

app/
  jade_templates /
    index.jade
    subfolder /
      subpage.jade
  html_templates /
    index.html
    subfolder /
      subpage.html

I would like to have a script that watches the jade_templates directory and compiles the corresponding html template to html_templates any time a change has been made.

How can this be accomplished?

Thank you.

EDIT The Jade README has this Sample Makefile, but I'm not sure how to adapt this to my needs.

JADE = $(shell find pages/*.jade)
HTML = $(JADE:.jade=.html)

all: $(HTML)

%.html: %.jade
    jade < $< --path $< > $@

clean:
    rm -f $(HTML)

.PHONY: clean
like image 263
Kyle Finley Avatar asked Mar 30 '12 16:03

Kyle Finley


People also ask

What is Jade in HTML?

Jade is a template engine for node. js and the default rendering engine for the Express web framework. It is a new, simplified language that compiles into HTML and is extremely useful for web developers. Jade is designed primarily for server-side templating in node.

Is Jade better than EJS?

According to some benchmark tests, EJS is way faster than Jade or Haml.

Is Jade template engines can be used with node js?

Jade is a template engine for Node. js. Jade syntax is easy to learn. It uses whitespace and indentation as a part of the syntax.

Is Pug better than HTML?

Notice that coding using the PUG framework is much easier and more readable than thr HTML codes. PUG makes use of indentation to distinguish between where a tag starts and ends. This makes the code much cleaner than HTML, where lack of indentation and a need for closing tags makes the code a little cluttered.


1 Answers

Since I had the need for a similar script I took the time and tried out a few tools and shell scripts out there (like forever) but couldn't find anything satisfactory.

So I went on to implement this solution. You can find it on github:

https://github.com/mihaifm/simplemon

See if it works for you. I added an example for jade as well.

Cheers!

like image 84
mihai Avatar answered Sep 30 '22 06:09

mihai