bootstrap_builders 0.0.14 → 0.0.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 761a775ab56a61a87c45d7911b2efbd7d9590f96
4
- data.tar.gz: b2995c1de7a321cded0757cae283e6dc05bd9d0e
3
+ metadata.gz: a04a892bcafa7876e948ec637d3693e97ad132a1
4
+ data.tar.gz: 365bbb87b39b7e9fab06f0737d035789f1b84de3
5
5
  SHA512:
6
- metadata.gz: 534cff36dc727c51c93196c42406294ad8d35fbac68e7f6644887c42fd819b6ef6a85ca2772c56cd50a70d56dbbc2e1095aecec286fe7d218cc733536b37fdb4
7
- data.tar.gz: dddfc2e1289e3a3f30e49a7b31c8181b0f8916124a914d999e06eeed0f517d878831f310819d44a83964d8270cde8904d2ae2feac0e48b659f4cfd62fe3bd459
6
+ metadata.gz: 8a45876cdf7d31649854fd06dc8e77f98e02ac8dc5bc1a620b78d23d39ce49a5dbf99955e9604a190b66d2ca0ac18a06c8c808216b69ef7afe2aa95f7cfebdf8
7
+ data.tar.gz: 9f07947f766a270eccb66d088e564a85a7bcfe9814f2fccf55e6524a36e5680480cae4e80ddd923bfc00cb732bae33acee44d1d81a86a3d1a11103625a431c69
@@ -1,3 +1,4 @@
1
1
  #= require bootstrap_builders/view-port-detection
2
2
  #= require bootstrap_builders/bb-btn-responsive
3
3
  #= require bootstrap_builders/tabs
4
+ #= require bootstrap_builders/url-builder/lib/url-builder
@@ -0,0 +1,27 @@
1
+ # UrlBuilder
2
+
3
+ ## Usage
4
+
5
+ Start by making a new object with any given URL
6
+
7
+ ```coffeescript
8
+ urlb = new UrlBuilder.new(window.location.href)
9
+ ```
10
+
11
+ ### Manipulate a query parameter
12
+
13
+ ```coffeescript
14
+ urlb.queryParameters["someParameter"] = "newValue"
15
+ ```
16
+
17
+ ### Generate a new URL
18
+
19
+ ```coffeescript
20
+ urlb.generateFullUrl() #=> "http://localhost:3000/?someParameter=newValue"
21
+ ```
22
+
23
+ ### Generate the path with query parameters
24
+
25
+ ```coffeescript
26
+ urlb.pathWithQueryParameters #=> "/?someParameter=newValue"
27
+ ```
@@ -0,0 +1,99 @@
1
+ class window.UrlBuilder
2
+ constructor: (url) ->
3
+ this.parseUrlFromString(url) if url
4
+
5
+ parseHostAndPortFromUrl: ->
6
+ if match = this.matchAndRemove(/^([A-z\d-\.]+)(|:(\d+))($|\/)/)
7
+ @host = match[1]
8
+
9
+ if match[3]
10
+ @port = parseInt(match[3])
11
+ @portSpecified = true
12
+ else
13
+ if @protocol == "https"
14
+ @port = 443
15
+ else
16
+ @port = 80
17
+
18
+ parsePathFromUrl: ->
19
+ if match = this.matchAndRemove(/^([^\?]+)/)
20
+ @path = "/" + match[1]
21
+ else
22
+ @path = ""
23
+
24
+ parseProtocolFromUrl: ->
25
+ if match = this.matchAndRemove(/^(.+?):\/\//)
26
+ @protocol = match[1]
27
+
28
+ parseQueryParametersFromUrl: ->
29
+ @queryParameters = {}
30
+
31
+ if this.matchAndRemove(/^\?/)
32
+ pairs = @url.split("&")
33
+
34
+ for pair in pairs
35
+ if match = pair.match(/^(.+?)=(.+)$/)
36
+ @queryParameters[match[1]] = match[2]
37
+
38
+ parseUrlFromString: (url) ->
39
+ @url = url
40
+
41
+ this.parseProtocolFromUrl()
42
+ this.parseHostAndPortFromUrl()
43
+ this.parsePathFromUrl()
44
+ this.parseQueryParametersFromUrl()
45
+
46
+ generateFullUrl: ->
47
+ url = @protocol + "://" + @host
48
+
49
+ if @portSpecified
50
+ url += ":" + @port
51
+
52
+ url += "/" + @path
53
+
54
+ if this.hasQueryParameters()
55
+ url += "?"
56
+ url += this.queryParametersAsString()
57
+
58
+ url
59
+
60
+ pathWithQueryParameters: ->
61
+ generatedPath = @path
62
+
63
+ if this.hasQueryParameters()
64
+ generatedPath += "?"
65
+ generatedPath += this.queryParametersAsString()
66
+
67
+ generatedPath
68
+
69
+ matchAndRemove: (regex) ->
70
+ if match = @url.match(regex)
71
+ @url = @url.replace(regex, "")
72
+ return match
73
+ else
74
+ return false
75
+
76
+ # Returns true if any query parameters has been saved
77
+ hasQueryParameters: ->
78
+ if @queryParameters && Object.keys(@queryParameters).length > 0
79
+ true
80
+ else
81
+ false
82
+
83
+ # Returns a hash containing the query parameters
84
+ queryParameters: ->
85
+ @queryParameters
86
+
87
+ queryParametersAsString: ->
88
+ queryParametersString = ""
89
+ first = true
90
+
91
+ for key, value of @queryParameters
92
+ if first
93
+ first = false
94
+ else
95
+ queryParametersString += "&"
96
+
97
+ queryParametersString += key + "=" + value
98
+
99
+ queryParametersString
@@ -1,3 +1,3 @@
1
1
  module BootstrapBuilders
2
- VERSION = "0.0.14".freeze
2
+ VERSION = "0.0.15".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_builders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -233,6 +233,8 @@ files:
233
233
  - app/assets/javascripts/bootstrap_builders.coffee
234
234
  - app/assets/javascripts/bootstrap_builders/bb-btn-responsive.coffee
235
235
  - app/assets/javascripts/bootstrap_builders/tabs.js.coffee
236
+ - app/assets/javascripts/bootstrap_builders/url-builder/README.md
237
+ - app/assets/javascripts/bootstrap_builders/url-builder/lib/url-builder.coffee
236
238
  - app/assets/javascripts/bootstrap_builders/view-port-detection.coffee
237
239
  - app/assets/stylesheets/bootstrap_builders.scss
238
240
  - app/assets/stylesheets/bootstrap_builders/bb-btn-responsive.scss
@@ -276,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
278
  version: '0'
277
279
  requirements: []
278
280
  rubyforge_project:
279
- rubygems_version: 2.2.2
281
+ rubygems_version: 2.5.1
280
282
  signing_key:
281
283
  specification_version: 4
282
284
  summary: A library to generate Bootstrap HTML for Rails.