Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Small util for transforming xhtml to html DSL
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Robin Brandt  
View profile  
 More options Jun 27 2009, 3:58 pm
From: Robin Brandt <robin.bra...@gmail.com>
Date: Sat, 27 Jun 2009 12:58:06 -0700 (PDT)
Local: Sat, Jun 27 2009 3:58 pm
Subject: Small util for transforming xhtml to html DSL
Hi all,

first of all thanks for your work on clojure. It's a lot of fun to
hack on it!

Maybe somebody has the same problem and can use the following code as
a start: I wanted to transform an XHTML-template to the HTML DSL
that's coming with clojure. Luckily everything is available in the
base or contrib libs so it wasn't that hard to do.

(ns de.evernet2000.util
  (:use clojure.contrib.str-utils)
  (:use clojure.contrib.duck-streams)
  (:use clojure.contrib.pprint)
  (:use [clojure.xml :only (parse)])
  (:import (java.io File)))

(defn format-attrs
  [m]
  (when m
    (format "%s" m)))

(defn empty-when-null
  [x]
  (if (nil? x)
    ""
    x))

(declare format-full-node)

(defn format-node
  [node]
  (cond
    (string? node) (format "\"%s\"" (.trim node))
    (nil? node) nil
    :else (format-full-node node)))

(defn format-full-node
  [node]
  (format "[%s %s %s]\n"
          (:tag node)
          (empty-when-null (format-attrs (:attrs node)))
          (str-join " " (map format-node (:content node)))))

(defn transform-file
  [filename]
  (print (pprint (read-string (format-node (parse filename))))))

Cheers,
Robin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Reeves  
View profile  
 More options Jun 29 2009, 3:39 pm
From: James Reeves <weavejes...@googlemail.com>
Date: Mon, 29 Jun 2009 12:39:06 -0700 (PDT)
Local: Mon, Jun 29 2009 3:39 pm
Subject: Re: Small util for transforming xhtml to html DSL
On Jun 27, 8:58 pm, Robin Brandt <robin.bra...@gmail.com> wrote:

> Maybe somebody has the same problem and can use the following code as
> a start: I wanted to transform an XHTML-template to the HTML DSL
> that's coming with clojure.

You mean Compojure? Although I guess the same HTML syntax has been
adopted by clojure.contrib.prxml.

This looks pretty useful. Thanks for taking the time to write it.

- James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »