tyler / speed_stache

An extension to Mustache that compiles templates to C

This URL has Read+Write access

name age message
file .gitignore Tue Oct 13 17:48:23 -0700 2009 ignore some crap [tyler]
file README Sun Oct 04 18:48:42 -0700 2009 Add limitations [tyler]
directory bin/ Sun Oct 04 18:47:41 -0700 2009 Initial commit. [tyler]
directory examples/ Tue Oct 13 18:29:24 -0700 2009 More straightforward examples [tyler]
directory lib/ Wed Oct 14 23:43:52 -0700 2009 Add the activate method for turning it on [tyler]
directory resources/ Tue Oct 13 17:48:06 -0700 2009 Proper support for loops. And much much faster. [tyler]
directory util/ Sun Oct 04 18:47:41 -0700 2009 Initial commit. [tyler]
README
Speed 'Stache compiles Mustache templates to C, and ultimately to object files which can be required in your Ruby code.  
It also provides a simple extension to Mustache to use those object files.

simple.html ---

  <div>
    Dear {{name}},

    What's up?
    {{#cool?}} You're cool! {{/cool?}}

    Love,
    Tyler
  </div>


simple.rb ---

  require 'mustache'

  class Simple < Mustache
    def name
      "Bob"
    end

    def cool?
      true
    end
  end

  Simple.new.to_html


Pretty simple example.  Obviously you just drop these files in the same directory, require mustache and go to town.  
Using Speed 'Stache isn't much harder.

The first step is to actually compile the templates.  At a Terminal...
  
  speed_stache/bin/compile_mustache simple.html

That should output some Makefile junk and leave you with a simple_template.o file.

Next we modify simple.rb above to the following:

simple.rb ---

  require 'mustache'
  require 'speed_stache'
  require 'simple_template'

  class Simple < Mustache
    include SimpleTemplate

    def name
      "Bob"
    end

    def cool?
      true
    end
  end

  Simple.new.to_html

It should output roughly the same thing as the first run above, but about 50 times faster!


*** LIMITATIONS ***

This doesn't actually implement Mustache in full yet.  It handles output and conditionals, but that's it.  No partials, 
no iterators... Not yet anyway!