railbar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 632ac5aca394d7c9addafb8836fdccc465f20e813535c7d36ed9a4e94848b4fe
4
+ data.tar.gz: f323837e55c0ed0a9ce3f07752385a7de45bbb8c58f67933a2074cdb1f5a8090
5
+ SHA512:
6
+ metadata.gz: b5989fd1cb1d436ca320a6847c477cf171795a0f80c5bdd845ca25783ebded55b8c7723210ea7f95f728500a23f37a280746be2fca73d5a0d805d9d944b5c5e8
7
+ data.tar.gz: f11b9897fcc8d29743ce08d0dca2298771961658a519b13364091ef459a61097bc3827f55f102cc3d040c14fc776246a18df96a16d5a78799b3dad6a80765d98
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Railbar
2
+
3
+ in the past it happend quite often to me that I confused any staging/test or even production system with my local development system because they look usually pretty the same. Luckily not a lot of harm done except for some lost time and confusion so far.
4
+ That's why I came up with the idea of **Railbar** for Ruby on Rails, a HTML rendered bar that makes it obvious which system you are currently working on. And when creating such a bar, why not adding some status checks like for Turbo or Stimulus with it?
5
+
6
+ ## Installation
7
+
8
+ Add this line to your Rails application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'railbar'
12
+ ```
13
+
14
+ Optionally only in your development group.
15
+
16
+ ```bash
17
+ $ bundle install
18
+ ```
19
+
20
+ finally add the bar to your layout file, e.g. `app/views/layouts/application.html.erb`
21
+
22
+ ```erb
23
+ ...
24
+ <%= railbar %>
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ coming ...
@@ -0,0 +1,7 @@
1
+ module Railbar
2
+ class TurboFrameStatusController < TurboStatusBaseController
3
+ def show
4
+ render partial: "railbar/turbo_frame_status_ok"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module Railbar
2
+ class TurboStatusBaseController < ActionController::Base
3
+ before_action :turbo_only!
4
+
5
+ private
6
+ def turbo_only!
7
+ unless turbo_frame_request? || turbo_stream_request?
8
+ raise ActionController::RoutingError, "This endpoint is only accessible via Turbo"
9
+ end
10
+ end
11
+
12
+ def turbo_stream_request?
13
+ request.format.turbo_stream?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ module Railbar
2
+ class TurboStreamFormStatusController < TurboStatusBaseController
3
+ skip_before_action :verify_authenticity_token
4
+ def update
5
+ render turbo_stream: turbo_stream.replace("railbar-turbo-stream-post-status", partial: "railbar/turbo_stream_form_status_ok")
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Railbar::ApplicationHelper
2
+ def railbar
3
+ rails_env = Rails.env
4
+ rails_version = Rails.version
5
+ rails_host = request.host
6
+ locals = { rails_env: rails_env,
7
+ rails_host: rails_host,
8
+ rails_version: rails_version }
9
+ render partial: "railbar/railbar", locals: locals
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ <script>
2
+ var items = document.querySelectorAll('railbar item');
3
+
4
+ items.forEach((item) => {
5
+ if (item.textContent.trim() === 'JS') {
6
+ item.className = 'ok';
7
+ }
8
+ });
9
+
10
+ </script>
@@ -0,0 +1,22 @@
1
+ <railbar>
2
+ <brand>🛤️ <a href="https://github.com/mtnstar/railbar" target="_blank">Railbar</a></brand>
3
+ <item class="primary"><%= rails_host %></item>
4
+ <item class="primary"><span class="railbar-rails-env"><%= rails_env %></item>
5
+ <item>Rails <%= rails_version %></item>
6
+ <item>Ruby <%= RUBY_VERSION %></item>
7
+ <item class="nok">JS</item>
8
+ <%= turbo_frame_tag "railbar-turbo-frame-status", src: "/railbar/turbo_frame_status" do %>
9
+ <item class="nok">Turbo Frames</item>
10
+ <% end %>
11
+ <item class="primary">Turbo Streams:</item>
12
+ <item id="railbar-turbo-stream-post-status" class="nok">Form (POST)</item>
13
+ <%= form_with url: "/railbar/turbo_stream_form_status" do |form| %>
14
+ <%= form.submit "", style: "display: none;", id: "railbar-turbo-stream-post-status-submit" %>
15
+ <% end %>
16
+
17
+ <%# <item class="nok">Stimulus</item> %>
18
+ <%= render "railbar/styling" %>
19
+ <%= render "railbar/js_status" %>
20
+ <%= render "railbar/turbo_stream_load_js" %>
21
+ <%#<%= render "railbar/stimulus_status" %>
22
+ </railbar>
@@ -0,0 +1,29 @@
1
+ <script>
2
+ document.addEventListener("DOMContentLoaded", function () {
3
+ let retryCount = 0;
4
+ const maxRetries = 20;
5
+ const checkStimulus = setInterval(function () {
6
+ if (typeof Stimulus !== "undefined") {
7
+ console.log("Stimulus is loaded and available!");
8
+ clearInterval(checkStimulus);
9
+ const application = Stimulus.start();
10
+ console.log("Stimulus application started.");
11
+
12
+ application.register("railbar_stimulus_status", class extends Stimulus.Controller {
13
+ connect() {
14
+ const items = this.element.querySelectorAll("railbar item");
15
+ items.forEach((item) => {
16
+ if (item.textContent.trim() === "Stimulus") {
17
+ item.className = "ok";
18
+ }
19
+ });
20
+ }
21
+ });
22
+ } else if (retryCount >= maxRetries) {
23
+ console.error("Stimulus could not be loaded after multiple attempts.");
24
+ clearInterval(checkStimulus); // Stop checking
25
+ }
26
+ retryCount++;
27
+ }, 100); // Check every 100ms
28
+ });
29
+ </script>
@@ -0,0 +1,47 @@
1
+ <style>
2
+ railbar {
3
+ padding: 10px;
4
+ width: 100%;
5
+ font-size: 14px;
6
+ font-family: Arial, sans-serif;
7
+ border-bottom: 0.75px solid grey;
8
+ display: block;
9
+ }
10
+
11
+ railbar brand a {
12
+ font-weight: bold;
13
+ text-decoration: none;
14
+ color: #212529;
15
+ }
16
+
17
+ .railbar-rails-env {
18
+ text-transform: uppercase;
19
+ }
20
+
21
+ railbar item {
22
+ background-color: #f8f9fa;
23
+ display: inline-block;
24
+ padding: .35em .65em;
25
+ font-weight: 700;
26
+ color: #212529;
27
+ text-align: center;
28
+ white-space: nowrap;
29
+ vertical-align: baseline;
30
+ border-radius: .25rem;
31
+ }
32
+
33
+ railbar item.primary {
34
+ background-color: #6c757d;
35
+ color: #fff;
36
+ }
37
+
38
+ railbar item.nok {
39
+ background-color: #dc3545;
40
+ color: #fff;
41
+ }
42
+
43
+ railbar item.ok {
44
+ background-color: #28a745;
45
+ color: #fff;
46
+ }
47
+ </style>
@@ -0,0 +1,3 @@
1
+ <%= turbo_frame_tag "railbar-turbo-frame-status" do %>
2
+ <item class="ok">Turbo Frames</item>
3
+ <% end %>
@@ -0,0 +1 @@
1
+ <item id="railbar-turbo-stream-form-status" class="ok">Form (POST)</item>
@@ -0,0 +1,24 @@
1
+ <script>
2
+ if (!window.RailbarTurboStreamStatus) {
3
+ const RailbarTurboStreamStatus = (() => {
4
+ function submitTurboStreamStatusForm() {
5
+ document.getElementById("railbar-turbo-stream-post-status-submit").click();
6
+ }
7
+
8
+ function init() {
9
+ submitTurboStreamStatusForm();
10
+ document.addEventListener("turbo:load", () => {
11
+ submitTurboStreamStatusForm();
12
+ })
13
+ }
14
+
15
+ return {
16
+ init
17
+ };
18
+ })();
19
+
20
+ window.addEventListener("load", RailbarTurboStreamStatus.init);
21
+ }
22
+
23
+ </script>
24
+
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ namespace "railbar" do
3
+ get "turbo_frame_status", to: "turbo_frame_status#show"
4
+ post "turbo_stream_form_status", to: "turbo_stream_form_status#update"
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ module Railbar
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Railbar
4
+
5
+ initializer "railbar.helpers" do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ helper Railbar::ApplicationHelper
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Railbar
2
+ VERSION = "0.1.0"
3
+ end
data/lib/railbar.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "railbar/version"
4
+ require "railbar/engine"
5
+
6
+ module Railbar
7
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railbar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mountain Star
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ description: A status bar for development and testing rails environments to distinguish
28
+ between development, staging, and production environments and show status of turbo/hotwire
29
+ email:
30
+ - github@mtnstar.net
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - app/controllers/railbar/turbo_frame_status_controller.rb
37
+ - app/controllers/railbar/turbo_status_base_controller.rb
38
+ - app/controllers/railbar/turbo_stream_form_status_controller.rb
39
+ - app/helpers/railbar/application_helper.rb
40
+ - app/views/railbar/_js_status.html.erb
41
+ - app/views/railbar/_railbar.html.erb
42
+ - app/views/railbar/_stimulus_status.html.erb
43
+ - app/views/railbar/_styling.html.erb
44
+ - app/views/railbar/_turbo_frame_status_ok.html.erb
45
+ - app/views/railbar/_turbo_stream_form_status_ok.html.erb
46
+ - app/views/railbar/_turbo_stream_load_js.html.erb
47
+ - config/routes.rb
48
+ - lib/railbar.rb
49
+ - lib/railbar/engine.rb
50
+ - lib/railbar/version.rb
51
+ homepage: https://github.com/mtnstar/railbar
52
+ licenses: []
53
+ metadata:
54
+ homepage_uri: https://github.com/mtnstar/railbar
55
+ source_code_uri: https://github.com/mtnstar/railbar
56
+ changelog_uri: https://github.com/mtnstar/railbar/blob/main/CHANGELOG.md
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 3.0.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.5.23
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A status bar for Rails development.
76
+ test_files: []