padrino-support 0.13.1.beta1 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/padrino-support.rb +1 -0
- data/lib/padrino-support/locale/de.yml +1 -1
- data/lib/padrino-support/utils.rb +35 -0
- data/test/test_utils.rb +59 -0
- metadata +14 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d453e0892637ad5ecd1ecd5f19beffae03301cc
|
4
|
+
data.tar.gz: c06c6d676c253f88efc4d52ba340c02f44a204a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21570003ba947f1294aa54274015119bf7027e8b31d9c74274e69ef0dca40654b3061bbc745a973e4c79eb778eb60de51d0730e8ffc992269bf9af5bcc815390
|
7
|
+
data.tar.gz: 9bb250daa864f0e41c202cf19c7329b9e9d855d27fe6182f3ac293058c748341b1bff49befbd57bca968965dbea1e9aeb5a61b1e9e09fdacfe7a7bfbb16e37fe
|
data/lib/padrino-support.rb
CHANGED
@@ -4,7 +4,7 @@ de:
|
|
4
4
|
# Benutze die strftime Parameter für die Formatierung
|
5
5
|
# Wenn keine Formate angegeben werden, wird "default" benutzt.
|
6
6
|
# Du kannst auch weitere Formate hinzufügen, wenn Du möchtest.
|
7
|
-
default: "
|
7
|
+
default: "%d.%m.%Y"
|
8
8
|
short: "%d. %b"
|
9
9
|
long: "%d. %B %Y"
|
10
10
|
only_day: "%e"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Padrino
|
4
|
+
module Utils
|
5
|
+
extend self
|
6
|
+
|
7
|
+
##
|
8
|
+
# Builds an URI query from a Hash or any Object.
|
9
|
+
#
|
10
|
+
# Examples (~ marks here that output is actually escaped by CGI):
|
11
|
+
#
|
12
|
+
# Utils.build_uri_query(:a => 1, :b => 2) #=> "a=1&b=2"
|
13
|
+
# Utils.build_uri_query(:a => [1, 2]) #=> ~"a[]=1&a[]=2"
|
14
|
+
# Utils.build_uri_query([1, 2], 'namespace') #=> ~"namespace[]=1&namespace[]=2"
|
15
|
+
# Utils.build_uri_query(:a => { :d => 2 }, :b => 3) #=> ~"a[d]=2&b=3"
|
16
|
+
#
|
17
|
+
def build_uri_query(object, namespace = nil)
|
18
|
+
case object
|
19
|
+
when Hash
|
20
|
+
object.map do |key, value|
|
21
|
+
next if value == {} || value == []
|
22
|
+
build_uri_query(value, namespace ? "#{namespace}[#{key}]" : key)
|
23
|
+
end.compact.join('&')
|
24
|
+
when Array
|
25
|
+
fail ArgumentError, 'namespace is missing' unless namespace
|
26
|
+
(object.empty? ? [''] : object).map do |value|
|
27
|
+
build_uri_query(value, "#{namespace}[]")
|
28
|
+
end.join('&')
|
29
|
+
else
|
30
|
+
fail ArgumentError, 'namespace is missing' unless namespace
|
31
|
+
"#{CGI.escape(namespace.to_s)}=#{CGI.escape(object.to_s)}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/test/test_utils.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
class MiniTest::Spec
|
4
|
+
def assert_query_equal(expected, actual, namespace=nil)
|
5
|
+
assert_equal expected.split('&').sort, Padrino::Utils.build_uri_query(actual, namespace).split('&').sort
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'Padrino::Utils.build_uri_query' do
|
10
|
+
it 'should do simple conversion' do
|
11
|
+
assert_query_equal 'a=10', :a => 10
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should do cgi escaping' do
|
15
|
+
assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should expand nested hashes' do
|
19
|
+
assert_query_equal 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas',
|
20
|
+
:person => { :login => 'seckar', :name => 'Nicholas' }
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should expand deeply nested hashes' do
|
24
|
+
assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10',
|
25
|
+
{ :account => { :person => { :id => 20 } }, :person => {:id => 10} }
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should accept arrays' do
|
29
|
+
assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20',
|
30
|
+
:person => {:id => [10, 20]}
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should accept empty arrays' do
|
34
|
+
assert_query_equal "person%5B%5D=",
|
35
|
+
[],
|
36
|
+
'person'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should expand nested hashes' do
|
40
|
+
assert_query_equal '',
|
41
|
+
{}
|
42
|
+
assert_query_equal 'a=1&b%5Bc%5D=3',
|
43
|
+
{ a: 1, b: { c: 3, d: {} } }
|
44
|
+
assert_query_equal '',
|
45
|
+
{ a: {b: {c: {}}} }
|
46
|
+
assert_query_equal 'b%5Bc%5D=false&b%5Be%5D=&b%5Bf%5D=&p=12',
|
47
|
+
{ p: 12, b: { c: false, e: nil, f: '' } }
|
48
|
+
assert_query_equal 'b%5Bc%5D=3&b%5Bf%5D=',
|
49
|
+
{ b: { c: 3, k: {}, f: '' } }
|
50
|
+
assert_query_equal 'b=3',
|
51
|
+
{a: [], b: 3}
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should accept namespace for hashes' do
|
55
|
+
assert_query_equal "user%5Bname%5D=Nakshay&user%5Bnationality%5D=Indian",
|
56
|
+
{ name: 'Nakshay', nationality: 'Indian' },
|
57
|
+
'user'
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.1
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -12,20 +12,20 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2016-01-17 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|
19
19
|
requirement: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - '>='
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '3.1'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- -
|
28
|
+
- - '>='
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '3.1'
|
31
31
|
description: A number of support methods and extensions for Padrino framework
|
@@ -34,9 +34,9 @@ executables: []
|
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
37
|
+
- .document
|
38
|
+
- .gitignore
|
39
|
+
- .yardopts
|
40
40
|
- LICENSE.txt
|
41
41
|
- Rakefile
|
42
42
|
- lib/padrino-support.rb
|
@@ -65,29 +65,31 @@ files:
|
|
65
65
|
- lib/padrino-support/locale/uk.yml
|
66
66
|
- lib/padrino-support/locale/zh_cn.yml
|
67
67
|
- lib/padrino-support/locale/zh_tw.yml
|
68
|
+
- lib/padrino-support/utils.rb
|
68
69
|
- padrino-support.gemspec
|
69
70
|
- test/helper.rb
|
70
71
|
- test/test_colorize.rb
|
71
72
|
- test/test_support_lite.rb
|
73
|
+
- test/test_utils.rb
|
72
74
|
homepage: http://www.padrinorb.com
|
73
75
|
licenses:
|
74
76
|
- MIT
|
75
77
|
metadata: {}
|
76
78
|
post_install_message:
|
77
79
|
rdoc_options:
|
78
|
-
-
|
80
|
+
- --charset=UTF-8
|
79
81
|
require_paths:
|
80
82
|
- lib
|
81
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
84
|
requirements:
|
83
|
-
- -
|
85
|
+
- - '>='
|
84
86
|
- !ruby/object:Gem::Version
|
85
87
|
version: '0'
|
86
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
89
|
requirements:
|
88
|
-
- -
|
90
|
+
- - '>='
|
89
91
|
- !ruby/object:Gem::Version
|
90
|
-
version: 1.3.
|
92
|
+
version: 1.3.6
|
91
93
|
requirements: []
|
92
94
|
rubyforge_project: padrino-support
|
93
95
|
rubygems_version: 2.4.8
|
@@ -98,4 +100,5 @@ test_files:
|
|
98
100
|
- test/helper.rb
|
99
101
|
- test/test_colorize.rb
|
100
102
|
- test/test_support_lite.rb
|
103
|
+
- test/test_utils.rb
|
101
104
|
has_rdoc:
|