From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Amirouche Boubekki Newsgroups: gmane.lisp.guile.user 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 Message-ID: References: <1438312101.7066.16.camel@Renee-desktop.suse> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1438334072 32486 80.91.229.3 (31 Jul 2015 09:14:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Jul 2015 09:14:32 +0000 (UTC) Cc: guile-user@gnu.org To: Nala Ginrut Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jul 31 11:14:23 2015 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZL6OU-0006R2-62 for guile-user@m.gmane.org; Fri, 31 Jul 2015 11:14:22 +0200 Original-Received: from localhost ([::1]:43632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL6OS-0006aD-Lp for guile-user@m.gmane.org; Fri, 31 Jul 2015 05:14:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL6OI-0006Zy-SP for guile-user@gnu.org; Fri, 31 Jul 2015 05:14:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZL6OD-0003vX-Mx for guile-user@gnu.org; Fri, 31 Jul 2015 05:14:10 -0400 Original-Received: from relay6-d.mail.gandi.net ([2001:4b98:c:538::198]:44799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL6OD-0003vJ-D4 for guile-user@gnu.org; Fri, 31 Jul 2015 05:14:05 -0400 Original-Received: from mfilter28-d.gandi.net (mfilter28-d.gandi.net [217.70.178.159]) by relay6-d.mail.gandi.net (Postfix) with ESMTP id 559A1FB8D8; Fri, 31 Jul 2015 11:14:04 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter28-d.gandi.net Original-Received: from relay6-d.mail.gandi.net ([IPv6:::ffff:217.70.183.198]) by mfilter28-d.gandi.net (mfilter28-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id VCpfeIzFntxT; Fri, 31 Jul 2015 11:14:02 +0200 (CEST) X-Originating-IP: 10.58.1.141 Original-Received: from webmail.gandi.net (unknown [10.58.1.141]) (Authenticated sender: amirouche@hypermove.net) by relay6-d.mail.gandi.net (Postfix) with ESMTPA id C0734FB8E9; Fri, 31 Jul 2015 11:14:02 +0200 (CEST) In-Reply-To: <1438312101.7066.16.camel@Renee-desktop.suse> X-Sender: amirouche@hypermove.net User-Agent: Roundcube Webmail/1.1.2 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4b98:c:538::198 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:11933 Archived-At: Le 2015-07-31 05:08, Nala Ginrut a =C3=A9crit=C2=A0: > 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: >=20 > (link (@ :rel "stylesheet" :href "static/css/bootstrap.min.css")) Yeah, this is a cosmectic change. >=20 > 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=20 reader. > Best regards. >=20 > On Thu, 2015-07-30 at 13:55 +0200, Amirouche Boubekki wrote: >> H=C3=A9llo, >>=20 >>=20 >> I've been lurking around skribillo and artanis. I don't really like=20 >> 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. >>=20 >> The code of skribe reader is included in sfx.scm. So the only=20 >> dependency >> is guile (2.0.11) and >> guile-reader that you can install using `guix package -i=20 >> guile-reader`. >>=20 >> This bare template language has the following features: >>=20 >> - wanna be simpler sxml syntax >> - templates with custom environment >> - external libraries loading inside the template >>=20 >>=20 >> # Wanna be simpler sxml syntax >>=20 >> Skribe reader (implemented with guile-reader) provide a handy syntax=20 >> to >> both define keywords and quasiquote. In an sxml context those features >> are used to implemented attributes and text nodes. >>=20 >> ## attributes >>=20 >> Attributes in sxml are defined as follow: >>=20 >> (div (@ (id "shell")) "This the main area") >>=20 >> Instead of requiring the nesting of `(attribute-name attribute-value)` >> sfx use >> the simpler keyword syntax `:keyword`. The above snippet becomes: >>=20 >> (div (@ :id "shell") "This the main area") >>=20 >> I'm not sure it's worth the trouble of diverting from sxml standard. >> That said, it looks >> more like plain xml. >>=20 >> ## text nodes >>=20 >> Text nodes can be defined as >>=20 >> (p [h=C3=A9llo hacker]) >>=20 >> This is looks the same as the default reader. It becomes handy when=20 >> you >> include an >> inline element inside the text node: >>=20 >> (p [h=C3=A9llo ,(b [hacker]) >>=20 >> `,()` is a special syntax of skribe reader which provides `(unquote)` >> inside [bracket] `quasiquote`. >>=20 >> With the default guile reader, this must be written as: >>=20 >> (p "h=C3=A9llo " (b "hacker")) >>=20 >> This is looks verbose and prone to error. One must not forget the=20 >> space >> in the >> string before the `(b)` element. >>=20 >>=20 >> # templates with custom environment >>=20 >> Right now this part of the template language is not really=20 >> 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=20 >> is >> evaled is defined as follow: >>=20 >> (define value (make-parameter 42)) >> (define amirouche (make-person "amirouche" 30)) >> (define env (let ((value value) >> (amirouche amirouche)) >> (the-environment))) >>=20 >>=20 >> Then `value` can be echo'ed inside the template using the unquote=20 >> syntax >> `,()`, e.g. >>=20 >> (p [Here is a lucky number for you =C2=AB,(value)=C2=BB]) >>=20 >> As you can see the previous snippet, there is also a `` 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. >>=20 >> # external libraries loading inside the template >>=20 >> Currently it's (only) possible to do `(use-modules)` inside the=20 >> template >> file. The template >> file looks like the following: >>=20 >> ``` >> (use-modules (person)) >>=20 >> `(html >> (body >> (p [My name is ,(person-name amirouche)]))) >> ``` >>=20 >> I could not make procedure definition work inside the template, this=20 >> my >> be linked to the way >> I eval the template. It's shame because for quick and dirty hacks it=20 >> can >> be handy like defining >> mini-templates inside the big template. >>=20 >>=20 >>=20 >>=20 >>=20 >> This is my second try at this and having a look at the code of haunt=20 >> [1] >> was helpful. >>=20 >> Hope this helps! >>=20 >>=20 >> [1] https://git.dthompson.us/haunt.git >>=20 >>=20 >>=20 --=20 Amirouche ~ amz3 ~ http://www.hyperdev.fr