ChangingThePresent
The Few, The Proud, The Pradipta 416
My Resume
Web DOC PDF
RTF ODT TXT
powered by emurse

Comatose CMS XML Text Filter

bryan / 14.Jan.2008

I recently contributed a new Text Filter to the Comatose "micro-CMS" project. The filter uses XML and XSLT to produce XHTML ready for Liquid or Erb rendering. It's stupidly simple.
  1. Install libxml
  2. Choose your version from libxml's download page. Install in the usual way, probably adding something like --prefix=/usr/local/ to ./configure

  3. Install libxslt
  4. Choose your version from libxslt's download page. Same install as libxml.

  5. install the ruby gem
  6. something like ruby gem install ruby-xslt

  7. add the filter to your project
  8. Add the following to environment.rb:

    require 'xml/xslt'
    
    TextFilters.define :xml, "XML" do
      require 'xml/xslt'
      
      def render_text(text)
         xslt = XML::XSLT.new()
         xslt.xml = text
         xslt.xsl = "/path/to/the/xslt/file.xslt"
         out = xslt.serve()
         return out
      end
    

Then in your Comatose pages, you should have the XML filter listed. Your XML should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href='foo.xslt' type='text/xsl'?>
<foo>
  <bar>
    <baz>{{ 'this is foo' }}</baz>
  </bar>
</foo>

For embedding weird stuff, just use CDATA, like:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href='foo.xslt' type='text/xsl'?>
<foo>
  <bar>
    <baz>
      <![CDATA[ 
        <a href="{{ 'foo' | link }}">foo</a>
      ]]>
    </baz>
  </bar>
</foo>

Sorry, comments are closed for this article.

back to top

micro theme by seaofclouds, and powered with Mephisto Hosting by hostingrails.com