Skip to content

Commit

Permalink
Minor cleanups to slim support
Browse files Browse the repository at this point in the history
bin/tilt no longer needs to handle engines not starting with Tilt::,
since slim was the only engine lazy registered by default that
did not start with Tilt::.

Avoid unnecessary class node when setting SlimTemplate constant.

Include slim in the table in the README.

Minor test cleanups, mostly by a frozen local variable used by
multiple tests.
  • Loading branch information
jeremyevans committed Apr 25, 2023
1 parent 7b6edac commit f019789
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Deprecate CoffeeScriptTemplate.default_no_wrap{,=} aliases of default_bare{,=} (jeremyevans)
* Deprecate {ERB,Erubis}Template#default_output_variable{,=} (jeremyevans)
* Deprecate non-string template code in PrawnTemplate (jeremyevans)
* Deprecate default lazy loading of slim/handlebars/org/emacs_org/jbuilder external template engines (jeremyevans)
* Deprecate default lazy loading of handlebars/org/emacs_org/jbuilder external template engines (jeremyevans)
* Handle `locals` as a local variable in templates (timriley) (#3)
* Do not cache output in PrawnTemplate#evaluate (jeremyevans)
* Do not mark PrawnTemplate as not allowing script, since it can be used to execute arbitrary Ruby code (jeremyevans)
Expand All @@ -26,6 +26,7 @@
* Add frozen_string_literal magic comment to all source files (jeremyevans)
* Support templates with frozen compiled source code (jeremyevans)
* Support :skip_compiled_encoding_detection template option to not scan compiled source code for encoding lines (jeremyevans)
* Ship slim template support with tilt (minad) (#4)
* Template#extract_{encoding,magic_comment} private methods now require a block (jeremyevans)

The repository switched to https://github.com/jeremyevans/tilt, so issue references above are for that
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Support for these template engines is included with Tilt:
| Redcarpet | .markdown, .mkd, .md | redcarpet |
| RedCloth | .textile | redcloth |
| RstPandoc | .rst | pandoc |
| Slim | .slim | slim |
| Sass | .sass | sass-embedded, sassc, or sass |
| Scss | .scss | sass-embedded, sassc, or sass |
| String | .str | none |
Expand Down
2 changes: 1 addition & 1 deletion lib/tilt/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def self.run(argv: ARGV, stdout: $stdout, stdin: $stdin, stderr: $stderr, script
groups = {}
Tilt.lazy_map.each do |pattern,engines|
engines.each do |engine,|
engine = engine.split('::').last.sub(/Template\z/, '') if engine.start_with?('Tilt::')
engine = engine.split('::').last.sub(/Template\z/, '')
(groups[engine] ||= []) << pattern
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/tilt/slim.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true
require_relative 'template'
require 'slim'

module Tilt
SlimTemplate = Slim::Template
end
Tilt::SlimTemplate = Slim::Template
31 changes: 9 additions & 22 deletions test/tilt_slimtemplate_test.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
require_relative 'test_helper'

checked_describe 'tilt/slim' do
data = (<<'END').freeze
html
body
h1= "Hey #{name}"
= raise MockError
p we never get here
END
self::MockError = Class.new(NameError)

it "registered for '.slim' files" do
assert_equal Tilt::SlimTemplate, Tilt['test.slim']
end

it "preparing and evaluating templates on #render" do
template = Tilt::SlimTemplate.new { |t| "p Hello World!" }
assert_equal "<p>Hello World!</p>", template.render
end

it "can be rendered more than once" do
template = Tilt::SlimTemplate.new { |t| "p Hello World!" }
3.times { assert_equal "<p>Hello World!</p>", template.render }
end
Expand Down Expand Up @@ -41,8 +45,6 @@
end

it "backtrace file and line reporting without locals" do
data = File.read(__FILE__).split("\n__END__\n").last
fail unless data.start_with? "html"
template = Tilt::SlimTemplate.new('test.slim', 10) { data }
begin
template.render
Expand All @@ -57,8 +59,6 @@
end

it "backtrace file and line reporting with locals" do
data = File.read(__FILE__).split("\n__END__\n").last
fail unless data.start_with? "html"
template = Tilt::SlimTemplate.new('test.slim') { data }
begin
template.render(self, :name => 'Joe', :foo => 'bar')
Expand Down Expand Up @@ -105,8 +105,6 @@
end

it "backtrace file and line reporting without locals" do
data = File.read(__FILE__).split("\n__END__\n").last
fail unless data.start_with? "html"
template = Tilt::SlimTemplate.new('test.slim', 10) { data }
begin
template.render(_Scope.new)
Expand All @@ -121,8 +119,6 @@
end

it "backtrace file and line reporting with locals" do
data = File.read(__FILE__).split("\n__END__\n").last
fail unless data.start_with? "html"
template = Tilt::SlimTemplate.new('test.slim') { data }
begin
template.render(_Scope.new, :name => 'Joe', :foo => 'bar')
Expand All @@ -135,12 +131,3 @@
end
end
end

__END__
html
body
h1= "Hey #{name}"

= raise MockError

p we never get here

0 comments on commit f019789

Please sign in to comment.