mirror of
https://gitea.invidious.io/iv-org/shard-kilt.git
synced 2024-08-15 00:43:15 +00:00
Added slang adapter + specs, reorganized specs and adapters
This commit is contained in:
parent
ae9e097221
commit
b152bf1153
14 changed files with 62 additions and 27 deletions
15
README.md
15
README.md
|
@ -12,6 +12,7 @@ Simplify developers' lives by abstracting template rendering for multiple templa
|
|||
| -------- | --------------- | ------------------ | ---------- |
|
||||
| ECR | .ecr | none (part of the stdlib) | |
|
||||
| Mustache | .mustache | [crustache](https://github.com/MakeNowJust/crustache) | [@MakeNowJust](https://github.com/MakeNowJust) |
|
||||
| Slang | .slang | [slang](https://github.com/jeromegn/slang) | [@jeromegn](https://github.com/jeromegn) |
|
||||
|
||||
See also:
|
||||
[Registering your own template engine](#registering-your-own-template-engine).
|
||||
|
@ -39,7 +40,10 @@ Both macros take a `filename` and a `io_name` (the latter defaults to `"__kilt_i
|
|||
|
||||
```crystal
|
||||
require "kilt"
|
||||
require "slang" # if you want to use Slang templates, for instance
|
||||
|
||||
# For slang, try:
|
||||
require "slang"
|
||||
require "kilt/slang"
|
||||
|
||||
# With a Class
|
||||
|
||||
|
@ -51,12 +55,14 @@ puts YourView.new.to_s # => <compiled template>
|
|||
|
||||
# Embedded
|
||||
|
||||
str = Kilt.render "path/to/template.slang"
|
||||
|
||||
# or
|
||||
|
||||
str = String.build do |__kilt_io__|
|
||||
Kilt.embed "path/to/template.slang"
|
||||
end
|
||||
|
||||
# or `Kilt.render "path/to/template.slang"`
|
||||
|
||||
puts str # => <compiled template>
|
||||
```
|
||||
|
||||
|
@ -73,7 +79,7 @@ module MyEngine
|
|||
end
|
||||
end
|
||||
|
||||
Kilt.register_engine("myeng", ::MyEngine.embed)
|
||||
Kilt.register_engine("myeng", MyEngine.embed)
|
||||
```
|
||||
|
||||
This can be part of your own `my-engine` library: in this case it should depend
|
||||
|
@ -94,3 +100,4 @@ Please contribute your own "adapter" if you create a template language for Cryst
|
|||
|
||||
- [jeromegn](https://github.com/jeromegn) Jerome Gravel-Niquet - creator, maintainer
|
||||
- [waterlink](https://github.com/waterlink) Oleksii Fedorov
|
||||
- [MakeNowJust](https://github.com/MakeNowJust) TSUYUSATO Kitsune
|
|
@ -7,5 +7,7 @@ authors:
|
|||
license: MIT
|
||||
|
||||
development_dependencies:
|
||||
slang:
|
||||
github: jeromegn/slang
|
||||
crustache:
|
||||
github: MakeNowJust/crustache
|
||||
|
|
1
spec/fixtures/test.slang
vendored
Normal file
1
spec/fixtures/test.slang
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
span = Process.pid
|
|
@ -1,5 +1,5 @@
|
|||
require "./spec_helper"
|
||||
require "../src/mustache"
|
||||
require "../spec_helper"
|
||||
require "../../src/kilt/crustache"
|
||||
|
||||
class MustacheView
|
||||
def has_key?(name)
|
||||
|
@ -13,9 +13,9 @@ class MustacheView
|
|||
Kilt.file "spec/fixtures/test.mustache", "__kilt_io__", self
|
||||
end
|
||||
|
||||
describe Kilt do
|
||||
describe "kilt/crustache" do
|
||||
|
||||
it "renders ecr" do
|
||||
it "renders crustache" do
|
||||
Kilt.render("spec/fixtures/test.mustache", { "pid" => Process.pid }).should eq("<span>#{Process.pid}</span>")
|
||||
end
|
||||
|
18
spec/kilt/slang_spec.cr
Normal file
18
spec/kilt/slang_spec.cr
Normal file
|
@ -0,0 +1,18 @@
|
|||
require "../spec_helper"
|
||||
require "../../src/kilt/slang"
|
||||
|
||||
class SlangView
|
||||
Kilt.file "spec/fixtures/test.slang"
|
||||
end
|
||||
|
||||
describe "kilt/slang" do
|
||||
|
||||
it "renders slang" do
|
||||
Kilt.render("spec/fixtures/test.slang").should eq("<span>#{Process.pid}</span>")
|
||||
end
|
||||
|
||||
it "works with classes" do
|
||||
SlangView.new.to_s.should eq("<span>#{Process.pid}</span>")
|
||||
end
|
||||
|
||||
end
|
|
@ -10,11 +10,6 @@ describe Kilt do
|
|||
Kilt.render("spec/fixtures/test.ecr").should eq("<span>#{Process.pid}</span>")
|
||||
end
|
||||
|
||||
it "renders registered engine" do
|
||||
Kilt.register_engine "raw", Raw.embed
|
||||
Kilt.render("spec/fixtures/test.raw").should eq("Hello World!")
|
||||
end
|
||||
|
||||
it "works with classes" do
|
||||
View.new.to_s.should eq("<span>#{Process.pid}</span>")
|
||||
end
|
||||
|
@ -25,4 +20,9 @@ describe Kilt do
|
|||
}
|
||||
end
|
||||
|
||||
it "renders registered engine" do
|
||||
Kilt.register_engine "raw", Raw.embed
|
||||
Kilt.render("spec/fixtures/test.raw").should eq("Hello World!")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
require "spec"
|
||||
require "../src/kilt"
|
||||
|
||||
module Raw
|
||||
macro embed(filename, io)
|
||||
{{ io.id }} << {{`cat #{filename}`.stringify}}
|
||||
end
|
||||
end
|
||||
require "./support/raw_engine"
|
5
spec/support/raw_engine.cr
Normal file
5
spec/support/raw_engine.cr
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Raw
|
||||
macro embed(filename, io)
|
||||
{{ io.id }} << {{`cat #{filename}`.stringify}}
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
require "ecr/macros"
|
||||
require "./kilt/*"
|
||||
require "./kilt/version"
|
||||
require "./kilt/exception"
|
||||
|
||||
module Kilt
|
||||
# macro only constant
|
||||
|
@ -32,4 +32,4 @@ module Kilt
|
|||
end
|
||||
end
|
||||
|
||||
Kilt.register_engine("ecr", embed_ecr)
|
||||
require "./kilt/ecr"
|
||||
|
|
4
src/kilt/crustache.cr
Normal file
4
src/kilt/crustache.cr
Normal file
|
@ -0,0 +1,4 @@
|
|||
require "../kilt"
|
||||
require "crustache"
|
||||
|
||||
Kilt.register_engine "mustache", embed_mustache
|
3
src/kilt/ecr.cr
Normal file
3
src/kilt/ecr.cr
Normal file
|
@ -0,0 +1,3 @@
|
|||
require "ecr/macros"
|
||||
|
||||
Kilt.register_engine("ecr", embed_ecr)
|
4
src/kilt/slang.cr
Normal file
4
src/kilt/slang.cr
Normal file
|
@ -0,0 +1,4 @@
|
|||
require "../kilt"
|
||||
require "slang"
|
||||
|
||||
Kilt.register_engine "slang", Slang.embed
|
|
@ -1,3 +1,3 @@
|
|||
module Kilt
|
||||
VERSION = "0.2.1"
|
||||
VERSION = "0.3.0"
|
||||
end
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
require "./kilt"
|
||||
require "crustache"
|
||||
|
||||
Kilt.register_engine "mustache", embed_mustache
|
Loading…
Reference in a new issue