Class: RubyNative::Helper::NavbarBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_native/helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ NavbarBuilder

Returns a new instance of NavbarBuilder.



62
63
64
65
# File 'lib/ruby_native/helper.rb', line 62

def initialize(context)
  @context = context
  @items = []
end

Instance Method Details

#button(title = nil, icon: nil, href: nil, click: nil, position: :trailing, selected: false, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ruby_native/helper.rb', line 67

def button(title = nil, icon: nil, href: nil, click: nil, position: :trailing, selected: false, &block)
  data = { native_button: "" }
  data[:native_title] = title if title
  data[:native_icon] = icon if icon
  data[:native_href] = href if href
  data[:native_click] = click if click
  data[:native_position] = position.to_s
  data[:native_selected] = "" if selected

  if block
    menu = NavbarMenuBuilder.new(@context)
    @context.capture(menu, &block)
    @items << @context.tag.div(data: data) { menu.to_html }
  else
    @items << @context.tag.div(data: data)
  end
end

#submit_button(title: "Save", click: "[type='submit']") ⇒ Object



85
86
87
88
89
90
91
# File 'lib/ruby_native/helper.rb', line 85

def submit_button(title: "Save", click: "[type='submit']")
  @items << @context.tag.div(data: {
    native_submit_button: "",
    native_title: title,
    native_click: click
  })
end

#to_htmlObject



93
94
95
# File 'lib/ruby_native/helper.rb', line 93

def to_html
  @context.safe_join(@items)
end