strada-rails 0.0.1 → 0.0.3

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: 7ba041b765b36676475aae45a8ed1c4a396a82384f3c920dd9b5da13c8ba354d
4
- data.tar.gz: c2982c99194493b435c821f44695d8812bd2418d656648d1b70eee0060209531
3
+ metadata.gz: c249357d91c182e542afecfe632377bf3a822fe8fbb698e467ee384db79ab77f
4
+ data.tar.gz: 3605854dfcb0eb32ce5717c0494547d4908f13e6429d14ba39171932fc9c57d1
5
5
  SHA512:
6
- metadata.gz: 790e4154a5b8a7233559253412fe44fe72bd1e8bff0a142f1b6ed0df21a9715b8a95e1536f1bedb4a0d0504c41b0645099c75561c4d0487736465089a0dda9ee
7
- data.tar.gz: 3710682666422aaafcb85c924a568deacde3b9cd7383848ac79212fbbd942778538e2db64fb6cc3f7bb03f3efb6082cdc2734de98fe651fc27585f95777ae2fe
6
+ metadata.gz: 24642340e1759c81dd49153ccbcbb43ed81efcf4efefcaacc8e8f71c144202d5bc674ebbe8924eea2d624f21090286d02cfb81c4d7b6742c40b8950ed346b900
7
+ data.tar.gz: 6495fc53530f6323186e47a42fe01736384b750140cb9780fb6a78de3d5558e8575174e3e2b3e196c1947dc180492295a6e098629983f31a9bb648c2bbc24d91
data/.DS_Store ADDED
Binary file
@@ -4,7 +4,7 @@
4
4
  * Hide the submit button when the "form" component is registered.
5
5
  */
6
6
  [data-bridge-components~=form] [data-controller~=bridge--form] [type=submit] {
7
- display: none
7
+ display: none;
8
8
  }
9
9
 
10
10
  /*
@@ -14,9 +14,16 @@
14
14
  display: none;
15
15
  }
16
16
 
17
+ /*
18
+ * Hide when the "menu" component is registered.
19
+ */
20
+ [data-bridge-components~=menu] [data-controller~=bridge--menu] {
21
+ display: none;
22
+ }
23
+
17
24
  /*
18
25
  * Hide when the "flash-message" component is registered.
19
26
  */
20
27
  [data-bridge-components~=flash-message] [data-controller~=bridge--flash-message] {
21
- display: none
28
+ display: none;
22
29
  }
@@ -0,0 +1,46 @@
1
+ import { BridgeComponent } from "@hotwired/strada"
2
+ import { BridgeElement } from "@hotwired/strada"
3
+
4
+ // Example
5
+ // https://github.com/lazaronixon/strada-rails/wiki/Menu
6
+ export default class extends BridgeComponent {
7
+ static component = "menu"
8
+ static targets = [ "title", "item" ]
9
+
10
+ show(event) {
11
+ if (this.enabled) {
12
+ event.stopImmediatePropagation()
13
+ this.notifyBridgeToDisplayMenu(event)
14
+ }
15
+ }
16
+
17
+ notifyBridgeToDisplayMenu(event) {
18
+ const title = new BridgeElement(this.titleTarget).title
19
+ const items = this.makeMenuItems(this.itemTargets)
20
+
21
+ this.send("display", { title, items }, message => {
22
+ const selectedIndex = message.data.selectedIndex
23
+ const selectedItem = new BridgeElement(this.itemTargets[selectedIndex])
24
+
25
+ selectedItem.click()
26
+ })
27
+ }
28
+
29
+ makeMenuItems(elements) {
30
+ const items = elements.map((element, index) => this.menuItem(element, index))
31
+ const enabledItems = items.filter(item => item)
32
+
33
+ return enabledItems
34
+ }
35
+
36
+ menuItem(element, index) {
37
+ const bridgeElement = new BridgeElement(element)
38
+
39
+ if (bridgeElement.disabled) return null
40
+
41
+ return {
42
+ title: bridgeElement.title,
43
+ index: index
44
+ }
45
+ }
46
+ }
@@ -5,14 +5,17 @@ export default class extends BridgeComponent {
5
5
 
6
6
  connect() {
7
7
  super.connect()
8
- this.notifyBridgeOfConnect()
8
+
9
+ if (this.bridgeElement.enabled) {
10
+ this.notifyBridgeOfConnect()
11
+ }
9
12
  }
10
13
 
11
14
  notifyBridgeOfConnect() {
12
15
  const title = this.bridgeElement.title
13
16
 
14
17
  this.send("connect", { title }, () => {
15
- this.element.click()
18
+ this.bridgeElement.click()
16
19
  })
17
20
  }
18
21
  }
@@ -0,0 +1,30 @@
1
+ APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
2
+
3
+ HIDE_ON_MOBILE_STYLE = <<-HTML.chomp
4
+ <% if turbo_native_app? %>
5
+ <style>.hide-on-mobile { display: none; }</style>
6
+ <% end %>
7
+ HTML
8
+
9
+ destination = Pathname(destination_root)
10
+
11
+ say "Copy bridge controllers"
12
+ directory "#{__dir__}/app/javascript/controllers/bridge", "app/javascript/controllers/bridge"
13
+
14
+ say "Update stimulus manifest"
15
+ rails_command "stimulus:manifest:update"
16
+
17
+ say "Copy strada stylesheet"
18
+ copy_file "#{__dir__}/app/assets/stylesheets/strada.css", "app/assets/stylesheets/strada.css"
19
+
20
+ unless destination.join("app/assets/application.css").exist?
21
+ if (stylesheets = Dir.glob "#{destination_root}/app/assets/stylesheets/application.*.{scss,css}").length > 0
22
+ insert_into_file stylesheets.first.to_s, %(@import 'strada.css';)
23
+ end
24
+ end
25
+
26
+ say "Add hide-on-mobile style in application layout"
27
+ insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n\n#{HIDE_ON_MOBILE_STYLE}", before: /\s*<\/head>/
28
+
29
+ say "Install Strada"
30
+ run "bun add @hotwired/stimulus"
@@ -6,12 +6,20 @@ HIDE_ON_MOBILE_STYLE = <<-HTML.chomp
6
6
  <% end %>
7
7
  HTML
8
8
 
9
+ destination = Pathname(destination_root)
10
+
9
11
  say "Copy bridge controllers"
10
12
  directory "#{__dir__}/app/javascript/controllers/bridge", "app/javascript/controllers/bridge"
11
13
 
12
14
  say "Copy strada stylesheet"
13
15
  copy_file "#{__dir__}/app/assets/stylesheets/strada.css", "app/assets/stylesheets/strada.css"
14
16
 
17
+ unless destination.join("app/assets/application.css").exist?
18
+ if (stylesheets = Dir.glob "#{destination_root}/app/assets/stylesheets/application.*.{scss,css}").length > 0
19
+ insert_into_file stylesheets.first.to_s, %(@import 'strada.css';)
20
+ end
21
+ end
22
+
15
23
  say "Add hide-on-mobile style in application layout"
16
24
  insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n\n#{HIDE_ON_MOBILE_STYLE}", before: /\s*<\/head>/
17
25
 
@@ -6,12 +6,23 @@ HIDE_ON_MOBILE_STYLE = <<-HTML.chomp
6
6
  <% end %>
7
7
  HTML
8
8
 
9
+ destination = Pathname(destination_root)
10
+
9
11
  say "Copy bridge controllers"
10
12
  directory "#{__dir__}/app/javascript/controllers/bridge", "app/javascript/controllers/bridge"
11
13
 
14
+ say "Update stimulus manifest"
15
+ rails_command "stimulus:manifest:update"
16
+
12
17
  say "Copy strada stylesheet"
13
18
  copy_file "#{__dir__}/app/assets/stylesheets/strada.css", "app/assets/stylesheets/strada.css"
14
19
 
20
+ unless destination.join("app/assets/application.css").exist?
21
+ if (stylesheets = Dir.glob "#{destination_root}/app/assets/stylesheets/application.*.{scss,css}").length > 0
22
+ insert_into_file stylesheets.first.to_s, %(@import 'strada.css';)
23
+ end
24
+ end
25
+
15
26
  say "Add hide-on-mobile style in application layout"
16
27
  insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n\n#{HIDE_ON_MOBILE_STYLE}", before: /\s*<\/head>/
17
28
 
@@ -1,3 +1,3 @@
1
1
  module Strada
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,12 +2,26 @@ def run_strada_install_template(path)
2
2
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
3
3
  end
4
4
 
5
+ def install_strada_with_importmap?
6
+ Rails.root.join("config/importmap.rb").exist?
7
+ end
8
+
9
+ def install_strada_with_bun?
10
+ Rails.root.join("package.json").exist? && Rails.root.join("bun.config.js").exist?
11
+ end
12
+
13
+ def install_strada_with_node?
14
+ Rails.root.join("package.json").exist? && !Rails.root.join("bun.config.js").exist?
15
+ end
16
+
5
17
  namespace :strada do
6
18
  desc "Install Strada into the app"
7
19
  task :install do
8
- if Rails.root.join("config/importmap.rb").exist?
20
+ if install_strada_with_importmap?
9
21
  Rake::Task["strada:install:importmap"].invoke
10
- elsif Rails.root.join("package.json").exist?
22
+ elsif install_strada_with_bun?
23
+ Rake::Task["strada:install:bun"].invoke
24
+ elsif install_strada_with_node?
11
25
  Rake::Task["strada:install:node"].invoke
12
26
  else
13
27
  puts "You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem."
@@ -24,5 +38,10 @@ namespace :strada do
24
38
  task :node do
25
39
  run_strada_install_template "strada_with_node"
26
40
  end
41
+
42
+ desc "Install Stimulus on an app running bun"
43
+ task :bun do
44
+ run_strada_install_template "strada_with_bun"
45
+ end
27
46
  end
28
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strada-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-29 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".DS_Store"
34
35
  - CHANGELOG.md
35
36
  - CODE_OF_CONDUCT.md
36
37
  - LICENSE.txt
@@ -55,7 +56,9 @@ files:
55
56
  - lib/install/app/assets/stylesheets/strada.css
56
57
  - lib/install/app/javascript/controllers/bridge/flash_message_controller.js
57
58
  - lib/install/app/javascript/controllers/bridge/form_controller.js
59
+ - lib/install/app/javascript/controllers/bridge/menu_controller.js
58
60
  - lib/install/app/javascript/controllers/bridge/nav_button_controller.js
61
+ - lib/install/strada_with_bun.rb
59
62
  - lib/install/strada_with_importmap.rb
60
63
  - lib/install/strada_with_node.rb
61
64
  - lib/strada-rails.rb
@@ -83,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
86
  - !ruby/object:Gem::Version
84
87
  version: '0'
85
88
  requirements: []
86
- rubygems_version: 3.4.19
89
+ rubygems_version: 3.4.20
87
90
  signing_key:
88
91
  specification_version: 4
89
92
  summary: Create fully native controls, driven by your web app.