uri_template 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,6 @@
1
+ # 0.0.2 - 1.11.2011
2
+ * BUGFIX: Concatenating empty sections no more leads to catch-all templates, when an emtpy template was appreciated.
3
+ + The extracted variables now contains the keys :suffix and :prefix if the match didn't consume the whole uri.
4
+
5
+ # 0.0.1 - 30.10.2011
6
+ Initial version
@@ -130,19 +130,22 @@ __REGEXP__
130
130
  end
131
131
 
132
132
  # @private
133
- class LeftBound
134
-
133
+ class Terminal
135
134
  def expand(*_)
136
135
  ''
137
136
  end
138
137
 
139
- def to_r_source(*_)
140
- '^'
141
- end
142
-
143
138
  def size
144
139
  0
145
140
  end
141
+ end
142
+
143
+ # @private
144
+ class LeftBound < Terminal
145
+
146
+ def to_r_source(*_)
147
+ '^'
148
+ end
146
149
 
147
150
  def to_s
148
151
  ''
@@ -151,20 +154,12 @@ __REGEXP__
151
154
  end
152
155
 
153
156
  # @private
154
- class RightBound
155
-
156
- def expand(*_)
157
- ''
158
- end
157
+ class RightBound < Terminal
159
158
 
160
159
  def to_r_source(*_)
161
160
  '$'
162
161
  end
163
162
 
164
- def size
165
- 0
166
- end
167
-
168
163
  def to_s
169
164
  ''
170
165
  end
@@ -172,16 +167,12 @@ __REGEXP__
172
167
  end
173
168
 
174
169
  # @private
175
- class Open
176
- def expand(*_)
177
- ''
178
- end
170
+ class Open < Terminal
171
+
179
172
  def to_r_source(*_)
180
173
  ''
181
174
  end
182
- def size
183
- 0
184
- end
175
+
185
176
  def to_s
186
177
  "\u2026"
187
178
  end
@@ -712,6 +703,12 @@ __REGEXP__
712
703
  return nil
713
704
  else
714
705
  result = extract_matchdata(m)
706
+ if m.pre_match and m.pre_match.size > 0
707
+ result.unshift( [:prefix, m.pre_match] )
708
+ end
709
+ if m.post_match and m.post_match.size > 0
710
+ result.push( [:suffix, m.post_match] )
711
+ end
715
712
  if post_processing.include? :convert_values
716
713
  result.map!{|k,v| [k, Utils.pair_array_to_hash(v)] }
717
714
  end
@@ -775,8 +772,8 @@ __REGEXP__
775
772
  # end
776
773
  # return "not found"
777
774
  # end
778
- # route( 'app_a/do_something' ) #=> "app_a: do_something with {}"
779
- # route( 'app_b/1337/something_else' ) #=> "app_b: something_else with {\"x\"=>\"1337\"}"
775
+ # route( 'app_a/do_something' ) #=> "app_a: do_something with {:suffix=>\"do_something\"}"
776
+ # route( 'app_b/1337/something_else' ) #=> "app_b: something_else with {\"x\"=>\"1337\", :suffix=>\"something_else\"}"
780
777
  # route( 'bla' ) #=> 'not found'
781
778
  #
782
779
  class Section < self
@@ -800,16 +797,40 @@ __REGEXP__
800
797
  #
801
798
  # @example
802
799
  # sect = URITemplate::Draft7::Section.new('/prefix…')
803
- # sect >> '…/mid…' >> '…/end' # URITemplate::Draft7::Section.new('/prefix/mid/end')
800
+ # sect >> '…/mid…' >> '…/end' #=> URITemplate::Draft7::Section.new('/prefix/mid/end')
801
+ #
802
+ # @example
803
+ # sect = URITemplate::Draft7::Section.new('/prefix…')
804
+ # sect >> '……' #=> sect
805
+ #
806
+ # @example Just ellipsis has a special syntax to allow empty matches.
807
+ # sect = URITemplate::Draft7::Section.new('…')
808
+ # combo = sect >> '…'
809
+ # combo.pattern #=> ""
810
+ # combo === "" #=> true
811
+ # combo === "/foo" #=> false
804
812
  #
805
813
  # @return Section
806
814
  def >>(other)
807
815
  o = self.class.try_convert(other)
808
816
  if o.kind_of? Section
809
- if !self.right_bound? and !o.left_bound?
810
- return self.class.new(self.tokens[0..-2] + o.tokens[1..-1], o.options)
817
+ if !self.right_bound?
818
+ if o.pattern == ELLIPSIS
819
+ return self.class.new("", o.options)
820
+ elsif !o.left_bound?
821
+ #if self.tokens.size == 1
822
+ # return o
823
+ #end
824
+ tkns = self.tokens[0..-2] + o.tokens[1..-1]
825
+ unless tkns.first.kind_of? Terminal
826
+ tkns.unshift(LeftBound.new)
827
+ end
828
+ unless tkns.last.kind_of? Terminal
829
+ tkns.push(RightBound.new)
830
+ end
831
+ return self.class.new(tkns, o.options)
832
+ end
811
833
  end
812
- else
813
834
  raise ArgumentError, "Expected something that could be converted to a URITemplate section, but got #{other.inspect}"
814
835
  end
815
836
  end
@@ -818,11 +839,12 @@ __REGEXP__
818
839
  # @private
819
840
  def tokenize!
820
841
  pat = pattern
821
- if pat == ELLIPSIS
822
- return [Open.new]
842
+ if pat == ELLIPSIS # just ellipsis
843
+ return [LeftBound.new, Open.new]
844
+ else
845
+ lb = (pat[0] != ELLIPSIS)
846
+ rb = (pat[-1] != ELLIPSIS)
823
847
  end
824
- lb = (pat[0] != ELLIPSIS)
825
- rb = (pat[-1] != ELLIPSIS)
826
848
  pat = pat[ (lb ? 0 : 1)..(rb ? -1 : -2) ]
827
849
  [lb ? LeftBound.new : Open.new] + Tokenizer.new(pat).to_a + [rb ? RightBound.new : Open.new]
828
850
  end
data/uri_template.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'uri_template'
3
- s.version = '0.0.1'
4
- s.date = '2011-10-30'
3
+ s.version = '0.0.2'
4
+ s.date = '2011-11-01'
5
5
  s.authors = ["HannesG"]
6
6
  s.email = %q{hannes.georg@googlemail.com}
7
7
  s.summary = 'A templating system for URIs.'
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
 
11
11
  s.require_paths = ['lib']
12
12
 
13
- s.files = Dir.glob('lib/**/**/*.rb') + ['uri_template.gemspec', 'README']
13
+ s.files = Dir.glob('lib/**/**/*.rb') + ['uri_template.gemspec', 'README', 'CHANGELOG']
14
14
 
15
15
  s.add_development_dependency 'rspec'
16
16
  s.add_development_dependency 'yard'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-30 00:00:00.000000000Z
12
+ date: 2011-11-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &14233820 !ruby/object:Gem::Requirement
16
+ requirement: &22417520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *14233820
24
+ version_requirements: *22417520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &14636440 !ruby/object:Gem::Requirement
27
+ requirement: &22415680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *14636440
35
+ version_requirements: *22415680
36
36
  description: ! 'A templating system for URIs, which implements http://tools.ietf.org/html/draft-gregorio-uritemplate-07
37
37
  . An implementation of an older version of that spec is known as addressable. This
38
38
  system however is intended to be extended when newer specs evolve. For now only
@@ -48,6 +48,7 @@ files:
48
48
  - lib/uri_template/utils.rb
49
49
  - uri_template.gemspec
50
50
  - README
51
+ - CHANGELOG
51
52
  homepage: http://github.com/hannesg/uri_template
52
53
  licenses: []
53
54
  post_install_message: