mirror of
https://gitea.invidious.io/iv-org/shard-kilt.git
synced 2024-08-15 00:43:15 +00:00
change default io name and document it
This commit is contained in:
parent
d761fe6b58
commit
394fea01da
3 changed files with 14 additions and 11 deletions
13
README.md
13
README.md
|
@ -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>
|
||||
|
|
10
src/kilt.cr
10
src/kilt.cr
|
@ -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
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Kilt
|
||||
VERSION = "0.1.0"
|
||||
VERSION = "0.1.1"
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue