0.2.2 • Published 8 years ago
fig-compiler v0.2.2
fig-compiler 
fig.js component compiler
usage
api
obj = compiler(input[, opts])
Where input is a string a of fig component. Available options for the opts object are as follows:
opts.filePath- required if you want to use pug's relative includes/extends inside of the componentopts.defaultName- name set for the component, if thelabelis missing on the componentopts.debug- if set totruepassesdebugandcompileDebugto pug, tldr: iffalseoutput is smaller, at the cost of some pretty error messages
Returns an obj which has a few properties:
obj.template- a function compiled by pug that takes a locals object and spits out HTML when asked toobj.style- just a string containing the contents of the style tag inside the componentobj.script- string of code which just so happens to be ran throughbabelwith thees-2015preset for your dearest convenience.obj.name- name of the component, taken from thelabeltag, oropts.defaultNameif that doesn't exist. Otherwiseundefined
connect middleware
For development pleasure, this module includes a simple connect middleware function, compatible with express. Used akin to express.static middleware, point it to the directory you store your fig components in, the middleware should compile the component on the fly (without caching) and serve it to the client.
:warning: Not meant to be used in production.
example
// server.js
const express = require('express')
const fig = require('fig-compiler/connect')
const app = express()
app.use(fig('components'))
app.listen(3000)
// client.js
const app = fig()
app.use('main-view.fig') // pulls from localhost:3000/main-view.fig
app._components.get('main-view') // should be the compiled componentinstall
npm install fig-compiler --save
license
MIT