bootstrap_builders 0.0.10 → 0.0.11

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: b9e79f5b4c3dc17543d62e1516237ca6786961ad
4
- data.tar.gz: 929ec7495a0ad53cb7b31f01b39cfaf5c6b8a7d5
3
+ metadata.gz: 3a0826b4f8fcc18607bb51d8737da9f2e4d9067c
4
+ data.tar.gz: 6647d3933ffcbadc667d2ac7e8a018eac3046dd7
5
5
  SHA512:
6
- metadata.gz: c639fc1b0f2479d0c5178cd0bddddb3e6bab5f1864b010641589c6eb2ca844e296936d4e741d03bd9e62425894d3739c7f100ef3112b59e5a5b159ab94bfc82a
7
- data.tar.gz: 5347f30dca008a81ee962d13c1073f97b5bd127af19f10ad42042bb331f74e026fde185722d1ae4738e43e49ac9f7b5944d1ffe2b5f60ccc5cdad6ba235babba
6
+ metadata.gz: bc159ed82574a9eb51cfe5033df325857f86a4ed0f0cc5453efaa5e50058d38f2ea7daf6f7b23f1faa63148a69bef398baef09b0208ed4be904bb50f48b33f28
7
+ data.tar.gz: caa58021299bc802189b91e3d9a31eb645fc19d7c2635032ff14452576b9bd9c0a1f2ccb8c97d2e21d2775f7a7cb6593b3920beb4e9a402a3e2b4a33aba17928
data/README.md CHANGED
@@ -14,6 +14,14 @@ module ApplicationHelper
14
14
  end
15
15
  ```
16
16
 
17
+ Then add to your `application.js`:
18
+ ```javascript
19
+ //= require bootstrap_builders
20
+ ```
21
+
22
+ Then add to your `application.css`:
23
+ //= require bootstrap_builders
24
+
17
25
  ## Usage
18
26
 
19
27
  ### Panel
@@ -95,6 +103,7 @@ The classes "bb-table" and "table" are always added.
95
103
  = bb_tabs :pills, :stacked do |tabs|
96
104
  = tabs.tab "Title", "id-of-content-container" do
97
105
  Content of tab
106
+ = tabs.tab "Load on demand", ajax_url: some_path
98
107
  ```
99
108
 
100
109
  ## Contributing to bootstrap_builders
@@ -0,0 +1,3 @@
1
+ #= require bootstrap_builders/view-port-detection
2
+ #= require bootstrap_builders/bb-btn-responsive
3
+ #= require bootstrap_builders/tabs
@@ -0,0 +1,9 @@
1
+ $ ->
2
+ $.bbUpdateResponsiveButtons = ->
3
+ if $.bbViewPortOrBelow("md")
4
+ $(".bb-btn-responsive").addClass("btn-xs")
5
+ else
6
+ $(".bb-btn-responsive").removeClass("btn-xs")
7
+
8
+ $.bbViewPortChange -> $.bbUpdateResponsiveButtons()
9
+ $.bbUpdateResponsiveButtons()
@@ -0,0 +1,14 @@
1
+ $ ->
2
+ $("body").on "click", ".bb-tabs-container .nav li[data-ajax-url]", ->
3
+ li = $(this)
4
+ link = $("a", li)
5
+ content_id = link.attr("href").substring(1, 999)
6
+ content = $(".bb-tabs-container #" + content_id + " .bb-tab-container")
7
+
8
+ return if li.data("ajax-loaded")
9
+ li.data("ajax-loaded", true)
10
+
11
+ content.fadeOut 0, ->
12
+ $.get li.data("ajax-url"), (data) ->
13
+ content.html(data)
14
+ content.fadeIn "fast"
@@ -0,0 +1,69 @@
1
+ $ ->
2
+ sizes = {
3
+ xs: [0, 767],
4
+ sm: [768, 991],
5
+ md: [992, 1199],
6
+ lg: [1200, 999999]
7
+ }
8
+
9
+ $.bbViewPort = ->
10
+ width = window.innerWidth
11
+
12
+ for size of sizes
13
+ size_width = sizes[size][0]
14
+ size_height = sizes[size][1]
15
+ return size if width >= size_width && width < size_height
16
+
17
+ throw "Could not figure out the Bootstrap view port from this width: " + width
18
+
19
+ $.bbViewPortOrAbove = (given_size) ->
20
+ current_size = $.bbViewPort()
21
+ reached = false
22
+
23
+ for size of sizes
24
+ reached = true if size == current_size
25
+
26
+ if size == given_size
27
+ if reached
28
+ return false
29
+ else
30
+ return true
31
+
32
+ throw "Invalid size: " + given_size
33
+
34
+ $.bbViewPortOrBelow = (given_size) ->
35
+ current_size = $.bbViewPort()
36
+ reached = false
37
+
38
+ for size of sizes
39
+ reached = true if size == current_size
40
+
41
+ if given_size == size
42
+ if reached
43
+ return true
44
+ else
45
+ return false
46
+
47
+ throw "Invalid size: " + given_size
48
+
49
+ viewport_callbacks = []
50
+ $.bbViewPortChange = (func) -> viewport_callbacks.push(func)
51
+
52
+ resize_timeout = null
53
+ current_viewport = $.bbViewPort()
54
+ $.bbViewPortOnChanged = ->
55
+ clearTimeout(resize_timeout) if resize_timeout
56
+
57
+ resize_timeout = setTimeout( ->
58
+ $("body").removeClass("bb-view-port-xs bb-view-port-sm bb-view-port-md bb-view-port-lg")
59
+ new_viewport = $.bbViewPort()
60
+ $("body").addClass("bb-view-port-" + new_viewport)
61
+
62
+ if new_viewport != current_viewport
63
+ current_viewport = new_viewport
64
+
65
+ for number, viewport_callback of viewport_callbacks
66
+ viewport_callback.call()
67
+ , 200)
68
+
69
+ $(window).resize -> $.bbViewPortOnChanged()
@@ -0,0 +1 @@
1
+ //= require bootstrap_builders/bb-btn-responsive
@@ -0,0 +1,6 @@
1
+ .bb-view-port-xs,
2
+ .bb-view-port-sm {
3
+ .bb-btn-responsive[data-bb-icon="true"] .bb-btn-label {
4
+ display: none;
5
+ }
6
+ }
@@ -1,20 +1,20 @@
1
1
  class BootstrapBuilders::ArgumentsParser
2
- attr_reader :arguments
2
+ attr_reader :arguments, :arguments_hash
3
3
 
4
4
  def initialize(args)
5
5
  @arguments = args.fetch(:arguments)
6
6
 
7
7
  if args[:argument_hash_default]
8
- @argument_hash = args.fetch(:argument_hash_default)
8
+ @arguments_hash = args.fetch(:argument_hash_default)
9
9
  else
10
- @argument_hash = {}
10
+ @arguments_hash = {}
11
11
  end
12
12
 
13
13
  if @arguments.last.is_a?(Hash)
14
- @argument_hash = @argument_hash.merge(@arguments.pop)
14
+ @arguments_hash = @arguments_hash.merge(@arguments.pop)
15
15
  end
16
16
 
17
- @arguments << @argument_hash
17
+ @arguments << @arguments_hash
18
18
 
19
19
  @short_true_arguments = args[:short_true_arguments]
20
20
  parse_short_true_arguments if @short_true_arguments
@@ -25,7 +25,7 @@ private
25
25
  def parse_short_true_arguments
26
26
  @arguments.delete_if do |argument|
27
27
  if @short_true_arguments.include?(argument)
28
- @argument_hash[argument] = true
28
+ @arguments_hash[argument] = true
29
29
  true
30
30
  else
31
31
  false
@@ -2,27 +2,21 @@ class BootstrapBuilders::Button
2
2
  attr_accessor :label
3
3
 
4
4
  def self.parse_url_args(args)
5
- if args.last.is_a?(Hash)
6
- real_args = args.pop
7
- else
8
- real_args = {}
9
- end
5
+ args_parser = BootstrapBuilders::ArgumentsParser.new(
6
+ arguments: args,
7
+ short_true_arguments: [:block, :confirm, :responsive, :lg, :md, :mini, :sm, :xs]
8
+ )
9
+ args = args_parser.arguments
10
10
 
11
11
  is_an_active_record = BootstrapBuilders::IsAChecker.is_a?(args.first, "ActiveRecord::Base")
12
12
  is_a_baza_model = BootstrapBuilders::IsAChecker.is_a?(args.first, "BazaModels::Model")
13
13
 
14
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, :confirm, :lg, :md, :mini, :sm, :xs]
21
- args.each do |arg|
22
- real_args[arg] = true if pass_args.include?(arg)
15
+ args_parser.arguments_hash[:url] ||= args.shift
23
16
  end
24
17
 
25
- real_args
18
+ args_parser.arguments_hash[:label] ||= args.shift if args.first.is_a?(String)
19
+ args_parser.arguments_hash
26
20
  end
27
21
 
28
22
  def initialize(args)
@@ -35,6 +29,11 @@ class BootstrapBuilders::Button
35
29
  @icon = args[:icon]
36
30
  @can = args[:can]
37
31
  @mini = args[:mini]
32
+
33
+ @data = args[:data] || {}
34
+ @data[:bb_icon] = @icon.present?
35
+
36
+ @args[:title] ||= @label if @args[:responsive] && @label.present?
38
37
  end
39
38
 
40
39
  def classes
@@ -42,6 +41,7 @@ class BootstrapBuilders::Button
42
41
  @classes = BootstrapBuilders::ClassAttributeHandler.new(class: ["btn", "btn-default"])
43
42
  @classes.add("btn-xs") if @mini
44
43
  @classes.add(@class) if @class
44
+ @classes.add("bb-btn-responsive") if @args[:responsive]
45
45
 
46
46
  size_classes = [:lg, :md, :sm, :xs]
47
47
  size_classes.each do |size_class|
@@ -61,7 +61,7 @@ class BootstrapBuilders::Button
61
61
 
62
62
  link_args = {
63
63
  class: classes.classes,
64
- data: @args[:data],
64
+ data: @data,
65
65
  method: @args[:method],
66
66
  target: @args[:target],
67
67
  remote: @args[:remote],
@@ -71,7 +71,11 @@ class BootstrapBuilders::Button
71
71
  @context.link_to(@url, link_args) do
72
72
  html = ""
73
73
  html << @context.content_tag(:i, nil, class: ["fa", "fa-#{@icon}"]) if @icon
74
- html << " #{@label}" if @label && !@mini
74
+
75
+ if @label && !@mini
76
+ html << @context.content_tag(:span, " #{@label}", class: "bb-btn-label")
77
+ end
78
+
75
79
  html.strip.html_safe
76
80
  end
77
81
  end
@@ -151,7 +155,6 @@ private
151
155
 
152
156
  def handle_confirm_argument
153
157
  return unless @args[:confirm]
154
- @args[:data] ||= {}
155
- @args[:data][:confirm] = I18n.t("are_you_sure")
158
+ @data[:confirm] = I18n.t("are_you_sure")
156
159
  end
157
160
  end
@@ -1,10 +1,11 @@
1
1
  class BootstrapBuilders::Tab
2
2
  attr_accessor :active, :container_html
3
- attr_reader :container_id, :label
3
+ attr_reader :ajax_url, :container_id, :label
4
4
 
5
5
  def initialize(args)
6
6
  @active = args[:active]
7
7
  @label = args.fetch(:label)
8
+ @ajax_url = args[:ajax_url]
8
9
 
9
10
  @container_id = args[:container_id].presence
10
11
  @container_id ||= SecureRandom.hex
@@ -6,7 +6,10 @@ class BootstrapBuilders::Table
6
6
  end
7
7
 
8
8
  def html
9
- @context.content_tag(:table, attributes, &@blk)
9
+ buffer = @context.content_tag(:table, attributes, &@blk)
10
+ return buffer unless @args[:responsive]
11
+
12
+ @context.content_tag(:div, buffer, class: "table-responsive")
10
13
  end
11
14
 
12
15
  private
@@ -29,6 +29,7 @@ class BootstrapBuilders::Tabs
29
29
  li = ul.add_ele(:li)
30
30
  li.add_ele(:a, str: tab.label, attr: {href: "##{tab.container_id}"}, data: {toggle: "tab"})
31
31
  li.classes << "active" if tab.active?
32
+ li.data[:ajax_url] = tab.ajax_url if tab.ajax_url.present?
32
33
  end
33
34
 
34
35
  tabs_content = container.add_ele(:div, classes: ["tab-content"])
@@ -1,3 +1,3 @@
1
1
  module BootstrapBuilders
2
- VERSION = "0.0.10".freeze
2
+ VERSION = "0.0.11".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.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-12 00:00:00.000000000 Z
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -230,8 +230,12 @@ files:
230
230
  - MIT-LICENSE
231
231
  - README.md
232
232
  - Rakefile
233
- - app/assets/javascripts/bootstrap_builders/application.js
234
- - app/assets/stylesheets/bootstrap_builders/application.css
233
+ - app/assets/javascripts/bootstrap_builders.coffee
234
+ - app/assets/javascripts/bootstrap_builders/bb-btn-responsive.coffee
235
+ - app/assets/javascripts/bootstrap_builders/tabs.js.coffee
236
+ - app/assets/javascripts/bootstrap_builders/view-port-detection.coffee
237
+ - app/assets/stylesheets/bootstrap_builders.scss
238
+ - app/assets/stylesheets/bootstrap_builders/bb-btn-responsive.scss
235
239
  - app/controllers/bootstrap_builders/application_controller.rb
236
240
  - app/helpers/bootstrap_builders/application_helper.rb
237
241
  - app/views/layouts/bootstrap_builders/application.html.erb
@@ -272,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
276
  version: '0'
273
277
  requirements: []
274
278
  rubyforge_project:
275
- rubygems_version: 2.4.0
279
+ rubygems_version: 2.2.2
276
280
  signing_key:
277
281
  specification_version: 4
278
282
  summary: A library to generate Bootstrap HTML for Rails.
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */