hotwire_native_rails 0.4.3 → 0.4.4

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: c93be4ec7b1c6d1da2a55b312102a3c9fab902f98d8db6ca563ec3cbb6aae841
4
- data.tar.gz: 255c754a95d230bab1d4875e9a264b361cc7ab18e2b1e63ed1d8a551a8c80d9c
3
+ metadata.gz: 6b64d65dc8f90e19441ff12633025b080fa0a99096dc3d32c2477aeda01780d1
4
+ data.tar.gz: 58c56ca7d31535fdb87028170962e16d28ac589cfde0b7d5b1f04cc7214aa7e9
5
5
  SHA512:
6
- metadata.gz: c4f1b9031c143ff32fba6d2e760e42125eea3aba64b90dfdd465b72284da0c6e8289bde70e2b6ed4ddd2cdb817b0701d3c714511e72f888db34fc1869d16c802
7
- data.tar.gz: dd763fa651b9f7ce2a27256ea641ea541e5e2436f01ed553967f8aff1595ef504b4f816488d8911e93a0730905153ec6ff7fc3e862293a01a693f690c41fb0de
6
+ metadata.gz: 93ce3791ac063e486b1ff7486774f927398d05b99f70681b840bfd6725623e3f6cf7e7a4a60697dee5df7222f5a33c10467908846881e28eda3c656e9eae910e
7
+ data.tar.gz: aa745e677e5099397ef9be5583b10f6ccc765cb2dd6dd5277753ae897409928881321c55ee26ff9ef91529d5566dc14a84e82f949ded6485fe5cc48894f10287
data/README.md CHANGED
@@ -46,7 +46,7 @@ Recommended to use with [my fork of iOS Hotwire Native starter app](https://gith
46
46
  Run the local version of the gem:
47
47
 
48
48
  ```ruby
49
- gem 'hotwire_native_rails', path: '/Users/yaroslavshmarov/Documents/GitHub.nosync/hotwire_native_rails'
49
+ gem 'hotwire_native_rails', path: '/Users/myusername/Documents/GitHub.nosync/hotwire_native_rails'
50
50
  ```
51
51
 
52
52
  Make a release to rubygems:
@@ -56,7 +56,7 @@ Make a release to rubygems:
56
56
  # 2. zip the gem
57
57
  gem build hotwire_native_rails.gemspec
58
58
  # 3. push the zip to rubygems
59
- gem push hotwire_native_rails-0.4.2.gem
59
+ gem push hotwire_native_rails-0.4.0.gem
60
60
  ```
61
61
 
62
62
  - [Github source](https://github.com/yshmarov/hotwire_native_rails)
@@ -2,7 +2,7 @@ class HotwireNativeGenerator < Rails::Generators::Base
2
2
  source_root File.expand_path("templates", __dir__)
3
3
 
4
4
  def add_gems
5
- gem "browser"
5
+ run "bundle add browser"
6
6
  end
7
7
 
8
8
  def copy_files
@@ -50,11 +50,13 @@ class HotwireNativeGenerator < Rails::Generators::Base
50
50
  end
51
51
 
52
52
  def add_css_variants
53
- return add_tailwind_css_variants if tailwind?
53
+ return add_tailwind_3_css_variants if tailwind3?
54
+ return add_tailwind_4_css_variants if tailwind4?
54
55
 
55
56
  add_hotwire_native_css
56
57
  end
57
58
 
59
+ # todo: set it only if tailwindcss
58
60
  def add_platform_identifier
59
61
  gsub_file "app/views/layouts/application.html.erb", "<html>", "<html <%= platform_identifier %>>"
60
62
  end
@@ -73,10 +75,14 @@ class HotwireNativeGenerator < Rails::Generators::Base
73
75
  Rails.root.join("package.json").exist?
74
76
  end
75
77
 
76
- def tailwind?
78
+ def tailwind3?
77
79
  Rails.root.join("config/tailwind.config.js").exist?
78
80
  end
79
81
 
82
+ def tailwind4?
83
+ Rails.root.join("app/assets/tailwind/application.css").exist?
84
+ end
85
+
80
86
  # class="hotwire-native:hidden"
81
87
  # class="non-hotwire-native:hidden"
82
88
  def add_tailwind_css_variants
@@ -93,6 +99,24 @@ class HotwireNativeGenerator < Rails::Generators::Base
93
99
  end
94
100
  end
95
101
 
102
+ def add_tailwind_4_css_variants
103
+ inject_into_file "app/assets/tailwind/application.css", after: "@import 'tailwindcss';\n" do
104
+ <<-CSS
105
+ @custom-variant hotwire-native {
106
+ html[data-hotwire-native] & {
107
+ @slot;
108
+ }
109
+ }
110
+
111
+ @custom-variant non-hotwire-native {
112
+ html:not([data-hotwire-native]) & {
113
+ @slot;
114
+ }
115
+ }
116
+ CSS
117
+ end
118
+ end
119
+
96
120
  # class="hotwire-native:hidden"
97
121
  def add_hotwire_native_css
98
122
  gsub_file "app/views/layouts/application.html.erb", "<body>", "<body class=\"<%= \"hotwire-native\" if turbo_native_app? %>\">"
@@ -8,6 +8,8 @@ module DeviceFormat
8
8
  private
9
9
 
10
10
  def set_variant
11
- request.variant = :mobile if turbo_native_app? || browser.device.mobile?
11
+ # request.variant = :mobile if turbo_native_app? || browser.device.mobile?
12
+ # request.variant = :mobile if browser.device.mobile?
13
+ request.variant = :native if turbo_native_app?
12
14
  end
13
15
  end
@@ -9,11 +9,14 @@ module HotwireNativeHelper
9
9
  # <% content_for :hotwire_native_title, "Sign in" %>
10
10
  # <% content_for :title, "Sign in | My App" %>
11
11
  def page_title
12
- if turbo_native_app?
13
- content_for(:hotwire_native_title) || content_for(:title) || @page_title || Rails.application.class.module_parent.name
14
- else
15
- content_for(:title) || Rails.application.class.module_parent.name
16
- end
12
+ title_options = [
13
+ (content_for(:hotwire_native_title) if turbo_native_app?),
14
+ content_for(:title),
15
+ @page_title,
16
+ Rails.application.class.module_parent.name
17
+ ]
18
+
19
+ title_options.compact.first
17
20
  end
18
21
 
19
22
  # forbid zooming on mobile devices
@@ -30,6 +33,8 @@ module HotwireNativeHelper
30
33
 
31
34
  # link_to 'Next', next_path, data: { turbo_action: replace_if_native }
32
35
  # https://turbo.hotwired.dev/handbook/drive#application-visits
36
+ # caution: if you open a modal on top of the root page, and replace, it will replace the root page.
37
+ # projects#show will replace projects#index => BAD
33
38
  def replace_if_native
34
39
  return 'replace' if turbo_native_app?
35
40
 
@@ -44,6 +49,10 @@ module HotwireNativeHelper
44
49
 
45
50
  # https://github.com/joemasilotti/daily-log/blob/main/rails/app/helpers/form_helper.rb
46
51
  class BridgeFormBuilder < ActionView::Helpers::FormBuilder
52
+ # CAUTION: the submit button has to have a title
53
+ # BAD: f.submit
54
+ # GOOD: f.submit "Save"
55
+ # GOOD: f.submit t('.save')
47
56
  def submit(value = nil, options = {})
48
57
  options[:data] ||= {}
49
58
  options['data-bridge--form-target'] = 'submit'
@@ -52,10 +61,8 @@ module HotwireNativeHelper
52
61
  end
53
62
  end
54
63
 
55
- # CAUTION: the submit button has to have a title
56
- # BAD: f.submit
57
- # GOOD: f.submit "Save"
58
- # GOOD: f.submit t('.save')
64
+ # add additional attributes in html options:
65
+ # <%= bridge_form_with(model: project, html: { data: { turbo_action: "advance" } }) do |form| %>
59
66
  def bridge_form_with(*, **options, &)
60
67
  options[:html] ||= {}
61
68
  options[:html][:data] ||= {}
@@ -2,7 +2,6 @@ import { BridgeComponent } from "@hotwired/hotwire-native-bridge"
2
2
  import { BridgeElement } from "@hotwired/hotwire-native-bridge"
3
3
  // aka Action Sheet
4
4
  // open a menu by clicking an HTML element
5
- // Question - can I have multiple menus on the same page?
6
5
 
7
6
  // Source:
8
7
  // https://github.com/hotwired/hotwire-native-demo/blob/main/public/javascript/controllers/bridge/menu_controller.js
@@ -5,9 +5,11 @@ import { BridgeComponent, BridgeElement } from "@hotwired/hotwire-native-bridge"
5
5
  // https://blog.corsego.com/hotwire-native-ui-menu-dropdown
6
6
 
7
7
  // Example:
8
- // <%= tag.div data: { controller: 'bridge--nav', bridge_side: 'left', bridge_image: 'person.circle' } do %>
9
- // <%= link_to "Users", users_path, data: { bridge__nav_target: 'item', bridge_image: 'person.circle' } %>
10
- // <%= link_to "Tasks", tasks_path, data: { bridge__nav_target: 'item', bridge_image: 'checklist' } %>
8
+ // <% if user_signed_in? %>
9
+ // <%= tag.div data: { controller: 'bridge--nav', bridge_side: 'left', bridge_image: 'person.circle' } do %>
10
+ // <%= link_to "Edit profile", edit_user_registration_path, data: { bridge__nav_target: 'item', bridge_image: 'person.circle' } %>
11
+ // <%= link_to "Sign out", destroy_user_session_path, data: { bridge__nav_target: 'item', bridge_image: 'power.circle', turbo_method: :delete } %>
12
+ // <% end %>
11
13
  // <% end %>
12
14
  export default class extends BridgeComponent {
13
15
  static component = "nav"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HotwireNativeRails
4
- VERSION = "0.4.3"
4
+ VERSION = "0.4.4"
5
5
  end
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire_native_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaro Shm
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-21 00:00:00.000000000 Z
10
+ date: 2025-03-11 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
12
  email:
15
13
  - yshmarov@gmail.com
16
14
  executables: []
@@ -52,7 +50,6 @@ metadata:
52
50
  homepage_uri: https://github.com/yshmarov/hotwire_native_rails
53
51
  source_code_uri: https://github.com/yshmarov/hotwire_native_rails
54
52
  changelog_uri: https://github.com/yshmarov/hotwire_native_rails/blob/main/CHANGELOG.md
55
- post_install_message:
56
53
  rdoc_options: []
57
54
  require_paths:
58
55
  - lib
@@ -67,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
64
  - !ruby/object:Gem::Version
68
65
  version: '0'
69
66
  requirements: []
70
- rubygems_version: 3.5.23
71
- signing_key:
67
+ rubygems_version: 3.6.2
72
68
  specification_version: 4
73
69
  summary: Generate Hotwire Native Rails helpers and bridge components
74
70
  test_files: []