bootstrap_builders 0.0.60 → 0.0.61

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b931613adf3a0e431b305e7c36dc97fc218a5388
4
- data.tar.gz: 50990ef9f9be4ee5a8e0fdcfcbbea8289554caea
3
+ metadata.gz: 250f6cde716d39a305a42b3345c8a388b38bf623
4
+ data.tar.gz: bab587be818ec8b518ae3641aebc9d3a4d7a2cfc
5
5
  SHA512:
6
- metadata.gz: db32506f27788225a1df4c51578d2e6736c67aab7c1ff4e7b338f37e26652bbfcda84e68447cc308e6c872ff188da4c4b2dd24f12a0375ed500f155cc0fc95f3
7
- data.tar.gz: cf2a7beff524b9cf7b1026b0323b2f8ffcaeb22bd25259802d275543c4fe568f6885f57d76da2bcd4c1b33b59d5aa1404b18735c3cb37d9c14782102b6cc11d7
6
+ metadata.gz: 17963e7e6bde475d527cfebeee201ea02f66bbc87bb25faf799a594261274973b9c791ea2a72632675bc65b362ec28ae508f6eb751723445a46a6feb2acd2f78
7
+ data.tar.gz: 5cfe540f4accaac79d0e2d837e74e9701bbe239802d58b6d180eb0ccf5449208139d02cb1d11582ec22b48daaecaf144270c13d731e5c4269353cfdaa6464a23
@@ -0,0 +1,27 @@
1
+ # UrlBuilder
2
+
3
+ ## Usage
4
+
5
+ Start by making a new object with any given URL
6
+
7
+ ```js
8
+ var urlb = new UrlBuilder.new(window.location.href)
9
+ ```
10
+
11
+ ### Manipulate a query parameter
12
+
13
+ ```js
14
+ urlb.queryParameters["someParameter"] = "newValue"
15
+ ```
16
+
17
+ ### Generate a new URL
18
+
19
+ ```js
20
+ urlb.generateFullUrl() #=> "http://localhost:3000/?someParameter=newValue"
21
+ ```
22
+
23
+ ### Generate the path with query parameters
24
+
25
+ ```js
26
+ urlb.pathWithQueryParameters #=> "/?someParameter=newValue"
27
+ ```
@@ -0,0 +1,140 @@
1
+ class UrlBuilder {
2
+ constructor(url) {
3
+ if (url) {
4
+ this.parseUrlFromString(url)
5
+ }
6
+ }
7
+
8
+ parseHostAndPortFromUrl() {
9
+ var match = this.matchAndRemove(/^([A-z\d-\.]+)(|:(\d+))($|\/)/)
10
+
11
+ if (match) {
12
+ this.host = match[1]
13
+
14
+ if (match[3]) {
15
+ this.port = parseInt(match[3])
16
+ this.portSpecified = true
17
+ } else {
18
+ if (this.protocol == "https") {
19
+ this.port = 443
20
+ } else {
21
+ this.port = 80
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ parsePathFromUrl() {
28
+ var match = this.matchAndRemove(/^([^\?]+)/)
29
+
30
+ if (match) {
31
+ this.path = "/" + match[1]
32
+ } else {
33
+ this.path = ""
34
+ }
35
+ }
36
+
37
+ parseProtocolFromUrl() {
38
+ var match = this.matchAndRemove(/^(.+?):\/\//)
39
+
40
+ if (match) {
41
+ this.protocol = match[1]
42
+ }
43
+ }
44
+
45
+ parseQueryParametersFromUrl() {
46
+ this.queryParameters = {}
47
+
48
+ if (this.matchAndRemove(/^\?/)) {
49
+ var pairs = this.url.split("&")
50
+
51
+ for(var pair in pairs) {
52
+ var match = pair.match(/^(.+?)=(.+)$/)
53
+ if (match) {
54
+ this.queryParameters[match[1]] = match[2]
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ parseUrlFromString(url) {
61
+ this.url = url
62
+
63
+ this.parseProtocolFromUrl()
64
+ this.parseHostAndPortFromUrl()
65
+ this.parsePathFromUrl()
66
+ this.parseQueryParametersFromUrl()
67
+ }
68
+
69
+ generateFullUrl() {
70
+ var url = this.protocol + "://" + this.host
71
+
72
+ if (this.portSpecified) {
73
+ url += ":" + this.port
74
+ }
75
+
76
+ url += this.path
77
+
78
+ if (this.hasQueryParameters()) {
79
+ url += "?"
80
+ url += this.queryParametersAsString()
81
+ }
82
+
83
+ return url
84
+ }
85
+
86
+ pathWithQueryParameters() {
87
+ var generatedPath = this.path
88
+
89
+ if (this.hasQueryParameters()) {
90
+ generatedPath += "?"
91
+ generatedPath += this.queryParametersAsString()
92
+ }
93
+
94
+ return generatedPath
95
+ }
96
+
97
+ matchAndRemove(regex) {
98
+ var match = this.url.match(regex)
99
+
100
+ if (match) {
101
+ this.url = this.url.replace(regex, "")
102
+ return match
103
+ } else {
104
+ return false
105
+ }
106
+ }
107
+
108
+ // Returns true if any query parameters has been saved
109
+ hasQueryParameters() {
110
+ if (this.queryParameters && Object.keys(this.queryParameters).length > 0) {
111
+ return true
112
+ } else {
113
+ return false
114
+ }
115
+ }
116
+
117
+ // Returns a hash containing the query parameters
118
+ queryParameters() {
119
+ this.queryParameters
120
+ }
121
+
122
+ queryParametersAsString() {
123
+ var queryParametersString = ""
124
+ var first = true
125
+
126
+ for(var key in this.queryParameters) {
127
+ var value = this.queryParameters[key]
128
+
129
+ if (first) {
130
+ first = false
131
+ } else {
132
+ queryParametersString += "&"
133
+ }
134
+
135
+ queryParametersString += key + "=" + value
136
+ }
137
+
138
+ return queryParametersString
139
+ }
140
+ }
@@ -1,3 +1,3 @@
1
1
  module BootstrapBuilders
2
- VERSION = "0.0.60".freeze
2
+ VERSION = "0.0.61".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_builders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.60
4
+ version: 0.0.61
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
@@ -52,6 +52,8 @@ files:
52
52
  - app/assets/javascripts/bootstrap_builders/bb-btn-responsive.js
53
53
  - app/assets/javascripts/bootstrap_builders/date-picker-input.es6
54
54
  - app/assets/javascripts/bootstrap_builders/tabs.js
55
+ - app/assets/javascripts/bootstrap_builders/url-builder/README.md
56
+ - app/assets/javascripts/bootstrap_builders/url-builder/lib/url-builder.es6
55
57
  - app/assets/javascripts/bootstrap_builders/view-port-detection.js
56
58
  - app/assets/stylesheets/bootstrap_builders.scss
57
59
  - app/assets/stylesheets/bootstrap_builders/bb-btn-responsive.scss