Module: RubyNative::Helper
- Defined in:
- lib/ruby_native/helper.rb
Defined Under Namespace
Classes: NavbarBuilder, NavbarMenuBuilder
Instance Method Summary
collapse
Instance Method Details
29
30
31
32
33
34
35
36
|
# File 'lib/ruby_native/helper.rb', line 29
def native_back_button_tag(text = nil, **options)
options[:class] = [options[:class], "native-back-button"].compact.join(" ")
default_content = tag.svg(
tag.path(d: "M15.75 19.5L8.25 12l7.5-7.5", stroke_linecap: "round", stroke_linejoin: "round"),
width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: 2.5
)
tag.button(text || default_content, onclick: "RubyNative.postMessage({action: 'back'})", **options)
end
|
#native_badge_tag(count = nil, home: nil, tab: nil) ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/ruby_native/helper.rb', line 38
def native_badge_tag(count = nil, home: nil, tab: nil)
home = count if count && home.nil?
tab = count if count && tab.nil?
data = { native_badge: "" }
data[:native_badge_home] = home unless home.nil?
data[:native_badge_tab] = tab unless tab.nil?
tag.div(data: data, hidden: true)
end
|
#native_fab_tag(icon:, href: nil, click: nil) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/ruby_native/helper.rb', line 56
def native_fab_tag(icon:, href: nil, click: nil)
data = { native_fab: true, native_icon: icon }
data[:native_href] = href if href
data[:native_click] = click if click
tag.div(data: data, hidden: true)
end
|
21
22
23
|
# File 'lib/ruby_native/helper.rb', line 21
def native_form_tag
tag.div(data: { native_form: true }, hidden: true)
end
|
#native_haptic_data(feedback = :success, **data) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/ruby_native/helper.rb', line 67
def native_haptic_data(feedback = :success, **data)
feedback = feedback.to_s
feedback = "success" if feedback.empty?
data[:native_haptic] = feedback
data
end
|
#native_navbar_tag(title = nil, &block) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/ruby_native/helper.rb', line 49
def native_navbar_tag(title = nil, &block)
builder = NavbarBuilder.new(self)
capture(builder, &block) if block
tag.div(data: { native_navbar: title.to_s }, hidden: true) { builder.to_html }
end
|
63
64
65
|
# File 'lib/ruby_native/helper.rb', line 63
def native_overscroll_tag(top:, bottom: nil)
tag.div(data: { native_overscroll_top: top, native_overscroll_bottom: bottom || top }, hidden: true)
end
|
#native_push_tag ⇒ Object
25
26
27
|
# File 'lib/ruby_native/helper.rb', line 25
def native_push_tag
tag.div(data: { native_push: true }, hidden: true)
end
|
#native_tabs_tag(enabled: true) ⇒ Object
16
17
18
19
|
# File 'lib/ruby_native/helper.rb', line 16
def native_tabs_tag(enabled: true)
return "".html_safe unless enabled
tag.div(data: { native_tabs: true }, hidden: true)
end
|
#ruby_native_screenshot_session? ⇒ Boolean
True when the current request is part of a Ruby Native screenshot run. Use this to render deterministically: freeze relative timestamps, hide push banners, suppress ads, disable A/B variants, skip notifications.
<% if ruby_native_screenshot_session? %>
Stamped 2 days ago
<% else %>
<%= time_ago_in_words(stamp.created_at) %>
<% end %>
12
13
14
|
# File 'lib/ruby_native/helper.rb', line 12
def ruby_native_screenshot_session?
cookies[:_ruby_native_screenshot_session] == "1"
end
|