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

don

v0.2.0

Published

Lispy html templating DSL

Downloads

15

Readme

#DON

'Document Object Notation' An embedded html templating DSL in Javascript

No license. Do what you want with this. Creator: Tim Farland

##Don is an embedded templating DSL for Javascript

It is inspired by the use of lisp s-expressions to compose html, and by the use of pure javascript as a templating language ala Coffeekup, but it primarily makes use of js array and objects to represent html. It supports haml-style abbreviations.

Don templates are functions that take an object and return normal js data adhering to a certain form.

These template functions are transformed into html by Don.render()

All examples given in Coffeescript unless otherwise noted.

Benefits:

  • Terse, but remains normal js
  • Use the bracket matching of your favourite editor
  • Js syntax checking can help spot malformed html
  • No complicated abstractions or syntax to learn
  • Use js data directly in templates (e.g. objects as tag attributes)
  • Fast enough without a compilation step
  • Flexible

Note: I've also included an experimental Ruby version.

###BREAKING CHANGES! Upgrading from 0.1.0 to 0.2.0

The code and api has been simplified - now Don is only a single function:

# Old
Don.render(data, template)
Don.renderIn(data, template)

# New
Don(template, data)
Don.call(data, template)

###Npm

npm install don

###Node usage

Don = require('don')

articleTemplate = (data, key) ->
    ['article', {id: data.id + key}
        ['h3', data.title]
        ['div', data.body]]
            
Don(
   articleTemplate
   {id: 123, title: 'My Article', body: 'Article text'},
)
            
# => '<article id="123"><h3>My Article</h3><div>Article text</div></article>'

Also check out don-express for easy integration into your Express app

###Partials

You can use the power of closures to implement partials (a layout is a function that takes a template and returns a template):

partial = (d) ->
    ['article', {id: d.id}
        ['h3', d.title]
        ['div'
            d.body
            ['a', {href: d.link}, d.anchor]]]     
 
layout = (partial) -> (d) ->
      [['!doctype html']
       ['html'
           ['head'
               ['meta', charset: 'utf-8']
               ['title', d.title]]
           ['body'
               ['section'
                   ['h1', d.title]
                   ['div', {class: 'articles'}, (partial a for a in d.articles)]]]]]    

###Haml-style abbreviations

You can place short ids and css classes in the tag position, and omit the tag if it is a div:

user = (d) ->
     ['#profile'
            ['img', {src: '/thumb/' + d.id, alt: d.name}]
            ['.btn .settings', 'Settings']]

# => <div id="profile"><img src="/thumb/123" alt="John"><div class="btn settings">Settings</div></div>

###Acceptable forms

The arrays must adhere to Don's definition of an 'htmlArray'

An htmlArray is an array with either:

[elementType]
[elementType, contents...]
[elementType, attributes]
[elementType, attributes, contents...]
[]
[htmlArray...]

where:

  • elementType is a string, e.g: 'div'
  • contents is an arbitrary number of:
  • string, or
  • htmlArray
  • attributes is a js object, e.g: {id: 'mydiv'}

examples:

htmlArray1 = ['br']
htmlArray2 = ['h1', 'page title']
htmlArray3 = ['h1' 
                'page title'
                ['span', 'subtitle']]
                
htmlArray4 = ['meta', {name: 'description', content: 'some webpage'}]
htmlArray5 = ['article', {id: 123}, 'the article content']
htmlArray6 = ['article', {id: 123} 
                'the article content'
                ['a', {href: '#'}, 'some link']]
                
htmlArray7 = []
htmlArray8 = [['br'], ['br']]

##Authors

don.js was created by Tim Farland, a web product designer based in Berlin.

##Disclaimer

This is experimental code! I can't guarantee that it won't change or break something in your app. Don't sue me.