All Projects → jeromegn → Slang

jeromegn / Slang

Licence: mit
Slim-inspired templating language for Crystal

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to Slang

closet
The Web Framework for Flashcards
Stars: ✭ 45 (-77.5%)
Mutual labels:  template-language
Bars
Bars is a lightweight high performance HTML aware templating engine. Bars emits DOM rather than DOM-strings, this means the DOM state is preserved even if data updates happen.
Stars: ✭ 5 (-97.5%)
Mutual labels:  template-language
Eval
Eval is a lightweight interpreter framework written in Swift, evaluating expressions at runtime
Stars: ✭ 157 (-21.5%)
Mutual labels:  template-language
bart
A compile time templating language for Rust inspired by Mustache
Stars: ✭ 29 (-85.5%)
Mutual labels:  template-language
Twirl
Twirl is Play's default template engine
Stars: ✭ 498 (+149%)
Mutual labels:  template-language
Awesome Twig
A curated list of amazingly awesome Twig extensions, snippets and tutorials
Stars: ✭ 63 (-68.5%)
Mutual labels:  template-language
sourcery-templates
Building Vapor projects using meta programming with Sourcery ✨
Stars: ✭ 24 (-88%)
Mutual labels:  template-language
Automad
A flat-file content management system and template engine
Stars: ✭ 163 (-18.5%)
Mutual labels:  template-language
Jinjasql
Template Language for SQL with Automatic Bind Parameter Extraction
Stars: ✭ 529 (+164.5%)
Mutual labels:  template-language
Phptal
PHP Template Attribute Language — template engine for XSS-proof well-formed XHTML and HTML5 pages
Stars: ✭ 155 (-22.5%)
Mutual labels:  template-language
Rascal
The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
Stars: ✭ 284 (+42%)
Mutual labels:  template-language
Ego
An ERB-style templating language for Go.
Stars: ✭ 477 (+138.5%)
Mutual labels:  template-language
Tuxedo
Tuxedo is a template language for Swift.
Stars: ✭ 80 (-60%)
Mutual labels:  template-language
hyperviews
Template language that produces `h` output
Stars: ✭ 26 (-87%)
Mutual labels:  template-language
Ehtml
HTML Framework that allows you not to write JavaScript code.
Stars: ✭ 161 (-19.5%)
Mutual labels:  template-language
khufu
A template language for incremental-dom or DSL for javascript views
Stars: ✭ 19 (-90.5%)
Mutual labels:  template-language
Srml
String Resource Markup Language. Style your localized strings for Android.
Stars: ✭ 49 (-75.5%)
Mutual labels:  template-language
Milk
Milk is Mustache in CoffeeScript -- great with your browser or NodeJS!
Stars: ✭ 192 (-4%)
Mutual labels:  template-language
Pongo2
Django-syntax like template-engine for Go
Stars: ✭ 2,111 (+955.5%)
Mutual labels:  template-language
Fleet
Templating System for Clojure
Stars: ✭ 148 (-26%)
Mutual labels:  template-language

Slang Build Status

Lightweight, terse, templating language for Crystal.

Installation

Add this to your application's shard.yml:

dependencies:
  slang:
    github: jeromegn/slang

Usage

Preferred: use Kilt

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:

dependencies:
  kilt:
    github: jeromegn/kilt
require "kilt/slang"

Kilt.render("path/to/file.slang") #=> <compiled template>

Example with Kemal (includes Kilt):

require "kilt/slang"

get "/" do
  render "path/to/file.slang"
end

Without Kilt

String.build do |str|
  Slang.embed("path/to/file.slang", "str")
end

Syntax

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 <p>
              = 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
    - if true == true
      #amazing-div some-attr="hello"
    - else
      #not-so-amazing-div some-attr="goodbye"
    /! 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:

some_var = "hello"
strings = ["ah", "oh"]

Compiles to HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>This is a title</title>
    <style>
      h1 {color: red;}
      p {color: green;}
    </style>
    <style>h2 {color: blue;}</style>
  </head>
  <body>
    <!--Visible multi-line comment
      <span>this is wrapped in a comment</span>
    -->
    <!--[if IE]>
      <p>Dat browser is old.</p>
    <![endif]-->
    <h1>This is a slang file</h1>
    <h2>This is blue</h2>
    <input type="checkbox"/>
    <input type="checkbox" checked/>
    <input type="checkbox" checked="checked"/>
    <span id="some-id" class="classname">
      <div id="hello" class="world world2">
        <span>
          <span data-some-var="hello world haha" two-attr="fun">and a hello</span>
          <span>
            <span class="deep_nested">
              <p>
                text inside of &lt;p&gt;
              </p>
              #{Process.pid}
              text node
              other text node
            </span>
          </span>
        </span>
        <span class="alongside" pid="#{Process.pid}">
          <custom-tag id="with-id" pid="#{Process.pid}">
            <span>ah</span>
            <span>oh</span>
          </custom-tag>
        </span>
      </div>
    </span>
    <div id="amazing-div" some-attr="hello"></div>
    <!--This is a visible comment-->
    <script>var num1 = 8*4;</script>
    <script>
      var num2 = 8*3;
      alert("8 * 3 + 8 * 4 = " + (num1 + num2));
    </script>
  </body>
</html>

Difference between single and double equals in Slang

  • = inserts HTML with escaped characters
  • == inserts HTML without escaping. It is needed when you have already rendered HTML and you need to insert it to your layout directly.

TODO

  • [x] Fix known limitations
  • [ ] More tests
  • [ ] Website
  • [ ] Documentation

Contributing

  1. Fork it ( https://github.com/jeromegn/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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].