Implemented SCSS-like partial imports.
h3rald h3rald@h3rald.com
Sun, 09 Dec 2018 16:46:15 +0100
7 files changed,
58 insertions(+),
36 deletions(-)
D
LICENSE
@@ -1,21 +0,0 @@
-MIT License - -Copyright (c) 2016 Fabio Cevasco - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE.
M
config.nim
→
config.nim
@@ -1,5 +1,5 @@
const pkgName* = "HastySite" - pkgVersion* = "1.2.2" + pkgVersion* = "1.3.0" pkgDescription* = "A small but powerful static site generator" pkgAuthor* = "Fabio Cevasco"
M
hastysite.nim
→
hastysite.nim
@@ -78,6 +78,10 @@ let PEG_CSS_VAR_INSTANCE = peg"""
instance <- 'var(--' {id} ')' id <- [a-zA-Z0-9_-]+ """ +let PEG_CSS_IMPORT = peg""" + import <- '@import' \s+ '\'' {partial} '\';' + partial <- [a-zA-Z0-9_-]+ +""" var CSS_VARS = initTable[string, string]()@@ -100,6 +104,22 @@ result = result.replace(instance, CSS_VARS[id])
else: stderr.writeLine("CSS variable '$1' is not defined." % ["--" & id]) +proc processCssImportPartials(text: string, hs: HastySite): string = + result = text + var folder = "assets/styles" + if hs.settings.hasKey("css-partials"): + folder = hs.settings["css-partials"].getStr + for def in result.findAll(PEG_CSS_IMPORT): + var matches: array[0..1, string] + discard def.match(PEG_CSS_IMPORT, matches) + let partial = folder/"_" & matches[0].strip & ".css" + var contents = "" + if partial.existsFile: + contents = partial.readFile + result = result.replace(def, contents) + else: + stderr.writeLine("@import: partial '$1' does not exist" % [partial]) + proc preprocessContent(file, dir: string, obj: var JsonNode): string = let fileid = file.replace(dir, "") var f: File@@ -243,6 +263,7 @@ json["templates"] = %"templates"
json["temp"] = %"temp" json["output"] = %"output" json["scripts"] = %"scripts" + json["css-partials"] = %"assets/styles" for key, value in json.pairs: createDir(dir/value.getStr) createDir(dir/"assets/fonts")@@ -381,7 +402,8 @@
def.symbol("preprocess-css") do (i: In): var vals = i.expect("string") let css = vals[0] - let res = css.getString.processCssVariables() + var res = css.getString.processCssImportPartials(hs) + res = res.processCssVariables() i.push res.newVal() def.symbol("mustache") do (i: In):
M
site/contents/about.md
→
site/contents/about.md
@@ -15,7 +15,7 @@ * can be extended, from the way it processes files to creating custom commands to do literally what you want.
* provides a simple but functional fully-working site template out-of-the-box, which is also the same template used for its [web site](https://hastysite.h3rald.com). * provides out-of-the-box Markdown support. But not just any markdown, [HastyScribe](https://h3rald.com/hastyscribe)-compatible markdown, which extends the alredy-amazing and powerful [Discount](https://www.pell.portland.or.us/~orc/Code/discount/) engine with more useful features such as snippets, macros, fields and transclusion. * provides a robust logic-less templating engine based on [mustache](https://mustache.github.io/). -* provides support for [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables), which doesn't substitute a full fledged CSS preprocessor like LESS or SASS, but it does help. +* provides support for SCSS-like partials and [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables), which don't substitute a full fledged CSS preprocessor like LESS or SASS, but they do help. ## Technology and Credits
M
site/contents/getting-started.md
→
site/contents/getting-started.md
@@ -4,7 +4,7 @@ title: "Getting Started"
content-type: page ----- -{{version => 1.2.2}} +{{version => 1.3.0}} ## Download
A
site/contents/posts/v130-released.md
@@ -0,0 +1,10 @@
+----- +id: v130-released +title: "Version 1.3.0 released" +content-type: post +date: "9 December 2018" +timestamp: 1544370271 +----- + +* Implemented basic support for SCSS-like partial imports. +
M
site/contents/reference.md
→
site/contents/reference.md
@@ -131,21 +131,32 @@ Starts the preprocessing phase of the build.
#} {#op||preprocess-css||{{s1}}||{{s2}}|| -Pre-process [CSS variable](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables) declarations and usages within {{s1}}, returning the resulting CSS code {{s2}}. +Pre-process CSS contents within {{s1}}, i.e.: + +1. Pseudo-SCSS partial imports. Partial CSS files must start with an underscore and be placed in the `css-partials` directory (set in your [settings.json](class:file), or [assets/styles](class:dir) if not specified). +2. [CSS variable](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables) declarations + +Returns the resulting CSS code {{s2}}. + +For example, the following CSS code in two different files: -For example, the following CSS code: -``` -:root { - --standard-gray: #cccccc; -} +\_vars.css: +: ``` + :root { + --standard-gray: #cccccc; + } + ``` -.note { - background-color: var(--standard-gray); -} -``` +style.css: +: ``` + @import 'vars'; + .note { + background-color: var(--standard-gray); + } + ``` -Will be converted to the following: +Will be converted into the following: ``` :root {