change default io name and document it

This commit is contained in:
Jerome Gravel-Niquet 2016-02-14 13:26:50 -05:00
parent d761fe6b58
commit 394fea01da
3 changed files with 14 additions and 11 deletions

View file

@ -25,11 +25,14 @@ dependencies:
# Any other template languages Crystal shard
```
Kilt essentially adds two macros `Kilt.embed` and `Kilt.file`, the code is really simple.
## Usage
Add template language dependencies, as listed in the support table above.
- Kilt essentially adds two macros `Kilt.embed` and `Kilt.file`, the code is really simple.
- Add template language dependencies, as listed in the support table above.
Both macros take a `filename` and a `io_name` (the latter defaults to `"__kilt_io__"`)
### Example
```crystal
require "kilt"
@ -45,8 +48,8 @@ puts YourView.new.to_s # => <compiled template>
# Embedded
str = String.build do |str|
Kilt.embed "path/to/template.slang", "str"
str = String.build do |__kilt_io__|
Kilt.embed "path/to/template.slang"
end
puts str # => <compiled template>

View file

@ -2,8 +2,8 @@ require "ecr/macros"
require "./kilt/*"
module Kilt
macro embed(filename, io_name = "__io__")
macro embed(filename, io_name = "__kilt_io__")
{% if filename.ends_with?(".ecr") %}
embed_ecr({{filename}}, {{io_name}})
{% elsif filename.ends_with?(".slang") %}
@ -13,9 +13,9 @@ module Kilt
{% end %}
end
macro file(filename)
def to_s(__io__)
Kilt.embed({{filename}}, "__io__")
macro file(filename, io_name = "__kilt_io__")
def to_s({{io_name.id}})
Kilt.embed({{filename}}, {{io_name}})
end
end

View file

@ -1,3 +1,3 @@
module Kilt
VERSION = "0.1.0"
VERSION = "0.1.1"
end