Skip to content

Instantly share code, notes, and snippets.

@robert-wallis
Created June 26, 2012 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert-wallis/3000270 to your computer and use it in GitHub Desktop.
Save robert-wallis/3000270 to your computer and use it in GitHub Desktop.
Static Jade Template Builder
JADE_C="../node/node_modules/jade/bin/jade"
template_OUT=../../static
template_JADE=*.jade */*.jade
template_HTML=$(foreach source_file, $(template_JADE), ${template_OUT}/${source_file:.jade=.html})
.PHONY: all
all: $(template_HTML)
$(template_OUT)/%.html: %.jade
$(JADE_C) $< --out $(template_OUT)/$(dir $<)
@robert-wallis
Copy link
Author

Description

  • JADE_C is the jade compiler, I could use just "jade" but that requires someone has already done "npm install -g jade" and I think on prod that step has not been done, all the source is inside the folder.
  • template_OUT points to the Nginx root folder for the site, to statically serve up the files, lightning fast.
  • template_JADE has a cool */*.jade expression in it, that will find all the jade files in subfolders, as well as this folder
  • template_HTML the for loop just does a string replace *.jade to *.html
  • .PHONY all isn't really a file that needs to be made, but just a rule, that depends on all the html being built and up to date.
  • %.html: %.jade is a rule that says how to build any .html file from any .jade file
  • $< are all the dependencies for this particular html file
  • $(dir $<) gets the directory/folder name for all the files, because in template_JADE I include not only the current dir, but subdirs too. So this will tell jade to build into that folder. This is the critical step because piping a jade file into the jade command won't accept filename includes, and the jade command will not render to a specific file, it only renders to a folder and changes the name to html "for you" automagically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment