temple 0.8.2 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +35 -0
- data/.gitignore +1 -0
- data/CHANGES +34 -1
- data/Gemfile +0 -1
- data/README.md +1 -1
- data/Rakefile +4 -11
- data/lib/temple/engine.rb +1 -0
- data/lib/temple/erb/engine.rb +3 -0
- data/lib/temple/erb/parser.rb +2 -1
- data/lib/temple/erb/template.rb +1 -0
- data/lib/temple/erb/trimming.rb +1 -0
- data/lib/temple/exceptions.rb +1 -0
- data/lib/temple/filter.rb +1 -0
- data/lib/temple/filters/ambles.rb +22 -0
- data/lib/temple/filters/code_merger.rb +1 -0
- data/lib/temple/filters/control_flow.rb +1 -0
- data/lib/temple/filters/dynamic_inliner.rb +2 -1
- data/lib/temple/filters/encoding.rb +1 -0
- data/lib/temple/filters/eraser.rb +1 -0
- data/lib/temple/filters/escapable.rb +1 -0
- data/lib/temple/filters/multi_flattener.rb +1 -0
- data/lib/temple/filters/remove_bom.rb +1 -0
- data/lib/temple/filters/static_analyzer.rb +1 -0
- data/lib/temple/filters/static_merger.rb +1 -0
- data/lib/temple/filters/string_splitter.rb +13 -1
- data/lib/temple/filters/validator.rb +1 -0
- data/lib/temple/generator.rb +5 -2
- data/lib/temple/generators/array.rb +1 -0
- data/lib/temple/generators/array_buffer.rb +1 -0
- data/lib/temple/generators/erb.rb +1 -0
- data/lib/temple/generators/rails_output_buffer.rb +4 -4
- data/lib/temple/generators/string_buffer.rb +2 -1
- data/lib/temple/grammar.rb +1 -0
- data/lib/temple/html/attribute_merger.rb +1 -0
- data/lib/temple/html/attribute_remover.rb +1 -0
- data/lib/temple/html/attribute_sorter.rb +1 -0
- data/lib/temple/html/dispatcher.rb +1 -0
- data/lib/temple/html/fast.rb +1 -0
- data/lib/temple/html/filter.rb +1 -0
- data/lib/temple/html/pretty.rb +1 -0
- data/lib/temple/html/safe.rb +1 -0
- data/lib/temple/map.rb +1 -0
- data/lib/temple/mixins/dispatcher.rb +1 -0
- data/lib/temple/mixins/engine_dsl.rb +1 -0
- data/lib/temple/mixins/grammar_dsl.rb +4 -2
- data/lib/temple/mixins/options.rb +1 -0
- data/lib/temple/mixins/template.rb +1 -0
- data/lib/temple/parser.rb +1 -0
- data/lib/temple/static_analyzer.rb +1 -0
- data/lib/temple/templates/rails.rb +7 -2
- data/lib/temple/templates/tilt.rb +2 -9
- data/lib/temple/templates.rb +1 -0
- data/lib/temple/utils.rb +5 -15
- data/lib/temple/version.rb +2 -1
- data/lib/temple.rb +2 -0
- data/spec/engine_spec.rb +189 -0
- data/{test/test_erb.rb → spec/erb_spec.rb} +12 -12
- data/spec/filter_spec.rb +29 -0
- data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
- data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
- data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
- data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +9 -9
- data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +10 -10
- data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
- data/{test/filters/test_static_analyzer.rb → spec/filters/static_analyzer_spec.rb} +6 -8
- data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
- data/spec/filters/string_splitter_spec.rb +50 -0
- data/spec/generator_spec.rb +179 -0
- data/spec/grammar_spec.rb +47 -0
- data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
- data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
- data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +7 -7
- data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
- data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +7 -7
- data/spec/map_spec.rb +39 -0
- data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
- data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
- data/{test/helper.rb → spec/spec_helper.rb} +5 -6
- data/{test/test_static_analyzer.rb → spec/static_analyzer_spec.rb} +6 -6
- data/spec/utils_spec.rb +39 -0
- data/temple.gemspec +3 -4
- metadata +34 -59
- data/.travis.yml +0 -30
- data/test/filters/test_string_splitter.rb +0 -25
- data/test/test_engine.rb +0 -189
- data/test/test_filter.rb +0 -29
- data/test/test_generator.rb +0 -158
- data/test/test_grammar.rb +0 -47
- data/test/test_map.rb +0 -39
- data/test/test_utils.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3fdf456fd2d277a110681cc1d0dd228bba3b75306b3caa78fb12ad668a7665c6
|
4
|
+
data.tar.gz: 7dfdd5001be5c652254aab301e391d7652c0bc1e44a00ee9fe5002c1899e99c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d5847567944020f1be6ddf6b96b056ff0154cb26b00e71d4c736337cddc3e1ceb402ef4eabc3fa8a150ec56fd560cb0ac22358c8f1673bc2dfabb8407a482b9
|
7
|
+
data.tar.gz: f8f766aeb193a7bf781297dff7628d2e9d09840a241130f4a04f60b72e16d237c965f327696788e29f58ddadc1ce843392a52619363fc19dc5da66966d42ed09
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: test
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
pull_request:
|
7
|
+
types:
|
8
|
+
- opened
|
9
|
+
- synchronize
|
10
|
+
- reopened
|
11
|
+
schedule:
|
12
|
+
- cron: "00 15 * * *"
|
13
|
+
jobs:
|
14
|
+
test:
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby:
|
20
|
+
- '2.5'
|
21
|
+
- '2.6'
|
22
|
+
- '2.7'
|
23
|
+
- '3.0'
|
24
|
+
- '3.1'
|
25
|
+
- '3.2'
|
26
|
+
- jruby
|
27
|
+
- truffleruby-head
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v3
|
30
|
+
- name: Set up Ruby
|
31
|
+
uses: ruby/setup-ruby@v1
|
32
|
+
with:
|
33
|
+
ruby-version: ${{ matrix.ruby }}
|
34
|
+
bundler-cache: true
|
35
|
+
- run: bundle exec rake spec
|
data/.gitignore
CHANGED
data/CHANGES
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
0.10.2
|
2
|
+
|
3
|
+
* Fix Sinatra capture_generator problem (#145)
|
4
|
+
|
5
|
+
0.10.1
|
6
|
+
|
7
|
+
* Use specified :capture_generator for nested captures (#112, #144)
|
8
|
+
* Compatibility with frozen string literals
|
9
|
+
|
10
|
+
0.10.0
|
11
|
+
|
12
|
+
* Regression: Revert changes to :capture_generator since 0.8.2 (#112, #113, #137)
|
13
|
+
* Regression: Ensure that output buffer is not reused for capturing in Rails (#135)
|
14
|
+
* Drop support for Rails 4.x
|
15
|
+
|
16
|
+
0.9.1
|
17
|
+
|
18
|
+
* Fix Slim's error in AttributeMerger due to 0.9.0's :capture_generator (#137)
|
19
|
+
* Use specified :capture_generator for nested captures (#112)
|
20
|
+
* Fix Temple::ERB::Engine's <%= to not escape and <%== to escape expressions
|
21
|
+
|
22
|
+
0.9.0
|
23
|
+
|
24
|
+
* Require Ruby 2.5+ (#131)
|
25
|
+
* Change default :capture_generator to self (#113)
|
26
|
+
* Improve compatibility with Rails 7.1 (#135)
|
27
|
+
* Support Rails 6.1's annotate_rendered_view_with_filenames
|
28
|
+
with Temple::Filters::Ambles (#134)
|
29
|
+
* Fix a crash in StringSplitter filter (#138)
|
30
|
+
* Fix a warning by Object#=~ since Ruby 2.6 (#129)
|
31
|
+
* Fix deprecated Tilt template mime type (#108)
|
32
|
+
* Stop using deprecated EscapeUtils from Temple::Utils (#136)
|
33
|
+
|
1
34
|
0.8.2
|
2
35
|
|
3
36
|
* Support TruffleRuby in Temple::Filters::StaticAnalyzer (#127)
|
@@ -16,7 +49,7 @@
|
|
16
49
|
|
17
50
|
0.7.8
|
18
51
|
|
19
|
-
* Fix
|
52
|
+
* Fix a warning in StaticAnalyzer
|
20
53
|
|
21
54
|
0.7.7
|
22
55
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Temple
|
2
2
|
======
|
3
3
|
|
4
|
-
[![
|
4
|
+
[![test](https://github.com/judofyr/temple/actions/workflows/test.yml/badge.svg)](https://github.com/judofyr/temple/actions/workflows/test.yml) [![Code Climate](https://codeclimate.com/github/judofyr/temple.svg)](https://codeclimate.com/github/judofyr/temple) [![Gem Version](https://badge.fury.io/rb/temple.svg)](https://rubygems.org/gems/temple) [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/temple/frames)
|
5
5
|
|
6
6
|
Temple is an abstraction and a framework for compiling templates to pure Ruby.
|
7
7
|
It's all about making it easier to experiment, implement and optimize template
|
data/Rakefile
CHANGED
@@ -1,15 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
2
3
|
|
3
|
-
|
4
|
-
task :
|
5
|
-
sh "bacon -Ilib -Itest --automatic --quiet"
|
6
|
-
end
|
7
|
-
|
8
|
-
#Rake::TestTask.new(:test) do |t|
|
9
|
-
# t.libs << 'lib' << 'test'
|
10
|
-
# t.pattern = 'test/**/test_*.rb'
|
11
|
-
# t.verbose = false
|
12
|
-
#end
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
task default: :spec
|
13
6
|
|
14
7
|
begin
|
15
8
|
require 'rcov/rcovtask'
|
data/lib/temple/engine.rb
CHANGED
data/lib/temple/erb/engine.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module ERB
|
3
4
|
# Example ERB engine implementation
|
@@ -7,6 +8,8 @@ module Temple
|
|
7
8
|
use Temple::ERB::Parser
|
8
9
|
use Temple::ERB::Trimming
|
9
10
|
filter :Escapable
|
11
|
+
filter :StringSplitter
|
12
|
+
filter :StaticAnalyzer
|
10
13
|
filter :MultiFlattener
|
11
14
|
filter :StaticMerger
|
12
15
|
generator :ArrayBuffer
|
data/lib/temple/erb/parser.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module ERB
|
3
4
|
# Example ERB parser
|
@@ -27,7 +28,7 @@ module Temple
|
|
27
28
|
when '#'
|
28
29
|
result << [:code, "\n" * code.count("\n")]
|
29
30
|
when /=/
|
30
|
-
result << [:escape, indicator.size
|
31
|
+
result << [:escape, indicator.size == 2, [:dynamic, code]]
|
31
32
|
else
|
32
33
|
result << [:code, code]
|
33
34
|
end
|
data/lib/temple/erb/template.rb
CHANGED
data/lib/temple/erb/trimming.rb
CHANGED
data/lib/temple/exceptions.rb
CHANGED
data/lib/temple/filter.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Temple
|
3
|
+
module Filters
|
4
|
+
class Ambles < Filter
|
5
|
+
define_options :preamble, :postamble
|
6
|
+
|
7
|
+
def initialize(*)
|
8
|
+
super
|
9
|
+
@preamble = options[:preamble]
|
10
|
+
@postamble = options[:postamble]
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(ast)
|
14
|
+
ret = [:multi]
|
15
|
+
ret << [:static, @preamble] if @preamble
|
16
|
+
ret << ast
|
17
|
+
ret << [:static, @postamble] if @postamble
|
18
|
+
ret
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Filters
|
3
4
|
# Inlines several static/dynamic into a single dynamic.
|
@@ -36,7 +37,7 @@ module Temple
|
|
36
37
|
# another one, we add both then.
|
37
38
|
state = :single
|
38
39
|
prev = [exp]
|
39
|
-
curr = [:dynamic, '"']
|
40
|
+
curr = [:dynamic, '"'.dup]
|
40
41
|
when :single
|
41
42
|
# Yes! We found another one. Add the current dynamic to the result.
|
42
43
|
state = :several
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
begin
|
2
3
|
require 'ripper'
|
3
4
|
rescue LoadError
|
@@ -7,7 +8,7 @@ module Temple
|
|
7
8
|
module Filters
|
8
9
|
# Compile [:dynamic, "foo#{bar}"] to [:multi, [:static, 'foo'], [:dynamic, 'bar']]
|
9
10
|
class StringSplitter < Filter
|
10
|
-
if defined?(Ripper) &&
|
11
|
+
if defined?(Ripper) && Ripper.respond_to?(:lex)
|
11
12
|
class << self
|
12
13
|
# `code` param must be valid string literal
|
13
14
|
def compile(code)
|
@@ -46,6 +47,7 @@ module Temple
|
|
46
47
|
|
47
48
|
case type
|
48
49
|
when :on_tstring_content
|
50
|
+
beg_str, end_str = escape_quotes(beg_str, end_str)
|
49
51
|
exps << [:static, eval("#{beg_str}#{str}#{end_str}").to_s]
|
50
52
|
when :on_embexpr_beg
|
51
53
|
embedded = shift_balanced_embexpr(tokens)
|
@@ -54,6 +56,16 @@ module Temple
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
59
|
+
# Some quotes are split-unsafe. Replace such quotes with null characters.
|
60
|
+
def escape_quotes(beg_str, end_str)
|
61
|
+
case [beg_str[-1], end_str]
|
62
|
+
when ['(', ')'], ['[', ']'], ['{', '}']
|
63
|
+
[beg_str.sub(/.\z/) { "\0" }, "\0"]
|
64
|
+
else
|
65
|
+
[beg_str, end_str]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
57
69
|
def shift_balanced_embexpr(tokens)
|
58
70
|
String.new.tap do |embedded|
|
59
71
|
embexpr_open = 1
|
data/lib/temple/generator.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
# Abstract generator base class
|
3
4
|
# Generators should inherit this class and
|
@@ -12,7 +13,7 @@ module Temple
|
|
12
13
|
define_options :save_buffer,
|
13
14
|
capture_generator: 'StringBuffer',
|
14
15
|
buffer: '_buf',
|
15
|
-
freeze_static:
|
16
|
+
freeze_static: true
|
16
17
|
|
17
18
|
def call(exp)
|
18
19
|
[preamble, compile(exp), postamble].flatten.compact.join('; ')
|
@@ -54,7 +55,9 @@ module Temple
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def on_capture(name, exp)
|
57
|
-
capture_generator.new(
|
58
|
+
capture_generator.new(capture_generator: options[:capture_generator],
|
59
|
+
freeze_static: options[:freeze_static],
|
60
|
+
buffer: name).call(exp)
|
58
61
|
end
|
59
62
|
|
60
63
|
def on_static(text)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Generators
|
3
4
|
# Implements a rails output buffer.
|
@@ -9,10 +10,9 @@ module Temple
|
|
9
10
|
#
|
10
11
|
# @api public
|
11
12
|
class RailsOutputBuffer < StringBuffer
|
12
|
-
define_options :streaming,
|
13
|
-
buffer_class: '
|
13
|
+
define_options :streaming, # ignored
|
14
|
+
buffer_class: 'ActionView::OutputBuffer',
|
14
15
|
buffer: '@output_buffer',
|
15
|
-
# output_buffer is needed for Rails 3.1 Streaming support
|
16
16
|
capture_generator: RailsOutputBuffer
|
17
17
|
|
18
18
|
def call(exp)
|
@@ -20,7 +20,7 @@ module Temple
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def create_buffer
|
23
|
-
if
|
23
|
+
if buffer == '@output_buffer'
|
24
24
|
"#{buffer} = output_buffer || #{options[:buffer_class]}.new"
|
25
25
|
else
|
26
26
|
"#{buffer} = #{options[:buffer_class]}.new"
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Generators
|
3
4
|
# Implements a string buffer.
|
@@ -10,7 +11,7 @@ module Temple
|
|
10
11
|
# @api public
|
11
12
|
class StringBuffer < ArrayBuffer
|
12
13
|
def create_buffer
|
13
|
-
"#{buffer} = ''"
|
14
|
+
"#{buffer} = ''.dup"
|
14
15
|
end
|
15
16
|
|
16
17
|
def return_buffer
|
data/lib/temple/grammar.rb
CHANGED
data/lib/temple/html/fast.rb
CHANGED
data/lib/temple/html/filter.rb
CHANGED
data/lib/temple/html/pretty.rb
CHANGED
data/lib/temple/html/safe.rb
CHANGED
data/lib/temple/map.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Mixins
|
3
4
|
# @api private
|
@@ -67,7 +68,7 @@ module Temple
|
|
67
68
|
unmatched.reverse_each do |u|
|
68
69
|
entry = u if u.flatten.size < entry.flatten.size
|
69
70
|
end
|
70
|
-
raise(InvalidExpression, PP.pp(entry.last, "#{@grammar}::#{entry.first} did not match\n"))
|
71
|
+
raise(InvalidExpression, PP.pp(entry.last, "#{@grammar}::#{entry.first} did not match\n".dup))
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
@@ -143,7 +144,8 @@ module Temple
|
|
143
144
|
start = Or.new(self)
|
144
145
|
curr = [start]
|
145
146
|
rule.each do |elem|
|
146
|
-
|
147
|
+
case elem
|
148
|
+
when /^(.*)(\*|\?|\+)$/
|
147
149
|
elem = Element.new(self, const_get($1))
|
148
150
|
curr.each {|c| c << elem }
|
149
151
|
elem << elem if $2 != '?'
|
data/lib/temple/parser.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Templates
|
3
4
|
class Rails
|
@@ -5,6 +6,10 @@ module Temple
|
|
5
6
|
|
6
7
|
def call(template, source = nil)
|
7
8
|
opts = {}.update(self.class.options).update(file: template.identifier)
|
9
|
+
if ActionView::Base.try(:annotate_rendered_view_with_filenames) && template.format == :html
|
10
|
+
opts[:preamble] = "<!-- BEGIN #{template.short_identifier} -->\n"
|
11
|
+
opts[:postamble] = "<!-- END #{template.short_identifier} -->\n"
|
12
|
+
end
|
8
13
|
self.class.compile((source || template.source), opts)
|
9
14
|
end
|
10
15
|
|
@@ -14,8 +19,8 @@ module Temple
|
|
14
19
|
|
15
20
|
def self.register_as(*names)
|
16
21
|
raise 'Rails is not loaded - Temple::Templates::Rails cannot be used' unless defined?(::ActionView)
|
17
|
-
if ::ActiveSupport::VERSION::MAJOR <
|
18
|
-
raise "Temple supports only Rails
|
22
|
+
if ::ActiveSupport::VERSION::MAJOR < 5
|
23
|
+
raise "Temple supports only Rails 5 and greater, your Rails version is #{::ActiveSupport::VERSION::STRING}"
|
19
24
|
end
|
20
25
|
names.each do |name|
|
21
26
|
::ActionView::Template.register_template_handler name.to_sym, new
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'tilt'
|
2
3
|
|
3
4
|
module Temple
|
@@ -7,14 +8,6 @@ module Temple
|
|
7
8
|
|
8
9
|
define_options mime_type: 'text/html'
|
9
10
|
|
10
|
-
def self.default_mime_type
|
11
|
-
options[:mime_type]
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.default_mime_type=(mime_type)
|
15
|
-
options[:mime_type] = mime_type
|
16
|
-
end
|
17
|
-
|
18
11
|
# Prepare Temple template
|
19
12
|
#
|
20
13
|
# Called immediately after template data is loaded.
|
@@ -22,7 +15,7 @@ module Temple
|
|
22
15
|
# @return [void]
|
23
16
|
def prepare
|
24
17
|
opts = {}.update(self.class.options).update(options).update(file: eval_file)
|
25
|
-
opts.delete(:mime_type)
|
18
|
+
metadata[:mime_type] = opts.delete(:mime_type)
|
26
19
|
if opts.include?(:outvar)
|
27
20
|
opts[:buffer] = opts.delete(:outvar)
|
28
21
|
opts[:save_buffer] = true
|
data/lib/temple/templates.rb
CHANGED
data/lib/temple/utils.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
begin
|
2
|
-
require '
|
3
|
+
require 'cgi/escape'
|
3
4
|
rescue LoadError
|
4
|
-
begin
|
5
|
-
require 'cgi/escape'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
5
|
end
|
9
6
|
|
10
7
|
module Temple
|
@@ -18,18 +15,11 @@ module Temple
|
|
18
15
|
# @param html [String] The string to escape
|
19
16
|
# @return [String] The escaped string
|
20
17
|
def escape_html_safe(html)
|
21
|
-
|
18
|
+
s = html.to_s
|
19
|
+
s.html_safe? || html.html_safe? ? s : escape_html(s)
|
22
20
|
end
|
23
21
|
|
24
|
-
if defined?(
|
25
|
-
# Returns an escaped copy of `html`.
|
26
|
-
#
|
27
|
-
# @param html [String] The string to escape
|
28
|
-
# @return [String] The escaped string
|
29
|
-
def escape_html(html)
|
30
|
-
EscapeUtils.escape_html(html.to_s, false)
|
31
|
-
end
|
32
|
-
elsif defined?(CGI.escapeHTML)
|
22
|
+
if defined?(CGI.escapeHTML)
|
33
23
|
# Returns an escaped copy of `html`.
|
34
24
|
#
|
35
25
|
# @param html [String] The string to escape
|
data/lib/temple/version.rb
CHANGED