phone_preview 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc78569a84670e434020eb9ce555cd7e21c00228025ceb52e18d9420adc8f8c2
4
+ data.tar.gz: e8e46b0e1f29452f1e90a012f4089cfeb190f7ae64fd5d11af0d1ac4dc6220cb
5
+ SHA512:
6
+ metadata.gz: 2768cd8b0e3058463d1839358c3d0693ac95cbe87aba06126de22176f0c67ea2c0e62dc971e332ba38ca8995b6270d2c6e668c3207a502010d81a3e50e484ca3
7
+ data.tar.gz: 97b463e508fc83fa547a938a5a3336ee2c416f1d0e9974213446cc3ec355bc2d6ea866cb890f852fe920f06270c9d6368d542c4afa851728829de2fb43a332d8
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Added
6
+
7
+ - `phone_preview` starts the app's server and an ngrok tunnel on one port, and prints the public address and a QR code of it.
8
+ - With no `PORT` set, `phone_preview` starts on port 3000.
9
+ - In development, emailed links use `PUBLIC_BASE_URL` over https with no port when it is set.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DYB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # phone_preview
2
+
3
+ Opens a Rails app running on your Mac on a phone, through an ngrok tunnel at a
4
+ fixed public address.
5
+
6
+ `phone_preview` starts the app's server and an ngrok tunnel on one port, prints
7
+ the public address and a QR code of it to scan with the phone's camera, and in
8
+ development makes emailed links use that address so they open on the phone.
9
+
10
+ ## Requirements
11
+
12
+ - An ngrok account with a reserved domain for the app, such as
13
+ `app-dev.ngrok.app`, and the `ngrok` command signed in to that account.
14
+ - `overmind`, which runs the server and the tunnel together.
15
+
16
+ ## Installing
17
+
18
+ Add the gem to the app's development group:
19
+
20
+ ```ruby
21
+ group :development do
22
+ gem "phone_preview"
23
+ end
24
+ ```
25
+
26
+ Give the app a `bin/phone` that names its public address and runs the gem's
27
+ command:
28
+
29
+ ```sh
30
+ #!/usr/bin/env sh
31
+
32
+ export PUBLIC_BASE_URL="${PUBLIC_BASE_URL:-https://app-dev.ngrok.app}"
33
+
34
+ exec bundle exec phone_preview "$@"
35
+ ```
36
+
37
+ ## Using it
38
+
39
+ Run `bin/phone`, or `up phone` from symphony, which picks the first free port.
40
+ Open the printed address on the phone, or scan the QR code.
41
+
42
+ With no `PORT` set, the server starts on port 3000.
43
+
44
+ When `PUBLIC_BASE_URL` is set in development, emailed links use it over https
45
+ with no port. With it unset, or outside development, emailed links keep the
46
+ app's own `action_mailer.default_url_options`.
47
+
48
+ Live connections through Action Cable need no setting, because Rails accepts a
49
+ connection whose origin matches the address the request arrives on.
data/exe/phone_preview ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require "rqrcode"
3
+
4
+ address = ENV.fetch("PUBLIC_BASE_URL")
5
+ ENV["PORT"] ||= "3000"
6
+
7
+ puts RQRCode::QRCode.new(address).as_ansi
8
+ puts "Open #{address} on your phone"
9
+
10
+ procfile = File.expand_path("../lib/phone_preview/Procfile", __dir__)
11
+ $stdout.flush
12
+ exec "overmind", "start", "-T", "--no-port", "-f", procfile, "-d", Dir.pwd
@@ -0,0 +1,2 @@
1
+ web: bin/rails server -p $PORT
2
+ tunnel: ngrok http --url=$PUBLIC_BASE_URL $PORT --log=stdout
@@ -0,0 +1,14 @@
1
+ require "uri"
2
+
3
+ module PhonePreview
4
+ class Railtie < Rails::Railtie
5
+ initializer "phone_preview.emailed_links", before: "action_mailer.set_configs" do |app|
6
+ address = ENV["PUBLIC_BASE_URL"].presence
7
+
8
+ if Rails.env.development? && address
9
+ public_uri = URI.parse(address)
10
+ app.config.action_mailer.default_url_options = { host: public_uri.host, protocol: public_uri.scheme }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module PhonePreview
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "phone_preview/version"
2
+
3
+ module PhonePreview
4
+ end
5
+
6
+ require "phone_preview/railtie" if defined?(Rails::Railtie)
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phone_preview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Schneider
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: railties
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rqrcode
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ description: Starts a Rails app in development with an ngrok tunnel on one port, prints
41
+ its public address and a QR code of it, and makes emailed links use that address.
42
+ email:
43
+ - tylercschneider@gmail.com
44
+ executables:
45
+ - phone_preview
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG.md
50
+ - LICENSE
51
+ - README.md
52
+ - exe/phone_preview
53
+ - lib/phone_preview.rb
54
+ - lib/phone_preview/Procfile
55
+ - lib/phone_preview/railtie.rb
56
+ - lib/phone_preview/version.rb
57
+ homepage: https://github.com/DYB-Development/phone_preview
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/DYB-Development/phone_preview
62
+ source_code_uri: https://github.com/DYB-Development/phone_preview
63
+ changelog_uri: https://github.com/DYB-Development/phone_preview/blob/main/CHANGELOG.md
64
+ bug_tracker_uri: https://github.com/DYB-Development/phone_preview/issues
65
+ documentation_uri: https://github.com/DYB-Development/phone_preview#readme
66
+ rubygems_mfa_required: 'true'
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.3.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 4.0.20
82
+ specification_version: 4
83
+ summary: Opens a locally running Rails app on a phone through an ngrok tunnel.
84
+ test_files: []