booties 0.0.2 → 0.0.3
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 +4 -4
- data/Rakefile +1 -5
- data/app/helpers/booties/application_helper.rb +2 -150
- data/app/helpers/booties/badge_helper.rb +46 -0
- data/app/helpers/booties/button_helper.rb +33 -0
- data/app/helpers/booties/flag_helper.rb +59 -0
- data/app/helpers/booties/modal_helper.rb +34 -0
- data/app/helpers/booties/panel_helper.rb +27 -0
- data/app/helpers/booties/tooltip_helper.rb +48 -0
- data/lib/booties.rb +1 -3
- data/lib/booties/panel.rb +2 -1
- data/lib/booties/utils.rb +9 -0
- data/lib/booties/version.rb +1 -1
- data/test/booties/utils_test.rb +22 -0
- data/test/dummy/app/controllers/home_controller.rb +6 -0
- data/test/dummy/app/views/home/button.html.erb +2 -0
- data/test/dummy/app/views/home/tooltip.html.erb +7 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/log/test.log +8186 -0
- data/test/dummy/test/controllers/home_controller_test.rb +16 -0
- data/test/helpers/booties/application_helper_test.rb +0 -79
- data/test/helpers/booties/badge_helper_test.rb +20 -0
- data/test/helpers/booties/button_helper_test.rb +25 -0
- data/test/helpers/booties/flag_helper_test.rb +30 -0
- data/test/helpers/booties/modal_helper_test.rb +19 -0
- data/test/helpers/booties/panel_helper_test.rb +32 -0
- data/test/helpers/booties/tooltip_helper_test.rb +48 -0
- data/test/stub_view.rb +4 -4
- data/test/test_helper.rb +1 -1
- metadata +43 -5
- data/lib/booties_test.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a66be60fe90b8f933b1069cd95547a3cf65c2aee
|
4
|
+
data.tar.gz: d7aa68425b199de2861dd327db7b4df785181f37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfc5aaa93a099d58ae25b1cdfe6a595615df279e36cb7d1b1abdace7099aeb56c12d96222d1b1fd92d6b95603f7f343eb51d9dbabd824d4b8628f1c0257aef94
|
7
|
+
data.tar.gz: 17d92569754f99df5a0e8276a20905ff3d7069bba910a39d889bc35d1d6a882330851eee2209bd419d421e758d5e51d8534e85cb5999c4dc585f959933916ca4
|
data/Rakefile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Booties
|
2
2
|
module ApplicationHelper
|
3
|
+
include Utils
|
4
|
+
|
3
5
|
##
|
4
6
|
# Renders an ol tag with the "breadcrumb" class and fills it with the
|
5
7
|
# content of the block. The following:
|
@@ -23,155 +25,5 @@ module Booties
|
|
23
25
|
def render_breadcrumbs(&block) # :nodoc:
|
24
26
|
content_tag :ol, class: 'breadcrumb', &block
|
25
27
|
end
|
26
|
-
|
27
|
-
##
|
28
|
-
# Renders a span tag with the "label" class and a contextual label class
|
29
|
-
# derived from +context+. Defaults to "label-default". The content of the
|
30
|
-
# tag is passed in as +content+. The following:
|
31
|
-
#
|
32
|
-
# <%= flag 'foo' %>
|
33
|
-
#
|
34
|
-
# will produce:
|
35
|
-
#
|
36
|
-
# <span class="label label-default">foo</span>
|
37
|
-
#
|
38
|
-
# Alternatively, you can pass the content in as a block. The following:
|
39
|
-
#
|
40
|
-
# <%= flag do %>
|
41
|
-
# foo
|
42
|
-
# <% end %>
|
43
|
-
#
|
44
|
-
# will produce:
|
45
|
-
#
|
46
|
-
# <span class="label label-default">foo</span>
|
47
|
-
#
|
48
|
-
# You can provide a different context for the label as +context+. The
|
49
|
-
# following:
|
50
|
-
#
|
51
|
-
# <%= flag 'foo', context: :primary %>
|
52
|
-
#
|
53
|
-
# will produce:
|
54
|
-
#
|
55
|
-
# <span class="label label-primary">foo</span>
|
56
|
-
#
|
57
|
-
# Additional options passed in through +options+ will be passed to
|
58
|
-
# #content_tag to be added as attributes to the span tag. The following:
|
59
|
-
#
|
60
|
-
# <%= flag 'foo', id: 'bar' %>
|
61
|
-
#
|
62
|
-
# will produce:
|
63
|
-
#
|
64
|
-
# <span class="label label-default" id="bar">foo</span>
|
65
|
-
#
|
66
|
-
# If the +:class+ option is passed in the contents will be merged with the
|
67
|
-
# classes required by Bootstrap labels. The following:
|
68
|
-
#
|
69
|
-
# <%= flag 'foo', class: 'bar' %>
|
70
|
-
#
|
71
|
-
# will produce:
|
72
|
-
#
|
73
|
-
# <span class="label label-default bar">foo</span>
|
74
|
-
def flag(content = nil, context: :default, **options, &block)
|
75
|
-
content ||= capture &block
|
76
|
-
classes = Booties.merge_classes %W[label label-#{context}],
|
77
|
-
options.delete(:class)
|
78
|
-
content_tag :span, content, class: classes, **options
|
79
|
-
end
|
80
|
-
|
81
|
-
##
|
82
|
-
# Renders a span tag with the "badge" class. The content of the tag is
|
83
|
-
# passed in as +content+. The following:
|
84
|
-
#
|
85
|
-
# <%= badge 'foo' %>
|
86
|
-
#
|
87
|
-
# will produce:
|
88
|
-
#
|
89
|
-
# <span class="badge">foo</span>
|
90
|
-
#
|
91
|
-
# Alternatively, you can pass the content in as a block. The following:
|
92
|
-
#
|
93
|
-
# <%= badge do %> foo <% end %>
|
94
|
-
#
|
95
|
-
# will produce:
|
96
|
-
#
|
97
|
-
# <span class="badge">foo</span>
|
98
|
-
#
|
99
|
-
# Any options passed in through +options+ will be passed to #content_tag to
|
100
|
-
# be added as attributes to the span tag. The following:
|
101
|
-
#
|
102
|
-
# <%= badge 'foo', id: 'bar' %>
|
103
|
-
#
|
104
|
-
# will produce:
|
105
|
-
#
|
106
|
-
# <span class="badge" id="bar">foo</span>
|
107
|
-
#
|
108
|
-
# If the +:class+ option is passed in, the contents will be merged with the
|
109
|
-
# classes required by Bootstrap badges. The following:
|
110
|
-
#
|
111
|
-
# <%= badge 'foo', class: 'bar' %>
|
112
|
-
#
|
113
|
-
# will produce:
|
114
|
-
#
|
115
|
-
# <span class="badge bar">foo</span>
|
116
|
-
def badge(content = nil, **options, &block)
|
117
|
-
content ||= capture &block
|
118
|
-
classes = Booties.merge_classes ['badge'], options.delete(:class)
|
119
|
-
content_tag :span, content, class: classes, **options
|
120
|
-
end
|
121
|
-
|
122
|
-
##
|
123
|
-
# Renders a modal dialog. The CSS id is provided by +id+. The fade effect
|
124
|
-
# will be enabled by default, but it will be disabled if +fade+ is falsey.
|
125
|
-
#
|
126
|
-
# The contents of the dialog are passed in as a block. An instance of
|
127
|
-
# Booties::Modal will be yielded as a parameter to the block (similar to
|
128
|
-
# the way a FormBuilder works in Rails).
|
129
|
-
#
|
130
|
-
# <%= modal 'foo' do |m| %>
|
131
|
-
# <%= m.header do %>
|
132
|
-
# Nesciunt qui iste vel a.
|
133
|
-
# <% end %>
|
134
|
-
# <%= m.body do %>
|
135
|
-
# <p>
|
136
|
-
# Autem atque perferendis veritatis. Molestiae aliquid nam
|
137
|
-
# reiciendis recusandae facere. Aut non nemo dicta.
|
138
|
-
# </p>
|
139
|
-
# <% end %>
|
140
|
-
# <%= m.footer do %>
|
141
|
-
# <%= m.dismiss class: 'btn btn-default' do %>
|
142
|
-
# Dismiss
|
143
|
-
# <% end %>
|
144
|
-
# <%= link_to @widget, class: 'btn btn-danger', method: :delete do %>
|
145
|
-
# Really Delete
|
146
|
-
# <% end %>
|
147
|
-
# <% end %>
|
148
|
-
# <% end %>
|
149
|
-
def modal(id, fade: true, with: Modal, &block)
|
150
|
-
with.new(self, id: id, fade: fade).render &block
|
151
|
-
end
|
152
|
-
|
153
|
-
##
|
154
|
-
# Renders a panel. The defult panel context is +:default+ but can be
|
155
|
-
# specified through +options+. The contents of the panel should be passed
|
156
|
-
# in as a block. An instance of the Booties::Panel will be yielded as a
|
157
|
-
# parameter to the block (similar to the way a FormBuilder works in Rails).
|
158
|
-
#
|
159
|
-
# <%= panel do |p| %>
|
160
|
-
# <%= p.heading do %>
|
161
|
-
# <%= p.title 'Consequatur quibusdam quia vel et sed in.' %>
|
162
|
-
# <% end %>
|
163
|
-
# <%= p.body do %>
|
164
|
-
# <p>
|
165
|
-
# Est fuga iste reiciendis laudantium dicta. Perspiciatis vero ut
|
166
|
-
# autem quod vel modi. Ea error omnis aliquam aut est.
|
167
|
-
# </p>
|
168
|
-
# <% end %>
|
169
|
-
# <%= p.footer do %>
|
170
|
-
# Voluptatibus rerum et est quo dicta perspiciatis.
|
171
|
-
# <% end %>
|
172
|
-
# <% end %>
|
173
|
-
def panel(with: Panel, **options, &block)
|
174
|
-
with.new(self, **options).render &block
|
175
|
-
end
|
176
28
|
end
|
177
29
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Booties
|
2
|
+
module BadgeHelper
|
3
|
+
include Utils
|
4
|
+
|
5
|
+
##
|
6
|
+
# Renders a span tag with the "badge" class. The content of the tag is
|
7
|
+
# passed in as +content+. The following:
|
8
|
+
#
|
9
|
+
# <%= badge 'foo' %>
|
10
|
+
#
|
11
|
+
# will produce:
|
12
|
+
#
|
13
|
+
# <span class="badge">foo</span>
|
14
|
+
#
|
15
|
+
# Alternatively, you can pass the content in as a block. The following:
|
16
|
+
#
|
17
|
+
# <%= badge do %> foo <% end %>
|
18
|
+
#
|
19
|
+
# will produce:
|
20
|
+
#
|
21
|
+
# <span class="badge">foo</span>
|
22
|
+
#
|
23
|
+
# Any options passed in through +options+ will be passed to #content_tag to
|
24
|
+
# be added as attributes to the span tag. The following:
|
25
|
+
#
|
26
|
+
# <%= badge 'foo', id: 'bar' %>
|
27
|
+
#
|
28
|
+
# will produce:
|
29
|
+
#
|
30
|
+
# <span class="badge" id="bar">foo</span>
|
31
|
+
#
|
32
|
+
# If the +:class+ option is passed in, the contents will be merged with the
|
33
|
+
# classes required by Bootstrap badges. The following:
|
34
|
+
#
|
35
|
+
# <%= badge 'foo', class: 'bar' %>
|
36
|
+
#
|
37
|
+
# will produce:
|
38
|
+
#
|
39
|
+
# <span class="badge bar">foo</span>
|
40
|
+
def badge(content = nil, **options, &block)
|
41
|
+
content ||= capture &block
|
42
|
+
classes = merge_classes ['badge'], options.delete(:class)
|
43
|
+
content_tag :span, content, class: classes, **options
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Booties
|
2
|
+
module ButtonHelper
|
3
|
+
include Utils
|
4
|
+
|
5
|
+
##
|
6
|
+
# Renders a link as a Bootstrap button. The default behavior is to add the
|
7
|
+
# .btn and btn-default classes to the rendered tag. The button context can
|
8
|
+
# be overridden to something other than .btn-default such as .btn-primary
|
9
|
+
# using the +context+ parameter. The +name+, +options+, +html_options+, and
|
10
|
+
# +block+ paramters are passed through to #link_to.
|
11
|
+
#
|
12
|
+
# If +html_options+ includes a +:class+ option, the classes will be merged
|
13
|
+
# with the required .btn classes.
|
14
|
+
#
|
15
|
+
# Examples:
|
16
|
+
#
|
17
|
+
# <%= btn_link_to 'View', thingies_path %>
|
18
|
+
#
|
19
|
+
# <a href="/thingies" class="btn btn-default">View</a>
|
20
|
+
#
|
21
|
+
# <%= btn_link_to 'Sign out', destroy_user_session_path, context: :danger, class: 'btn-xs', method: :delete %>
|
22
|
+
#
|
23
|
+
# <a href="/users/sign_out" class="btn btn-danger btn-xs" data-method="delete">Sign out</a>
|
24
|
+
def btn_link_to(name = nil, options = nil, html_options = nil, &block)
|
25
|
+
name, options, html_options = capture(&block), name, options if block_given?
|
26
|
+
html_options ||= {}
|
27
|
+
context = html_options.delete(:context) { :default }
|
28
|
+
html_options[:class] = \
|
29
|
+
merge_classes %W[btn btn-#{context}], html_options[:class]
|
30
|
+
link_to name, options, html_options
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Booties
|
2
|
+
module FlagHelper
|
3
|
+
include Utils
|
4
|
+
|
5
|
+
##
|
6
|
+
# Renders a span tag with the "label" class and a contextual label class
|
7
|
+
# derived from +context+. Defaults to "label-default". The content of the
|
8
|
+
# tag is passed in as +content+. The following:
|
9
|
+
#
|
10
|
+
# <%= flag 'foo' %>
|
11
|
+
#
|
12
|
+
# will produce:
|
13
|
+
#
|
14
|
+
# <span class="label label-default">foo</span>
|
15
|
+
#
|
16
|
+
# Alternatively, you can pass the content in as a block. The following:
|
17
|
+
#
|
18
|
+
# <%= flag do %>
|
19
|
+
# foo
|
20
|
+
# <% end %>
|
21
|
+
#
|
22
|
+
# will produce:
|
23
|
+
#
|
24
|
+
# <span class="label label-default">foo</span>
|
25
|
+
#
|
26
|
+
# You can provide a different context for the label as +context+. The
|
27
|
+
# following:
|
28
|
+
#
|
29
|
+
# <%= flag 'foo', context: :primary %>
|
30
|
+
#
|
31
|
+
# will produce:
|
32
|
+
#
|
33
|
+
# <span class="label label-primary">foo</span>
|
34
|
+
#
|
35
|
+
# Additional options passed in through +options+ will be passed to
|
36
|
+
# #content_tag to be added as attributes to the span tag. The following:
|
37
|
+
#
|
38
|
+
# <%= flag 'foo', id: 'bar' %>
|
39
|
+
#
|
40
|
+
# will produce:
|
41
|
+
#
|
42
|
+
# <span class="label label-default" id="bar">foo</span>
|
43
|
+
#
|
44
|
+
# If the +:class+ option is passed in the contents will be merged with the
|
45
|
+
# classes required by Bootstrap labels. The following:
|
46
|
+
#
|
47
|
+
# <%= flag 'foo', class: 'bar' %>
|
48
|
+
#
|
49
|
+
# will produce:
|
50
|
+
#
|
51
|
+
# <span class="label label-default bar">foo</span>
|
52
|
+
def flag(content = nil, context: :default, **options, &block)
|
53
|
+
content ||= capture &block
|
54
|
+
classes = merge_classes %W[label label-#{context}],
|
55
|
+
options.delete(:class)
|
56
|
+
content_tag :span, content, class: classes, **options
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Booties
|
2
|
+
module ModalHelper
|
3
|
+
##
|
4
|
+
# Renders a modal dialog. The CSS id is provided by +id+. The fade effect
|
5
|
+
# will be enabled by default, but it will be disabled if +fade+ is falsey.
|
6
|
+
#
|
7
|
+
# The contents of the dialog are passed in as a block. An instance of
|
8
|
+
# Booties::Modal will be yielded as a parameter to the block (similar to
|
9
|
+
# the way a FormBuilder works in Rails).
|
10
|
+
#
|
11
|
+
# <%= modal 'foo' do |m| %>
|
12
|
+
# <%= m.header do %>
|
13
|
+
# Nesciunt qui iste vel a.
|
14
|
+
# <% end %>
|
15
|
+
# <%= m.body do %>
|
16
|
+
# <p>
|
17
|
+
# Autem atque perferendis veritatis. Molestiae aliquid nam
|
18
|
+
# reiciendis recusandae facere. Aut non nemo dicta.
|
19
|
+
# </p>
|
20
|
+
# <% end %>
|
21
|
+
# <%= m.footer do %>
|
22
|
+
# <%= m.dismiss class: 'btn btn-default' do %>
|
23
|
+
# Dismiss
|
24
|
+
# <% end %>
|
25
|
+
# <%= link_to @widget, class: 'btn btn-danger', method: :delete do %>
|
26
|
+
# Really Delete
|
27
|
+
# <% end %>
|
28
|
+
# <% end %>
|
29
|
+
# <% end %>
|
30
|
+
def modal(id, fade: true, with: Modal, &block)
|
31
|
+
with.new(self, id: id, fade: fade).render &block
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Booties
|
2
|
+
module PanelHelper
|
3
|
+
##
|
4
|
+
# Renders a panel. The defult panel context is +:default+ but can be
|
5
|
+
# specified through +options+. The contents of the panel should be passed
|
6
|
+
# in as a block. An instance of the Booties::Panel will be yielded as a
|
7
|
+
# parameter to the block (similar to the way a FormBuilder works in Rails).
|
8
|
+
#
|
9
|
+
# <%= panel do |p| %>
|
10
|
+
# <%= p.heading do %>
|
11
|
+
# <%= p.title 'Consequatur quibusdam quia vel et sed in.' %>
|
12
|
+
# <% end %>
|
13
|
+
# <%= p.body do %>
|
14
|
+
# <p>
|
15
|
+
# Est fuga iste reiciendis laudantium dicta. Perspiciatis vero ut
|
16
|
+
# autem quod vel modi. Ea error omnis aliquam aut est.
|
17
|
+
# </p>
|
18
|
+
# <% end %>
|
19
|
+
# <%= p.footer do %>
|
20
|
+
# Voluptatibus rerum et est quo dicta perspiciatis.
|
21
|
+
# <% end %>
|
22
|
+
# <% end %>
|
23
|
+
def panel(with: Panel, **options, &block)
|
24
|
+
with.new(self, **options).render &block
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Booties
|
2
|
+
module TooltipHelper
|
3
|
+
##
|
4
|
+
# Wraps the content provided by +block+ with a Bootstrap tooltip. The text
|
5
|
+
# of the tooltip is passed in through the required +title+ parameter. The
|
6
|
+
# optional +placement+ parameter can be used to control alignment of the
|
7
|
+
# tooltip. Valid placements are :top, :bottom, :left, and :right.
|
8
|
+
# Additional paramters given in +options+ are passed through to
|
9
|
+
# #content_tag to be placed on the resulting tag.
|
10
|
+
#
|
11
|
+
# A caveat: Bootstrap tooltips are opt-in. You must initialize them
|
12
|
+
# yourself. One way to do this is to include the following Javascript
|
13
|
+
# snippet on the page:
|
14
|
+
#
|
15
|
+
# $(function() { $('[data-toggle="tooltip"]').tooltip() }
|
16
|
+
#
|
17
|
+
# Examples:
|
18
|
+
#
|
19
|
+
# <%= tooltip title: 'This is a tooltip' do %>
|
20
|
+
# This has a tooltip.
|
21
|
+
# <% end %>
|
22
|
+
#
|
23
|
+
# <span data-toggle="tooltip" title="This is a tooltip">This has a tooltip.</span>
|
24
|
+
#
|
25
|
+
# <%= tooltip title: 'This is a tooltip', placement: :bottom %>
|
26
|
+
# This has a tooltip.
|
27
|
+
# <% end %>
|
28
|
+
#
|
29
|
+
# <span data-toggle="tooltip" data-placement="bottom" title="This is a tooltip">This has a tooltip.</span>
|
30
|
+
#
|
31
|
+
# <%= tooltip title: 'This is a tooltip', class: 'tooltip' %>
|
32
|
+
# This has a tooltip.
|
33
|
+
# <% end %>
|
34
|
+
#
|
35
|
+
# <span data-toggle="tooltip" title="This is a tooltip" class="tooltip">This has a tooltip.</span>
|
36
|
+
def tooltip(title:, placement: nil, **options, &block)
|
37
|
+
unless [nil, :top, :bottom, :right, :left].include? placement
|
38
|
+
raise ArgumentError, "invalid placement: #{placement.inspect}," \
|
39
|
+
' valid placements are: :top, :bottom, :right, :left'
|
40
|
+
end
|
41
|
+
|
42
|
+
data = { toggle: 'tooltip' }
|
43
|
+
data[:placement] = placement if placement
|
44
|
+
|
45
|
+
content_tag :span, data: data, title: title, **options, &block
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|