From 1b1485c9ee42f4f5e7a48b5098be03c3904eb671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=98=E5=8F=B6?= Date: Thu, 15 Mar 2012 18:30:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E6=A1=A3,=20?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=86=99,=20=E6=9C=AA=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README | 22 ---------------------- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++---- json2page.coffee | 4 ++-- 3 files changed, 47 insertions(+), 28 deletions(-) delete mode 100644 README diff --git a/README b/README deleted file mode 100644 index 1519d8a..0000000 --- a/README +++ /dev/null @@ -1,22 +0,0 @@ - -Json2page is a script aiming to make writing web pages easy in CoffeeScript. -So the template is the js objects one write in a decided format, -after that, the objects can be compiled to HTML for any use. -You may look through these demos first to get the basic concept: -http://docview.nodejitsu.com/leaf/projects/json2page/show.html?html -And here's one page I use this to render a page: -http://docview.nodejitsu.com/app.coffee?raw - -Is a pity we can't handle DOM like what we do on other data. -JQuery is quite a good tool, but HTML itself is clumsy. -One day in April I saw this piece of code which converts json to css -https://github.com/tyrondis/jcss -It's really simple, then I got the idea to simplize html in js. -My first version of converter more or less is based on this attention. -I remmembered a script(forget..) which converts arrays to html, that's powerfull.. -For js object, there's no range, no repeat.. it quite bad for html. -Only one thing: objects looks really concise in coffee, but array not. - -Basicly, an object defined like this: - input = - $html: 'context' \ No newline at end of file diff --git a/README.md b/README.md index 8fe1f7f..bfae43c 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,49 @@ Nesting tags is avalable: """ -Tags must contain an '$', (html) attributes shoould not: +Tags must contain an '$', (html) attributes shoold not: - input = - id$nav: - "" \ No newline at end of file + input = + id$nav: + attr: 'something' + class: 'else' + """ + + """ + +Write stylesheets together with HTML, numbers will become `#{}px` + + input = + $style: + body: + width: 2 + $nav: + style: + background: "#eef" + """ + + + """ + +You may use `$pipe` to connect pieces of codes: + + a = $nav: + $text: 'Tx' + input = + $header: + $pipe: a + """ + + """ + +Really a small tool. Hope you will like it. \ No newline at end of file diff --git a/json2page.coffee b/json2page.coffee index c12b767..1659f27 100644 --- a/json2page.coffee +++ b/json2page.coffee @@ -27,7 +27,7 @@ json2page = (data) -> _tag = item.tag || 'div' match = _tag.match /^([a-z]+)\d*$/ if _tag.match /^page\d*$/ then html += item.value - else if _tag.match /^text\d*/ + else if _tag.match /^text\d*$/ html += item.value.replace('<','<').replace('>','>').replace(' ',' ') else html += "<#{match[1]} " @@ -102,4 +102,4 @@ out = (data) -> (json2page data)[1..] if window? then window.json2page = out -if exports? then exports.json2page = out \ No newline at end of file +if exports? then exports.json2page = out