fix build error
(cherry picked from commit a867d4f92d61511b0e3f509c5c049c6f046ae087)
This commit is contained in:
parent
ade6d8c752
commit
8a7d2b652c
75
Fix-warning-when-using-yield-in-templates-on-ruby-2.7.patch
Normal file
75
Fix-warning-when-using-yield-in-templates-on-ruby-2.7.patch
Normal file
@ -0,0 +1,75 @@
|
||||
From dbb4df94e5bc6e533fc2ed09b2fd70df39c049c3 Mon Sep 17 00:00:00 2001
|
||||
From: Jeremy Evans <code@jeremyevans.net>
|
||||
Date: Fri, 31 May 2019 09:58:55 -0700
|
||||
Subject: [PATCH] Fix warning when using yield in templates on ruby 2.7
|
||||
|
||||
Take the class of the scope, and pass it through the
|
||||
compilation methods. Call class_eval on the scope's
|
||||
class so that constant lookup works, and switch the
|
||||
singleton class opening to instance_exec.
|
||||
|
||||
This radically simplifies the compiled template method
|
||||
code, and I would guess it speeds it up significantly
|
||||
as well. However, this approach can cause a memory
|
||||
leak if you are creating anonymous classes at runtime
|
||||
and then passing instances of those classes as the scope
|
||||
of the render.
|
||||
---
|
||||
lib/tilt/template.rb | 19 +++++++------------
|
||||
1 file changed, 7 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/lib/tilt/template.rb b/lib/tilt/template.rb
|
||||
index 604ed47..13d08ff 100644
|
||||
--- a/lib/tilt/template.rb
|
||||
+++ b/lib/tilt/template.rb
|
||||
@@ -166,7 +166,7 @@ def prepare
|
||||
def evaluate(scope, locals, &block)
|
||||
locals_keys = locals.keys
|
||||
locals_keys.sort!{|x, y| x.to_s <=> y.to_s}
|
||||
- method = compiled_method(locals_keys)
|
||||
+ method = compiled_method(locals_keys, scope.class)
|
||||
method.bind(scope).call(locals, &block)
|
||||
end
|
||||
|
||||
@@ -231,9 +231,9 @@ def read_template_file
|
||||
end
|
||||
|
||||
# The compiled method for the locals keys provided.
|
||||
- def compiled_method(locals_keys)
|
||||
+ def compiled_method(locals_keys, scope_class=nil)
|
||||
LOCK.synchronize do
|
||||
- @compiled_method[locals_keys] ||= compile_template_method(locals_keys)
|
||||
+ @compiled_method[[scope_class, locals_keys]] ||= compile_template_method(locals_keys, scope_class)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -247,7 +247,7 @@ def local_extraction(local_keys)
|
||||
end.join("\n")
|
||||
end
|
||||
|
||||
- def compile_template_method(local_keys)
|
||||
+ def compile_template_method(local_keys, scope_class=nil)
|
||||
source, offset = precompiled(local_keys)
|
||||
local_code = local_extraction(local_keys)
|
||||
|
||||
@@ -261,17 +261,12 @@ def compile_template_method(local_keys)
|
||||
method_source << <<-RUBY
|
||||
TOPOBJECT.class_eval do
|
||||
def #{method_name}(locals)
|
||||
- Thread.current[:tilt_vars] = [self, locals]
|
||||
- class << self
|
||||
- this, locals = Thread.current[:tilt_vars]
|
||||
- locals = locals
|
||||
- this.instance_eval do
|
||||
- #{local_code}
|
||||
+ #{local_code}
|
||||
RUBY
|
||||
offset += method_source.count("\n")
|
||||
method_source << source
|
||||
- method_source << "\nend;end;end;end"
|
||||
- Object.class_eval(method_source, eval_file, line - offset)
|
||||
+ method_source << "\nend;end;"
|
||||
+ (scope_class || Object).class_eval(method_source, eval_file, line - offset)
|
||||
unbind_compiled_method(method_name)
|
||||
end
|
||||
|
||||
@ -2,11 +2,13 @@
|
||||
%{?_with_bootstrap: %global bootstrap 1}
|
||||
Name: rubygem-%{gem_name}
|
||||
Version: 2.0.8
|
||||
Release: 3
|
||||
Release: 4
|
||||
Summary: Generic interface to multiple Ruby template engines
|
||||
License: MIT
|
||||
URL: http://github.com/rtomayko/tilt
|
||||
Source0: https://rubygems.org/gems/tilt-%{version}.gem
|
||||
Patch0: tilt-2.0.10-Fix-Ruby-3.0-compatibility.patch
|
||||
Patch1: Fix-warning-when-using-yield-in-templates-on-ruby-2.7.patch
|
||||
BuildRequires: ruby(release) rubygems-devel ruby nodejs-devel rubygem(creole)
|
||||
BuildRequires: rubygem(minitest) rubygem(nokogiri) rubygem(erubis) rubygem(builder)
|
||||
BuildRequires: rubygem(maruku) rubygem(RedCloth) rubygem(redcarpet) rubygem(coffee-script)
|
||||
@ -32,6 +34,10 @@ Documentation for %{name}.
|
||||
%prep
|
||||
%setup -q -c -T
|
||||
%gem_install -n %{SOURCE0}
|
||||
cd .%{gem_instdir}
|
||||
%patch0 -p1
|
||||
%patch1 -p1
|
||||
cd -
|
||||
sed -i -e 's|/usr/bin/env ruby|/usr/bin/ruby|' .%{gem_instdir}/bin/tilt
|
||||
|
||||
%build
|
||||
@ -85,6 +91,9 @@ popd
|
||||
%{gem_instdir}/test
|
||||
|
||||
%changelog
|
||||
* Wed Feb 9 2022 liyanan <liyanan32@huawei.com> - 2.0.8-4
|
||||
- Fix build error
|
||||
|
||||
* Sun Feb 07 2020 huanghaitao <huanghaitao8@huawei.com> - 2.0.8-3
|
||||
- Swith rubygem-ronn-ng to drop rubygem-ronn
|
||||
|
||||
|
||||
40
tilt-2.0.10-Fix-Ruby-3.0-compatibility.patch
Normal file
40
tilt-2.0.10-Fix-Ruby-3.0-compatibility.patch
Normal file
@ -0,0 +1,40 @@
|
||||
From 7c7d7d2101ca4b5c6c887f65a7be9b81982f3fa6 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
|
||||
Date: Mon, 18 Jan 2021 12:49:31 +0100
|
||||
Subject: [PATCH] Fix Ruby 3.0 compatibility.
|
||||
|
||||
This fixes issues such as:
|
||||
|
||||
~~~
|
||||
1) Error:
|
||||
CSVTemplateTest#test_compiles_and_evaluates_the_template_on_render:
|
||||
TypeError: no implicit conversion of Hash into String
|
||||
/usr/share/ruby/csv.rb:1273:in `initialize'
|
||||
/usr/share/ruby/csv.rb:1273:in `new'
|
||||
/usr/share/ruby/csv.rb:1273:in `generate'
|
||||
(__TEMPLATE__):in `__tilt_920'
|
||||
/builddir/build/BUILD/tilt-2.0.10/usr/share/gems/gems/tilt-2.0.10/lib/tilt/template.rb:170:in `call'
|
||||
/builddir/build/BUILD/tilt-2.0.10/usr/share/gems/gems/tilt-2.0.10/lib/tilt/template.rb:170:in `evaluate'
|
||||
/builddir/build/BUILD/tilt-2.0.10/usr/share/gems/gems/tilt-2.0.10/lib/tilt/template.rb:109:in `render'
|
||||
/builddir/build/BUILD/tilt-2.0.10/usr/share/gems/gems/tilt-2.0.10/test/tilt_csv_test.rb:15:in `block in <class:CSVTemplateTest>'
|
||||
~~~
|
||||
---
|
||||
lib/tilt/csv.rb | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/tilt/csv.rb b/lib/tilt/csv.rb
|
||||
index fd0e602..7dfa220 100644
|
||||
--- a/lib/tilt/csv.rb
|
||||
+++ b/lib/tilt/csv.rb
|
||||
@@ -50,7 +50,7 @@ module Tilt
|
||||
|
||||
def precompiled_template(locals)
|
||||
<<-RUBY
|
||||
- #{@outvar} = #{self.class.engine}.generate(#{options}) do |csv|
|
||||
+ #{@outvar} = #{self.class.engine}.generate(**#{options}) do |csv|
|
||||
#{data}
|
||||
end
|
||||
RUBY
|
||||
--
|
||||
2.29.2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user