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
|
# Any other template languages Crystal shard
|
||||||
```
|
```
|
||||||
|
|
||||||
Kilt essentially adds two macros `Kilt.embed` and `Kilt.file`, the code is really simple.
|
|
||||||
|
|
||||||
## Usage
|
## 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
|
```crystal
|
||||||
require "kilt"
|
require "kilt"
|
||||||
|
@ -45,8 +48,8 @@ puts YourView.new.to_s # => <compiled template>
|
||||||
|
|
||||||
# Embedded
|
# Embedded
|
||||||
|
|
||||||
str = String.build do |str|
|
str = String.build do |__kilt_io__|
|
||||||
Kilt.embed "path/to/template.slang", "str"
|
Kilt.embed "path/to/template.slang"
|
||||||
end
|
end
|
||||||
|
|
||||||
puts str # => <compiled template>
|
puts str # => <compiled template>
|
||||||
|
|
|
@ -3,7 +3,7 @@ require "./kilt/*"
|
||||||
|
|
||||||
module Kilt
|
module Kilt
|
||||||
|
|
||||||
macro embed(filename, io_name = "__io__")
|
macro embed(filename, io_name = "__kilt_io__")
|
||||||
{% if filename.ends_with?(".ecr") %}
|
{% if filename.ends_with?(".ecr") %}
|
||||||
embed_ecr({{filename}}, {{io_name}})
|
embed_ecr({{filename}}, {{io_name}})
|
||||||
{% elsif filename.ends_with?(".slang") %}
|
{% elsif filename.ends_with?(".slang") %}
|
||||||
|
@ -13,9 +13,9 @@ module Kilt
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro file(filename)
|
macro file(filename, io_name = "__kilt_io__")
|
||||||
def to_s(__io__)
|
def to_s({{io_name.id}})
|
||||||
Kilt.embed({{filename}}, "__io__")
|
Kilt.embed({{filename}}, {{io_name}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module Kilt
|
module Kilt
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.1"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue