wrap_it_ruby 0.1.2 → 0.2.0

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: 546061b459f946a814bf75744300a927d749c2c33e73d06ccedddadce8ae4322
4
- data.tar.gz: d8a6befe95c7205adc5fbe077220860758e78f0e34a2b7cc85ed49c50646cd05
3
+ metadata.gz: 8ce1f71d5f276d68be720746927f8329d7bc67b7a10feead3c3192f12cc4e419
4
+ data.tar.gz: c66c7abbdd059a99148798242cc0796694410f98cbd96dec504e7bf1ee1342d8
5
5
  SHA512:
6
- metadata.gz: 044ff45b60b4f3ffa7fa63f41069f35ffcd409942e04337a2f89423c4e0d87921f1f3c6f4f78882936b137e0605623b05ac8647dc559694ea9931663bb1d2b84
7
- data.tar.gz: 5f2864d543e079bb5cd1fc26a44cc003466d3be0201c3274c66d84888d8542cee7d0d981e4f898d218358ecaa56927dab8c12ca6b0e2d8448208926cc7e03b05
6
+ metadata.gz: d3a604c19cba59629d6714be6f04ee0a5481578be2dd4de4e8c40225521dd6c1408ea4f6ddd6702a957938273db2bc1350fa881ffbdcb568187c87e762977138
7
+ data.tar.gz: 5583c57ac4793d85d57d96d04dab4f0e984358485e366bb311b089ac7187b1dee34ded804cacc4f5e15999c214ff0ef97559cfe88689969253b2dad352d7676f
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WrapItRuby
4
- class ProxyController < ApplicationController
4
+ class ProxyController < ::ApplicationController
5
+ include WrapItRuby::MenuHelper
6
+ include WrapItRuby::IframeHelper
7
+
5
8
  def show
6
9
  get_menu_item.then do |menu_item|
7
10
  target_path = request.path.delete_prefix(menu_item["route"])
@@ -1,8 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
1
  module WrapItRuby
4
2
  module IframeHelper
5
- def iframe(**)
3
+ def iframe_wrapper(**)
6
4
  tag.div(class: "iframe-wrapper") do
7
5
  tag.iframe(**)
8
6
  end
@@ -1,9 +1,58 @@
1
- # frozen_string_literal: true
1
+ require "yaml"
2
2
 
3
3
  module WrapItRuby
4
- # View helper that exposes menu_config and related queries to templates.
5
- # Delegates to WrapItRuby::Menu for the actual loading logic.
4
+ # Loads and queries the menu configuration from the host app's
5
+ # config/menu.yml file.
6
+ #
7
+ # Can be used as a module (extend self) or included in controllers/helpers.
8
+ #
9
+ # The render_menu method requires the view context (ComponentHelper from
10
+ # rails-active-ui must be available), so call it from views/layouts, not
11
+ # as a bare module method.
12
+ #
6
13
  module MenuHelper
7
- include WrapItRuby::Menu
14
+ def menu_config = load_menu
15
+
16
+ # Renders the sidebar menu using rails-active-ui component helpers.
17
+ # Must be called from a view context where ComponentHelper is included.
18
+ def render_menu
19
+ Menu(attached: true) {
20
+ WrapItRuby::MenuHelper.menu_config.each do |group|
21
+ if group["items"]
22
+ group["items"].each do |item|
23
+ MenuItem(href: item["route"]) { text item["label"] }
24
+ end
25
+ else
26
+ MenuItem(href: group["route"]) { text group["label"] }
27
+ end
28
+ end
29
+ }
30
+ end
31
+
32
+ def all_menu_items
33
+ menu_config.flat_map { |item| [item, *item.fetch("items", [])] }
34
+ end
35
+
36
+ def all_proxy_menu_items
37
+ all_menu_items.select { |item| item["type"] == "proxy" }
38
+ end
39
+
40
+ def proxy_paths
41
+ all_menu_items
42
+ .select { |item| item["type"] == "proxy" }
43
+ .map { |item| item["route"] }
44
+ end
45
+
46
+ extend self
47
+
48
+ private
49
+
50
+ def menu_file
51
+ Rails.root.join("config/menu.yml")
52
+ end
53
+
54
+ def load_menu
55
+ @menu_config ||= YAML.load_file(menu_file)
56
+ end
8
57
  end
9
58
  end
data/config/routes.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  WrapItRuby::Engine.routes.draw do
4
- root "home#index"
5
-
6
4
  get "/*path", to: "proxy#show", constraints: ->(req) {
7
- WrapItRuby::Menu.proxy_paths.any? { |p| req.path.start_with?(p) }
5
+ WrapItRuby::MenuHelper.proxy_paths.any? { |p| req.path.start_with?(p) }
8
6
  }
9
7
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ui"
3
4
  require "wrap_it_ruby/middleware/proxy_middleware"
4
5
  require "wrap_it_ruby/middleware/root_relative_proxy_middleware"
5
6
  require "wrap_it_ruby/middleware/script_injection_middleware"
@@ -34,6 +35,19 @@ module WrapItRuby
34
35
  initializer "wrap_it_ruby.assets" do |app|
35
36
  app.config.assets.paths << Engine.root.join("app/assets/javascripts")
36
37
  app.config.assets.paths << Engine.root.join("app/assets/stylesheets")
38
+
39
+ # rails-active-ui ships stylesheets.css directly in app/assets/
40
+ app.config.assets.paths << Ui::Engine.root.join("app/assets")
41
+ end
42
+
43
+ # Make engine helpers (MenuHelper, IframeHelper) available in host app views.
44
+ # MenuHelper#render_menu depends on ComponentHelper from rails-active-ui,
45
+ # which is already injected into ActionView by the Ui engine.
46
+ initializer "wrap_it_ruby.helpers" do
47
+ ActiveSupport.on_load(:action_view) do
48
+ include WrapItRuby::MenuHelper
49
+ include WrapItRuby::IframeHelper
50
+ end
37
51
  end
38
52
  end
39
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WrapItRuby
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/wrap_it_ruby.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "wrap_it_ruby/version"
4
- require "wrap_it_ruby/menu"
5
4
  require "wrap_it_ruby/engine"
6
5
 
7
6
  module WrapItRuby
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrap_it_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Kidd
@@ -105,23 +105,17 @@ files:
105
105
  - Rakefile
106
106
  - app/assets/javascripts/wrap_it_ruby/interception.js
107
107
  - app/assets/stylesheets/wrap_it_ruby/application.css
108
- - app/controllers/wrap_it_ruby/application_controller.rb
109
- - app/controllers/wrap_it_ruby/home_controller.rb
110
108
  - app/controllers/wrap_it_ruby/proxy_controller.rb
111
109
  - app/helpers/wrap_it_ruby/iframe_helper.rb
112
110
  - app/helpers/wrap_it_ruby/menu_helper.rb
113
111
  - app/javascript/wrap_it_ruby/controllers/iframe_proxy_controller.js
114
- - app/views/wrap_it_ruby/home/index.html.erb
115
- - app/views/wrap_it_ruby/layouts/application.html.erb
116
112
  - app/views/wrap_it_ruby/proxy/show.html.ruby
117
- - app/views/wrap_it_ruby/shared/_navbar.html.ruby
118
113
  - config/importmap.rb
119
114
  - config/routes.rb
120
115
  - lib/generators/wrap_it_ruby/install/install_generator.rb
121
116
  - lib/generators/wrap_it_ruby/install/templates/menu.yml
122
117
  - lib/wrap_it_ruby.rb
123
118
  - lib/wrap_it_ruby/engine.rb
124
- - lib/wrap_it_ruby/menu.rb
125
119
  - lib/wrap_it_ruby/middleware/proxy_middleware.rb
126
120
  - lib/wrap_it_ruby/middleware/root_relative_proxy_middleware.rb
127
121
  - lib/wrap_it_ruby/middleware/script_injection_middleware.rb
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WrapItRuby
4
- class ApplicationController < ::ApplicationController
5
- include WrapItRuby::Menu
6
-
7
- layout "wrap_it_ruby/application"
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WrapItRuby
4
- class HomeController < ApplicationController
5
- def index
6
- end
7
- end
8
- end
@@ -1 +0,0 @@
1
- <p>Welcome, <%= current_user&.display_name || current_user&.uid %>.</p>
@@ -1,30 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title><%= content_for(:title) || site_title %></title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <meta name="apple-mobile-web-app-capable" content="yes">
7
- <meta name="application-name" content="<%= site_title %>">
8
- <meta name="mobile-web-app-capable" content="yes">
9
- <%= csrf_meta_tags %>
10
- <%= csp_meta_tag %>
11
-
12
- <%= yield :head %>
13
-
14
- <link rel="icon" href="/icon.png" type="image/png">
15
- <link rel="icon" href="/icon.svg" type="image/svg+xml">
16
- <link rel="apple-touch-icon" href="/icon.png">
17
-
18
- <%= stylesheet_link_tag "semantic.min.css", "data-turbo-track": "reload" %>
19
- <%= stylesheet_link_tag "wrap_it_ruby/application", "data-turbo-track": "reload" %>
20
- <%= fui_javascript_tags %>
21
- <%= javascript_importmap_tags %>
22
- </head>
23
-
24
- <body>
25
- <div id="site-wrapper">
26
- <div id="site-menu"><%= render "wrap_it_ruby/shared/navbar" %></div>
27
- <div id="site-content"><%= yield %></div>
28
- </div>
29
- </body>
30
- </html>
@@ -1,11 +0,0 @@
1
- Menu(attached: true) {
2
- WrapItRuby::Menu.menu_config.each do |group|
3
- if group["items"]
4
- group["items"].each do |item|
5
- MenuItem(href: item["route"]) { text item["label"] }
6
- end
7
- else
8
- MenuItem(href: group["route"]) { text group["label"] }
9
- end
10
- end
11
- }
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaml"
4
-
5
- module WrapItRuby
6
- # Loads and queries the menu configuration from the host app's
7
- # config/menu.yml file.
8
- #
9
- # Can be used as a module (extend self) or included in controllers/helpers.
10
- #
11
- module Menu
12
- def menu_config = load_menu
13
-
14
- def all_menu_items
15
- menu_config.flat_map { |item| [item, *item.fetch("items", [])] }
16
- end
17
-
18
- def all_proxy_menu_items
19
- all_menu_items.select { |item| item["type"] == "proxy" }
20
- end
21
-
22
- def proxy_paths
23
- all_menu_items
24
- .select { |item| item["type"] == "proxy" }
25
- .map { |item| item["route"] }
26
- end
27
-
28
- extend self
29
-
30
- private
31
-
32
- def menu_file
33
- Rails.root.join("config/menu.yml")
34
- end
35
-
36
- def load_menu
37
- @menu_config ||= YAML.load_file(menu_file)
38
- end
39
- end
40
- end