Class: BootstrapBuilders::ButtonDropDown
- Inherits:
-
Object
- Object
- BootstrapBuilders::ButtonDropDown
- Defined in:
- lib/bootstrap_builders/button_drop_down.rb
Instance Attribute Summary collapse
-
#view_context ⇒ Object
Returns the value of attribute view_context.
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize(*args) ⇒ ButtonDropDown
constructor
A new instance of ButtonDropDown.
- #option(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ButtonDropDown
Returns a new instance of ButtonDropDown.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/bootstrap_builders/button_drop_down.rb', line 4 def initialize(*args) args_parser = BootstrapBuilders::ArgumentsParser.new( arguments: args, short_true_arguments: [:block, :danger, :link, :info, :primary, :sm, :warning, :xs] ) args_parser.arguments_hash[:label] ||= args.shift if args.first.is_a?(String) @args = args_parser.arguments_hash @buttons = [] end |
Instance Attribute Details
#view_context ⇒ Object
Returns the value of attribute view_context.
2 3 4 |
# File 'lib/bootstrap_builders/button_drop_down.rb', line 2 def view_context @view_context end |
Instance Method Details
#html ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bootstrap_builders/button_drop_down.rb', line 30 def html btn_group = HtmlGen::Element.new(:div, classes: ["btn-group"]) = btn_group.add_ele( :button, attr: { "aria-haspopup" => true, "aria-exapended" => false, type: "button" }, classes: classes.classes, data: { toggle: "dropdown" } ) .add_ele(:i, classes: ["fa", "fa-fw", "fa-#{@args.fetch(:icon)}"]) if @args[:icon].present? .add_str(@args.fetch(:label)) if @args[:label].present? .add_ele(:span, classes: ["caret"]) if !@args.key?(:caret) || @args[:cart] ul = btn_group.add_ele(:ul, classes: ["dropdown-menu"]) @buttons.each do || li = ul.add_ele(:li) link_args = {class: BootstrapBuilders::ClassAttributeHandler.short([:class])} link_args.deep_merge!(data: {confirm: I18n.t("are_you_sure")}) if [:confirm] link_args.deep_merge!(data: {method: [:method]}) if [:method].present? link_args.deep_merge!(data: [:data]) if [:data] link = view_context.link_to(.fetch(:url), link_args) do if [:icon] view_context.safe_join [view_context.content_tag(:i, nil, class: ["fa", "fa-fw", "fa-#{.fetch(:icon)}"]), " ", .fetch(:label)] else .fetch(:label) end end li.add_html(link) end btn_group.html end |
#option(*args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bootstrap_builders/button_drop_down.rb', line 15 def option(*args) args_parser = BootstrapBuilders::ArgumentsParser.new( arguments: args, short_true_arguments: [:confirm] ) args = args_parser.arguments args_parser.arguments_hash[:url] ||= args.shift if args.first.is_a?(Array) || args.first.is_a?(String) || is_an_active_record || is_a_baza_model args_parser.arguments_hash[:label] ||= args.shift if args.first.is_a?(String) @buttons << args_parser.arguments_hash end |