From 19f2f5b51472666bc8efdeb96b95354cdf3dec08 Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Wed, 9 Mar 2016 22:36:57 +0000 Subject: [PATCH] Change tagline, fix comments --- .editorconfig | 14 ++++++++++++++ Makefile | 15 +++++++++++---- README.md | 10 +++++++--- fawkss | 16 +++++++++++----- tests/03-includes.scss | 21 +++++++++++++++++++++ tests/includes/_partial.scss | 5 +++++ tests/includes/full.scss | 4 ++++ 7 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 .editorconfig create mode 100644 tests/03-includes.scss create mode 100644 tests/includes/_partial.scss create mode 100644 tests/includes/full.scss diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2d3f13c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# Code styles for Fawkss. + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = tab +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/Makefile b/Makefile index f9d809f..7c70fe7 100644 --- a/Makefile +++ b/Makefile @@ -88,20 +88,27 @@ test-after: @printf ">> $(BOLD)Finished executing tests.$(RESET)\n" $(TESTS): + # Generate temporary test files from concatenated original. @awk "/--- TEST ---/ {f=1;next} /--- EXPECTED ---/ {exit} f" $@ >> $@.test.$(TMPPID) @awk "/--- EXPECTED ---/ {f=1;next} /--- END ---/ {exit} f" $@ >> $@.expected.$(TMPPID) + # Calculate time and execute Fawkss with test file. + $(eval ts = $(shell date +"%s%3N")) @$(FAWKSS) $@.test.$(TMPPID) > $@.actual.$(TMPPID) - @printf ">> $(BOLD)Testing file '$@'...$(RESET) " + $(eval te = $(shell date +"%s%3N")) + # Generate diff between expected and actual results and print back to user. @result=$$($(DIFF) -ud $@.actual.$(TMPPID) $@.expected.$(TMPPID) | tail -n +3); \ - if [ -z "$${result}" ]; then \ - printf "$(GREEN)OK$(RESET)\n"; \ + tt=`echo "$(ts) $(te)" | awk '{printf "(%.3fs)\n", (($$2-$$1)/1000)}'`; \ + printf ">> $(BOLD)Testing file '$@'...$(RESET) "; \ + if [ -z "$$result" ]; then \ + printf "$(GREEN)OK$(RESET) $$tt\n"; \ else \ printf "$(RED)FAIL$(RESET)\n"; \ - echo "$${result}"; \ + echo "$$result"; \ fi \ + # Clean up temporary files. @rm -f $@.test.$(TMPPID) $@.expected.$(TMPPID) $@.actual.$(TMPPID) ## Show usage information for this Makefile. diff --git a/README.md b/README.md index d8c197a..8db8582 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Fawkss — The simple CSS preprocessor [![MIT License][license-svg]][license-url] +# Fawkss — The [ig]noble CSS preprocessor [![MIT License][license-svg]][license-url] Fawkss [fɔːks] is a simple CSS preprocessor built as a single AWK (nawk/gawk/mawk) script. Syntactically, it borrows as much as possible from the SASS language, for convenience and familiarity. @@ -8,10 +8,10 @@ This is more of a fun project than a production-ready piece of software, though Currently, the following features are implemented: - * C99/C++-style comments (.i.e. `// This is a comment`) + * C99/C++-style comments (i.e. `// This is a comment`) * Variables -A full test-suite is provided (depending only on Bash and AWK), which should serve as a good example of the existing feature-set. +A full test-suite is provided (depending only on `make` and `awk`), which should serve as a good example of the existing feature-set. ## Roadmap @@ -19,6 +19,10 @@ It is intended that the script never balloons to more than ~1000 lines of code. That being said, I do not plan to implement any context-sensitive functionality (such as nesting etc.), which may be nigh-impossible in AWK anyways. Consider it a feature. +## Testing & Documentation + +A `Makefile` is provided for running tests and producing documentation for Fawkss. Run `make help` in the project root for more information. + ## Are you kidding me? Nope. I wouldn't suggest you actually use this for anything, though. diff --git a/fawkss b/fawkss index 153827d..87c0863 100755 --- a/fawkss +++ b/fawkss @@ -1,7 +1,7 @@ #!/usr/bin/awk -f # -# Fawkss — The simple CSS preprocessor. -# ===================================== +# Fawkss — The [ig]noble CSS preprocessor. +# ======================================== # # Fawkss is a CSS preprocessor for people who dislike CSS preprocessors. It # implements a subset of the SCSS syntax while remaining relatively simple. @@ -37,6 +37,12 @@ function trim(str, chars) { return substr(str, RSTART, RLENGTH) } +# > Function `file_exists` checks if file pointed to by `filename` exists, and +# > returns `1` if true, `0` if false. +function file_exists(filename) { + return (system("[ -e '" filename "' ]") == 0) ? 1 : 0; +} + # Initialization # -------------- # @@ -76,7 +82,7 @@ $0 ~ rules["variable-define"] { name = trim(substr(token[1], index(token[1], "$"))) value = trim(substr(token[2], 0, lastindex(token[2], ";") - 1)) - # Assign variable to global variables table. + # Assign variable to the global variables table. variables[name] = value next } @@ -94,7 +100,7 @@ $0 ~ rules["variable-define"] { # > :root{background: white;} // Another inline comment. # > # > As opposed to regular CSS comments (i.e. `/* */`), inline comments are removed -# > from the processed result. Inline comments inside string are not removed. +# > from the processed result. Inline comments inside strings are not removed. $0 ~ rules["comment"] { # Remove any special cases from the line. while (match($0, rules["comment-exception"])) { @@ -149,7 +155,7 @@ $0 ~ rules["variable-name"] { # ------------- # # This block contains line-printing rules, for results generated in the above -# blocks. +# blocks. # # > Match empty line. Consecutive empty lines do not print, and are instead # > squashed down to a single line. diff --git a/tests/03-includes.scss b/tests/03-includes.scss new file mode 100644 index 0000000..ba7a523 --- /dev/null +++ b/tests/03-includes.scss @@ -0,0 +1,21 @@ +// +// Simple include tests for Fawkss. +// + +--- TEST --- + +@include "includes/partial" +@include "includes/full.scss" + +--- EXPECTED --- + +.partial { + content: 'This is a partial'; +} + +.full { + content: 'This is a full include'; + color: white; +} + +--- END --- \ No newline at end of file diff --git a/tests/includes/_partial.scss b/tests/includes/_partial.scss new file mode 100644 index 0000000..c4f3705 --- /dev/null +++ b/tests/includes/_partial.scss @@ -0,0 +1,5 @@ +$col-white: #fff; + +.partial { + content: 'This is a partial'; +} \ No newline at end of file diff --git a/tests/includes/full.scss b/tests/includes/full.scss new file mode 100644 index 0000000..39212b7 --- /dev/null +++ b/tests/includes/full.scss @@ -0,0 +1,4 @@ +.full { + content: 'This is a full include'; + color $col-white; +} \ No newline at end of file