Git Product home page Git Product logo

crate's Introduction

crate

Crate is a ClojureScript implementation of the awesome Hiccup html templating library.

Usage

(ns myapp
 (:use-macros [crate.def-macros :only [defpartial]])
 (:require [crate.core :as crate]))

(crate/html [:p.woot {:id "blah"} "Hey!"])
=> <p class="woot" id="blah">Hey!</p>

(defpartial header []
 [:header
   [:h1 "My app!"]])

(header)
=> <header><h1>My app!</h1></header>

Differences from Hiccup

  • The crate.core/html returns dom nodes instead of strings of html
  • You can use dom nodes in element bodies like this:
(crate/html [:div (crate/raw "<span>foo</span><strong>bar</strong>")])
=> <div><span>foo</span><strong>bar</strong></div>

License

Copyright (C) 2011 Chris Granger

Distributed under the Eclipse Public License, the same as Clojure.

crate's People

Contributors

arthuredelstein avatar bmaddy avatar ibdknox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crate's Issues

Escaping of Tag Content

I believe in Hiccup the content portion of tags is not HTML-escaped by default. In Crate, when I provide a string with raw HTML inside it, it appears that the Google methods used by Crate createTextNode and/or setTextContent do escape the content string.

I need to be able to pass raw HTML strings as the content to elements. How can I go about this using Crate?

Merge with Dommy?

I noticed you've been contributing to the dommy project. Should crate and dommy merge to make life easier for the end user?
David

error while using crate-0.2-alpha2

Hi,

I receive the following error when running by "lein run" -

SEVERE: /home/murtaza/workspace/noir-cljs/faiz/resources/public/cljs/noir/cljs/client/watcher.js:3: ERROR - required "crate.tags" namespace never provided
goog.require('crate.tags');
^

ERROR: JSC_MISSING_PROVIDE_ERROR. required "crate.tags" namespace never provided at /home/murtaza/workspace/noir-cljs/faiz/resources/public/cljs/noir/cljs/client/watcher.js line 3 : 12
May 09, 2012 1:41:51 PM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 1 error(s), 0 warning(s)

Below is my project. clj -

(defproject faiz "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://exampl.com/FIXME"
:plugins [[lein-difftest "1.3.7"]
[lein-marginalia "0.7.0"]
[lein-pprint "1.1.1"]
[lein-swank "1.4.4"]
[lein-ring "0.6.4"]
[clj-ns-browser "1.2.0"]]
:dependencies [[org.clojure/clojure "1.4.0"]
[noir-cljs "0.3.2" :exclusions [org.clojure/clojure]]
[jayq "0.1.0-alpha3"]
[fetch "0.1.0-alpha2"]
[crate "0.2.0-alpha2"]
[noir "1.3.0-beta4"]
[com.novemberain/monger "1.0.0-beta4"]
[waltz "0.1.0-alpha1"]
[com.datomic/datomic "0.1.3065"]]
:cljsbuild {:builds [{}]}
:main ^{:skip-aot true} faiz.server
:ring {:handler faiz.server/handler})

Thanks,
Murtaza

Create git tags when releasing

I'd like to request that you create a git tag when you release new jars to clojars (or something equivalent). I'm trying to track down a bug, and it's unclear to me which revision of the source code that jar was built from (and whether, in fact, it was built from any revision that I can see, and not a private local branch).

Inserting crate-generated element via jquery is puzzling

Run into a rather interesting problem.

An element generated as html and inserted into the page via jquery does not pick up the assigned styles.

The style is in the HTML, but the browser (Chrome, Firefox) does not render it at all.

The generated html can be saved via the browser, and the HTML file when opened DOES have the style applied.

The same code generated via javascript directly (bypassing crate) or by using an explicit html string from within clojurescript also has the correct style.

It appears to be an issue with crate-generated elements only.

eg:

(-> (jquery "body")         
  (.append (crate/html [:h1{:class "red"} "Test inside a jquery"]) ))))

Where the red class simply defines:

.red {
color:red;
}

I have tried several variations of crate here including defpartial, defhtml with the same results.
Same results using jayq or non-wrapped jquery.
Similarly, using different jquery methods (inner, append, html, etc).

Am I missing something very obvious?

[:svg ...] converted to dom is not visible.

The statement (dom/append (dom/getElement "test") (crate/html drawing)) changes the DOM node test as expected, but visually nothing changes. However, in Opera produced node tags are in uppercase, like <SVG ...>.

Setting innerHTML like

(set! (.-innerHTML (dom/getElement "test")) (dom/getOuterHtml (crate/html drawing)))

has visual effect and produces same DOM nodes.

Tested in FF, Chrome, Opera.

(ns test
    (:require
        [goog.dom :as dom]
        [crate.core :as crate]))

(def drawing [:svg
        {:style "display:block;margin:auto;height:100;width:100;background-color:#222222"}
        [:rect {
            :style "fill:orange"
            :x 10 :y 10
            :height 80 :width 80
        }]])

Inconsistent behavior of bound elements

Steps to reproduce:

Start a browser-repl via cljsbuild (tried with Firefox and Chromium), and evaluate the following expressions in order of appearance:

(ns mynamespace
(:use [jayq.core :only [$ append css inner]])
(:require [crate.core :as cr]
[crate.binding :as cb])
(:use-macros [crate.def-macros :only [defpartial]]))

(def zomg (atom "hey"))

(defpartial t [a]
[:p a])

(append ($ :body) (cr/html [:div (cb/bound zomg t)]))

(swap! zomg str " blah")
(swap! zomg str " woo")
(swap! zomg str " cool")

Result:

  • After evaluating the append expression, "hey" appears.
  • After evaluation any of the swap expressions, "[object HTMLParagraphElement]" appears in place of "hey"
  • re-evaluation of the append-expression shows the swapped atom after the "[object HTMLParagraphElement]"
  • re-swapping appends another "[object HTMLParagraphElement]", replacing the string
  • ...repeat

Using lein-cljsbuild 0.2.1 and

:dependencies [[org.clojure/clojure "1.4.0"]
[crate "0.2.0-alpha4"]
[jayq "0.1.0-alpha4"]]

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.