Skip to content

Instantly share code, notes, and snippets.

@defunkt
Forked from kastner/1-README.md
Created October 12, 2009 17:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save defunkt/208551 to your computer and use it in GitHub Desktop.
Save defunkt/208551 to your computer and use it in GitHub Desktop.

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
$:.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
{{ name }}
{{<partial}}
class PartialDemo
module Views
class Index < Mustache
def name() "Erik" end
end
end
end
Batteries not {{ included }}
class PartialDemo
module Views
class Partial < Mustache
def included() "included" end
end
end
end
class PartialDemo < Sinatra::Base
register Mustache::Sinatra
set :views, './'
set :mustaches, './'
get '/' do
mustache :index
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment