Simplify logic further via registering extensions without dot

This commit is contained in:
Oleksii Fedorov 2016-02-15 03:37:26 +01:00
parent a43ad3c09c
commit 69b31b6e5d
3 changed files with 5 additions and 6 deletions

View file

@ -70,7 +70,7 @@ module MyEngine
end
end
Kilt.register_template(".myeng", ::MyEngine.embed)
Kilt.register_template("myeng", ::MyEngine.embed)
```
This can be part of your own `my-engine` library: in this case it should depend

View file

@ -2,7 +2,7 @@ require "spec"
require "../src/kilt"
require "slang"
Kilt.register_template(".slang", embed_slang)
Kilt.register_template("slang", embed_slang)
macro render_file(filename)
String.build do |__io__|

View file

@ -11,10 +11,9 @@ module Kilt
macro embed(filename, io_name = "__kilt_io__")
{% ext = filename.split(".").last %}
{% ext_with_dot = ".#{ext.id}" %}
{% if ::Kilt::TEMPLATES[ext_with_dot] %}
{{::Kilt::TEMPLATES[ext_with_dot]}}({{filename}}, {{io_name}})
{% if ::Kilt::TEMPLATES[ext] %}
{{::Kilt::TEMPLATES[ext]}}({{filename}}, {{io_name}})
{% else %}
raise Kilt::Exception.new("Unsupported template type \"" + {{ext}} + "\"")
{% end %}
@ -27,4 +26,4 @@ module Kilt
end
end
::Kilt.register_template(".ecr", embed_ecr)
::Kilt.register_template("ecr", embed_ecr)