bootstrap_ui_helper 0.3.0
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/bootstrap_ui_helper.js +113 -0
- data/app/assets/stylesheets/bootstrap_ui_helper.css +12 -0
- data/app/helpers/alert_box_helper.rb +50 -0
- data/app/helpers/badge_helper.rb +12 -0
- data/app/helpers/bootstrap_form_helper.rb +191 -0
- data/app/helpers/bootstrap_form_options_helper.rb +141 -0
- data/app/helpers/breadcrumb_helper.rb +23 -0
- data/app/helpers/button_helper.rb +91 -0
- data/app/helpers/button_to_helper.rb +17 -0
- data/app/helpers/dropdown_helper.rb +137 -0
- data/app/helpers/format_helper.rb +12 -0
- data/app/helpers/icon_helper.rb +112 -0
- data/app/helpers/label_helper.rb +33 -0
- data/app/helpers/link_helper.rb +53 -0
- data/app/helpers/modal_helper.rb +65 -0
- data/app/helpers/nav_helper.rb +56 -0
- data/app/helpers/navbar_helper.rb +68 -0
- data/app/helpers/panel_helper.rb +78 -0
- data/app/helpers/panel_row_helper.rb +12 -0
- data/app/helpers/progress_bar_helper.rb +72 -0
- data/app/helpers/valid_icons.rb +160 -0
- data/bootstrap_ui_helper.gemspec +23 -0
- data/codeclimate.yml +58 -0
- data/lib/bootstrap_ui_helper.rb +6 -0
- data/lib/bootstrap_ui_helper/version.rb +3 -0
- metadata +103 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
module LabelHelper
|
2
|
+
include FormatHelper
|
3
|
+
|
4
|
+
def label_bui(content=nil, options={})
|
5
|
+
return if content.blank?
|
6
|
+
|
7
|
+
tag = options.delete(:tag).try(:to_sym).presence || :span
|
8
|
+
prepend_class(options, 'label', get_label_type(options.delete(:type)))
|
9
|
+
|
10
|
+
content_tag tag, content, options
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def get_label_type(type)
|
16
|
+
case type.try(:to_sym)
|
17
|
+
when :default
|
18
|
+
'label-default'
|
19
|
+
when :primary
|
20
|
+
'label-primary'
|
21
|
+
when :success
|
22
|
+
'label-success'
|
23
|
+
when :info
|
24
|
+
'label-info'
|
25
|
+
when :warning
|
26
|
+
'label-warning'
|
27
|
+
when :danger
|
28
|
+
'label-danger'
|
29
|
+
else
|
30
|
+
'label-default'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module LinkHelper
|
2
|
+
include FormatHelper
|
3
|
+
|
4
|
+
def navbar_link_to(name = nil, options = nil, html_options = nil, &block)
|
5
|
+
html_options, options, name = options, name, block if block_given?
|
6
|
+
options ||= {}
|
7
|
+
html_options ||= {}
|
8
|
+
|
9
|
+
prepend_class(html_options, 'navbar-link')
|
10
|
+
|
11
|
+
return link_to(name, options, html_options) unless block_given?
|
12
|
+
|
13
|
+
link_to options, html_options do
|
14
|
+
yield name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def navbar_link(name = nil, options = nil, html_options = nil, &block)
|
19
|
+
html_options, options, name = options, name, block if block_given?
|
20
|
+
options ||= {}
|
21
|
+
html_options ||= {}
|
22
|
+
|
23
|
+
prepend_class(html_options, 'navbar-link')
|
24
|
+
active = 'active' if html_options.delete(:active)
|
25
|
+
|
26
|
+
|
27
|
+
content_tag :li, class: active do
|
28
|
+
if block_given?
|
29
|
+
link_to options, html_options do
|
30
|
+
yield name
|
31
|
+
end
|
32
|
+
else
|
33
|
+
link_to name, options, html_options
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def navbar_brand(name = nil, options = nil, html_options = nil, &block)
|
39
|
+
html_options, options, name = options, name, block if block_given?
|
40
|
+
options ||= {}
|
41
|
+
html_options ||= {}
|
42
|
+
|
43
|
+
prepend_class(html_options, 'navbar-brand')
|
44
|
+
|
45
|
+
if block_given?
|
46
|
+
link_to options, html_options do
|
47
|
+
yield name
|
48
|
+
end
|
49
|
+
else
|
50
|
+
link_to name, options, html_options
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module ModalHelper
|
2
|
+
include ActionView::Helpers
|
3
|
+
include FormatHelper
|
4
|
+
|
5
|
+
def modal(options={}, &block)
|
6
|
+
button_options = options.delete(:button) || {}
|
7
|
+
|
8
|
+
caption = button_options.delete(:caption) || 'Modal'
|
9
|
+
modal_dialog_id = options[:id] || "modal-#{rand(0...999)}"
|
10
|
+
button_options[:data] = (button_options[:data] || {}).merge({toggle: 'modal', target: "##{modal_dialog_id}"})
|
11
|
+
size = case options.delete(:size).try(:to_sym)
|
12
|
+
when :xsmall
|
13
|
+
'modal-sm'
|
14
|
+
when :large
|
15
|
+
'modal-lg'
|
16
|
+
else
|
17
|
+
end
|
18
|
+
|
19
|
+
prepend_class(options, 'modal', 'fade')
|
20
|
+
options.merge!({id: modal_dialog_id, tabindex: -1, role: 'dialog', aria: {hidden: true}})
|
21
|
+
|
22
|
+
((button caption, button_options) +
|
23
|
+
(content_tag :div, options do
|
24
|
+
content_tag :div, class: "modal-dialog #{size}" do
|
25
|
+
content_tag :div, class: 'modal-content' do
|
26
|
+
yield if block_given?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end)).html_safe
|
30
|
+
end
|
31
|
+
|
32
|
+
def modal_header(content_or_options=nil, options={}, &block)
|
33
|
+
content_or_options.is_a?(Hash) ? options = content_or_options : content = content_or_options
|
34
|
+
|
35
|
+
prepend_class(options, 'modal-title')
|
36
|
+
|
37
|
+
content_tag :div, class: 'modal-header' do
|
38
|
+
("<button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>×</span></button>" +
|
39
|
+
(content_tag :h3, options do
|
40
|
+
content.presence || capture(&block)
|
41
|
+
end)).html_safe
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def modal_body(content_or_options=nil, options={}, &block)
|
46
|
+
content_or_options.is_a?(Hash) ? options = content_or_options : content = content_or_options
|
47
|
+
|
48
|
+
prepend_class(options, 'modal-body')
|
49
|
+
|
50
|
+
content_tag :div, options do
|
51
|
+
content.presence || capture(&block)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def modal_footer(content_or_options=nil, options={}, &block)
|
56
|
+
content_or_options.is_a?(Hash) ? options = content_or_options : content = content_or_options
|
57
|
+
|
58
|
+
prepend_class(options, 'modal-footer')
|
59
|
+
|
60
|
+
content_tag :div, options do
|
61
|
+
content.presence || capture(&block)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module NavHelper
|
2
|
+
|
3
|
+
class NavCreator
|
4
|
+
include FormatHelper
|
5
|
+
include ActionView::Helpers
|
6
|
+
|
7
|
+
attr_accessor :options
|
8
|
+
attr_accessor :output_buffer
|
9
|
+
|
10
|
+
def initialize(options)
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
nav_options = {
|
16
|
+
as: options.delete(:as).presence || :tabs,
|
17
|
+
layout: options.delete(:layout).presence
|
18
|
+
}
|
19
|
+
|
20
|
+
tag = options.delete(:tag).try(:to_sym).presence || :ul
|
21
|
+
active = options.delete(:active)
|
22
|
+
|
23
|
+
prepend_class(options, 'nav', build_nav_class(nav_options))
|
24
|
+
|
25
|
+
options.merge!(data: {bui: 'nav', active_el_locator: active})
|
26
|
+
|
27
|
+
[tag, options]
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def build_nav_class(options)
|
32
|
+
as = case options[:as].try(:to_sym)
|
33
|
+
when :tabs
|
34
|
+
'nav-tabs'
|
35
|
+
when :pills
|
36
|
+
'nav-pills'
|
37
|
+
else
|
38
|
+
end
|
39
|
+
layout = case options[:layout].try(:to_sym)
|
40
|
+
when :stacked
|
41
|
+
'nav-stacked'
|
42
|
+
when :justified
|
43
|
+
'nav-justified'
|
44
|
+
else
|
45
|
+
end
|
46
|
+
|
47
|
+
"#{as} #{layout}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def nav(options={}, &block)
|
52
|
+
tag, options = NavCreator.new(options).render
|
53
|
+
|
54
|
+
content_tag tag, options, &block
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module NavbarHelper
|
2
|
+
include ActionView::Helpers
|
3
|
+
|
4
|
+
# TODO: add navbar form support
|
5
|
+
def navbar(options={}, &block)
|
6
|
+
style = options.delete(:inverse).presence ? 'navbar navbar-inverse' : 'navbar navbar-default'
|
7
|
+
container = options.delete(:fluid).presence ? 'container-fluid' : 'container'
|
8
|
+
padding = options.delete(:padding).presence || '70px'
|
9
|
+
position, position_style = parse_position(options.delete(:position), padding)
|
10
|
+
|
11
|
+
prepend_class(options, style, position)
|
12
|
+
|
13
|
+
options[:data] = (options[:data] || {}).merge(bui: 'navbar')
|
14
|
+
|
15
|
+
(position_style + (content_tag :nav, options do
|
16
|
+
content_tag :div, class: container, &block
|
17
|
+
end)).html_safe
|
18
|
+
end
|
19
|
+
|
20
|
+
def vertical(options={}, &block)
|
21
|
+
prepend_class(options, 'navbar-header')
|
22
|
+
|
23
|
+
content_tag :div, options do
|
24
|
+
(content_tag :button,
|
25
|
+
class: 'navbar-toggle collapsed',
|
26
|
+
type: :button,
|
27
|
+
data: {toggle: 'collapse'},
|
28
|
+
aria: {expanded: false} do
|
29
|
+
("<span class='icon-bar'></span>" * 3).html_safe
|
30
|
+
end) + capture(&block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def horizontal(options={}, &block)
|
35
|
+
prepend_class(options, 'collapse navbar-collapse')
|
36
|
+
|
37
|
+
content_tag :div, options, &block
|
38
|
+
end
|
39
|
+
|
40
|
+
def navbar_menu(options={}, &block)
|
41
|
+
style = case options.delete(:position).try(:to_sym)
|
42
|
+
when :right
|
43
|
+
'nav navbar-nav navbar-right'
|
44
|
+
when :left
|
45
|
+
'nav navbar-nav navbar-left'
|
46
|
+
else
|
47
|
+
'nav navbar-nav'
|
48
|
+
end
|
49
|
+
|
50
|
+
prepend_class(options, style)
|
51
|
+
content_tag :ul, options, &block
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def parse_position(position, padding)
|
57
|
+
case position.try(:to_sym)
|
58
|
+
when :static
|
59
|
+
['navbar-static-top', '']
|
60
|
+
when :top
|
61
|
+
['navbar-fixed-top', "<style>body {padding-top: #{padding}}</style>"]
|
62
|
+
when :bottom
|
63
|
+
['navbar-fixed-bottom', "<style>body {padding-bottom: #{padding}}</style>"]
|
64
|
+
else
|
65
|
+
['', '']
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module PanelHelper
|
2
|
+
include ActionView::Helpers
|
3
|
+
|
4
|
+
class PanelCreator
|
5
|
+
include FormatHelper
|
6
|
+
include ActionView::Helpers
|
7
|
+
|
8
|
+
attr_accessor :content
|
9
|
+
attr_accessor :options
|
10
|
+
attr_accessor :block
|
11
|
+
attr_accessor :output_buffer
|
12
|
+
|
13
|
+
def initialize(content=nil, options, block)
|
14
|
+
@content = content
|
15
|
+
@options = options
|
16
|
+
@block = block
|
17
|
+
end
|
18
|
+
|
19
|
+
def render
|
20
|
+
heading = options.delete(:heading)
|
21
|
+
title = options.delete(:title)
|
22
|
+
footer = options.delete(:footer)
|
23
|
+
tag = options.delete(:tag).try(:to_sym).presence || :div
|
24
|
+
type = get_panel_type(options.delete(:type))
|
25
|
+
|
26
|
+
prepend_class(options, 'panel', type)
|
27
|
+
|
28
|
+
content_tag tag, options do
|
29
|
+
(panel_header(heading, title) + panel_body(content, block) +
|
30
|
+
panel_footer(footer)).html_safe
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def panel_header(heading, title)
|
36
|
+
return '' if heading.blank? && title.blank?
|
37
|
+
|
38
|
+
if title.present?
|
39
|
+
"<div class='panel-heading'><h3 class='panel-title'>#{title}</h3></div>"
|
40
|
+
else
|
41
|
+
"<div class='panel-heading'>#{heading}</div>"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def panel_body(content, block)
|
46
|
+
content_tag :div, class: 'panel-body' do
|
47
|
+
content.presence || block
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def panel_footer(footer)
|
52
|
+
footer.present? ? "<div class='panel-footer'>#{footer}</div>" : ''
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_panel_type(type)
|
56
|
+
case type.try(:to_sym)
|
57
|
+
when :primary
|
58
|
+
'panel-primary'
|
59
|
+
when :info
|
60
|
+
'panel-info'
|
61
|
+
when :success
|
62
|
+
'panel-success'
|
63
|
+
when :warning
|
64
|
+
'panel-warning'
|
65
|
+
when :danger
|
66
|
+
'panel-danger'
|
67
|
+
else
|
68
|
+
'panel-default'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def panel(content_or_options=nil, options={}, &block)
|
74
|
+
content_or_options.is_a?(Hash) ? options = content_or_options : content = content_or_options
|
75
|
+
|
76
|
+
PanelCreator.new(content, options, capture(&block)).render
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module PanelRowHelper
|
2
|
+
|
3
|
+
def panel_row(options={}, &block)
|
4
|
+
column_class = options.delete(:column_class) || ''
|
5
|
+
data = (options[:data] || {}).merge(bui: 'panel_row',
|
6
|
+
column_class: column_class)
|
7
|
+
options[:data] = data
|
8
|
+
prepend_class(options, 'row')
|
9
|
+
|
10
|
+
content_tag :div, options, &block
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ProgressBarHelper
|
2
|
+
|
3
|
+
class ProgressBarCreator
|
4
|
+
include FormatHelper
|
5
|
+
include ActionView::Helpers
|
6
|
+
|
7
|
+
attr_accessor :options
|
8
|
+
attr_accessor :output_buffer
|
9
|
+
|
10
|
+
def initialize(options)
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
percentage, label = process_progress_bar_options
|
16
|
+
options[:style] = "width: #{percentage}%"
|
17
|
+
options[:role] = 'progressbar'
|
18
|
+
options[:aria] = {valuemax: 100, valuemin: 0, valuenow: percentage}
|
19
|
+
|
20
|
+
content_tag :div, options do
|
21
|
+
label.present? ? label : (content_tag :span, label, class: 'sr-only')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def process_progress_bar_options
|
27
|
+
percentage = options.delete(:percentage) || 0
|
28
|
+
label = options.delete(:label)
|
29
|
+
striped = options.delete(:striped).presence
|
30
|
+
animated = options.delete(:animated).presence
|
31
|
+
type = get_progress_bar_type
|
32
|
+
|
33
|
+
prepend_class(options, 'progress-bar', type)
|
34
|
+
|
35
|
+
unless label.is_a?(String)
|
36
|
+
label = label.is_a?(TrueClass) ? "#{percentage}%" : nil
|
37
|
+
end
|
38
|
+
|
39
|
+
if animated
|
40
|
+
prepend_class(options, 'progress-bar-striped active')
|
41
|
+
elsif striped
|
42
|
+
prepend_class(options, 'progress-bar-striped')
|
43
|
+
end
|
44
|
+
|
45
|
+
[percentage, label]
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_progress_bar_type
|
49
|
+
case options.delete(:type).try(:to_sym)
|
50
|
+
when :info
|
51
|
+
'progress-bar-info'
|
52
|
+
when :success
|
53
|
+
'progress-bar-success'
|
54
|
+
when :warning
|
55
|
+
'progress-bar-warning'
|
56
|
+
when :danger
|
57
|
+
'progress-bar-danger'
|
58
|
+
else
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def progress_bar(bars_or_options=nil, options={})
|
64
|
+
bars = bars_or_options.is_a?(Hash) ? [bars_or_options] : bars_or_options
|
65
|
+
|
66
|
+
prepend_class(options, 'progress')
|
67
|
+
|
68
|
+
content_tag :div, options do
|
69
|
+
bars.map { |bar| ProgressBarCreator.new(bar).render }.join('').html_safe
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|