iron-web 1.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
+ == 1.1.1 / 2013-03-13
2
+
3
+ * Handle setting Url params with keys, accessing with keys using #get_param
4
+
5
+ == 1.1.0 / 2013-03-12
6
+
7
+ * Fix parsing of multi-value params to be keyed without the "[]" - NOTE: BREAKING CHANGE!
8
+ * Fix rendering of multi-value params to enforce addition of "[]"
9
+ * Add Url#set_params(hash) to allow setting multiple params at once
10
+ * Add optional param to Url#make_absolute to allow explicitly setting the server
11
+
1
12
  == 1.0.2 / 2012-06-03
2
13
 
3
14
  * Add ability to access attributes on elements using []/[]=
@@ -9,9 +20,9 @@
9
20
 
10
21
  == 1.0.0 / 2012-03-02
11
22
 
12
- * Broke out extensions from older irongaze gem
23
+ * Break out extensions from older irongaze gem
13
24
  * Updated Url and Color classes with misc fixes
14
25
  * Added Url and Color spec coverage
15
26
  * Major Html::Element spec work, basic Html spec coverage
16
27
  * Add html_safe support for non-Rails environments
17
- * Added to GitHub
28
+ * Add to GitHub
@@ -16,6 +16,8 @@ A set of classes useful in the generation of HTML content.
16
16
  >> url.params[:key] = 'some value'
17
17
  >> url.to_s
18
18
  => '/home?key=some+value'
19
+ >> url.make_absolute(false, 'google.com')
20
+ => 'http://google.com/home?key=some+value'
19
21
 
20
22
  * Color - an RGB/A color manipulation class, useful in generating CSS etc.
21
23
 
@@ -89,3 +91,7 @@ setting them during construction.
89
91
  To install, simply run:
90
92
 
91
93
  sudo gem install iron-web
94
+
95
+ RVM users can skip the sudo:
96
+
97
+ gem install iron-web
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.1.1
@@ -63,10 +63,11 @@ class Url
63
63
  str += '?'
64
64
  str += params.collect do |k,v|
65
65
  if v.is_a?(Array)
66
+ k = k.gsub('[]','')
66
67
  v.collect do |vs|
67
68
  val = vs.respond_to?(:to_param) ? vs.to_param : vs
68
69
  val = val.to_s
69
- CGI::escape(k.to_s) + '=' + CGI::escape(val)
70
+ CGI::escape(k.to_s) + '[]=' + CGI::escape(val)
70
71
  end
71
72
  else
72
73
  val = v.respond_to?(:to_param) ? v.to_param : v
@@ -103,7 +104,13 @@ class Url
103
104
  @params = {}
104
105
  params.split('&').each do |p|
105
106
  k, v = p.split('=')
106
- add_param(CGI::unescape(k), CGI::unescape(v)) if k && v
107
+ if k && v
108
+ if k.ends_with?('[]')
109
+ add_param(CGI::unescape(k.gsub('[]','')), [CGI::unescape(v)])
110
+ else
111
+ add_param(CGI::unescape(k), CGI::unescape(v))
112
+ end
113
+ end
107
114
  end
108
115
  end
109
116
 
@@ -153,14 +160,22 @@ class Url
153
160
 
154
161
  # Override current param val or set if none
155
162
  def set_param(k, v)
156
- @params[k] = v
163
+ @params[k.to_s] = v
164
+ end
165
+
166
+ def set_params(hash)
167
+ hash.each_pair {|k,v|
168
+ set_param(k, v)
169
+ }
157
170
  end
158
171
 
159
172
  # Add a param value (can be called multiply for the same param key)
160
173
  def add_param(k, v)
174
+ k = k.to_s
161
175
  oldval = @params[k]
162
176
  if oldval
163
177
  @params[k] = oldval.is_a?(Array) ? oldval + [v] : [oldval, v]
178
+ @params[k].flatten!
164
179
  else
165
180
  @params[k] = v
166
181
  end
@@ -172,10 +187,14 @@ class Url
172
187
  if key_or_regex.is_a?(Regexp)
173
188
  k.match(key_or_regex)
174
189
  else
175
- k == key_or_regex
190
+ k == key_or_regex.to_s
176
191
  end
177
192
  end
178
193
  end
194
+
195
+ def get_param(k)
196
+ @params[k.to_s]
197
+ end
179
198
 
180
199
  # Reset params
181
200
  def clear_params
@@ -200,10 +219,10 @@ class Url
200
219
  end
201
220
 
202
221
  # Ensure url contains a server + scheme section, eg converts '/foo' into 'http://example.com/foo'.
203
- def make_absolute(secure = false)
222
+ def make_absolute(secure = false, server = nil)
204
223
  unless absolute? && secure? == secure
205
- raise 'No default server in Url#make_absolute' unless @server || Url.default_server
206
- @server = Url.default_server unless @server
224
+ raise 'No default server set for Url#make_absolute' unless server || @server || Url.default_server
225
+ @server ||= (server || Url.default_server)
207
226
  unless @scheme
208
227
  @scheme = Url.default_scheme
209
228
  @port = nil
@@ -30,7 +30,7 @@ describe Url do
30
30
  u.port.should == 819
31
31
  u.path.should == '/this/is-a-bunch.jpg'
32
32
  u.params['of'].should == 'crazy'
33
- u.params['free[]'].should == '55'
33
+ u.params['free'].should == ['55']
34
34
  u.fragment.should == 'now'
35
35
  end
36
36
 
@@ -60,6 +60,7 @@ describe Url do
60
60
  u = Url.new('/scores')
61
61
  u.add_param('soccer', '123')
62
62
  u.add_param('soccer', '456')
63
+ u.to_s.should match(/soccer\[\]=/)
63
64
  u = Url.parse(u.to_s)
64
65
  val = u.params['soccer']
65
66
  val.should be_an(Array)
@@ -94,8 +95,22 @@ describe Url do
94
95
  u.make_absolute.should == 'http://irongaze.com/bar'
95
96
  end
96
97
 
98
+ it 'should allow explicit servers in make_absolute' do
99
+ u = Url.parse('/bob')
100
+ u.make_absolute(true, 'microsoft.com').should == 'https://microsoft.com/bob'
101
+ end
102
+
97
103
  it 'should escape params correctly' do
98
104
  Url.build('/foo', 'one:two' => 'http://other.com').should == '/foo?one%3Atwo=http%3A%2F%2Fother.com'
99
105
  end
100
106
 
107
+ it 'should allow setting and getting using symbols or strings' do
108
+ u = Url.parse('/')
109
+ u.set_param(:bob, 4)
110
+ u.to_s.should == '/?bob=4'
111
+ u.set_param('bob', 5)
112
+ u.to_s.should == '/?bob=5'
113
+ u.get_param(:bob).should == 5
114
+ end
115
+
101
116
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-03 00:00:00.000000000 Z
12
+ date: 2013-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron-extensions