Giter Site home page Giter Site logo

lua-pug's Introduction

lua-pug v0.2.0

This package generates HTML from a https://github.com/pugjs/pug AST.

local pug = require('pug')

-- Create an HTML renderer.
local render = pug{
  template = 'div !{greeting}, #[b name]!',
  globals = { greeting = '<em>Hola</em>' },
}

-- Render some HTML!
local html = render{
  globals = { name = 'Señorita' },
}

You must use https://github.com/aleclarson/pug2lua to generate the Lua render function from your Pug template. You also have the option of using MoonScript within Pug expressions/blocks.

For Atom support of MoonScript in Pug, you should use https://github.com/aleclarson/language-pug, which expects https://github.com/OttoRobba/atom-moonscript to exist.

Options

These options are supported by the pug function:

  • path: string
  • render: function
  • template: string
  • resolve: (ref: string, parent: string) => function|string
  • globals: table
  • mixins: { string => function }

The path string can be used by your resolve function to identify which template contains the include statement being resolved. Other than that, it's useless.

You must define render or template. Typically, you will being using the template option. Remember that the mixins option is ignored when using the template option. It's expected that your template string will return a render function and an optional mixins table.

The resolve function is required if you plan to use the include keyword. Otherwise, the include is silently skipped. You can return a render function or an HTML string.

You can pass the same globals table for every template if you desire. Templates will not be able to modify it. By default, nothing is provided to templates (even _G variables) except the runtime required to render HTML.

The pug function returns a render function that you can call unlimited times to generate HTML.

These options are recognized by the render function:

  • resolve: function
  • globals: table
  • mixins: table

Passing globals to a render function will shadow any globals provided when creating the render function, but you will still have access to unshadowed globals. Same goes for the mixins table.

Remember that an included template will always use the same globals as its parent template. If the included template defines its own global variables, they won't leak into the parent template. Any mutations to global variables won't leak either (except table mutations).

lua-pug's People

Contributors

aleclarson avatar

Watchers

 avatar  avatar

lua-pug's Issues

shorthand style props

x: 'translateX'
y: 'translateY'
z: 'translateZ'
originX: 'transformOriginX'
originY: 'transformOriginY'

And transform props like rotate, scale, etc should be supported outside of the transform prop.

for..in loop mangles table keys

for key, value in { a = 1, b = 2 }
  div #{key} = #{value}

The above example will not work, because a and b will be prefixed with env. when it's assumed they are variable references and not table properties.

The workaround

- obj = { a = 1, b = 2 }
for key, value in obj
  div #{key} = #{value}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.