padrino-helpers 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/padrino/rendering.rb +3 -1
- data/lib/padrino-helpers/translation_helpers.rb +2 -1
- data/padrino-helpers.gemspec +8 -3
- data/test/test_rendering.rb +54 -0
- data/test/test_translation_helpers.rb +62 -0
- metadata +12 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 924909fe1054736b28e1ab952d79295455cb02678e634fadf70632672baaee66
|
|
4
|
+
data.tar.gz: 53e1a1f8c8e69f4723355f0857e69196543cd72cd1d6e90b526481f446b24350
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 022652651c54083698e889064b555ae5262d041e770f80880a22998f0c95c4ce30302952b51aa6e338a4b58a61de76a9a4be377e6ab1108aec53e860ff700730
|
|
7
|
+
data.tar.gz: 14c646b16ad8a04f93f828b888de6bf2ec6dc20d6ff36d28aa2e93da3dcfdafc1fac514964be0bbe03fd451eaf8b7bab58e83fe4e41f27506ad43ec440176111
|
data/lib/padrino/rendering.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'padrino/core_ext/output_safety'
|
|
2
2
|
require 'padrino-support'
|
|
3
3
|
require 'pathname'
|
|
4
|
+
require 'tilt'
|
|
4
5
|
|
|
5
6
|
module Padrino
|
|
6
7
|
##
|
|
@@ -431,7 +432,8 @@ unless defined? Padrino::Rendering::ErubisTemplate
|
|
|
431
432
|
rescue LoadError
|
|
432
433
|
# do nothing since erubis is not available
|
|
433
434
|
else
|
|
434
|
-
|
|
435
|
+
# Tilt 2.5 dropped its Erubis template; without it there is nothing to extend.
|
|
436
|
+
require 'padrino/rendering/erubis_template' if defined?(Tilt::ErubisTemplate)
|
|
435
437
|
end
|
|
436
438
|
end
|
|
437
439
|
|
data/padrino-helpers.gemspec
CHANGED
|
@@ -8,16 +8,21 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.authors = ['Padrino Team', 'Nathan Esquenazi', "Davide D'Agostino", 'Arthur Chiu']
|
|
9
9
|
s.email = 'padrinorb@gmail.com'
|
|
10
10
|
s.summary = 'Helpers for padrino'
|
|
11
|
-
s.homepage = '
|
|
11
|
+
s.homepage = 'https://padrinorb.com'
|
|
12
12
|
s.description = 'Tag helpers, asset helpers, form helpers, form builders and many more helpers for padrino'
|
|
13
|
+
s.required_ruby_version = '>= 2.7.8'
|
|
13
14
|
s.required_rubygems_version = '>= 1.3.6'
|
|
14
15
|
s.version = Padrino.version
|
|
15
|
-
s.date = Time.now.strftime('%Y-%m-%d')
|
|
16
16
|
s.license = 'MIT'
|
|
17
|
+
s.metadata = {
|
|
18
|
+
'bug_tracker_uri' => 'https://github.com/padrino/padrino-framework/issues',
|
|
19
|
+
'changelog_uri' => 'https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc',
|
|
20
|
+
'documentation_uri' => 'https://padrinorb.com/guides/',
|
|
21
|
+
'source_code_uri' => 'https://github.com/padrino/padrino-framework'
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
s.extra_rdoc_files = Dir['*.rdoc']
|
|
19
25
|
s.files = `git ls-files`.split("\n")
|
|
20
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
26
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
22
27
|
s.require_paths = ['lib']
|
|
23
28
|
s.rdoc_options = ['--charset=UTF-8']
|
data/test/test_rendering.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require_relative 'helper'
|
|
2
2
|
require 'slim'
|
|
3
3
|
require 'liquid'
|
|
4
|
+
require 'open3'
|
|
4
5
|
|
|
5
6
|
describe 'Rendering' do
|
|
6
7
|
def setup
|
|
@@ -821,6 +822,59 @@ describe 'Rendering' do
|
|
|
821
822
|
end
|
|
822
823
|
end
|
|
823
824
|
|
|
825
|
+
describe 'when loading padrino-helpers' do
|
|
826
|
+
def erubis_stub
|
|
827
|
+
"module Erubis; class Eruby; end; end\n"
|
|
828
|
+
end
|
|
829
|
+
|
|
830
|
+
def hidden
|
|
831
|
+
"raise LoadError, 'hidden'\n"
|
|
832
|
+
end
|
|
833
|
+
|
|
834
|
+
# Loads padrino-helpers in a subprocess with stub libraries on the load path (a stub that
|
|
835
|
+
# raises LoadError hides a gem the bundle has), renders ERB, runs check and returns the body.
|
|
836
|
+
def render_erb_with(stubs, check: '', core_first: true)
|
|
837
|
+
script = <<~RUBY
|
|
838
|
+
#{"require 'padrino-core'" if core_first}
|
|
839
|
+
require 'padrino-helpers'
|
|
840
|
+
require 'padrino-core'
|
|
841
|
+
app = Sinatra.new(Padrino::Application) do
|
|
842
|
+
register Padrino::Helpers
|
|
843
|
+
get('/') { render :erb, '<%= "<b>" %><% content_tag(:p) do %>ok<% end %>' }
|
|
844
|
+
end
|
|
845
|
+
File.write('body.html', Rack::MockRequest.new(app).get('/').body)
|
|
846
|
+
#{check}
|
|
847
|
+
RUBY
|
|
848
|
+
Dir.mktmpdir do |dir|
|
|
849
|
+
stubs.each { |name, code| File.write(File.join(dir, "#{name}.rb"), code) }
|
|
850
|
+
env = { 'BUNDLE_GEMFILE' => File.expand_path('../../Gemfile', __dir__) }
|
|
851
|
+
_out, err, status = Open3.capture3(env, RbConfig.ruby, '-rbundler/setup', '-I', dir, '-e', script, chdir: dir)
|
|
852
|
+
assert status.success?, err
|
|
853
|
+
File.read(File.join(dir, 'body.html'))
|
|
854
|
+
end
|
|
855
|
+
end
|
|
856
|
+
|
|
857
|
+
it 'should load and render erb when the erubis gem is installed and Tilt has no Erubis template' do
|
|
858
|
+
skip 'this Tilt still ships Erubis support' if defined?(Tilt::ErubisTemplate)
|
|
859
|
+
check = "abort 'erubis was not loaded' unless defined?(Erubis::Eruby)"
|
|
860
|
+
assert_equal '<b><p>ok</p>', render_erb_with({ 'erubis' => erubis_stub }, check: check)
|
|
861
|
+
end
|
|
862
|
+
|
|
863
|
+
it "should render erb with Ruby's ERB when Tilt has no Erubis template and erubi is missing" do
|
|
864
|
+
skip 'this Tilt still ships Erubis support' if defined?(Tilt::ErubisTemplate)
|
|
865
|
+
check = <<~'RUBY'
|
|
866
|
+
abort 'erubis was not loaded' unless defined?(Erubis::Eruby)
|
|
867
|
+
abort "erb is #{Tilt['erb']}" unless Tilt['erb'] == Padrino::Rendering::ERBTemplate && !defined?(Erubi)
|
|
868
|
+
RUBY
|
|
869
|
+
assert_equal '<b><p>ok</p>', render_erb_with({ 'erubis' => erubis_stub, 'erubi' => hidden }, check: check)
|
|
870
|
+
end
|
|
871
|
+
|
|
872
|
+
it 'should load before padrino-core when nothing else loads Tilt' do
|
|
873
|
+
stubs = %w[erubis haml hamlit slim].to_h { |name| [name, hidden] }
|
|
874
|
+
assert_equal '<b><p>ok</p>', render_erb_with(stubs, core_first: false)
|
|
875
|
+
end
|
|
876
|
+
end
|
|
877
|
+
|
|
824
878
|
describe 'rendering with helpers that use render' do
|
|
825
879
|
%w[erb haml slim].each do |engine|
|
|
826
880
|
it "should work with #{engine}" do
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
|
|
3
|
+
describe 'TranslationHelpers' do
|
|
4
|
+
include Padrino::Helpers::TranslationHelpers
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@locale = I18n.locale
|
|
8
|
+
@enforce = I18n.enforce_available_locales
|
|
9
|
+
I18n.enforce_available_locales = false
|
|
10
|
+
I18n.backend.store_translations(
|
|
11
|
+
:xx,
|
|
12
|
+
date: { formats: { default: '%Y/%m/%d', short: '%d.%m' } },
|
|
13
|
+
time: { formats: { default: '%H.%M.%S', short: '%H.%M' } }
|
|
14
|
+
)
|
|
15
|
+
I18n.backend.store_translations(
|
|
16
|
+
:yy,
|
|
17
|
+
date: { formats: { default: '%d-%m-%Y', short: '%m-%d' } }
|
|
18
|
+
)
|
|
19
|
+
I18n.locale = :xx
|
|
20
|
+
@date = Date.new(2024, 3, 5)
|
|
21
|
+
@time = Time.utc(2024, 3, 5, 14, 7, 9)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
after do
|
|
25
|
+
I18n.locale = @locale
|
|
26
|
+
I18n.enforce_available_locales = @enforce
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
%i[l localize].each do |name|
|
|
30
|
+
describe "##{name}" do
|
|
31
|
+
it 'should localize a date without options' do
|
|
32
|
+
assert_equal '2024/03/05', send(name, @date)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should localize a time without options' do
|
|
36
|
+
assert_equal '14.07.09', send(name, @time)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'should accept a symbol format' do
|
|
40
|
+
assert_equal '05.03', send(name, @date, format: :short)
|
|
41
|
+
assert_equal '14.07', send(name, @time, format: :short)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'should accept a string format' do
|
|
45
|
+
assert_equal '2024-03-05', send(name, @date, format: '%Y-%m-%d')
|
|
46
|
+
assert_equal '14:07:09', send(name, @time, format: '%H:%M:%S')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'should accept a locale' do
|
|
50
|
+
assert_equal '05-03-2024', send(name, @date, locale: :yy)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'should accept a locale and a format' do
|
|
54
|
+
assert_equal '03-05', send(name, @date, locale: :yy, format: :short)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'should accept an options hash' do
|
|
58
|
+
assert_equal '05.03', send(name, @date, { format: :short })
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: padrino-helpers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.18.
|
|
4
|
+
version: 0.18.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Padrino Team
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2026-
|
|
14
|
+
date: 2026-11-01 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: padrino-support
|
|
@@ -19,14 +19,14 @@ dependencies:
|
|
|
19
19
|
requirements:
|
|
20
20
|
- - '='
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: 0.18.
|
|
22
|
+
version: 0.18.2
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - '='
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 0.18.
|
|
29
|
+
version: 0.18.2
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: tilt
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -232,10 +232,15 @@ files:
|
|
|
232
232
|
- test/test_rendering.rb
|
|
233
233
|
- test/test_rendering_extensions.rb
|
|
234
234
|
- test/test_tag_helpers.rb
|
|
235
|
-
|
|
235
|
+
- test/test_translation_helpers.rb
|
|
236
|
+
homepage: https://padrinorb.com
|
|
236
237
|
licenses:
|
|
237
238
|
- MIT
|
|
238
|
-
metadata:
|
|
239
|
+
metadata:
|
|
240
|
+
bug_tracker_uri: https://github.com/padrino/padrino-framework/issues
|
|
241
|
+
changelog_uri: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc
|
|
242
|
+
documentation_uri: https://padrinorb.com/guides/
|
|
243
|
+
source_code_uri: https://github.com/padrino/padrino-framework
|
|
239
244
|
post_install_message:
|
|
240
245
|
rdoc_options:
|
|
241
246
|
- "--charset=UTF-8"
|
|
@@ -245,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
245
250
|
requirements:
|
|
246
251
|
- - ">="
|
|
247
252
|
- !ruby/object:Gem::Version
|
|
248
|
-
version:
|
|
253
|
+
version: 2.7.8
|
|
249
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
250
255
|
requirements:
|
|
251
256
|
- - ">="
|