Support capture and content_for with Hamlit

This commit is contained in:
Takashi Kokubun 2019-11-28 17:26:16 -08:00
parent 04a02ac2b7
commit 78d48cdd08
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD
15 changed files with 40 additions and 6 deletions

View File

@ -16,8 +16,10 @@ group :development, :test do
end
platform :jruby, :ruby do
gem 'slim', '2.1.0'
gem 'hamlit'
gem 'hamlit-block', '>= 0.7.1'
gem 'liquid', '~> 2.6.x'
gem 'slim'
end
platform :ruby do

View File

@ -29,9 +29,10 @@ module Sinatra
erb? && Tilt[:erb] == Tilt::ErubisTemplate
end
# @return [Boolean] Returns true if current engine is `:haml`.
# @return [Boolean] Returns true if current engine is `:haml` and
# `Tilt[:haml]` is set to `Tilt::HamlTemplate`.
def haml?
@current_engine == :haml
@current_engine == :haml && Tilt[:haml] == Tilt::HamlTemplate
end
# @return [Boolean] Returns true if current engine is `:sass`.

View File

@ -240,8 +240,8 @@ module Sinatra
:css => [:less, :sass, :scss],
:xml => [:builder, :nokogiri],
:js => [:coffee],
:html => [:erb, :erubi, :erubis, :haml, :slim, :liquid, :radius, :mab,
:markdown, :textile, :rdoc],
:html => [:erb, :erubi, :erubis, :haml, :halmit, :slim, :liquid, :radius,
:mab, :markdown, :textile, :rdoc],
:all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
[:mab] - [:find_template, :markaby]),
:json => [:yajl],

View File

@ -23,6 +23,9 @@ describe Sinatra::Capture do
if engine == :erubi || engine == :erubis
lang = :erb
end
if engine == :hamlit
lang = :haml
end
require "#{engine}"
it "captures content" do
@ -35,6 +38,7 @@ describe Sinatra::Capture do
end
describe('haml') { it_behaves_like "a template language", :haml }
describe('hamlit') { it_behaves_like "a template language", :hamlit }
describe('slim') { it_behaves_like "a template language", :slim }
describe('erubi') { it_behaves_like "a template language", :erubi }
describe('erubis') { it_behaves_like "a template language", :erubis }

View File

@ -0,0 +1,2 @@
- content_for :bar do
bar

View File

@ -0,0 +1,2 @@
- if content_for? :foo
!= yield_content :foo

View File

@ -0,0 +1 @@
= yield_content :foo

View File

@ -0,0 +1,8 @@
- content_for :foo do
foo
- content_for :foo do
bar
- content_for :baz do
WON'T RENDER ME
- content_for :foo do
baz

View File

@ -0,0 +1,3 @@
= yield_content :foo
= yield_content :foo
= yield_content :foo

View File

@ -0,0 +1 @@
- content_for :foo, 'foo'

View File

@ -0,0 +1 @@
!= yield_content :foo, 1, 2

View File

@ -0,0 +1,2 @@
- content_for :foo do
foo

View File

@ -0,0 +1,3 @@
- content_for :foo do |a, b|
%i= a
=b

View File

@ -0,0 +1,2 @@
!= yield_content :foo do
baz

View File

@ -9,6 +9,8 @@ describe Sinatra::ContentFor do
end
Tilt.prefer Tilt::ERBTemplate
require 'hamlit/block'
Tilt.register Tilt::HamlTemplate, :haml
extend Forwardable
def_delegators :subject, :content_for, :clear_content_for, :yield_content
@ -89,7 +91,7 @@ describe Sinatra::ContentFor do
end
# TODO: liquid radius markaby builder nokogiri
engines = %w[erb erubi erubis haml slim]
engines = %w[erb erubi erubis haml hamlit slim]
engines.each do |inner|
describe inner.capitalize do