bootstrap_builders 0.0.35 → 0.0.36

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
  SHA1:
3
- metadata.gz: f2b06accaf876db61d654dc89c1fe33f18c70fea
4
- data.tar.gz: 665c836f455f3253e3fcf1f9cfee09dca5f1c516
3
+ metadata.gz: 4571e92b44351b95c299f60199ae1737a88b83d0
4
+ data.tar.gz: 8e10bc455d5a0ed5cd63b77971d3a6db934b028f
5
5
  SHA512:
6
- metadata.gz: f167b8feb7cc107f438f3fa2b653c0fceeb4ee2fe67d32f3a47b86c5e192d212294b5a2c23e9938b26ecbcf77a8cea0ff3cc1046a70e06ffd1e9558ac19a0979
7
- data.tar.gz: fce11dc15053ef889fc702fa549d97053c2f3099dcccca74d4bf820827713c9c257f7b638479f3b72ab8e40f629f068a787e07eeba81037ddec78fd3dc1086c2
6
+ metadata.gz: 123d8be3ff044d9d0f4677203a4581616ed5315518ced3f908f3d9a396df1cad76caf90326b313f6b35c967b0c0a3c97d913daec191509032aa630ba27b8963a
7
+ data.tar.gz: 25351832e0a318d5fedce2761d1fbbb88130f77da77de21fcf867416fe966b1273e5692e85f15b391d2980654c51d3d9506af9dcca6d5327399f5052480b4c10
@@ -7,6 +7,14 @@ module BootstrapBuilders::ButtonsHelper
7
7
  button.html
8
8
  end
9
9
 
10
+ def bb_btn_drop_down(*args)
11
+ btn_drop_down = BootstrapBuilders::ButtonDropDown.new(*args)
12
+ btn_drop_down.view_context = self
13
+
14
+ yield btn_drop_down
15
+ btn_drop_down.html
16
+ end
17
+
10
18
  def bb_edit_btn(*args)
11
19
  args = BootstrapBuilders::Button.parse_url_args(args)
12
20
  args[:label] = t("edit") unless args.key?(:label)
@@ -10,6 +10,7 @@ module BootstrapBuilders
10
10
  autoload :AttributeRows
11
11
  autoload :ArgumentsParser
12
12
  autoload :Button
13
+ autoload :ButtonDropDown
13
14
  autoload :CapybaraSpecHelpers
14
15
  autoload :ClassAttributeHandler
15
16
  autoload :Configuration
@@ -0,0 +1,66 @@
1
+ class BootstrapBuilders::ButtonDropDown
2
+ attr_accessor :view_context
3
+
4
+ def initialize(args)
5
+ @args = args
6
+ @buttons = []
7
+ end
8
+
9
+ def option(*args)
10
+ args_parser = BootstrapBuilders::ArgumentsParser.new(
11
+ arguments: args,
12
+ short_true_arguments: [:confirm]
13
+ )
14
+
15
+ args = args_parser.arguments
16
+
17
+ if args.first.is_a?(Array) || args.first.is_a?(String) || is_an_active_record || is_a_baza_model
18
+ args_parser.arguments_hash[:url] ||= args.shift
19
+ end
20
+
21
+ args_parser.arguments_hash[:label] ||= args.shift if args.first.is_a?(String)
22
+
23
+ @buttons << args_parser.arguments_hash
24
+ end
25
+
26
+ def html
27
+ btn_group = HtmlGen::Element.new(:div, classes: ["btn-group"])
28
+ main_button = btn_group.add_ele(
29
+ :button,
30
+ attr: {
31
+ "aria-haspopup" => true,
32
+ "aria-exapended" => false,
33
+ type: "button"
34
+ },
35
+ classes: ["btn", "btn-default", "dropdown-toggle"],
36
+ data: {
37
+ toggle: "dropdown"
38
+ }
39
+ )
40
+ main_button.add_str(@args.fetch(:label))
41
+ main_button.add_ele(:span, classes: ["caret"])
42
+
43
+ ul = btn_group.add_ele(:ul, classes: ["dropdown-menu"])
44
+
45
+ @buttons.each do |button|
46
+ li = ul.add_ele(:li)
47
+
48
+ url = button.fetch(:url)
49
+ url = view_context.polymorphic_url(url) if url.is_a?(Array)
50
+
51
+ a_href = li.add_ele(:a, attr: {href: url}, classes: BootstrapBuilders::ClassAttributeHandler.short(button[:class]))
52
+
53
+ a_href.data[:confirm] = I18n.t("are_you_sure") if button[:confirm]
54
+ a_href.data[:method] = button[:method]
55
+ a_href.data.merge!(button[:data]) if button[:data]
56
+
57
+ if button[:icon]
58
+ a_href.add_ele(:i, classes: ["fa", "fa-fw", "fa-#{button.fetch(:icon)}"])
59
+ end
60
+
61
+ a_href.add_str(button.fetch(:label))
62
+ end
63
+
64
+ btn_group.html
65
+ end
66
+ end
@@ -1,6 +1,10 @@
1
1
  class BootstrapBuilders::ClassAttributeHandler
2
2
  attr_reader :classes
3
3
 
4
+ def self.short(classes)
5
+ BootstrapBuilders::ClassAttributeHandler.new(class: classes).classes
6
+ end
7
+
4
8
  def initialize(args)
5
9
  @classes = convert_to_array(args.fetch(:class))
6
10
  end
@@ -24,6 +28,7 @@ class BootstrapBuilders::ClassAttributeHandler
24
28
  private
25
29
 
26
30
  def convert_to_array(argument)
31
+ return unless argument.present?
27
32
  return argument.split(/\s+/) if argument.is_a?(String)
28
33
  return argument if argument.is_a?(Array)
29
34
  return [] if args.fetch(:class).nil?
@@ -1,3 +1,3 @@
1
1
  module BootstrapBuilders
2
- VERSION = "0.0.35".freeze
2
+ VERSION = "0.0.36".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_builders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.13
33
+ version: 0.0.15
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.13
40
+ version: 0.0.15
41
41
  description: A library to generate Bootstrap HTML for Rails.
42
42
  email:
43
43
  - kaspernj@gmail.com
@@ -72,6 +72,7 @@ files:
72
72
  - lib/bootstrap_builders/arguments_parser.rb
73
73
  - lib/bootstrap_builders/attribute_rows.rb
74
74
  - lib/bootstrap_builders/button.rb
75
+ - lib/bootstrap_builders/button_drop_down.rb
75
76
  - lib/bootstrap_builders/capybara_spec_helpers.rb
76
77
  - lib/bootstrap_builders/class_attribute_handler.rb
77
78
  - lib/bootstrap_builders/configuration.rb