infopark_rails_connector 6.8.0.406.131718077 → 6.8.0.444.171626367

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.
@@ -5,8 +5,7 @@ module RailsConnector
5
5
  # Returns the path for +target+ using the +CmsController+ routes.
6
6
  # +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
7
7
  # If +target+ is a +Linklist+, it must be non-empty. The first +Link+ from the +LinkList+ will be used.
8
- # +options+ are optional and include url settings such as path parameters or protocol
9
- # +options+ are only passed on if +target+ is an +Obj+.
8
+ # +options+ are optional and include url settings such as path parameters or protocol.
10
9
  # @return [String]
11
10
  # @api public
12
11
  def cms_path(target, options = {})
@@ -16,8 +15,7 @@ module RailsConnector
16
15
  # Returns the absolute URL for target using the +CmsController+ routes.
17
16
  # +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
18
17
  # If +target+ is a +Linklist+, it must be non-empty. The first +Link+ from the +LinkList+ will be used.
19
- # +options+ are optional and include url settings such as path parameters or protocol
20
- # +options+ are only passed on if +target+ is an +Obj+.
18
+ # +options+ are optional and include url settings such as path parameters or protocol.
21
19
  # @return [String]
22
20
  # @api public
23
21
  def cms_url(target, options = {})
@@ -29,12 +27,12 @@ module RailsConnector
29
27
 
30
28
  def cms_path_or_url(target, path_or_url, options = {})
31
29
  if target.is_a?(Link)
32
- cms_path_or_url_for_links(target, path_or_url)
30
+ cms_path_or_url_for_links(target, path_or_url, options)
33
31
  elsif target.is_a?(Obj)
34
32
  cms_path_or_url_for_objs(target, path_or_url, options)
35
33
  elsif target.respond_to?(:first)
36
34
  if target.first.is_a?(Link)
37
- cms_path_or_url_for_links(target.first, path_or_url)
35
+ cms_path_or_url_for_links(target.first, path_or_url, options)
38
36
  else
39
37
  return LINK_TO_EMPTY_LINKLIST
40
38
  end
@@ -44,11 +42,12 @@ module RailsConnector
44
42
  end
45
43
  end
46
44
 
47
- def cms_path_or_url_for_links(link, path_or_url)
45
+ def cms_path_or_url_for_links(link, path_or_url, options = {})
48
46
  return LINK_TO_UNREACHABLE if link.internal? && link.destination_object.nil?
49
- append_search_and_fragment(
50
- basic_url_or_path_for_link(link, path_or_url), link
51
- )
47
+ url = basic_url_or_path_for_link(link, path_or_url, options)
48
+ url = append_search(url, link) if options.empty?
49
+
50
+ append_fragment(url, link)
52
51
  end
53
52
 
54
53
  def cms_path_or_url_for_objs(obj, path_or_url, options = {})
@@ -72,15 +71,18 @@ module RailsConnector
72
71
 
73
72
  private
74
73
 
75
- def basic_url_or_path_for_link(link, path_or_url)
74
+ def basic_url_or_path_for_link(link, path_or_url, options = {})
76
75
  if link.internal?
77
- __send__("cms_#{path_or_url}", link.destination_object)
76
+ __send__("cms_#{path_or_url}", link.destination_object, options)
78
77
  else
79
78
  if link.external_prefix?
80
- remove_external_prefix(link.url)
79
+ url = remove_external_prefix(link.url)
81
80
  else
82
- link.url
81
+ url = link.url
83
82
  end
83
+
84
+ url = merge_options(url, options) if options.any?
85
+ url
84
86
  end
85
87
  end
86
88
 
@@ -88,11 +90,25 @@ module RailsConnector
88
90
  link.gsub(/external:/, "").strip
89
91
  end
90
92
 
91
- def append_search_and_fragment(url,link)
92
- result = url
93
- result += "?#{link.search}" unless link.search.blank?
94
- result += "##{link.fragment}" unless link.fragment.blank?
95
- result
93
+ def append_search(url, link)
94
+ url += "?#{link.search}" unless link.search.blank?
95
+ url
96
96
  end
97
+
98
+ def append_fragment(url, link)
99
+ url += "##{link.fragment}" unless link.fragment.blank?
100
+ url
101
+ end
102
+
103
+ def merge_options(url, options)
104
+ parsed_url = URI.parse(url)
105
+
106
+ search = Rack::Utils.parse_query(parsed_url.query)
107
+ merged_search = search.merge(options.stringify_keys)
108
+ parsed_url.query = merged_search.to_query
109
+
110
+ parsed_url.to_s
111
+ end
112
+
97
113
  end
98
114
  end
@@ -61,10 +61,11 @@ module RailsConnector
61
61
  # @api public
62
62
  attr_reader :doc
63
63
 
64
- def initialize(id, score, doc={})
64
+ def initialize(id, score, doc={}, obj=nil)
65
65
  @id = id
66
66
  @score = score
67
67
  @doc = doc
68
+ @obj = obj
68
69
  end
69
70
 
70
71
  # Returns the hit's corresponding Obj (or nil if none found in the database).
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_rails_connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 263434717
4
+ hash: 343251185
5
5
  prerelease:
6
6
  segments:
7
7
  - 6
8
8
  - 8
9
9
  - 0
10
- - 406
11
- - 131718077
12
- version: 6.8.0.406.131718077
10
+ - 444
11
+ - 171626367
12
+ version: 6.8.0.444.171626367
13
13
  platform: ruby
14
14
  authors:
15
15
  - Infopark AG
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-12-04 00:00:00 +01:00
20
+ date: 2012-12-06 00:00:00 +01:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency