hotwire_native_rails 0.2.0 → 0.3.1
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 +4 -4
- data/README.md +17 -3
- data/lib/generators/hotwire_native/hotwire_native_generator.rb +8 -1
- data/lib/generators/hotwire_native/templates/controllers/hotwire_native/v1/ios/path_configuration_controller.rb +45 -1
- data/lib/generators/hotwire_native/templates/helpers/hotwire_native_helper.rb +15 -0
- data/lib/generators/hotwire_native/templates/javascript/controllers/bridge/nav_controller.js +36 -0
- data/lib/hotwire_native_rails/version.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: db9feb69df016d6781d12df5d095422b9984afe20e0128add4ec5db096bc9232
         | 
| 4 | 
            +
              data.tar.gz: ae82da4ac986d04d552d47207b7c93dc75fea6cde2e38944f8b9926997d89b3e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 18302cf1e8af968d95a23685db7d7020375060bc7a22b628b146d3596791fcdd18409f818d04456594b030d2ab40bc98f90b4d6c1d08fd3108448929155c16f8
         | 
| 7 | 
            +
              data.tar.gz: 1385c781224c90744b7eeea4b7fa5690524768cd5fc21db85085ac1725b42ae0f901bc433a80082771ba88e1ca04f1a1c8918dbbcf692e87f82d015cc48a9bfb
         | 
    
        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  | 
| 16 | 
            +
            rails g hotwire_native
         | 
| 17 17 | 
             
            ```
         | 
| 18 18 |  | 
| 19 19 | 
             
            ## Usage
         | 
| @@ -23,6 +23,7 @@ rails g hotwire_native_rails | |
| 23 23 | 
             
            - use `data: { turbo_action: replace_if_native }` to submit authentication forms & forms in modals
         | 
| 24 24 | 
             
            - `:mobile` request variant. `index.html+mobile.erb`
         | 
| 25 25 | 
             
            - override link_to to not open internal links in in-app browser on native app
         | 
| 26 | 
            +
            - conditionally override page title for native apps
         | 
| 26 27 |  | 
| 27 28 | 
             
            #### CSS
         | 
| 28 29 | 
             
            - `turbo-native:` css variant (works with CSS and Tailwind)
         | 
| @@ -30,10 +31,23 @@ rails g hotwire_native_rails | |
| 30 31 | 
             
            #### Bridge Components
         | 
| 31 32 | 
             
            - install Hotwire Native Bridge (works with Importmaps and Node)
         | 
| 32 33 | 
             
            - add default bridge components (`Form`, `Menu`, `Button`)
         | 
| 33 | 
            -
            - ` | 
| 34 | 
            +
            - add `Nav` (UIMenu) bridge component
         | 
| 35 | 
            +
            - `bridge_form_with` - easily apply Bridge `Form` component
         | 
| 34 36 |  | 
| 35 37 | 
             
            #### Path Configuration
         | 
| 36 38 | 
             
            - `path_configuration_controller` for `ios` and `android`
         | 
| 37 39 |  | 
| 40 | 
            +
            ## Development
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            Make a release to rubygems:
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            ```sh
         | 
| 45 | 
            +
            # 1. update version in version.rb
         | 
| 46 | 
            +
            # 2. zip the gem
         | 
| 38 47 | 
             
            gem build hotwire_native_rails.gemspec
         | 
| 39 | 
            -
             | 
| 48 | 
            +
            # 3. push the zip to rubygems
         | 
| 49 | 
            +
            gem push hotwire_native_rails-0.2.0.gem
         | 
| 50 | 
            +
            ```
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            - [Github source](https://github.com/yshmarov/hotwire_native_rails)
         | 
| 53 | 
            +
            - [Rubygems source](https://rubygems.org/gems/hotwire_native_rails)
         | 
| @@ -20,7 +20,9 @@ class HotwireNativeGenerator < Rails::Generators::Base | |
| 20 20 | 
             
             end
         | 
| 21 21 |  | 
| 22 22 | 
             
              def add_detect_device_to_application_controller
         | 
| 23 | 
            -
                 | 
| 23 | 
            +
                inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base\n" do
         | 
| 24 | 
            +
                  "  include DetectDevice\n"
         | 
| 25 | 
            +
                end
         | 
| 24 26 | 
             
              end
         | 
| 25 27 |  | 
| 26 28 | 
             
              def add_routes
         | 
| @@ -33,6 +35,7 @@ class HotwireNativeGenerator < Rails::Generators::Base | |
| 33 35 | 
             
                copy_file "javascript/controllers/bridge/menu_controller.js", "app/javascript/controllers/bridge/menu_controller.js"
         | 
| 34 36 | 
             
                copy_file "javascript/controllers/bridge/form_controller.js", "app/javascript/controllers/bridge/form_controller.js"
         | 
| 35 37 | 
             
                copy_file "javascript/controllers/bridge/overflow_menu_controller.js", "app/javascript/controllers/bridge/overflow_menu_controller.js"
         | 
| 38 | 
            +
                copy_file "javascript/controllers/bridge/nav_controller.js", "app/javascript/controllers/bridge/nav_controller.js"
         | 
| 36 39 |  | 
| 37 40 | 
             
                run "bin/importmap pin @hotwired/stimulus @hotwired/hotwire-native-bridge" if importmaps?
         | 
| 38 41 | 
             
                run "yarn add @hotwired/stimulus @hotwired/hotwire-native-bridge" if node?
         | 
| @@ -52,6 +55,10 @@ class HotwireNativeGenerator < Rails::Generators::Base | |
| 52 55 | 
             
                gsub_file "app/views/layouts/application.html.erb", "<html>", "<html <%= platform_identifier %>>"
         | 
| 53 56 | 
             
              end
         | 
| 54 57 |  | 
| 58 | 
            +
              def set_page_title
         | 
| 59 | 
            +
                gsub_file "app/views/layouts/application.html.erb", /<title>.*<\/title>/, "<title><%= page_title %></title>"
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 55 62 | 
             
              private
         | 
| 56 63 |  | 
| 57 64 | 
             
              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 | 
            +
            }
         | 
    
        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. | 
| 4 | 
            +
              version: 0.3.1
         | 
| 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
         |