From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut 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:08:21 +0800 Organization: HFG Message-ID: <1438312101.7066.16.camel@Renee-desktop.suse> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1438312125 6225 80.91.229.3 (31 Jul 2015 03:08:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Jul 2015 03:08:45 +0000 (UTC) Cc: guile-user@gnu.org To: Amirouche Boubekki Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jul 31 05:08:39 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 1ZL0gY-0004my-Lh for guile-user@m.gmane.org; Fri, 31 Jul 2015 05:08:38 +0200 Original-Received: from localhost ([::1]:42969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL0gX-0008Or-Kt for guile-user@m.gmane.org; Thu, 30 Jul 2015 23:08:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL0gP-0008Ol-RY for guile-user@gnu.org; Thu, 30 Jul 2015 23:08:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZL0gM-0002Z3-Kj for guile-user@gnu.org; Thu, 30 Jul 2015 23:08:29 -0400 Original-Received: from mail-pa0-x22b.google.com ([2607:f8b0:400e:c03::22b]:34468) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL0gM-0002Yu-95 for guile-user@gnu.org; Thu, 30 Jul 2015 23:08:26 -0400 Original-Received: by pacan13 with SMTP id an13so33707675pac.1 for ; Thu, 30 Jul 2015 20:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:mime-version:content-transfer-encoding; bh=fkKY8wxBAtQ3D6eBO9YfEvCC5rSkIhvHl/J5nWGC4Yc=; b=vcgXRLOiQHwQH2N7HUFcsLDsRdCxEWUIse6B3Oz3fLCD2bYmJHDaaL/gh+kjwe2Mlk cSWUxQXakmpSaXNwR6F4bSAD3PShy1eVefqJlmB5XiTWL9SLdvN3cKUj9T/0PNFF1owR INBjOTNWL97h9q8srVx7W9ssiql87Q1+3BAaSNpVrQvOy2Ekeq/wWciUXmAAeO5gQ40s 3EuTyRl/GoZuQLTXeW8ur8wBGGsv3uWNvO8YHdcnLCOVTm0D9M5oMyNOP6KxDBvrGWoX xmMhb7i07QpiSL11Co/bJfy4xHakf8LBluyYlmo7k6M+Ngq1KALfaKVc+x3AYwf8z/zh wt5A== X-Received: by 10.66.185.199 with SMTP id fe7mr1631150pac.48.1438312105367; Thu, 30 Jul 2015 20:08:25 -0700 (PDT) Original-Received: from [147.2.147.174] ([203.192.156.9]) by smtp.gmail.com with ESMTPSA id lv12sm4599182pab.18.2015.07.30.20.08.23 (version=SSLv3 cipher=RC4-SHA bits=128/128); Thu, 30 Jul 2015 20:08:24 -0700 (PDT) In-Reply-To: X-Mailer: Evolution 3.4.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::22b 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:11932 Archived-At: 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 > 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 > > >