Skip to content

Commit

Permalink
New CSS preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Sep 7, 2016
1 parent 077bfc1 commit 22f0771
Show file tree
Hide file tree
Showing 62 changed files with 365 additions and 503 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# cache
/docs/.yummy
# output of templates expansion
tests/generated/*.jqe
tests/generated/*.jqs
tests/generated/*.txt
# man pages
jqt.1.gz
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ all: check
.PHONY: clean clobber install uninstall

clean:
rm -f tests/generated/* jqt.1.gz
rm -f tests/*/generated/* jqt.1.gz

clobber: clean

Expand Down Expand Up @@ -166,8 +166,8 @@ $(eval $(call TestJQT,syntax))
#
# Test macro expansion
#
.PHONY: test-expand test-mpjqt
test-expand: test-mpjqt test-mpmd test-mpjson
.PHONY: test-expand test-mpjqt test-mpmd test-mpjson test-mpcss
test-expand: test-mpjqt test-mpmd test-mpjson test-mpcss

define TestMacroExpand
# Run one example
Expand All @@ -184,6 +184,7 @@ endef
$(eval $(call TestMacroExpand,jqt,mpjqt))
$(eval $(call TestMacroExpand,md,mpmd))
$(eval $(call TestMacroExpand,json,mpjson))
$(eval $(call TestMacroExpand,css,mpcss))

#
# Test file format conversions
Expand Down
17 changes: 9 additions & 8 deletions bin/jqt
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,15 @@ function expand_json
function expand_css
{
local -r minify=$1
local -r -a user=( -U '' '' '(\W' ',\W' ')' '(' ')' '$' '' )
local -r -a meta=( -M '\n&' '\n' '\b' '\b' '\n' '(' ')' )
local -r -a user=( -U '&' '' '{\W' '}{\W' '}' '{' '}' '&' '' )
local -r -a meta=( -M '&' '' '{\W' '}{\W' '}' '{' '}' )
local -r -a skips=(
+cccc '&\n' '' # continuation line (& and \n removed)
+cccc '\\n' '' # continuation line (\ and \n removed)
+cccc '/*' '*/' # multiline comment
+cccc '//' '\n' # line comment
# multiline comment: see below
+sqqq '`' '`' '\' # literal string; like sh single quotes
+ssss '"' '"' '\' # CSS string
+ssss "'" "'" '\' # CSS string
+sSSS '"' '"' '\' # CSS string
+sSSS "'" "'" '\' # CSS string
)
local -r -a gpp_opts=(
--nostdinc
Expand All @@ -224,10 +223,12 @@ function expand_css
"${DEFINE[@]}"
)
if [[ $minify == 'min' ]]; then
gpp "${gpp_opts[@]}" \
# +cccc '/*' '*/' # removed multiline comment
gpp "${gpp_opts[@]}" +cccc '/*' '*/' \
| sed 's/^[ \t]\+//;s/[ \t]$//;/^$/d;s/[\t ]*\([{}:,;>+~]\)[\t ]*/\1/g'
else
gpp "${gpp_opts[@]}"
# +cSSS '/*' '*/' # expanded multiline comment
gpp "${gpp_opts[@]}" +sSSS '/*' '*/' ''
fi
echo # always generate almost one line!!!
}
Expand Down
3 changes: 2 additions & 1 deletion docs/content/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ the character `>`. The more common predefined macros have this syntax:
<%undef x>
```

Inside macro definitions argument references are prefixed by a dollar (`$1`, `$2`, etc.):
Inside macro definitions argument references are prefixed by a dollar (`$1`, `$2`, etc.),
but named arguments are also possible:

```
<%define sc
Expand Down
3 changes: 2 additions & 1 deletion docs/content/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ The more common predefined macros have this syntax:
<%undef x>
```

Inside macro definitions argument references are prefixed by a dollar (`$1`, `$2`, etc.):
Inside macro definitions argument references are prefixed by a dollar (`$1`, `$2`, etc.),
but named arguments are also possible:

```
<%define euro \u20AC>
Expand Down
41 changes: 20 additions & 21 deletions docs/content/engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,33 @@ The CSS minimization is not extremely aggressive, but is safe and sufficient.
#### Macro calls

The macro syntax used by _jqt_ in CSS files is very similar to the syntax used by the traditional
preprocessing of C and C++ languages, but changing the prefix character `#` by
TeX language macro processor, but changing the prefix character `\\` by
`&`.
The more common predefined macros have this syntax:

```
&defeval x y
&define x y
&elif expr
&defeval{x}{y}
&define{x}{y}
&elif{expr}
&else
&endif
&eval expr
&if expr
&ifdef x
&ifeq x y
&ifndef x
&ifneq x y
&include file
&undef x
&eval{expr}
&if{expr}
&ifdef{x}
&ifeq{x}{y}
&ifndef{x}
&ifneq{x}{y}
&include{file}
&undef{x}
```

Inside macro definitions argument references are prefixed by a dollar (`$1`, `$2`, etc.).
Inside macro definitions argument references are prefixed by an ampersand (`&1`, `&2`, etc.),
but named arguments are also possible.
The more used features are the inclusion on external files and the definition of simple constants:

```
&include theme.css
&define Blue #0000FF
&include{theme.css}
&define{Blue}{#0000FF}
{ color: &Blue; }
```
Expand All @@ -177,19 +178,17 @@ This table summarizes all the available skips in CSS files:
Delimiters Macro expansion Delimiters removed Content removed
------------- --------------- ------------------ ---------------
`&\n`[^1] No Yes There is no content
`\\n`[^2] No Yes There is no content
`/*` `*/` No Yes Yes
`/*` `*/`[^2] Yes/No No/Yes No/Yes
`//` `\n`[^3] No Yes Yes
`` ` `` `` ` `` No Yes No
`"` `"` No No No
`'` `'` No No No
`"` `"` Yes No No
`'` `'` Yes No No

Table: **Semantics for all CSS skips**

[^1]: An ampersand followed by a newline is treated as a line continuation (that
is, the ampersand and the newline are removed and effectively ignored).
[^2]: A backslash followed by a newline is treated as a line continuation (that
is, the backslash and the newline are removed and effectively ignored).
[^2]: Multiline comments are expanded and preserved when not minifying CSS.
[^3]: This represents a newline character.

<#
Expand Down
3 changes: 2 additions & 1 deletion docs/content/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ The more common predefined macros have this syntax:
<%undef x>
```

Inside macro definitions argument references are prefixed by a dollar (`$1`, `$2`, etc.):
Inside macro definitions argument references are prefixed by a dollar (`$1`, `$2`, etc.),
but named arguments are also possible:

```
<%define stylesheet
Expand Down
Loading

0 comments on commit 22f0771

Please sign in to comment.