3.0.2 • Published 6 years ago

hoquet v3.0.2

Weekly downloads
32
License
MIT
Repository
-
Last release
6 years ago

hoquet

JavaScript HTML templating with s-expressions.

Installation

Install with npm:

$ npm install --save hoquet

Example

var hoquet = require('hoquet');

function layout(c) {
  return [
      "html", [
          "head",
          ["title", c.title],
          c.styles.map(function(href) {
              return ["link", {
                  rel: "stylesheet",
                  type: "text/css",
                  href: href
              }];
          }),
          c.head
      ],
      ["body", c.body]
  ];
}

var index = layout({title: "My Page",
                    styles: ["styles/reset.css",
                             "styles/main.css"],
                    body: ["div",
                           ["h1", "A message"]
                           ["p", "Hello World"]],
                    head: [["meta", {"name":"description",
                                     "content":"hello"}],
                           ["/js/lib/foo.js",
                            "/js/main.js"].map(function(src) {
                               return ["script", { src: src }];
                           })]});

API

.render

function that takes a structured array or a variable list of structured arrays and converts them into a String of HTML.

e.g.

    var hoquet = require('hoquet');
    
    hoquet.render(['p','foo'],['p','bar']);
    // <p>foo</p><p>bar</p>
    
    hoquet.render([['p','foo'],['p','bar']]);
    // <p>foo</p><p>bar</p>
    
    hoquet.render([[[[[['p','foo'],['p','bar']]]]]]);
    // <p>foo</p><p>bar</p>

    
    hoquet.render(['p', 'This is a ', ['span', 'paragraph'], ' with a span']);
    // <p>This is a <span>paragraph</span> with a span</p>

    hoquet.render(['div',{id: 'foo', class: 'bar'}, null]);
    //<div id="foo" class="bar"></div>

    hoquet.render(['meta', {foo: 'bar'}]);
    // <meta foo="bar" />

    hoquet.render(['ul', ['bread', 'milk', 'eggs'].map(function(x) {
      return(['li', x]);
    })]);
    // <ul><li>bread</li><li>milk</li><li>eggs</li></ul>

for more specifics, see ./test/test.js

Testing

From the repo root:

npm install
npm test

License

MIT

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.1.1

8 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago