From: Nala Ginrut <nalaginrut@gmail.com>
To: Amirouche Boubekki <amirouche@hypermove.net>
Cc: guile-user@gnu.org
Subject: Re: sfx: baby steps of an html templating engine based on skribillo's skribe reader and sxml
Date: Fri, 31 Jul 2015 11:08:21 +0800 [thread overview]
Message-ID: <1438312101.7066.16.camel@Renee-desktop.suse> (raw)
In-Reply-To: <ad49adb4e1073f838ceb9134bb7b99b9@hypermove.net>
IMO, skribillo is for static pages, and Artanis is largely for dynamic
pages. After quick review of your code, it seems what you want is to
redefine SXML:
(link (@ :rel "stylesheet" :href "static/css/bootstrap.min.css"))
It looks cleaner than SXML, but if you want to define a syntax, it's
better have a formal grammar definition, say, BNF or something similar.
Best regards.
On Thu, 2015-07-30 at 13:55 +0200, Amirouche Boubekki wrote:
> Héllo,
>
>
> I've been lurking around skribillo and artanis. I don't really like the
> rails-like syntax
> of artanis, even if it has its use-cases and I wanted to hack on
> something "small", so
> I've put together sfx.
>
> The code of skribe reader is included in sfx.scm. So the only dependency
> is guile (2.0.11) and
> guile-reader that you can install using `guix package -i guile-reader`.
>
> This bare template language has the following features:
>
> - wanna be simpler sxml syntax
> - templates with custom environment
> - external libraries loading inside the template
>
>
> # Wanna be simpler sxml syntax
>
> Skribe reader (implemented with guile-reader) provide a handy syntax to
> both define keywords and quasiquote. In an sxml context those features
> are used to implemented attributes and text nodes.
>
> ## attributes
>
> Attributes in sxml are defined as follow:
>
> (div (@ (id "shell")) "This the main area")
>
> Instead of requiring the nesting of `(attribute-name attribute-value)`
> sfx use
> the simpler keyword syntax `:keyword`. The above snippet becomes:
>
> (div (@ :id "shell") "This the main area")
>
> I'm not sure it's worth the trouble of diverting from sxml standard.
> That said, it looks
> more like plain xml.
>
> ## text nodes
>
> Text nodes can be defined as
>
> (p [héllo hacker])
>
> This is looks the same as the default reader. It becomes handy when you
> include an
> inline element inside the text node:
>
> (p [héllo ,(b [hacker])
>
> `,()` is a special syntax of skribe reader which provides `(unquote)`
> inside [bracket] `quasiquote`.
>
> With the default guile reader, this must be written as:
>
> (p "héllo " (b "hacker"))
>
> This is looks verbose and prone to error. One must not forget the space
> in the
> string before the `(b)` element.
>
>
> # templates with custom environment
>
> Right now this part of the template language is not really userfriendly.
> But you can pass custom
> variables to the template but those must be parameters. In the example
> sfx.scm (which includes
> example use of the procedures) the environment in which the template is
> evaled is defined as follow:
>
> (define value (make-parameter 42))
> (define amirouche (make-person "amirouche" 30))
> (define env (let ((value value)
> (amirouche amirouche))
> (the-environment)))
>
>
> Then `value` can be echo'ed inside the template using the unquote syntax
> `,()`, e.g.
>
> (p [Here is a lucky number for you «,(value)»])
>
> As you can see the previous snippet, there is also a `<record>` record
> inside the environment.
> One can (maybe) provide in the environment the required procedures to
> echo the correct
> fields but this is verbose. Instead sfx use `(use-modules)` inside the
> template definition
> file. This is presented in the following and last part.
>
> # external libraries loading inside the template
>
> Currently it's (only) possible to do `(use-modules)` inside the template
> file. The template
> file looks like the following:
>
> ```
> (use-modules (person))
>
> `(html
> (body
> (p [My name is ,(person-name amirouche)])))
> ```
>
> I could not make procedure definition work inside the template, this my
> be linked to the way
> I eval the template. It's shame because for quick and dirty hacks it can
> be handy like defining
> mini-templates inside the big template.
>
>
>
>
>
> This is my second try at this and having a look at the code of haunt [1]
> was helpful.
>
> Hope this helps!
>
>
> [1] https://git.dthompson.us/haunt.git
>
>
>
next prev parent reply other threads:[~2015-07-31 3:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-30 11:55 sfx: baby steps of an html templating engine based on skribillo's skribe reader and sxml Amirouche Boubekki
2015-07-30 13:13 ` Amirouche Boubekki
2015-07-30 16:52 ` Amirouche Boubekki
2015-07-31 12:03 ` Amirouche Boubekki
2015-07-31 3:08 ` Nala Ginrut [this message]
2015-07-31 9:14 ` Amirouche Boubekki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438312101.7066.16.camel@Renee-desktop.suse \
--to=nalaginrut@gmail.com \
--cc=amirouche@hypermove.net \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).