ruby_native 0.10.8 → 0.10.10

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: a84e26b885c93151197f1ae505a45b9cb99d8f3049df4b89dce036c431411a51
4
- data.tar.gz: cba347806df4afc1f3e21c1b0201e616148633632c712eb44c432166b43f1115
3
+ metadata.gz: 1bb5b7670bd2d4d61029b914d26318ed49b9238dd285830a96804dc249be2402
4
+ data.tar.gz: 13f7f057b4be15c33e5c1c5fdade61102dd153a7a1aaba3c789d67bd730f950b
5
5
  SHA512:
6
- metadata.gz: 7add53e3f05dc87ff5688b0b5714cb627c0a60facc70dde3322cf898d7d5128ffef60b64eca922fefee35441775e1b0ee18108499a795603081cd841ff4e0d70
7
- data.tar.gz: 91bc86d031b25887d4c321ce50dbc10227ecc89f84c9fc2b695091289c1d128a10cecd398e19d5f0928ac40a03c6fac4884d815a21319b370ebe670684dfe561
6
+ metadata.gz: ae5949c2f376250485552b39960c5ba5b02d2618a0d15572ca53ac551ce1fc17c8bd418eadd138a9d51dfd3746737193f4f2916befc44bb697b4e32ea362ade3
7
+ data.tar.gz: 7248a218a8a196571628e8233bb687ac73ba51281eb23d24ffbd31b21be94e82ecf7e2e5ba410af36bfc0b43aab8c8b1b7d4b2ef1ae370c3512bb33d5f230909
@@ -81,6 +81,27 @@ background_color:
81
81
 
82
82
  Match these to your CSS framework's dark mode colors. For Bootstrap, `#212529` is `--bs-body-bg` in dark mode.
83
83
 
84
+ ### Navbar branding
85
+
86
+ Replace the navigation bar's text title with a centered logo and set your own bar colors. This is global chrome: the same bar on every screen.
87
+
88
+ ```yaml
89
+ appearance:
90
+ navbar:
91
+ logo: "<%= image_url('logo.png') %>"
92
+ background_color: "#3B3F54"
93
+ foreground_color: "#FFFFFF"
94
+ status_bar: light
95
+ ```
96
+
97
+ `config/ruby_native.yml` is evaluated as ERB, so `logo` can be any Rails expression that returns a URL. Use `image_url` for a local asset: the URL is fingerprinted, so the app caches the logo and re-downloads it only when the image changes. A full URL works too, so the logo can live on a CDN:
98
+
99
+ ```yaml
100
+ logo: "https://cdn.example.com/logo.png"
101
+ ```
102
+
103
+ `background_color` and `foreground_color` each accept a hex string or a `{ light:, dark: }` object. `status_bar` sets the status bar content to `light` (white) or `dark` to match your bar; omit it to let the system decide.
104
+
84
105
  ## View helpers
85
106
 
86
107
  Use these in your layouts and views:
@@ -34,6 +34,28 @@ appearance:
34
34
  # Default: false (portrait-only).
35
35
  # landscape: true
36
36
 
37
+ # Brand the navigation bar across the whole app: a centered logo in place of
38
+ # the page title, plus your own bar colors.
39
+ # https://rubynative.com/docs/appearance#navbar-branding
40
+ # navbar:
41
+ # # Centered logo, shown instead of the page title. Set this to an image URL.
42
+ # # For a local asset, point it at image_url wrapped in ERB so the URL is
43
+ # # fingerprinted (the app re-downloads only when the image changes). The
44
+ # # docs page above has the exact snippet to copy.
45
+ # logo: "https://cdn.example.com/logo.png"
46
+ #
47
+ # # Bar background color.
48
+ # # Accepts a hex string, or { light:, dark: } for dark mode support.
49
+ # background_color: "#3B3F54"
50
+ #
51
+ # # Title and bar-button color.
52
+ # # Accepts a hex string, or { light:, dark: } for dark mode support.
53
+ # foreground_color: "#FFFFFF"
54
+ #
55
+ # # Status bar content, to match your bar. Options: light (white) or dark.
56
+ # # Omit to let the system decide.
57
+ # status_bar: light
58
+
37
59
  # Configure the native tab bar on the bottom of the screen.
38
60
  # https://rubynative.com/docs/tabs
39
61
  tabs:
@@ -126,6 +126,22 @@ module RubyNative
126
126
  end
127
127
  end
128
128
 
129
+ # Adds a native share button to the nav bar. Tapping it opens the
130
+ # platform share sheet for `url:` (defaults to the current page on the
131
+ # web side) so it works even where embedded web views don't support
132
+ # `navigator.share`. Icons follow the same rules as the other navbar
133
+ # buttons: `icon:` applies to every platform and `icons:` ({ ios:,
134
+ # android: }) overrides per platform.
135
+ def share_button(url: nil, title: "Share", icon: "square.and.arrow.up", icons: nil, position: :trailing)
136
+ resolved = RubyNative::Helper.resolve_icon(icon: icon, icons: icons, platform: @context.try(:native_platform))
137
+ data = { native_button: "", native_share: "" }
138
+ data[:native_title] = title if title
139
+ data[:native_icon] = resolved if resolved
140
+ data[:native_position] = position.to_s
141
+ data[:native_share_url] = url if url
142
+ @items << @context.tag.div(data: data)
143
+ end
144
+
129
145
  def submit_button(title: "Save", click: "[type='submit']")
130
146
  @items << @context.tag.div(data: {
131
147
  native_submit_button: "",
@@ -155,6 +171,19 @@ module RubyNative
155
171
  @items << @context.tag.div(data: data)
156
172
  end
157
173
 
174
+ # Adds a share entry to a navbar button's dropdown menu. Selecting it
175
+ # opens the platform share sheet for `url:` (defaults to the current
176
+ # page on the web side). Icons follow the same `icon:`/`icons:` rules
177
+ # as the other menu items.
178
+ def share_item(title = "Share", url: nil, icon: "square.and.arrow.up", icons: nil, selected: false)
179
+ resolved = RubyNative::Helper.resolve_icon(icon: icon, icons: icons, platform: @context.try(:native_platform))
180
+ data = { native_menu_item: "", native_title: title, native_share: "" }
181
+ data[:native_share_url] = url if url
182
+ data[:native_icon] = resolved if resolved
183
+ data[:native_selected] = "" if selected
184
+ @items << @context.tag.div(data: data)
185
+ end
186
+
158
187
  def to_html
159
188
  @context.safe_join(@items)
160
189
  end
@@ -1,3 +1,3 @@
1
1
  module RubyNative
2
- VERSION = "0.10.8"
2
+ VERSION = "0.10.10"
3
3
  end
data/lib/ruby_native.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "erb"
1
2
  require "ruby_native/version"
2
3
  require "ruby_native/helper"
3
4
  require "ruby_native/native_version"
@@ -37,7 +38,7 @@ module RubyNative
37
38
  path = Rails.root.join("config", "ruby_native.yml")
38
39
  return unless path.exist?
39
40
 
40
- self.config = YAML.load_file(path).deep_symbolize_keys
41
+ self.config = YAML.load(render_config(path)).deep_symbolize_keys
41
42
  self.config[:app] ||= {}
42
43
  self.config[:app][:entry_path] ||= self.config.dig(:tabs, 0, :path) || "/"
43
44
  self.config[:auth] ||= {}
@@ -46,6 +47,23 @@ module RubyNative
46
47
  backfill_error_icons
47
48
  end
48
49
 
50
+ # config/ruby_native.yml is rendered as ERB before it is parsed, so a
51
+ # developer can interpolate Rails helpers into it. The motivating case is the
52
+ # navbar logo: `logo: "<%= image_url("logo.png") %>"` resolves to a
53
+ # fingerprinted asset URL the native app downloads and caches, and because the
54
+ # digest changes whenever the asset changes, the cache busts itself. A full
55
+ # URL (a CDN, say) works just as well; the app only ever sees a URL to fetch.
56
+ #
57
+ # The template renders against the controller helper proxy, so `image_url` and
58
+ # friends behave exactly as they do in a view. With no request or asset host
59
+ # they degrade to a relative path -- asset helpers never raise "missing host"
60
+ # the way routing helpers do -- and the native app resolves any relative URL
61
+ # against the base URL it already fetched the config from.
62
+ def self.render_config(path)
63
+ helpers = ActionController::Base.helpers
64
+ ERB.new(path.read, trim_mode: "-").result(helpers.instance_eval { binding })
65
+ end
66
+
49
67
  # Mirrors per-platform `icons:` into the legacy flat `icon:` field so native
50
68
  # binaries that only read `tab.icon` keep rendering an icon. Explicit `icon:`
51
69
  # wins; otherwise falls back to `icons.ios`, then `icons.android`.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.8
4
+ version: 0.10.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Masilotti