Giter Site home page Giter Site logo

kilt's Introduction

Kilt Build Status Dependency Status devDependency Status

Generic templating interface for Crystal.

Goal

Simplify developers' lives by abstracting template rendering for multiple template languages.

Supported out of the box

Language File extensions Required libraries Maintainer
ECR .ecr none (part of the stdlib)
Mustache .mustache crustache @MakeNowJust
Slang .slang slang @jeromegn
Temel .temel temel @f
Crikey .crikey crikey @domgetter

See also: Registering your own template engine.

Installation

Add this to your application's shard.yml:

dependencies:
  kilt:
    github: jeromegn/kilt

  # Any other template languages Crystal shard

Usage

  • 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

require "kilt"

# For slang, add:
require "kilt/slang"

# 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 = Kilt.render "path/to/template.slang"

# or

str = String.build do |__kilt_io__|
  Kilt.embed "path/to/template.slang"
end

puts str # => <compiled template>

Registering your own template engine

Use Kilt.register_engine(extension, embed_command) macro:

require "kilt"

module MyEngine
  macro embed(filename, io_name)
    # ....
  end
end

Kilt.register_engine("myeng", MyEngine.embed)

This can be part of your own my-engine library: in this case it should depend on kilt directly, or this could be a part of adapter library, like: kilt-my-engine, which will depend on both kilt and my-engine.

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

kilt's People

Contributors

jeromegn avatar waterlink avatar makenowjust avatar fernandes avatar domgetter avatar f avatar

Watchers

James Cloos avatar Elias Perez avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.