Coder Social home page Coder Social logo

gacelita / sablono Goto Github PK

View Code? Open in Web Editor NEW

This project forked from r0man/sablono

0.0 2.0 0.0 607 KB

Lisp/Hiccup style templating for Facebook's React in ClojureScript.

License: Eclipse Public License 1.0

Emacs Lisp 0.08% Clojure 99.68% HTML 0.24%

sablono's Introduction

ŜABLONO

https://img.shields.io/clojars/v/sablono.svg https://travis-ci.org/r0man/sablono.svg http://jarkeeper.com/r0man/sablono/status.svg https://jarkeeper.com/r0man/sablono/downloads.svg

Lisp/Hiccup style templating for Facebook’s React in ClojureScript.

http://imgs.xkcd.com/comics/tags.png

Dependencies

Ŝablono doesn’t declare a dependency on React anymore. Use the React dependencies from one of the ClojureScript wrappers or provide the dependencies yourself like this:

[cljsjs/react "15.4.2-2"]
[cljsjs/react-dom "15.4.2-2"]

If you want to do server rendering and use the render or render-static functions from the sablono.server namespace you need to add the following dependency as well:

[cljsjs/react-dom-server "15.4.2-2"]

Usage

Most functions from Hiccup are provided in the sablono.core namespace. The library can be used with Om like this:

(ns example
  (:require [om.core :as om :include-macros true]
            [sablono.core :as html :refer-macros [html]]))

(defn widget [data]
  (om/component
   (html [:div "Hello world!"
          [:ul (for [n (range 1 10)]
                 [:li {:key n} n])]
          (html/submit-button "React!")])))

(om/root widget {} {:target (. js/document (getElementById "my-app"))})

By default, Ŝablono will wrap any forms in the body of hiccup with a call to sablono.interpreter/interpret. If your code returns a React element, then you can skip the call to this function by marking the s-expression with the metadata tag :inline. For example:

[:div {}
 ^:inline (function-that-returns-react-component)]

HTML Tags

Ŝablono only supports tags and attributes that can be handled by React. This means you can’t have your own custom tags and attributes at the moment. For more details take a look at the Tags and Attributes section in the React documentation.

HTML Attributes

HTML attributes in React are camel-cased and the class and for attributes are treated special. Ŝablono renames attributes with dashes in their name to the camel-cased version and handles the class and for special case. This is more consistent with Hiccup and naming conventions used in Clojure.

An input element with event listeners attached to it would look like this in Ŝablono:

(html [:input
       {:auto-complete "off"
        :class "autocomplete"
        :on-change #(on-change %1)
        :on-key-down #(on-key-down %1)
        :type "text"}])

Setting innerHTML of a DOM node

It is not recommended to directly set the innerHTML of DOM nodes, but in some cases it is necessary. i.e. injecting a HTML string that was generated from Markdown.

(html [:div {:dangerouslySetInnerHTML {:__html "<div>hello world</div>" }}])

You can read more at React’s special attributes.

FAQ

How to run the tests?

You need to have Node.js and PhantomJS installed for the ClojureScript test.

Make sure you have all dependencies installed. The following command installs the Maven and Node.js dependencies.

lein deps

To run all Clojure and ClojureScript tests run the following command:

lein ci

For development the ClojureScript tests can be run with lein-doo. To run the tests on Node.js run the following command:

lein doo node nodejs auto

To run the tests on PhantomJS use this command:

lein doo phantom none auto

Thanks

This library is based on James Reeves excellent Hiccup library.

License

Copyright © 2013-2016 r0man

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

sablono's People

Contributors

r0man avatar tonsky avatar eslick avatar joelash avatar aamedina avatar kidpollo avatar akhudek avatar elliot42 avatar asmala avatar jwhitlark avatar jenanwise avatar gacelita avatar kennyjwilli avatar lynaghk avatar mikekap avatar the-kenny avatar ostronom avatar sgrove avatar totakke avatar ajchemist avatar nha avatar

Watchers

James Cloos avatar  avatar

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.