kastner (owner)

Forks

Revisions

gist: 208082 Download_button fork
public
Public Clone URL: git://gist.github.com/208082.git
Embed All Files: show embed
1-README.md #

Sinatra+Mustache Partial Madness

2 problems

  1. It is looking for ./partial.html and not partial.mustache
  2. Using the method chain in config.ru you should see "klass is Partial". It seems like it should be PartialDemo::Views::Partial
config.ru #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$:.unshift '../../Ruby/mustache/lib'
require 'sinatra/base'
require 'mustache/sinatra'
require 'partial_demo'
 
use Rack::Lint
use Rack::ShowExceptions
 
Mustache::Template.class_eval do
  alias_method :_cmp_partial, :compile_partial unless method_defined?(:_cmp_partial)
  def compile_partial(name)
    puts "--------------------------------------------"
    puts "klass is #{Mustache.classify(name)}"
    puts "--------------------------------------------\n\n"
    _cmp_partial(name)
  end
end
 
run PartialDemo.new
 
index.mustache #
1
2
{{ name }}
{{<partial}}
index.rb #
1
2
3
4
5
6
7
class PartialDemo
  module Views
    class Index < Mustache
      def name() "Erik" end
    end
  end
end
partial.mustache #
1
Batteries not {{ included }}
partial.rb #
1
2
3
4
5
6
7
class PartialDemo
  module Views
    class Partial < Mustache
      def included() "included" end
    end
  end
end
partial_demo.rb #
1
2
3
4
5
6
7
8
9
10
class PartialDemo < Sinatra::Base
  register Mustache::Sinatra
  
  set :views, './'
  set :mustaches, './'
  
  get '/' do
    mustache :index
  end
end