No commit activity in last 3 years
No release in over 3 years
This is an adaptor gem allowing the use of the Thymeleaf.rb template engine as a Tilt rendering engine for Sinatra
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.7.0
~> 1.4
~> 0.1.2
 Project Readme

Gem Version

sinatra-thymeleaf

Sinatra template support for Thymeleaf.rb

Thymeleaf.rb

Thymeleaf.rb is a Ruby adaptation of Thymeleaf, a natural templating engine.

It allows to create natural templates (HTML that can be correctly displayed in browsers and also work as static prototypes) and render with a data set to provide them functionality.

You can find Thymeleaf.rb here: https://github.com/trabe/thymeleaf-rb Templating language is here: http://www.thymeleaf.org

Usage

This is a gem so just pop it in your Gemfile:

gem 'sinatra-thymeleaf'

Then, require it and activate the helper in your app:

require 'sinatra/base'
require 'sinatra-thymeleaf'

class App < Sinatra::Base
  helpers Sinatra::Thymeleaf
  
    get "/test" do
        thyme :test
    end
end

The views have an html externsion and should be placed in the views directory. That's about it.

I'll continue to add functionality and details, as I'm looking to use this in a project. Please add issues if you spot any problems.

Template parameters

The template variables can be passed by using the locals parameter, like this:

  thyme :test, {:param => 'value'>}

#Localization support You can use i18n localization in your templates, like this:

  <span data-th-text="${t['new.message']}">Some text</span>

This works by using I18n.t directly so remember to configure i18n for your sinatra app

#Flash support You can use the sinatra-flash gem to flash messages through to the thymeleaf template

Just add this to your route:

flash[:success] = "Whohoo!"
flash[:error] = "Damn!"

Also, add this to your template:

<div data-th-unless="${flash[:success].nil?}" class="alert alert-success">
  <strong>Success!</strong>
  <span data-th-text="${flash[:success]}"> That worked! </span>
</div>
<div data-th-unless="${flash[:error].nil?}" class="alert alert-danger">
  <strong>Oups!</strong>
  <span data-th-text="${flash[:error]}"> Something went wrong! </span>
</div>

And you should be good to go