All Projects â†’ slime-lang â†’ Slime

slime-lang / Slime

Licence: mit
Minimalistic HTML templates for Elixir, inspired by Slim.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Slime

flutterby
A flexible, Ruby-powered static site generator.
Stars: ✭ 56 (-82.22%)
Mutual labels:  slim
Cors
🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.
Stars: ✭ 266 (-15.56%)
Mutual labels:  slim
Pandoc Ruby
Ruby wrapper for Pandoc
Stars: ✭ 299 (-5.08%)
Mutual labels:  markup
bart
A compile time templating language for Rust inspired by Mustache
Stars: ✭ 29 (-90.79%)
Mutual labels:  template-engine
Deck
Slide Decks
Stars: ✭ 261 (-17.14%)
Mutual labels:  markup
Daisyrec
A developing recommender system in pytorch. Algorithm: KNN, LFM, SLIM, NeuMF, FM, DeepFM, VAE and so on, which aims to fair comparison for recommender system benchmarks
Stars: ✭ 280 (-11.11%)
Mutual labels:  slim
bh-php
PHP port of https://github.com/bem/bh. It's cool thing but better use this:
Stars: ✭ 33 (-89.52%)
Mutual labels:  template-engine
Webmarkupmin
The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
Stars: ✭ 312 (-0.95%)
Mutual labels:  markup
Doxyrest
A compiler from Doxygen XML to reStructuredText -- hence, the name. It parses XML databases generated by Doxygen and produces reStructuredText for the Python documentation generator Sphinx.
Stars: ✭ 265 (-15.87%)
Mutual labels:  template-engine
Http Rpc
Lightweight REST for Java
Stars: ✭ 298 (-5.4%)
Mutual labels:  template-engine
Hunt Framework
A Web framework for D Programming Language. Full-stack high-performance.
Stars: ✭ 256 (-18.73%)
Mutual labels:  template-engine
Cookie
A Template-based File Generator. Like cookiecutter but works with file templates instead of project templates.
Stars: ✭ 261 (-17.14%)
Mutual labels:  template-engine
Docpad
Empower your website frontends with layouts, meta-data, pre-processors (markdown, jade, coffeescript, etc.), partials, skeletons, file watching, querying, and an amazing plugin system. DocPad will streamline your web development process allowing you to craft powerful static sites quicker than ever before.
Stars: ✭ 3,035 (+863.49%)
Mutual labels:  template-engine
view-twig
Yii View Twig Renderer
Stars: ✭ 24 (-92.38%)
Mutual labels:  template-engine
Openjdk Docker
Scripts for creating Docker images of OpenJDK binaries.
Stars: ✭ 299 (-5.08%)
Mutual labels:  slim
chaarts
Charts with HTML & CSS
Stars: ✭ 79 (-74.92%)
Mutual labels:  markup
Deeplabv3 Tensorflow
Reimplementation of DeepLabV3
Stars: ✭ 277 (-12.06%)
Mutual labels:  slim
Rivets
Lightweight and powerful data binding.
Stars: ✭ 3,221 (+922.54%)
Mutual labels:  template-engine
Email Templates
📫 Create, preview, and send custom email templates for Node.js. Highly configurable and supports automatic inline CSS, stylesheets, embedded images and fonts, and much more!
Stars: ✭ 3,291 (+944.76%)
Mutual labels:  template-engine
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (-6.35%)
Mutual labels:  template-engine

Slime Build Status Hex Version License

A refreshing way to slim down your markup in Elixir.

Slime is an Elixir library for rendering Slim-like templates as HTML.

For use with Phoenix, please see PhoenixSlime.

Easily turn this:

doctype html
html
  head
    meta name="keywords" description="Slime"
    title = site_title
    javascript:
      alert('Slime supports embedded javascript!');
  body
    #id.class
      ul
        = Enum.map [1, 2], fn x ->
          li = x

Into this:

<!DOCTYPE html>
<html>
<head>
  <meta name="keywords" description="Slime">
  <title>Website Title</title>
  <script>alert('Slime supports embedded javascript!');</script>
</head>

<body>
  <div class="class" id="id">
    <ul>
      <li>1</li>
      <li>2</li>
    </ul>
  </div>
</body>
</html>

With this:

Slime.render(source, site_title: "Website Title")

Reference

Attributes

Attributes can be assigned in a similar fashion to regular HTML.

a href="elixir-lang.org" target="_blank" Elixir
<a href="elixir-lang.org" target="_blank">Elixir</a>

Elixir expressions can be used as attribute values using the interpolation syntax.

a href="#{my_variable}" Elixir
<a href="elixir-lang.org">Elixir</a>

Boolean attributes can be set using boolean values

input type="checkbox" checked=true
input type="checkbox" checked=false
<input type="checkbox" checked>
<input type="checkbox">

There is a literal syntax for class and id attributes

.foo.bar
select.bar
#foo
body#bar
<div class="foo bar"></div>
<select class="bar"></select>
<div id"foo"></div>
<body id="bar"></body>

Code

Elixir can be written inline using - and =.

- evalutes the expression. = evalutes the expression, and then inserts the value into template.

- number = 40
p = number + 2
<p>42</p>

The interpolation syntax can be used to insert expressions into text.

- name = "Felix"
p My cat's name is #{name}
<p>My cat's name is Felix</p>

Comments

Lines can be commented out using the / character.

/ p This line is commented out
p This line is not
<p>This line is not</p>

HTML <!-- --> comments can be inserted using /!

/! Hello, world!
<!-- Hello, world! -->

Conditionals

We can use the regular Elixir flow control such as the if expression.

- condition = true
= if condition do
  p It was true.
- else
  p It was false.
<p>It was true.</p>

Doctype

There are shortcuts for common doctypes.

doctype html
doctype xml
doctype transitional
doctype strict
doctype frameset
doctype 1.1
doctype basic
doctype mobile
<!DOCTYPE html>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">

Iteration

Elixir's collection manipulation expressions can be used to iterate over collections in your templates.

- names = ["Sarah", "Mia", "Harry"]

/! Enum.map
= Enum.map names, fn name ->
  p = name

/! for comprehension
= for name <- names do
  h1 = name
<!-- Enum.map -->
<p>Sarah</p>
<p>Mia</p>
<p>Harry</p>

<!-- for comprehension -->
<h1>Sarah</h1>
<h1>Mia</h1>
<h1>Harry</h1>

Embedded engines

Examples:

javascript:
  console.log("Test javascript");

css:
  body {
    color: black;
  }

elixir:
  a = [1, 2, 3]
  b = Enum.map(a, &(&1 + 1))

eex:
  Hello from <%= "eex" %>

You can define your own embedded engine in slime application config:

# config.exs
config :slime, :embedded_engines, %{
  markdown: MyApp.MarkdownEngine
}

# markdown_engine.ex
defmodule MyApp.MarkdownEngine do
  @behaviour Slime.Parser.EmbeddedEngine

  def render(text, _options) do
    Earmark.to_html(text)
  end
end

Because the engines are being read on compile time you need to recompile the library after you have added new engines. You can do this by:

mix deps.compile slime --force

Precompilation

Templates can be compiled into module functions like EEx templates, using functions Slime.function_from_file/5 and Slime.function_from_string/5.

To use slime templates (and Slime) with Phoenix, please see PhoenixSlim.

Differences to Ruby Slim

We aim for feature parity with the original Slim implementation, but we deviate in some respects. We do this to be true to Elixir – just like the original Slim implementation is true to its Ruby foundations.

For example, in Slime you do

= if condition do
  p It was true.
- else
  p It was false.

where Ruby Slim would do

- if condition
  p It was true.
- else
  p It was false.

Note the do and the initial =, because we render the return value of the conditional as a whole.

Debugging

If you have trouble locating exceptions in Slime templates, you can add

config :slime, :keep_lines, true

to your config.exs file. With this option Slime will keep original template lines in result eex and html. Keep in mind, that output is slightly different from default Slime output, for example | works like ', and empty lines are not ignored.

Contributing

Feedback, feature requests, and fixes are welcomed and encouraged. Please make appropriate use of Issues and Pull Requests. All code should have accompanying tests.

License

MIT license. Please see LICENSE for details.

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].