bootstrap_builders 0.0.4 → 0.0.5

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: c2e43bdc56f44def9fdde24067ba74e9496dd833
4
- data.tar.gz: fec8d583324e41c4728d2ceb50f36e9567fd0076
3
+ metadata.gz: 8dde6106e46dfa88dceddc2232f34675a416faf1
4
+ data.tar.gz: 770ce0e84fbd41666f72e70fa5feba3fa7f0f282
5
5
  SHA512:
6
- metadata.gz: 0f19384fe95607c4d333ae2cf2fab73f4b2db0adf4a698b3bb1c7e792bc7130a8c3b8a1b69f27b474b90009d4df8954f7f5fe4ecf865d309e0ce0661c8b95eec
7
- data.tar.gz: bc903302b6ca80d51f885dd512a8a08a738bc6c7e52aad5c217a544ce7d865b61a80ed95c36e58b535453c6a038f5ba3aaad8103eca77e77fae64ec09ac43203
6
+ metadata.gz: bf0fc0ccbe0f09f2562ef273be119922fd148a0bcad6ed63c41823aa313f9cd37e8ebea0e94e6463de4634b03ae71b618024ade3a2ec22fa9ee1ae6e2e4b0870
7
+ data.tar.gz: efe44e6d699588e0047795a10126fdab0b5afdbfac414013ecfc604287e42b52baabedea3cab1c64be3b8e2d53ece51a0de5452fbb4376b8f2056c61cebd8bbf
data/README.md CHANGED
@@ -72,6 +72,7 @@ The classes "bb-table" and "table" are always added.
72
72
  = bb_new_btn url: [:admin, User]
73
73
  = bb_edit_btn url: [:admin, user], mini: true
74
74
  = bb_destroy_btn url: [:admin, user], label: false
75
+ = bb_btn "/url", "My label", :block, :lg, confirm: true
75
76
  ```
76
77
 
77
78
  ## Contributing to bootstrap_builders
@@ -101,4 +101,9 @@ module BootstrapBuilders::ApplicationHelper
101
101
  table = BootstrapBuilders::Table.new(args.merge(context: self, blk: blk))
102
102
  table.html
103
103
  end
104
+
105
+ def bb_flash(args = {})
106
+ flash = BootstrapBuilders::Flash.new(args.merge(context: self))
107
+ flash.html
108
+ end
104
109
  end
@@ -1,5 +1,4 @@
1
1
  require "bootstrap_builders/engine"
2
- require "haml"
3
2
  require "html_gen"
4
3
 
5
4
  module BootstrapBuilders
@@ -9,6 +8,7 @@ module BootstrapBuilders
9
8
  autoload :Button
10
9
  autoload :ClassAttributeHandler
11
10
  autoload :Configuration
11
+ autoload :Flash
12
12
  autoload :IsAChecker
13
13
  autoload :Panel
14
14
  autoload :Table
@@ -8,12 +8,25 @@ class BootstrapBuilders::Button
8
8
  real_args = {}
9
9
  end
10
10
 
11
- real_args[:url] ||= args.shift if args.first
12
- real_args[:label] ||= args.shift if args.first
11
+ is_an_active_record = BootstrapBuilders::IsAChecker.is_a?(args.first, "ActiveRecord::Base")
12
+ is_a_baza_model = BootstrapBuilders::IsAChecker.is_a?(args.first, "BazaModels::Model")
13
+
14
+ if args.first.is_a?(Array) || args.first.is_a?(String) || is_an_active_record || is_a_baza_model
15
+ real_args[:url] ||= args.shift
16
+ end
17
+
18
+ real_args[:label] ||= args.shift if args.first.is_a?(String)
19
+
20
+ pass_args = [:block, :lg, :md, :sm, :xs]
21
+ args.each do |arg|
22
+ real_args[arg] = true if pass_args.include?(arg)
23
+ end
24
+
13
25
  real_args
14
26
  end
15
27
 
16
28
  def initialize(args)
29
+ @args = args
17
30
  @label = args[:label]
18
31
  @class = args[:class]
19
32
  @url = args.fetch(:url)
@@ -21,15 +34,21 @@ class BootstrapBuilders::Button
21
34
  @context = args.fetch(:context)
22
35
  @icon = args[:icon]
23
36
  @can = args[:can]
24
- @small = args[:small]
25
37
  @mini = args[:mini]
26
38
  end
27
39
 
28
40
  def classes
29
41
  unless @classes
30
42
  @classes = BootstrapBuilders::ClassAttributeHandler.new(class: ["btn", "btn-default"])
31
- @classes.add("btn-xs") if @mini || @small
43
+ @classes.add("btn-xs") if @mini
32
44
  @classes.add(@class) if @class
45
+
46
+ size_classes = [:lg, :md, :sm, :xs]
47
+ size_classes.each do |size_class|
48
+ next unless @args[size_class]
49
+ btn_size_class = "btn-#{size_class}"
50
+ @classes.add(btn_size_class) unless @classes.include?(btn_size_class)
51
+ end
33
52
  end
34
53
 
35
54
  @classes
@@ -9,6 +9,10 @@ class BootstrapBuilders::ClassAttributeHandler
9
9
  @classes += convert_to_array(class_argument)
10
10
  end
11
11
 
12
+ def include?(attr_class)
13
+ @classes.include?(attr_class)
14
+ end
15
+
12
16
  private
13
17
 
14
18
  def convert_to_array(argument)
@@ -1,3 +1,5 @@
1
+ module BootstrapBuilders; end
2
+
1
3
  class BootstrapBuilders::Engine < ::Rails::Engine
2
4
  isolate_namespace BootstrapBuilders
3
5
  end
@@ -0,0 +1,44 @@
1
+ class BootstrapBuilders::Flash
2
+ def initialize(args)
3
+ @class = args[:class]
4
+ @alert_types = [:success, :info, :warning, :danger]
5
+ @context = args.fetch(:context)
6
+ end
7
+
8
+ def html
9
+ flash_messages = []
10
+ @context.flash.each do |type, message|
11
+ # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
12
+ next if message.blank?
13
+
14
+ type = type.to_sym
15
+ type = :success if type == :notice
16
+ type = :danger if type == :alert
17
+ type = :danger if type == :error
18
+ next unless @alert_types.include?(type)
19
+
20
+ close_button = @context.content_tag(:button, @context.raw("&times;"), type: "button", class: "close", "data-dismiss" => "alert")
21
+
22
+ Array(message).each do |msg|
23
+ text = @context.content_tag(:div, close_button + msg, class: classes(type))
24
+ flash_messages << text if msg
25
+ end
26
+ end
27
+ flash_messages.join("\n").html_safe
28
+ end
29
+
30
+ private
31
+
32
+ def classes(type)
33
+ classes = []
34
+
35
+ if @class.is_a?(String)
36
+ classes += @class.split(/\s+/)
37
+ elsif @class.is_a?(Array)
38
+ classes += @class
39
+ end
40
+
41
+ classes += ["bb-flash", "alert", "alert-#{type}"]
42
+ classes
43
+ end
44
+ end
@@ -57,9 +57,11 @@ private
57
57
  def add_table
58
58
  table_responsive = @panel.add_ele(:div, classes: ["table-responsive"])
59
59
 
60
+ bs_classes = BootstrapBuilders.configuration.default_table_classes - [:bordered]
61
+
60
62
  table_args = {
61
63
  class: "bb-panel-table",
62
- bs_classes: ["table-striped", "table-hover", "bb-panel-table"],
64
+ bs_classes: bs_classes,
63
65
  context: @context,
64
66
  blk: @block
65
67
  }
@@ -1,3 +1,3 @@
1
1
  module BootstrapBuilders
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.0.5".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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -243,6 +243,7 @@ files:
243
243
  - lib/bootstrap_builders/class_attribute_handler.rb
244
244
  - lib/bootstrap_builders/configuration.rb
245
245
  - lib/bootstrap_builders/engine.rb
246
+ - lib/bootstrap_builders/flash.rb
246
247
  - lib/bootstrap_builders/is_a_checker.rb
247
248
  - lib/bootstrap_builders/panel.rb
248
249
  - lib/bootstrap_builders/table.rb
@@ -268,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
269
  version: '0'
269
270
  requirements: []
270
271
  rubyforge_project:
271
- rubygems_version: 2.4.0
272
+ rubygems_version: 2.2.2
272
273
  signing_key:
273
274
  specification_version: 4
274
275
  summary: A library to generate Bootstrap HTML for Rails.