Module: RubyNative::Helper
- Defined in:
- lib/ruby_native/helper.rb
Defined Under Namespace
Classes: MenuBuilder
Instance Method Summary collapse
- #native_app? ⇒ Boolean
- #native_back_button_tag(text = nil, **options) ⇒ Object
- #native_button_tag(title, url, ios_image: nil, side: :right, **options) ⇒ Object
- #native_form_data ⇒ Object
- #native_form_tag ⇒ Object
- #native_menu_tag(title:, side: :right, &block) ⇒ Object
- #native_push_tag ⇒ Object
- #native_search_tag ⇒ Object
- #native_submit_data ⇒ Object
- #native_tabs_tag(enabled: true) ⇒ Object
Instance Method Details
#native_app? ⇒ Boolean
3 4 5 |
# File 'lib/ruby_native/helper.rb', line 3 def native_app? request.user_agent.to_s.include?("Ruby Native") end |
#native_back_button_tag(text = nil, **options) ⇒ Object
33 34 35 36 |
# File 'lib/ruby_native/helper.rb', line 33 def (text = nil, **) [:class] = [[:class], "native-back-button"].compact.join(" ") tag.(text || "Back", onclick: "webkit.messageHandlers.rubyNative.postMessage({action: 'back'})", **) end |
#native_button_tag(title, url, ios_image: nil, side: :right, **options) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/ruby_native/helper.rb', line 42 def (title, url, ios_image: nil, side: :right, **) data = .delete(:data) || {} data[:controller] = "bridge--button" data[:bridge_side] = side.to_s data[:bridge_ios_image] = ios_image if ios_image link_to title, url, **, data: data end |
#native_form_data ⇒ Object
18 19 20 |
# File 'lib/ruby_native/helper.rb', line 18 def native_form_data { controller: "bridge--form" } end |
#native_form_tag ⇒ Object
14 15 16 |
# File 'lib/ruby_native/helper.rb', line 14 def native_form_tag tag.div(data: { native_form: true }, hidden: true) end |
#native_menu_tag(title:, side: :right, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_native/helper.rb', line 51 def (title:, side: :right, &block) builder = MenuBuilder.new(self) capture(builder, &block) tag.div(style: "display:none", data: { controller: "bridge--menu", bridge__menu_title_value: title, bridge__menu_side_value: side.to_s }) { builder.to_html } end |
#native_push_tag ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ruby_native/helper.rb', line 26 def native_push_tag safe_join([ tag.div(data: { native_push: true }, hidden: true), tag.div(data: { controller: "bridge--push" }) ]) end |
#native_search_tag ⇒ Object
38 39 40 |
# File 'lib/ruby_native/helper.rb', line 38 def native_search_tag tag.div(data: { controller: "bridge--search" }) end |
#native_submit_data ⇒ Object
22 23 24 |
# File 'lib/ruby_native/helper.rb', line 22 def native_submit_data { bridge__form_target: "submit" } end |
#native_tabs_tag(enabled: true) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/ruby_native/helper.rb', line 7 def native_tabs_tag(enabled: true) safe_join([ (tag.div(data: { native_tabs: true }, hidden: true) if enabled), tag.div(data: { controller: "bridge--tabs", bridge__tabs_enabled_value: enabled }) ].compact) end |