gdk-toogle 1.0.2 → 1.2.1

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
  SHA256:
3
- metadata.gz: cacce942effef205bff4a9e31cd15889c6e3faba254dd3efee2e238519940147
4
- data.tar.gz: f1e506fe72c8dbe264382fa96544a66e232ea0b40fb0bfb4fb14772b3a0e9702
3
+ metadata.gz: 977eaeeeceacce09f2f02a5990dbdc7cea1e24cb8f27380aeff745a5f3732119
4
+ data.tar.gz: d30b7f35dea5420bbec127746d04e2da9acb35a74ab4a0428eaf1655b1a4a32a
5
5
  SHA512:
6
- metadata.gz: aac129e17fb36ea58e72b2bd12dbf9d90b52d8055ab787146fc3fccaf0eec5cd178d6f1cf21672e0de6fd48aa9ab9ea15fa5a7d328e522ff430286ecf0c49d16
7
- data.tar.gz: 83a9942634aab84f4058e743f900f538c5e5bc69c74f8c678c8738b544c96d377ef091cc96302164e33f03bc611db886cd90b10581b47b75a3b5e070ff32173f
6
+ metadata.gz: abf5c9edc2b9235bd914f031d4f29663f9f4ad07f7d0ed5abe0173e59c8f65f1fc7dc33994dfb050cbebf794b434fba9a2e279793117e40080a55ac7db1bd44e
7
+ data.tar.gz: 8ef3d8bcc547f4ac8da980bbaa40f866e4b87393b20aaba8ff4e91fa4211d0c94513cc9c6e8c67b3090497f27c7ed5b03547c1950750528e868631594d087bf9
data/README.md CHANGED
@@ -81,7 +81,8 @@ Keep Ruby and gem versions at or below what GitLab itself runs (see
81
81
  One design goal of this little Rails engine was to keep it free of any dependencies, that GitLab uses today.
82
82
  Because, tomorrow we might decide to ditch one or the other tech we use today, and Toogle shouldn't break just because GitLab removes `sassc`, as an example (that actually happened during development).
83
83
 
84
- That's why Toogle only depends on the bare basics: `rails`, `sprockets` and `haml`.
84
+ That's why Toogle only depends on the bare basics: `rails` and `haml`.
85
+ It doesn't even use the host's asset pipeline: the engine serves its own CSS and JS files.
85
86
 
86
87
  ### Javascript
87
88
 
@@ -33,25 +33,20 @@ document.addEventListener("alpine:init", () => {
33
33
  definitionsUrl,
34
34
 
35
35
  init() {
36
- const featuresLoaded = this.fetchFeatures();
37
-
38
- const definitionsLoaded = fetch(this.definitionsUrl, {
39
- method: "GET",
40
- headers: {
41
- Accept: "application/json",
42
- },
43
- })
44
- .then((response) => response.json())
45
- .then((data) => {
46
- this.definitions = data;
47
- })
48
- .catch(showFetchError);
36
+ const loading = this.reload();
49
37
 
50
38
  if (shareName) {
51
- Promise.all([featuresLoaded, definitionsLoaded]).then(() =>
39
+ loading.then(() =>
52
40
  this.openDetails(shareName)
53
41
  );
54
42
  }
43
+
44
+ this.onReload = () => this.reload();
45
+ window.addEventListener("reload", this.onReload);
46
+ },
47
+
48
+ destroy() {
49
+ window.removeEventListener("reload", this.onReload);
55
50
  },
56
51
 
57
52
  openDetails(name) {
@@ -119,6 +114,27 @@ document.addEventListener("alpine:init", () => {
119
114
  .catch(showFetchError);
120
115
  },
121
116
 
117
+ fetchDefinitions() {
118
+ return fetch(this.definitionsUrl, {
119
+ method: "GET",
120
+ headers: {
121
+ Accept: "application/json",
122
+ },
123
+ })
124
+ .then((response) => response.json())
125
+ .then((data) => {
126
+ this.definitions = data;
127
+ })
128
+ .catch(showFetchError);
129
+ },
130
+
131
+ reload() {
132
+ const featuresLoaded = this.fetchFeatures();
133
+ const definitionsLoaded = this.fetchDefinitions();
134
+
135
+ return Promise.all([featuresLoaded, definitionsLoaded])
136
+ },
137
+
122
138
  // Animates the layout change, e.g. a row moving between the sections.
123
139
  // Only the moving row gets a view-transition-name (see the view), so the
124
140
  // browser snapshots one row, not all ~700 — keeping toggles fast no
@@ -246,4 +262,31 @@ document.addEventListener("alpine:init", () => {
246
262
  },
247
263
  },
248
264
  }));
265
+
266
+ Alpine.data("gitBranchWatcher", (branch, branchUrl) => ({
267
+ branch,
268
+ branchUrl,
269
+
270
+ init() {
271
+ this.$watch("branch", () => {
272
+ this.$dispatch("reload")
273
+ });
274
+
275
+ window.addEventListener("focus", () => this.fetchCurrentBranch())
276
+ },
277
+
278
+ fetchCurrentBranch() {
279
+ fetch(this.branchUrl, {
280
+ method: "GET",
281
+ headers: {
282
+ Accept: "application/json",
283
+ },
284
+ })
285
+ .then((response) => response.json())
286
+ .then((data) => {
287
+ this.branch = data;
288
+ })
289
+ .catch(showFetchError);
290
+ },
291
+ }))
249
292
  });
@@ -1,10 +1,10 @@
1
- @import "variables";
1
+ @import "variables.css";
2
2
 
3
- @import "elements";
4
- @import "layout";
5
- @import "utilities";
3
+ @import "elements.css";
4
+ @import "layout.css";
5
+ @import "utilities.css";
6
6
 
7
- @import "components/toggle";
7
+ @import "components/toggle.css";
8
8
 
9
9
  [x-cloak] {
10
10
  display: none !important;
@@ -51,11 +51,18 @@ body {
51
51
 
52
52
  > footer {
53
53
  display: flex;
54
- justify-content: right;
54
+ justify-content: space-between;
55
55
  align-items: center;
56
56
  gap: 2em;
57
57
  padding: 1rem;
58
58
  font-size: smaller;
59
+
60
+ code {
61
+ color: var(--color-text-muted);
62
+ overflow: hidden;
63
+ text-overflow: ellipsis;
64
+ white-space: nowrap;
65
+ }
59
66
  }
60
67
  }
61
68
 
@@ -0,0 +1,29 @@
1
+ module Toogle
2
+ # Serves our own CSS and JS instead of going through the host's asset
3
+ # pipeline: hosts that only serve precompiled assets, or whose web server
4
+ # answers /assets/* itself, never deliver them otherwise.
5
+ class AssetsController < ApplicationController
6
+ ROOT = Engine.root.join("app/assets")
7
+
8
+ # Only these files are served, so no path from the URL ever reaches the
9
+ # filesystem.
10
+ FILES = Dir[ROOT.join("{stylesheets,javascript}/**/*.{css,js}")]
11
+ .index_by { Pathname(_1).relative_path_from(ROOT).to_s }
12
+
13
+ # Static public files: nothing to protect, and Rails' cross-origin check
14
+ # would otherwise refuse to serve JavaScript to a <script> tag.
15
+ skip_forgery_protection
16
+
17
+ def show
18
+ file = FILES[params[:path]]
19
+ return head :not_found unless file
20
+
21
+ # Send the content, not the file: GitLab enables X-Sendfile, which hands
22
+ # file bodies to Workhorse, and Workhorse may run on another host (as in
23
+ # Caproni) where this path doesn't exist.
24
+ send_data File.read(file),
25
+ type: Mime::Type.lookup_by_extension(File.extname(file).delete(".")),
26
+ disposition: :inline
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module Toogle
2
+ class BranchesController < ApplicationController
3
+ def show
4
+ render json: GitRepo.current_branch.to_json
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Toogle
2
+ class GitRepo
3
+ def self.current_branch
4
+ `git rev-parse --abbrev-ref HEAD`.chomp
5
+ end
6
+ end
7
+ end
@@ -11,8 +11,8 @@
11
11
  %title Feature flags
12
12
  = csrf_meta_tags
13
13
  = csp_meta_tag
14
- = stylesheet_link_tag "toogle/application", media: "all"
15
- = javascript_include_tag 'toogle/application'
14
+ %link(rel="stylesheet" media="all" href="#{asset_file_path("stylesheets/toogle/application.css", v: Toogle::VERSION)}")
15
+ %script(src="#{asset_file_path("javascript/toogle/application.js", v: Toogle::VERSION)}")
16
16
  %script(defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js")
17
17
 
18
18
  %body
@@ -56,5 +56,6 @@
56
56
  = yield
57
57
 
58
58
  %footer
59
+ %code(x-data="gitBranchWatcher(#{Toogle::GitRepo.current_branch.to_json}, '#{branch_url}')" x-text="branch" title="Current git branch")
59
60
  %a(href="https://gitlab.com/thutterer/toogle" target="_blank")
60
61
  = Toogle::VERSION
data/config/routes.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  Toogle::Engine.routes.draw do
2
+ get "assets/*path", to: "assets#show", format: false, as: :asset_file
3
+
4
+ resource :branch, only: %i[show]
5
+
2
6
  resources :definitions, only: %i[index]
3
7
 
4
8
  # Keep this line last as it matches any URL
@@ -1,3 +1,3 @@
1
1
  module Toogle
2
- VERSION = "1.0.2"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gdk-toogle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Hutterer
@@ -90,7 +90,6 @@ files:
90
90
  - MIT-LICENSE
91
91
  - README.md
92
92
  - Rakefile
93
- - app/assets/config/toogle_manifest.js
94
93
  - app/assets/javascript/toogle/application.js
95
94
  - app/assets/stylesheets/toogle/application.css
96
95
  - app/assets/stylesheets/toogle/components/toggle.css
@@ -99,10 +98,13 @@ files:
99
98
  - app/assets/stylesheets/toogle/utilities.css
100
99
  - app/assets/stylesheets/toogle/variables.css
101
100
  - app/controllers/toogle/application_controller.rb
101
+ - app/controllers/toogle/assets_controller.rb
102
+ - app/controllers/toogle/branches_controller.rb
102
103
  - app/controllers/toogle/definitions_controller.rb
103
104
  - app/controllers/toogle/features_controller.rb
104
105
  - app/models/toogle/definition.rb
105
106
  - app/models/toogle/feature.rb
107
+ - app/services/toogle/git_repo.rb
106
108
  - app/views/layouts/toogle/application.html.haml
107
109
  - app/views/toogle/features/_details_button.html.haml
108
110
  - app/views/toogle/features/index.html.haml
@@ -132,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
134
  - !ruby/object:Gem::Version
133
135
  version: '0'
134
136
  requirements: []
135
- rubygems_version: 4.0.16
137
+ rubygems_version: 4.0.22
136
138
  specification_version: 4
137
139
  summary: Toogle toggles feature flags
138
140
  test_files: []
@@ -1,2 +0,0 @@
1
- //= link toogle/application.css
2
- //= link toogle/application.js