bootstrap_builders 0.0.1 → 0.0.2

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: bbcbc8147a3418dade652132f1cde174721cc431
4
- data.tar.gz: e4e53315ad98d24c9469cee66ddf8366fb1ef7ac
3
+ metadata.gz: 1576e39d9ed78b4073ffe113990c3cefd7194f26
4
+ data.tar.gz: f0797a630cac750ce9ff5d3f272b98fc560fe4e1
5
5
  SHA512:
6
- metadata.gz: 041f03df796090e49b25770b9f7390d129cd48b4023224812d3383693e271dc9b156e14e2b4b9c68b74c45ba01e6383bec9675f78bb69e10b4508e93dba94cbd
7
- data.tar.gz: 55c2f14caff539a410d230c98bbf6d2ca9ea6f505e6c5d79a86461e2026975342861e617399e9e7125dd2d8c93e0409d9934ac3f9342ba432346ca26fa820f56
6
+ metadata.gz: 09840ce0caaba4c24fd594442e2a07af223eae29f88faf969f188b804b2e68be2faf6b7e37436dc36f07807c7787ffbff8c8a8e55a9fd5429ed06334826b44f8
7
+ data.tar.gz: e018461fbad769c278cd78f2455d470591c639439d63c99607eddf0937eb61c32f7d42dba154f233f6f416f224f558dee408eb48240d012d5cf8ccc54cbc4318
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "html_gen", ">= 0.0.6"
3
+ gem "html_gen", ">= 0.0.7"
4
4
  gem "auto_autoloader", ">= 0.0.4"
5
5
 
6
6
  # Add dependencies to develop your gem here.
data/Gemfile.lock CHANGED
@@ -28,7 +28,7 @@ GEM
28
28
  oauth2
29
29
  hashie (3.4.3)
30
30
  highline (1.7.8)
31
- html_gen (0.0.6)
31
+ html_gen (0.0.7)
32
32
  string-cases
33
33
  jeweler (2.0.1)
34
34
  builder
@@ -90,7 +90,7 @@ DEPENDENCIES
90
90
  auto_autoloader (>= 0.0.4)
91
91
  best_practice_project!
92
92
  bundler (~> 1.0)
93
- html_gen (>= 0.0.6)
93
+ html_gen (>= 0.0.7)
94
94
  jeweler (~> 2.0.1)
95
95
  rdoc (~> 3.12)
96
96
  rspec (~> 3.4.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bootstrap_builders 0.0.1 ruby lib
5
+ # stub: bootstrap_builders 0.0.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bootstrap_builders"
9
- s.version = "0.0.1"
9
+ s.version = "0.0.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -28,12 +28,13 @@ Gem::Specification.new do |s|
28
28
  "README.md",
29
29
  "Rakefile",
30
30
  "VERSION",
31
+ "bootstrap_builders.gemspec",
31
32
  "lib/bootstrap_builders.rb",
33
+ "lib/bootstrap_builders/application_helpers.rb",
32
34
  "lib/bootstrap_builders/box.rb",
33
35
  "lib/bootstrap_builders/button.rb",
34
- "lib/bootstrap_builders/helpers.rb",
35
- "spec/bootstrap_builders/box_spec.rb",
36
- "spec/bootstrap_builders/button_spec.rb",
36
+ "spec/bootstrap_helpers/box_spec.rb",
37
+ "spec/bootstrap_helpers/button_spec.rb",
37
38
  "spec/spec_helper.rb",
38
39
  "spec/support/working_helpers.rb"
39
40
  ]
@@ -46,7 +47,7 @@ Gem::Specification.new do |s|
46
47
  s.specification_version = 4
47
48
 
48
49
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
- s.add_runtime_dependency(%q<html_gen>, [">= 0.0.6"])
50
+ s.add_runtime_dependency(%q<html_gen>, [">= 0.0.7"])
50
51
  s.add_runtime_dependency(%q<auto_autoloader>, [">= 0.0.4"])
51
52
  s.add_development_dependency(%q<rspec>, ["~> 3.4.0"])
52
53
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
@@ -55,7 +56,7 @@ Gem::Specification.new do |s|
55
56
  s.add_development_dependency(%q<best_practice_project>, [">= 0"])
56
57
  s.add_development_dependency(%q<rubocop>, ["= 0.36.0"])
57
58
  else
58
- s.add_dependency(%q<html_gen>, [">= 0.0.6"])
59
+ s.add_dependency(%q<html_gen>, [">= 0.0.7"])
59
60
  s.add_dependency(%q<auto_autoloader>, [">= 0.0.4"])
60
61
  s.add_dependency(%q<rspec>, ["~> 3.4.0"])
61
62
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -65,7 +66,7 @@ Gem::Specification.new do |s|
65
66
  s.add_dependency(%q<rubocop>, ["= 0.36.0"])
66
67
  end
67
68
  else
68
- s.add_dependency(%q<html_gen>, [">= 0.0.6"])
69
+ s.add_dependency(%q<html_gen>, [">= 0.0.7"])
69
70
  s.add_dependency(%q<auto_autoloader>, [">= 0.0.4"])
70
71
  s.add_dependency(%q<rspec>, ["~> 3.4.0"])
71
72
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
File without changes
@@ -1,4 +1,4 @@
1
- module Helpers
1
+ module ApplicationHelpers
2
2
  def bs_box(*opts, &blk)
3
3
  title = opts.shift unless opts.first.is_a?(Hash)
4
4
  width = opts.shift unless opts.first.is_a?(Hash)
@@ -12,28 +12,27 @@ module Helpers
12
12
  args = {}
13
13
  end
14
14
 
15
- BootstrapBuilders::Box.new(args.merge(title: title, width: width, right: right, block: blk)).html
15
+ BootstrapBuilders::Box.new(args.merge(title: title, width: width, right: right, block: blk, context: self)).html
16
16
  end
17
17
 
18
18
  def bs_edit_button(args)
19
- BootstrapBuilders::Button.new(args.merge(title: t("edit"), icon: "wrench", context: self)).html
19
+ BootstrapBuilders::Button.new(args.merge(title: t("edit"), icon: "wrench", context: self, can_type: :edit)).html
20
20
  end
21
21
 
22
22
  def bs_destroy_button(args)
23
- args[:class] ||= []
24
- args[:class] << "btn-danger"
25
-
26
23
  args[:data] ||= {}
27
24
  args[:data][:confirm] ||= t("are_you_sure")
28
25
 
29
- BootstrapBuilders::Button.new(args.merge(title: t("delete"), icon: "remove", context: self, method: :delete)).html
26
+ button = BootstrapBuilders::Button.new(args.merge(title: t("delete"), icon: "remove", context: self, can_type: :destroy, method: :delete))
27
+ button.classes << "btn-danger"
28
+ button.html
30
29
  end
31
30
 
32
31
  def bs_new_button(args)
33
- BootstrapBuilders::Button.new(args.merge(title: t("add_new"), icon: "pencil", context: self)).html
32
+ BootstrapBuilders::Button.new(args.merge(title: t("add_new"), icon: "pencil", context: self, can_type: :new)).html
34
33
  end
35
34
 
36
35
  def bs_show_button(args)
37
- BootstrapBuilders::Button.new(args.merge(title: t("show"), icon: "zoom-in", context: self)).html
36
+ BootstrapBuilders::Button.new(args.merge(title: t("show"), icon: "zoom-in", context: self, can_type: :show)).html
38
37
  end
39
38
  end
@@ -5,12 +5,17 @@ class BootstrapBuilders::Box
5
5
  @right = args[:right]
6
6
  @table = args[:table]
7
7
  @block = args.fetch(:block)
8
+ @context = args.fetch(:context)
8
9
 
9
- @width = "#{@width}px" if @width.is_a?(Fixnum) || @width.is_a?(Integer)
10
+ if @width.is_a?(Fixnum) || @width.is_a?(Integer)
11
+ @width = "#{@width}px"
12
+ else
13
+ @width = "100%"
14
+ end
10
15
  end
11
16
 
12
17
  def html
13
- @panel = HtmlGen::Element.new(:div, classes: ["panel", "panel-default"], css: {width: @width})
18
+ @panel = HtmlGen::Element.new(:div, inden: " ", classes: ["panel", "panel-default"], css: {width: @width})
14
19
 
15
20
  add_heading if @title || @right
16
21
 
@@ -34,14 +39,14 @@ private
34
39
  def add_heading
35
40
  heading = @panel.add_ele(:div, classes: ["panel-heading", "clearfix"])
36
41
  title = heading.add_ele(:div, classes: ["panel-title", "pull-left"], str: @title)
37
- title.add_ele(:div, classes: ["pull-right"], str_html: @right)
42
+ heading.add_ele(:div, classes: ["pull-right"], str_html: @right.to_s) if @right
38
43
  end
39
44
 
40
45
  def add_table
41
- @panel.add_ele(:table, classes: ["table", "table-striped", "table-hover"], str_html: @block.call)
46
+ @panel.add_html(@context.content_tag(:table, nil, class: ["table", "table-striped", "table-hover"], &@block))
42
47
  end
43
48
 
44
49
  def add_body
45
- @panel.add_ele(:div, classes: ["panel-body"], str_html: @block.call)
50
+ @panel.add_html(@context.content_tag(:div, nil, class: ["panel-body"], &@block))
46
51
  end
47
52
  end
@@ -0,0 +1,63 @@
1
+ class BootstrapBuilders::Button
2
+ def initialize(args)
3
+ @title = args.fetch(:title)
4
+ @mini = args[:mini]
5
+ @class = args[:class]
6
+ @url = args.fetch(:url)
7
+ @args = args
8
+ @context = args.fetch(:context)
9
+ @icon = args.fetch(:icon)
10
+ can = args[:can]
11
+ end
12
+
13
+ def classes
14
+ unless @classes
15
+ @classes = ["btn", "btn-default"]
16
+ @classes << "btn-xs" if @mini
17
+
18
+ if @class.is_a?(String)
19
+ @classes += @class.split(/\s+/)
20
+ elsif @class.is_a?(Array)
21
+ @classes += @class
22
+ end
23
+ end
24
+
25
+ @classes
26
+ end
27
+
28
+ def html
29
+ return unless can?
30
+
31
+ @context.link_to @url, class: classes, data: @args[:data], method: @args[:method], remote: @args[:remote] do
32
+ html = ""
33
+ html << @context.content_tag(:i, nil, class: ["fa", "fa-#{@icon}"])
34
+ html << " #{@title}"
35
+ html.html_safe
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def model_from_url(url)
42
+ if url.is_a?(Array) && url.last.is_a?(ActiveRecord::Base)
43
+ url.last
44
+ elsif url.is_a?(ActiveRecord::Base)
45
+ url
46
+ else
47
+ return nil
48
+ end
49
+ end
50
+
51
+ def can?
52
+ return true if !can_object || !@args[:can_type]
53
+ @context.can? @args.fetch(:can_type), can_object
54
+ end
55
+
56
+ def can_object
57
+ if @args[:can]
58
+ @args[:can]
59
+ elsif @args[:url].is_a?(Array) && @args[:url].last.is_a?(ActiveRecord::Base)
60
+ @args[:url].last
61
+ end
62
+ end
63
+ end
@@ -7,6 +7,6 @@ describe BootstrapBuilders::Button do
7
7
  html = bs_edit_button(url: "/test/url")
8
8
  expect(html).to include "/test/url"
9
9
  expect(html).to include "edit"
10
- expect(html).to include "fa-wrench"
10
+ expect(html).to include "fa fa-wrench"
11
11
  end
12
12
  end
@@ -1,5 +1,5 @@
1
1
  module WorkingHelpers
2
- include BootstrapBuilders::Helpers
2
+ include BootstrapBuilders::ApplicationHelpers
3
3
 
4
4
  def t(key)
5
5
  key
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_builders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.6
19
+ version: 0.0.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.6
26
+ version: 0.0.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: auto_autoloader
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -139,11 +139,11 @@ files:
139
139
  - README.md
140
140
  - Rakefile
141
141
  - VERSION
142
- - bootstrap_helpers.gemspec
143
- - lib/bootstrap_helpers.rb
144
- - lib/bootstrap_helpers/box.rb
145
- - lib/bootstrap_helpers/button.rb
146
- - lib/bootstrap_helpers/helpers.rb
142
+ - bootstrap_builders.gemspec
143
+ - lib/bootstrap_builders.rb
144
+ - lib/bootstrap_builders/application_helpers.rb
145
+ - lib/bootstrap_builders/box.rb
146
+ - lib/bootstrap_builders/button.rb
147
147
  - spec/bootstrap_helpers/box_spec.rb
148
148
  - spec/bootstrap_helpers/button_spec.rb
149
149
  - spec/spec_helper.rb
@@ -1,41 +0,0 @@
1
- class BootstrapBuilders::Button
2
- def initialize(args)
3
- @title = args.fetch(:title)
4
- @mini = args[:mini]
5
- @class = args[:class]
6
- @url = args.fetch(:url)
7
- @args = args
8
- @context = args.fetch(:context)
9
- @icon = args.fetch(:icon)
10
- end
11
-
12
- def html
13
- classes = ["btn", "btn-default"]
14
- classes << "btn-xs" if @mini
15
-
16
- if @class.is_a?(String)
17
- classes += @class.split(/\s+/)
18
- elsif @class.is_a?(Array)
19
- classes += @class
20
- end
21
-
22
- @context.link_to @url, class: classes, data: @args[:data], method: @args[:method], remote: @args[:remote] do
23
- html = ""
24
- html << @context.content_tag(:i, class: ["fa", "fa-#{@icon}"])
25
- html << " #{@title}"
26
- html.html_safe
27
- end
28
- end
29
-
30
- private
31
-
32
- def model_from_url(url)
33
- if url.is_a?(Array) && url.last.is_a?(ActiveRecord::Base)
34
- url.last
35
- elsif url.is_a?(ActiveRecord::Base)
36
- url
37
- else
38
- return nil
39
- end
40
- end
41
- end