ruby_native 0.10.11 → 0.10.14

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: ac513c84f990a0a7e941a473d7716d2378cfc181025bcb64e5254d55ab6670f6
4
- data.tar.gz: 46bd471f9a9fe986d87f4d4e3bef763a947dc6072c46e3214b34a83218edc77d
3
+ metadata.gz: 7b83fa869135734b170e4b23a8ca46984c54ea5b830326af54003f1a9006830a
4
+ data.tar.gz: 84e8db6d56e06beb29933463939dfa970d90bc652f52e68bd0b5ad8f41dc273f
5
5
  SHA512:
6
- metadata.gz: 8b5789805d6d25d8f74b2a2d20d6ec3ae89d3366d440bad818981dfbf74d8b83a02258ceb81831ec729986a3be3c48a02e24a24aca390953af6bf60d6201c7a1
7
- data.tar.gz: 99109eb6b6c7e6c887ed360129e5e38959d9a848be7320bf6c9a076344d6aedbc13ca69f79982eff55a0298b1957953313ac019f2f1e78cc241dad0b74fd8fc6
6
+ metadata.gz: c555bdb8ff38ae5a851b81a733aed0554949b1d15352de103f7c90415a56a2b8ce8a21acd5f1724e8b6ebd648ba1a875a9b03f86b1d150f451b53369c2fb23f5
7
+ data.tar.gz: 7de2e7778924c227c6501201af4a5d233c4b1000a99edc93f5074c824526ce248c7cd8d98fa3f963a9935deae69c92fa8f74cf920c3f1e731415545ff80f329a
@@ -4,10 +4,20 @@ module RubyNative
4
4
  skip_forgery_protection
5
5
 
6
6
  def create
7
- device = current_user.push_devices.find_or_initialize_by(token: params[:token])
7
+ device = ruby_native_user.push_devices.find_or_initialize_by(token: params[:token])
8
8
  device.update!(platform: params[:platform], name: params[:name])
9
9
  head :ok
10
10
  end
11
+
12
+ private
13
+
14
+ # Resolves the signed-in user via RubyNative.current_user_resolver, which is
15
+ # either a controller method name (Symbol) or a callable run in the
16
+ # controller. Defaults to `current_user`.
17
+ def ruby_native_user
18
+ resolver = RubyNative.current_user_resolver
19
+ resolver.respond_to?(:call) ? instance_exec(&resolver) : send(resolver)
20
+ end
11
21
  end
12
22
  end
13
23
  end
@@ -187,7 +187,8 @@ module RubyNative
187
187
  puts ""
188
188
  puts url
189
189
  puts ""
190
- puts "Scan the QR code or paste the URL into the Ruby Native Preview app."
190
+ puts "Scan the QR code or paste the URL into the Ruby Native app."
191
+ puts "Don't have it yet? Download it at https://rubynative.com/try/download"
191
192
  if @url
192
193
  puts "Keep this running and your Rails server reachable at #{@url}."
193
194
  else
@@ -120,12 +120,25 @@ module RubyNative
120
120
  if block
121
121
  menu = NavbarMenuBuilder.new(@context)
122
122
  @context.capture(menu, &block)
123
- @items << @context.tag.div(data: data) { menu.to_html }
123
+ add(@context.tag.div(data: data) { menu.to_html })
124
124
  else
125
- @items << @context.tag.div(data: data)
125
+ add(@context.tag.div(data: data))
126
126
  end
127
127
  end
128
128
 
129
+ # Adds a segment to the nav bar. On iOS the segments render as a centered
130
+ # segmented control (the same control the App Store uses for Apps/Games).
131
+ # Mark the current page's segment `selected: true`. Tapping a segment
132
+ # navigates to its `href` (or clicks the `click` selector), replacing
133
+ # history so the back button doesn't walk back through segment switches.
134
+ def segment(title, href: nil, click: nil, selected: false)
135
+ data = { native_segment: "", native_title: title }
136
+ data[:native_href] = href if href
137
+ data[:native_click] = click if click
138
+ data[:native_selected] = "" if selected
139
+ add(@context.tag.div(data: data))
140
+ end
141
+
129
142
  # Adds a native share button to the nav bar. Tapping it opens the
130
143
  # platform share sheet for `url:` (defaults to the current page on the
131
144
  # web side) so it works even where embedded web views don't support
@@ -139,20 +152,32 @@ module RubyNative
139
152
  data[:native_icon] = resolved if resolved
140
153
  data[:native_position] = position.to_s
141
154
  data[:native_share_url] = url if url
142
- @items << @context.tag.div(data: data)
155
+ add(@context.tag.div(data: data))
143
156
  end
144
157
 
145
158
  def submit_button(title: "Save", click: "[type='submit']")
146
- @items << @context.tag.div(data: {
159
+ add(@context.tag.div(data: {
147
160
  native_submit_button: "",
148
161
  native_title: title,
149
162
  native_click: click
150
- })
163
+ }))
151
164
  end
152
165
 
153
166
  def to_html
154
167
  @context.safe_join(@items)
155
168
  end
169
+
170
+ private
171
+
172
+ # Collects a signal element and returns a blank, html-safe string. That
173
+ # lets the builder read naturally with `<%=` in ERB (`<%= navbar.button %>`)
174
+ # without emitting anything, since the nav bar renders from the collected
175
+ # items in `to_html`, not from these return values. Silent `<% %>` tags
176
+ # keep working too.
177
+ def add(item)
178
+ @items << item
179
+ ActiveSupport::SafeBuffer.new
180
+ end
156
181
  end
157
182
 
158
183
  class NavbarMenuBuilder
@@ -168,7 +193,7 @@ module RubyNative
168
193
  data[:native_click] = click if click
169
194
  data[:native_icon] = resolved if resolved
170
195
  data[:native_selected] = "" if selected
171
- @items << @context.tag.div(data: data)
196
+ add(@context.tag.div(data: data))
172
197
  end
173
198
 
174
199
  # Adds a share entry to a navbar button's dropdown menu. Selecting it
@@ -181,12 +206,21 @@ module RubyNative
181
206
  data[:native_share_url] = url if url
182
207
  data[:native_icon] = resolved if resolved
183
208
  data[:native_selected] = "" if selected
184
- @items << @context.tag.div(data: data)
209
+ add(@context.tag.div(data: data))
185
210
  end
186
211
 
187
212
  def to_html
188
213
  @context.safe_join(@items)
189
214
  end
215
+
216
+ private
217
+
218
+ # See NavbarBuilder#add: collects the item and returns a blank, html-safe
219
+ # string so menu items read naturally with `<%= menu.item %>` in ERB.
220
+ def add(item)
221
+ @items << item
222
+ ActiveSupport::SafeBuffer.new
223
+ end
190
224
  end
191
225
  end
192
226
  end
@@ -1,3 +1,3 @@
1
1
  module RubyNative
2
- VERSION = "0.10.11"
2
+ VERSION = "0.10.14"
3
3
  end
data/lib/ruby_native.rb CHANGED
@@ -22,6 +22,12 @@ module RubyNative
22
22
  mattr_accessor :screenshot_key
23
23
  mattr_accessor :screenshot_sign_in
24
24
 
25
+ # How the push endpoint finds the signed-in user to attach a device token to.
26
+ # Accepts a controller method name (Symbol) or a callable evaluated in the
27
+ # controller, e.g. `-> { Current.person }`. Defaults to `current_user`, so
28
+ # Devise apps need no configuration. Set via `RubyNative.configure`.
29
+ mattr_accessor :current_user_resolver, default: :current_user
30
+
25
31
  def self.configure
26
32
  yield self
27
33
  end
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.11
4
+ version: 0.10.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Masilotti