npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

herb-foliage

v0.0.3

Published

A DSL to write HTML to a DOM

Downloads

2

Readme

Foliage - HTML in javascript

The basic idea of foliage is to provide modular, non-magical, easy to use, easy to extend, html-builders in javascript. The philosophy is that markup is for computers and code is for humans. Foliage tries to make client coding as human as possible.

Easy to use

The core concept of foliage is just a clever element implementation. The element is designed to make it easy to compose a tree of elements and have those elements create the corresponding dom-elements when given a parent to create those in. The functionality in the Foliage element is intended to be visually easy to understand and practically unsurprising to use.

Here is an example of how to print 'hello world' in a paragraph using foliage:

define(['foliage'], function(f) {
    return f.p("hello-world");
});

For such a simple example there is a bit of amd boilerplate in order to import foliage and assign the html builder to the variable f but it should be pretty clear that the intention is to print hello world in a p tag.

Lets see how to compose several elements:

define(['foliage'], function(f) {
   return f.ol(
             f.li("It is hard"),
             f.li(f.strong("not"), "to"),
             f.ul(
                f.li("figure"),
                f.li("out"),
                f.li("what this")),
             f.li("will", "look", "like"),
             f.li(f.img({src: "http://placekitten.com/g/200/200", 
                         alt: "there can not be enough cats in examples"})))
});

The above example shows basic composability and also introduces attributes.

Here is a summary of of the effect of different arguments to an element:

"a string"

becomes a text element under the element.

1337

becomes a textelemet under the element.

{attr1: 'value1', attr2: "value2"}

Becomes attributes on the element.

"#some-id"

is equivalent to

{id: 'some-id'}

This is convenient since the id attribute is so common.

".some-class"

is equivalent to

f.addClass("some-class")

to make it easier to add one or more classes to an element.

f.span("text")

Becomes a span element with a text element under the current element.

function(parent) {$(parent).click(function(){alert("somebody clicked the element")})}

Invokes the function on element when invoked.

For your convenience all html 4 elements has been declared on the foliage object.

Non-magical

What you do with foliage is very close to what you would do in HTML. It is generally quite simple to imagine what the resulting HTML will look like when reading foliage code. Foliage does not pretend that you are not generating HTML like some ui-frameworks. Instead foliage tries to make it more convenient to write HTML without robbing the user of control.

Modular

Foliage is modular both on a high and a low level. On a high level foliage relies heavily on AMD-modules. AMD is not optional, it is a core concept of Foliage. Foliage does not care which AMD-loader you use but the examples are using curl.

On a lower level Foliage is composable using functional programming. Therefore it is easy to reuse concepts and layouts with foliage. In the examples we have seen the result of each element invocation is a function taking anything that jquery interprets as an element as it's argument. Any number of these functions can then be passed as arguments into other elements to form trees.

Foliage does nothing to enforce this but all of foliage is written in a stateless fashion. What that means is that each foliage function will behave the same given that you call it with the same parameters. Beware though, foliage functions manipulate the DOM that means that the functions do have sideffects.

Without exceptions the followin is true for foliage:

  • composing foliage elements does not have sideffects

  • passing a JQuery element or expression to a foliage element will typically alter that element or add elements to it.