unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Amirouche Boubekki <amirouche@hypermove.net>
To: Nala Ginrut <nalaginrut@gmail.com>
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:14:02 +0200	[thread overview]
Message-ID: <e8e20bf8a4f2f27095cabb0dc4a30dde@hypermove.net> (raw)
In-Reply-To: <1438312101.7066.16.camel@Renee-desktop.suse>

Le 2015-07-31 05:08, Nala Ginrut a écrit :
> IMO, skribillo is for static pages, and Artanis is largely for dynamic
> pages.

This is realized with dynamic page in minds.

> After quick review of your code, it seems what you want is to
> redefine SXML:
> 
> (link (@ :rel "stylesheet" :href "static/css/bootstrap.min.css"))

Yeah, this is a cosmectic change.

> 
> 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.

I have to say that I don't know how guile-reader does implement the 
reader.

> 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
>> 
>> 
>> 

-- 
Amirouche ~ amz3 ~ http://www.hyperdev.fr



      reply	other threads:[~2015-07-31  9:14 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
2015-07-31  9:14   ` Amirouche Boubekki [this message]

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=e8e20bf8a4f2f27095cabb0dc4a30dde@hypermove.net \
    --to=amirouche@hypermove.net \
    --cc=guile-user@gnu.org \
    --cc=nalaginrut@gmail.com \
    /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).