Added Mustache adapter

This commit is contained in:
TSUYUSATO Kitsune 2016-02-15 13:18:42 +09:00
parent a222267254
commit ae9e097221
5 changed files with 41 additions and 5 deletions

View file

@ -8,9 +8,10 @@ Simplify developers' lives by abstracting template rendering for multiple templa
## Supported out of the box
| Language | File extensions | Required libraries |
| -------- | --------------- | ------------------ |
| ECR | .ecr | none (part of the stdlib) |
| Language | File extensions | Required libraries | Maintainer |
| -------- | --------------- | ------------------ | ---------- |
| ECR | .ecr | none (part of the stdlib) | |
| Mustache | .mustache | [crustache](https://github.com/MakeNowJust/crustache) | [@MakeNowJust](https://github.com/MakeNowJust) |
See also:
[Registering your own template engine](#registering-your-own-template-engine).
@ -92,4 +93,4 @@ Please contribute your own "adapter" if you create a template language for Cryst
## Contributors
- [jeromegn](https://github.com/jeromegn) Jerome Gravel-Niquet - creator, maintainer
- [waterlink](https://github.com/waterlink) Oleksii Fedorov
- [waterlink](https://github.com/waterlink) Oleksii Fedorov

View file

@ -4,4 +4,8 @@ version: 0.1.0
authors:
- Jerome Gravel-Niquet <jeromegn@gmail.com>
license: MIT
license: MIT
development_dependencies:
crustache:
github: MakeNowJust/crustache

1
spec/fixtures/test.mustache vendored Normal file
View file

@ -0,0 +1 @@
<span>{{pid}}</span>

26
spec/mustache_spec.cr Normal file
View file

@ -0,0 +1,26 @@
require "./spec_helper"
require "../src/mustache"
class MustacheView
def has_key?(name)
name == "pid"
end
def [](name)
name == "pid" ? Process.pid : nil
end
Kilt.file "spec/fixtures/test.mustache", "__kilt_io__", self
end
describe Kilt do
it "renders ecr" do
Kilt.render("spec/fixtures/test.mustache", { "pid" => Process.pid }).should eq("<span>#{Process.pid}</span>")
end
it "works with classes" do
MustacheView.new.to_s.should eq("<span>#{Process.pid}</span>")
end
end

4
src/mustache.cr Normal file
View file

@ -0,0 +1,4 @@
require "./kilt"
require "crustache"
Kilt.register_engine "mustache", embed_mustache