Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toddsundsted/slang
Slim-inspired templating language for Crystal
https://github.com/toddsundsted/slang
crystal kilt slang template-language
Last synced: about 1 month ago
JSON representation
Slim-inspired templating language for Crystal
- Host: GitHub
- URL: https://github.com/toddsundsted/slang
- Owner: toddsundsted
- License: mit
- Created: 2020-09-11T22:33:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-10T13:41:32.000Z (8 months ago)
- Last Synced: 2024-06-14T00:23:53.466Z (5 months ago)
- Topics: crystal, kilt, slang, template-language
- Language: Crystal
- Homepage:
- Size: 182 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Slang
[![Build Status](https://github.com/toddsundsted/slang/actions/workflows/ci.yml/badge.svg)](https://github.com/toddsundsted/slang/actions)
Lightweight, terse, templating language for Crystal. Originally
forked from [jeromegn/slang](https://github.com/jeromegn/slang). Now
with more [Slim](https://github.com/slim-template/slim) compatibility.## Installation
To install the latest code, add this to your application's `shard.yml`,
or pin it to a [released version](https://github.com/toddsundsted/slang/releases):```yaml
dependencies:
slang:
github: toddsundsted/slang
branch: main
```## Usage
### Preferred: use Kilt
[Kilt](https://github.com/jeromegn/kilt) is included as a dependency for this project. It should help integrating non-ECR template engines.
Add this to your application's `shard.yml`:
```yaml
dependencies:
slang:
github: toddsundsted/slang
branch: main
kilt:
github: jeromegn/kilt
``````
require "kilt/slang"Kilt.render("path/to/file.slang") #=>
```Example with [Kemal](http://kemalcr.com) (includes Kilt):
```crystal
require "kilt/slang"get "/" do
render "path/to/file.slang"
end
```### Without Kilt
```crystal
String.build do |str|
Slang.embed("path/to/file.slang", "str")
end
```## Syntax
```slim
doctype html
html
head
meta name="viewport" content="width=device-width,initial-scale=1.0"
title This is a title
css:
h1 {color: red;}
p {color: green;}
style h2 {color: blue;}
body
/! Visible multi-line comment
span this is wrapped in a comment
/[if IE]
p Dat browser is old.
/ Invisible multi-line comment
span this is wrapped in a comment
h1 This is a slang file
h2 This is blue
input type="checkbox" checked=false
input type="checkbox" checked=true
input type="checkbox" checked="checked"
span#some-id.classname
#hello.world.world2
- some_var = "hello world haha"
span
span data-some-var=some_var two-attr="fun" and a #{p("hello")}
span
span.deep_nested
p
| text inside of
= Process.pid
| text node
' other text node
span.alongside pid=Process.pid
custom-tag#with-id pid="#{Process.pid}"
- ["ah", "oh"].each do |s|
span = s
/ This is an invisible comment
#amazing-div some-attr="hello"
/! This is a visible comment
script var num1 = 8*4;javascript:
var num2 = 8*3;
alert("8 * 3 + 8 * 4 = " + (num1 + num2));
```Given the context:
```crystal
some_var = "hello"
strings = ["ah", "oh"]
```Compiles to HTML:
```html
This is a title
h1 {color: red;}
p {color: green;}
h2 {color: blue;}
This is a slang file
This is blue
and a hello
text inside of <p>
#{Process.pid}
text node
other text node
ah
oh
var num1 = 8*4;
var num2 = 8*3;
alert("8 * 3 + 8 * 4 = " + (num1 + num2));
```
## Contributing
1. Fork it ( https://github.com/toddsundsted/slang/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request## Contributors
- [jeromegn](https://github.com/jeromegn) Jerome Gravel-Niquet - creator, maintainer
- [toddsundsted](https://github.com/toddsundsted) Todd Sundsted - maintainer of this fork
- [kRaw1er](https://github.com/kRaw1er) Dmitry Neveshkin
- [elorest](https://github.com/elorest) Isaac Sloan