This repository has been archived by the owner on Jan 19, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
pair_elems = 'html head title body script ' | ||
pair_elems+= 'div nav header footer section article ' | ||
pair_elems+= 'p span textarea br pre code ' | ||
pair_elems+= 'ul li ol table tr td' | ||
pair_elems = pair_elems.split ' ' | ||
|
||
single_elems = 'img meta input link' | ||
single_elems = single_elems.split ' ' | ||
|
||
write = (attrs) -> | ||
attr_str = '' | ||
if typeof attrs is 'object' | ||
for key, value of attrs | ||
attr_str+= " #{key}=\"#{value}\"" | ||
return attr_str | ||
|
||
for elem in pair_elems | ||
do (elem) -> | ||
global[elem] = (attrs, elems...) -> | ||
"<#{elem}#{write attrs}>#{elems.join ''}</#{elem}>" | ||
|
||
for elem in single_elems | ||
do (elem) -> global[elem] = (attrs) -> "<#{elem}#{write attrs}/>" | ||
|
||
global.text = (str) -> str.replace(/\s/g, ' ') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
|
||
global.style = (attrs) -> | ||
str = '' | ||
for key, value of attrs | ||
st = '' | ||
for k, v of value | ||
while (k.match /\d$/)? | ||
k = k[...-1] | ||
st+= "#{k}: #{v};" | ||
str += "#{key}{#{st}}" | ||
return "<style>#{str}</style>" | ||
|
||
global.hsla = (h, s, l, a) -> "hsla(#{h},#{s}%,#{l}%,#{a/100})" | ||
global._ = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
require './index' | ||
|
||
page = html _, | ||
head _, | ||
title _, | ||
text 'html' | ||
style | ||
body: | ||
color: 'red' | ||
div: | ||
color: 'blue' | ||
color2: 'bue' | ||
color4: 'ue' | ||
body _, | ||
div id: 'main', | ||
div id: 'left_bar', | ||
nav id: 'home_button', class: 'nav' | ||
nav id: 'search_button', class: 'nav' | ||
nav id: 'msg_button', class: 'nav' | ||
nav id: 'back_button', class: 'nav' | ||
div id: 'right_bar', | ||
article class: 'post', | ||
p _, | ||
text 'need to clarify sth' | ||
text 'more things need to be examined' | ||
article class: 'post' | ||
article class: 'post' | ||
article class: 'post' | ||
|
||
console.log page |