bootstrap4_helper 0.0.0 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
1
+ module Bootstrap4Helper
2
+ # Builds a Nav Component that can be used in other components.
3
+ #
4
+ #
5
+ class Nav < Component
6
+ # Class constructor
7
+ #
8
+ # @param [ActionView] template
9
+ # @param [Hash] opts
10
+ # @option opts [String] :id
11
+ # @option opts [String] :class
12
+ # @option opts [Hash] :data
13
+ # @option opts [Hash] :child
14
+ #
15
+ def initialize(template, opts = {}, &block)
16
+ super(template)
17
+
18
+ @id = opts.fetch(:id, uuid)
19
+ @class = opts.fetch(:class, '')
20
+ @data = opts.fetch(:data, {})
21
+ @child = opts.fetch(:child, {})
22
+ @content = block || proc { '' }
23
+
24
+ @dropdown = Dropdown.new(@template)
25
+ end
26
+
27
+ # rubocop:disable Metrics/MethodLength
28
+
29
+ # Adds an nav-item to the nav component. this method gets used when the nav-item
30
+ # links to content in a tab or something.
31
+ #
32
+ # @param [Symbol|String] target
33
+ # @param [Hash] opts
34
+ # @option opts [String] :id
35
+ # @option opts [String] :class
36
+ # @option opts [Hash] :data
37
+ # @option opts [Hash] :aria
38
+ # @return [String]
39
+ #
40
+ def item(target, opts = {})
41
+ id = opts.fetch(:id, nil)
42
+ klass = opts.fetch(:class, '')
43
+ data = opts.fetch(:data, {})
44
+ aria = opts.fetch(:aria, {})
45
+
46
+ content_tag :li, id: id, class: 'nav-item', data: data do
47
+ content_tag(
48
+ :a,
49
+ class: "nav-link #{klass}",
50
+ href: "##{target}",
51
+ tabindex: -1,
52
+ data: @child[:data],
53
+ aria: aria
54
+ ) do
55
+ block_given? ? yield : target.to_s.titleize
56
+ end
57
+ end
58
+ end
59
+ # rubocop:enable Metrics/MethodLength
60
+
61
+ # Use this when the nav item is nothing more than a hyperlink.
62
+ #
63
+ # @param [String|NilClass] name
64
+ # @param [Hash|NilClass] options
65
+ # @param [Hash|NilClass] html_options
66
+ # @return [String]
67
+ #
68
+ def link(name = nil, options = nil, html_options = nil, &block)
69
+ html_options = (html_options || {}).merge(class: 'nav-link')
70
+
71
+ @template.link_to(name, options, html_options, &block)
72
+ end
73
+
74
+ # Creates a dropdown menu for the nav.
75
+ #
76
+ # @param [NilClass|Symbol|String] name
77
+ # @param [Hash] opts
78
+ # @option opts [String] :id
79
+ # @option opts [String] :class
80
+ # @option opts [Hash] :data
81
+ # @option opts [Hash] :aria
82
+ # @return [String]
83
+ #
84
+ def dropdown(name, opts = {}, &block)
85
+ id = opts.fetch(:id, nil)
86
+ klass = opts.fetch(:class, '')
87
+ data = opts.fetch(:data, {})
88
+ aria = opts.fetch(:aria, {}).merge(haspopup: true, expanded: false)
89
+
90
+ content_tag :li, id: id, class: 'nav-item dropdown', data: data do
91
+ content_tag(
92
+ :a,
93
+ name,
94
+ class: "nav-link dropdown-toggle #{klass}",
95
+ href: '#',
96
+ data: { toggle: 'dropdown' },
97
+ role: 'button',
98
+ aria: aria
99
+ ) + @dropdown.menu(opts, &block).to_s.html_safe
100
+ end
101
+ end
102
+
103
+ # String representation of the object.
104
+ #
105
+ # @return [String]
106
+ #
107
+ def to_s
108
+ content_tag :ul, id: @id, class: "nav #{@class}" do
109
+ @content.call(self)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -1,4 +1,12 @@
1
1
  module Bootstrap4Helper
2
+ # Simple Railtie to hook out module into ActionView.
3
+ #
4
+ #
2
5
  class Railtie < ::Rails::Railtie
6
+ config.after_initialize do
7
+ ActiveSupport.on_load(:action_view) do
8
+ include Bootstrap4Helper if Bootstrap4Helper.config.autoload_in_views?
9
+ end
10
+ end
3
11
  end
4
12
  end
@@ -0,0 +1,44 @@
1
+ module Bootstrap4Helper
2
+ # Builds a simple CSS spinner component.
3
+ #
4
+ #
5
+ class Spinner < Component
6
+ # Class constructor
7
+ #
8
+ # @note The different support types are: `:border` and `:grow`
9
+ #
10
+ # @param [ActionView] template
11
+ # @param [Hash] opts
12
+ # @option opts [Symbol] :type
13
+ # @option opts [String] :id
14
+ # @option opts [String] :class
15
+ # @option opts [Hash] :data
16
+ #
17
+ def initialize(template, opts = {}, &block)
18
+ super(template)
19
+
20
+ @type = opts.fetch(:type, :border)
21
+ @id = opts.fetch(:id, uuid)
22
+ @class = opts.fetch(:class, '')
23
+ @data = opts.fetch(:data, {})
24
+ @content = block || proc { '' }
25
+ end
26
+
27
+ # String representation of the object.
28
+ #
29
+ # @return [String]
30
+ #
31
+ def to_s
32
+ content_tag(
33
+ :span,
34
+ id: @id,
35
+ class: "spinner-#{@type} #{@class}",
36
+ role: 'status',
37
+ aria: { hidden: true },
38
+ data: @data
39
+ ) do
40
+ content_tag :span, 'Loading', class: 'sr-only'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,70 @@
1
+ module Bootstrap4Helper
2
+ # Builds a Tab component.
3
+ #
4
+ #
5
+ class Tab < Component
6
+ # Class constructor
7
+ #
8
+ # @note The support types are: `:tabs` and `:pills`
9
+ #
10
+ # @param [ActionView] template
11
+ # @param [Hash] opts
12
+ # @option opts [Symbol] :type
13
+ # @option opts [String] :id
14
+ # @option opts [String] :class
15
+ # @option opts [Hash] :data
16
+ #
17
+ def initialize(template, opts = {}, &block)
18
+ super(template)
19
+
20
+ @type = opts.fetch(:type, :tabs)
21
+ @id = opts.fetch(:id, uuid)
22
+ @class = opts.fetch(:class, '')
23
+ @data = opts.fetch(:data, {})
24
+ @content = block || proc { '' }
25
+ end
26
+
27
+ # Builds a custom Nav component for the tabs.
28
+ #
29
+ # @param [Hash] opts
30
+ # @option opts [String] :class
31
+ # @option opts [Hash] :data
32
+ # @return [Nav]
33
+ #
34
+ def nav(opts = {}, &block)
35
+ opts[:class] = (opts[:class] || '') << " nav-#{@type}"
36
+ opts[:data] = (opts[:data] || {}).merge(toggle: 'tab')
37
+ opts[:child] = {
38
+ data: {
39
+ toggle: 'tab'
40
+ }
41
+ }
42
+
43
+ Nav.new(@template, opts, &block)
44
+ end
45
+
46
+ # Builds the Content object for the Tab.
47
+ #
48
+ # @param [Hash] opts
49
+ # @option opts [String] :id
50
+ # @option opts [String] :class
51
+ # @option opts [Hash] :data
52
+ # @return [Tab::Content]
53
+ #
54
+ def content(opts = {}, &block)
55
+ Content.new(@template, opts, &block)
56
+ end
57
+
58
+ # This has a weird interaction. Because this object doesn't actually return any wrapping
59
+ # string or DOM element, we want to return nil, so that only the output buffer on the sub components are
60
+ # returned.
61
+ # If we return the return value of the block, we will get the last element added to the input
62
+ # buffer as an unescaped string.
63
+ #
64
+ def to_s
65
+ @content.call(self)
66
+
67
+ nil
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,58 @@
1
+ module Bootstrap4Helper
2
+ class Tab
3
+ # Build a Content component to be used with Tabs
4
+ #
5
+ #
6
+ class Content < Component
7
+ # Class constructor
8
+ #
9
+ # @param [ActionView] template
10
+ # @param [Hash] opts
11
+ # @option opts [String] :id
12
+ # @option opts [String] :class
13
+ # @option opts [Hash] :data
14
+ #
15
+ def initialize(template, opts = {}, &block)
16
+ super(template)
17
+
18
+ @id = opts.fetch(:id, uuid)
19
+ @class = opts.fetch(:class, '')
20
+ @data = opts.fetch(:data, {})
21
+ @content = block || proc { '' }
22
+ end
23
+
24
+ # Builds the pane for the tab.
25
+ #
26
+ # @param [Symbol] source
27
+ # @param [Hash] opts
28
+ # @option opts [String] :class
29
+ # @option opts [Hash] :data
30
+ # @return [String]
31
+ #
32
+ def pane(source, opts = {}, &block)
33
+ id = opts.fetch(:id, source)
34
+ klass = opts.fetch(:class, '')
35
+ data = opts.fetch(:data, {})
36
+
37
+ content_tag(
38
+ :div,
39
+ id: id,
40
+ class: "tab-pane #{klass}",
41
+ role: 'tabpanel',
42
+ data: data,
43
+ &block
44
+ )
45
+ end
46
+
47
+ # String representation of the object.
48
+ #
49
+ # @return [String]
50
+ #
51
+ def to_s
52
+ content_tag :div, id: @id, class: "tab-content #{@class}" do
53
+ @content.call(self)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module Bootstrap4Helper
2
- VERSION = '0.0.0'.freeze
2
+ VERSION = '1.0.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,29 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap4_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert David
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-06 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ - - "<="
18
21
  - !ruby/object:Gem::Version
19
- version: 5.2.3
22
+ version: 7.0.0
20
23
  type: :runtime
21
24
  prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bootstrap
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 4.3.1
40
+ type: :development
41
+ prerelease: false
22
42
  version_requirements: !ruby/object:Gem::Requirement
23
43
  requirements:
24
44
  - - "~>"
25
45
  - !ruby/object:Gem::Version
26
- version: 5.2.3
46
+ version: 4.3.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: jquery-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 5.2.4
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 5.2.4
75
+ - !ruby/object:Gem::Dependency
76
+ name: redcarpet
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: solargraph
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
27
117
  - !ruby/object:Gem::Dependency
28
118
  name: sqlite3
29
119
  requirement: !ruby/object:Gem::Requirement
@@ -49,7 +139,27 @@ files:
49
139
  - README.md
50
140
  - Rakefile
51
141
  - lib/bootstrap4_helper.rb
142
+ - lib/bootstrap4_helper/accordion.rb
143
+ - lib/bootstrap4_helper/accordion_group.rb
144
+ - lib/bootstrap4_helper/alert.rb
145
+ - lib/bootstrap4_helper/badge.rb
146
+ - lib/bootstrap4_helper/card.rb
147
+ - lib/bootstrap4_helper/card_column.rb
148
+ - lib/bootstrap4_helper/card_deck.rb
149
+ - lib/bootstrap4_helper/card_group.rb
150
+ - lib/bootstrap4_helper/card_grouping.rb
151
+ - lib/bootstrap4_helper/component.rb
152
+ - lib/bootstrap4_helper/configuration.rb
153
+ - lib/bootstrap4_helper/constants.rb
154
+ - lib/bootstrap4_helper/dropdown.rb
155
+ - lib/bootstrap4_helper/dropdown/menu.rb
156
+ - lib/bootstrap4_helper/initialize.rb
157
+ - lib/bootstrap4_helper/modal.rb
158
+ - lib/bootstrap4_helper/nav.rb
52
159
  - lib/bootstrap4_helper/railtie.rb
160
+ - lib/bootstrap4_helper/spinner.rb
161
+ - lib/bootstrap4_helper/tab.rb
162
+ - lib/bootstrap4_helper/tab/content.rb
53
163
  - lib/bootstrap4_helper/version.rb
54
164
  - lib/tasks/bootstrap4_helper_tasks.rake
55
165
  homepage: https://github.com/rdavid369/bootstrap4-helper
@@ -71,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
181
  - !ruby/object:Gem::Version
72
182
  version: '0'
73
183
  requirements: []
74
- rubyforge_project:
75
- rubygems_version: 2.7.6
184
+ rubygems_version: 3.1.3
76
185
  signing_key:
77
186
  specification_version: 4
78
187
  summary: Library for rapidly building bootstrap 4 components