hotwire_native_rails 0.2.0 → 0.3.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: 4a4224784bdab848b3b193b9902b70940618a3d37aa48b9502f5e98756fe4d31
4
- data.tar.gz: cf49ce2b8982ae85ac45032bf39f64b20971f6521e83e9080a417fb0269fd9da
3
+ metadata.gz: c99841c967e01bca985531db7d5cfcc08b4068542a9377d4785accf30df06647
4
+ data.tar.gz: 0347e31a0697276735e135a3992a7827148a42287e7ebb766e153c4bcbb0f054
5
5
  SHA512:
6
- metadata.gz: 92d384f1c486c93494a14e2635739a335e68a599201fcf3642ce1f19986d1d2b951fd7fbfb3a0e85bec69d0bddc45f6b34e0df5c23a7e6aae5c9f5f635c43755
7
- data.tar.gz: 2bf89e359cd0e1518367f32ae7edd349e6aee123ccdd09b4cbb73335d8c113d6b230838f56bee15aee092b4de791615a113eaf90622214807b68a01c83138863
6
+ metadata.gz: aecb1c68523353ca6ffe80e95427fb155fc57a9d8041c71f4c6713767ea371453a3e907e2cec799e298fa1b80cbc5092f806278bd4f9743e88831386107b9f48
7
+ data.tar.gz: 238a0fc863a5e1310c0451169d0fcf32cba2817aa36c99522012c1893b0a87cd55ba690b7f78b29d21ccb43ea58740faf96b12e148b9e2c414613f0c01c9ab35
data/README.md CHANGED
@@ -13,7 +13,7 @@ bundle add hotwire_native_rails
13
13
  Run the generator:
14
14
 
15
15
  ```sh
16
- rails g hotwire_native_rails
16
+ rails g hotwire_native
17
17
  ```
18
18
 
19
19
  ## Usage
@@ -30,10 +30,23 @@ rails g hotwire_native_rails
30
30
  #### Bridge Components
31
31
  - install Hotwire Native Bridge (works with Importmaps and Node)
32
32
  - add default bridge components (`Form`, `Menu`, `Button`)
33
- - `bridge_form_with` - easily apply Bridge Form component
33
+ - add `Nav` (UIMenu) bridge component
34
+ - `bridge_form_with` - easily apply Bridge `Form` component
34
35
 
35
36
  #### Path Configuration
36
37
  - `path_configuration_controller` for `ios` and `android`
37
38
 
39
+ ## Development
40
+
41
+ Make a release to rubygems:
42
+
43
+ ```sh
44
+ # 1. update version in version.rb
45
+ # 2. zip the gem
38
46
  gem build hotwire_native_rails.gemspec
39
- gem push hotwire_native_rails-0.1.0.gem
47
+ # 3. push the zip to rubygems
48
+ gem push hotwire_native_rails-0.2.0.gem
49
+ ```
50
+
51
+ - [Github source](https://github.com/yshmarov/hotwire_native_rails)
52
+ - [Rubygems source](https://rubygems.org/gems/hotwire_native_rails)
@@ -33,6 +33,7 @@ class HotwireNativeGenerator < Rails::Generators::Base
33
33
  copy_file "javascript/controllers/bridge/menu_controller.js", "app/javascript/controllers/bridge/menu_controller.js"
34
34
  copy_file "javascript/controllers/bridge/form_controller.js", "app/javascript/controllers/bridge/form_controller.js"
35
35
  copy_file "javascript/controllers/bridge/overflow_menu_controller.js", "app/javascript/controllers/bridge/overflow_menu_controller.js"
36
+ copy_file "javascript/controllers/bridge/nav_controller.js", "app/javascript/controllers/bridge/nav_controller.js"
36
37
 
37
38
  run "bin/importmap pin @hotwired/stimulus @hotwired/hotwire-native-bridge" if importmaps?
38
39
  run "yarn add @hotwired/stimulus @hotwired/hotwire-native-bridge" if node?
@@ -52,6 +53,10 @@ class HotwireNativeGenerator < Rails::Generators::Base
52
53
  gsub_file "app/views/layouts/application.html.erb", "<html>", "<html <%= platform_identifier %>>"
53
54
  end
54
55
 
56
+ def set_page_title
57
+ gsub_file "app/views/layouts/application.html.erb", /<title>.*<\/title>/, "<title><%= page_title %></title>"
58
+ end
59
+
55
60
  private
56
61
 
57
62
  def importmaps?
@@ -1,5 +1,49 @@
1
1
  class HotwireNative::V1::Ios::PathConfigurationsController < ActionController::Base
2
2
  def show
3
- render json: {}
3
+ render json:
4
+ {
5
+ "settings": {
6
+ "enable_feature_x": true
7
+ },
8
+ "rules": [
9
+ {
10
+ "patterns": [
11
+ "/new$",
12
+ "/edit$",
13
+ "/signin$",
14
+ "/strada-form$"
15
+ ],
16
+ "properties": {
17
+ "context": "modal",
18
+ "pull_to_refresh_enabled": false
19
+ }
20
+ },
21
+ {
22
+ "patterns": [
23
+ "/numbers$"
24
+ ],
25
+ "properties": {
26
+ "view_controller": "numbers"
27
+ }
28
+ },
29
+ {
30
+ "patterns": [
31
+ "/numbers/[0-9]+$"
32
+ ],
33
+ "properties": {
34
+ "view_controller": "numbers_detail",
35
+ "context": "modal"
36
+ }
37
+ },
38
+ {
39
+ "patterns": [
40
+ "^/$"
41
+ ],
42
+ "properties": {
43
+ "presentation": "replace_root"
44
+ }
45
+ },
46
+ ]
47
+ }
4
48
  end
5
49
  end
@@ -1,6 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HotwireNativeHelper
4
+ # before
5
+ # <title><%= content_for(:title) || "My App" %></title>
6
+ # after
7
+ # <title><%= page_title %></title>
8
+ # usage
9
+ # <% content_for :turbo_native_title, "Sign in" %>
10
+ # <% content_for :title, "Sign in | My App" %>
11
+ def page_title
12
+ if turbo_native_app?
13
+ content_for(:turbo_native_title) || content_for(:title) || Rails.application.class.module_parent.name
14
+ else
15
+ content_for(:title) || Rails.application.class.module_parent.name
16
+ end
17
+ end
18
+
4
19
  # forbid zooming on mobile devices
5
20
  def viewport_meta_tag
6
21
  content = ['width=device-width,initial-scale=1']
@@ -0,0 +1,36 @@
1
+ import { BridgeComponent, BridgeElement } from "@hotwired/hotwire-native-bridge"
2
+
3
+ // Docs:
4
+ // https://blog.corsego.com/hotwire-native-ui-menu-dropdown
5
+ export default class extends BridgeComponent {
6
+ static component = "nav"
7
+ static targets = ["item"]
8
+
9
+ connect() {
10
+ super.connect()
11
+
12
+ const items = this.itemTargets.map((item, index) => {
13
+ const itemElement = new BridgeElement(item)
14
+
15
+ return {
16
+ title: itemElement.title,
17
+ image: itemElement.bridgeAttribute("image") ?? "none",
18
+ destructive: item.dataset.turboMethod === "delete",
19
+ state: itemElement.bridgeAttribute("state") ?? "off",
20
+ index
21
+ }
22
+ })
23
+
24
+ const element = this.bridgeElement
25
+ const title = element.bridgeAttribute("title") ?? ""
26
+ const side = element.bridgeAttribute("side") || "left"
27
+ const image = element.bridgeAttribute("image") || "none"
28
+
29
+ this.send("connect", { items, title, image, side }, (message) => {
30
+ const selectedIndex = message.data.selectedIndex
31
+ const selectedItem = new BridgeElement(this.itemTargets[selectedIndex]);
32
+
33
+ selectedItem.click()
34
+ })
35
+ }
36
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HotwireNativeRails
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire_native_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaro Shm
@@ -35,6 +35,7 @@ files:
35
35
  - lib/generators/hotwire_native/templates/javascript/controllers/bridge/button_controller.js
36
36
  - lib/generators/hotwire_native/templates/javascript/controllers/bridge/form_controller.js
37
37
  - lib/generators/hotwire_native/templates/javascript/controllers/bridge/menu_controller.js
38
+ - lib/generators/hotwire_native/templates/javascript/controllers/bridge/nav_controller.js
38
39
  - lib/generators/hotwire_native/templates/javascript/controllers/bridge/overflow_menu_controller.js
39
40
  - lib/generators/hotwire_native/templates/javascript/controllers/bridge/review_prompt_controller.js
40
41
  - lib/generators/hotwire_native/templates/routes/hotwire_native.rb