Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f31dad1
Showing
12 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/doc/ | ||
/libs/ | ||
/.crystal/ | ||
/.shards/ | ||
|
||
|
||
# Libraries don't need dependency lock | ||
# Dependencies will be locked in application that uses them | ||
/shard.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
language: crystal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Jerome Gravel-Niquet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Kilt | ||
|
||
Generic templating interface for Crystal. | ||
|
||
## Goal | ||
|
||
Simplify developers' lives by abstracting template rendering for multiple template languages. | ||
|
||
## Supported | ||
|
||
| Language | File extensions | Required libraries | | ||
| -------- | --------------- | ------------------ | | ||
| ECR | .ecr | none | | ||
| Slang | .slang | [slang](https://github.com/jeromegn/slang) | | ||
|
||
## Installation | ||
|
||
Add this to your application's `shard.yml`: | ||
|
||
```yaml | ||
dependencies: | ||
kilt: | ||
github: jeromegn/kilt | ||
|
||
# Any other template languages Crystal shard | ||
``` | ||
|
||
## Usage | ||
|
||
Add template language dependencies, as listed in the support table above. | ||
|
||
```crystal | ||
require "kilt" | ||
require "slang" # if you want to use Slang templates, for instance | ||
# With a Class | ||
class YourView | ||
Kilt.file("path/to/template.ecr") # Adds a to_s method | ||
end | ||
puts YourView.new.to_s # => <compiled template> | ||
# Embedded | ||
str = String.build do |str| | ||
Kilt.embed "path/to/template.slang", "str" | ||
end | ||
puts str # => <compiled template> | ||
``` | ||
|
||
## Contributing | ||
|
||
Please contribute your own "adapter" if you create a template language for Crystal that's not yet supported here! | ||
|
||
1. Fork it ( https://github.com/jeromegn/kilt/fork ) | ||
2. Create your feature branch (git checkout -b my-awesome-template-language) | ||
3. Commit your changes (git commit -am 'Add my-awesome-template-language') | ||
4. Push to the branch (git push origin my-awesome-template-language) | ||
5. Create a new Pull Request | ||
|
||
## Contributors | ||
|
||
- [jeromegn](https://github.com/jeromegn) Jerome Gravel-Niquet - creator, maintainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: kilt | ||
version: 0.1.0 | ||
|
||
authors: | ||
- Jerome Gravel-Niquet <jeromegn@gmail.com> | ||
|
||
license: MIT | ||
|
||
development_dependencies: | ||
slang: | ||
github: jeromegn/slang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<span><%= Process.pid %></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
span = Process.pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "./spec_helper" | ||
|
||
class View | ||
Kilt.file "spec/fixtures/test.ecr" | ||
end | ||
|
||
describe Kilt do | ||
|
||
it "renders ecr" do | ||
render_file("spec/fixtures/test.ecr").should eq("<span>#{Process.pid}</span>") | ||
end | ||
|
||
it "renders slang" do | ||
render_file("spec/fixtures/test.slang").should eq("<span>#{Process.pid}</span>") | ||
end | ||
|
||
it "works with classes" do | ||
View.new.to_s.should eq("<span>#{Process.pid}</span>") | ||
end | ||
|
||
it "raises with unsupported filetype" do | ||
expect_raises(Kilt::Exception, "Unsupported template type \"abc\"") { | ||
render_file("test.abc") | ||
} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "spec" | ||
require "slang" | ||
require "../src/kilt" | ||
|
||
macro render_file(filename) | ||
String.build do |__io__| | ||
Kilt.embed({{filename}}, "__io__") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "ecr/macros" | ||
require "./kilt/*" | ||
|
||
module Kilt | ||
|
||
macro embed(filename, io_name = "__io__") | ||
{% if filename.ends_with?(".ecr") %} | ||
embed_ecr({{filename}}, {{io_name}}) | ||
{% elsif filename.ends_with?(".slang") %} | ||
embed_slang({{filename}}, {{io_name}}) | ||
{% else %} | ||
raise Kilt::Exception.new("Unsupported template type \"" + {{filename.split(".").last}} + "\"") | ||
{% end %} | ||
end | ||
|
||
macro file(filename) | ||
def to_s(__io__) | ||
Kilt.embed({{filename}}, "__io__") | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Kilt | ||
class Exception < ::Exception | ||
# Nothing special | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Kilt | ||
VERSION = "0.1.0" | ||
end |