rails-bootstrap-helpers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +158 -0
  4. data/Rakefile +38 -0
  5. data/lib/rails-bootstrap-helpers.rb +20 -0
  6. data/lib/rails-bootstrap-helpers/core_ext/abstract.rb +72 -0
  7. data/lib/rails-bootstrap-helpers/helpers/alert_helper.rb +45 -0
  8. data/lib/rails-bootstrap-helpers/helpers/base_helper.rb +32 -0
  9. data/lib/rails-bootstrap-helpers/helpers/button_helper.rb +55 -0
  10. data/lib/rails-bootstrap-helpers/helpers/form_tag_helper.rb +22 -0
  11. data/lib/rails-bootstrap-helpers/helpers/label_helper.rb +35 -0
  12. data/lib/rails-bootstrap-helpers/helpers/options_helper.rb +32 -0
  13. data/lib/rails-bootstrap-helpers/rails/engine.rb +15 -0
  14. data/lib/rails-bootstrap-helpers/renderers/abstract_button_renderer.rb +86 -0
  15. data/lib/rails-bootstrap-helpers/renderers/button_renderer.rb +43 -0
  16. data/lib/rails-bootstrap-helpers/renderers/renderer.rb +14 -0
  17. data/lib/rails-bootstrap-helpers/version.rb +3 -0
  18. data/lib/tasks/bootstrap-rails-helpers_tasks.rake +4 -0
  19. data/spec/dummy/README.rdoc +261 -0
  20. data/spec/dummy/Rakefile +7 -0
  21. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/spec/dummy/config.ru +4 -0
  27. data/spec/dummy/config/application.rb +59 -0
  28. data/spec/dummy/config/boot.rb +10 -0
  29. data/spec/dummy/config/database.yml +25 -0
  30. data/spec/dummy/config/environment.rb +5 -0
  31. data/spec/dummy/config/environments/development.rb +37 -0
  32. data/spec/dummy/config/environments/production.rb +67 -0
  33. data/spec/dummy/config/environments/test.rb +37 -0
  34. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/spec/dummy/config/initializers/inflections.rb +15 -0
  36. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  37. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  38. data/spec/dummy/config/initializers/session_store.rb +8 -0
  39. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  40. data/spec/dummy/config/locales/en.yml +5 -0
  41. data/spec/dummy/config/routes.rb +58 -0
  42. data/spec/dummy/db/test.sqlite3 +0 -0
  43. data/spec/dummy/log/test.log +47 -0
  44. data/spec/dummy/public/404.html +26 -0
  45. data/spec/dummy/public/422.html +26 -0
  46. data/spec/dummy/public/500.html +25 -0
  47. data/spec/dummy/public/favicon.ico +0 -0
  48. data/spec/dummy/script/rails +6 -0
  49. data/spec/helpers/alert_helper_spec.rb +24 -0
  50. data/spec/helpers/base_helper_spec.rb +18 -0
  51. data/spec/helpers/button_helper_spec.rb +94 -0
  52. data/spec/helpers/form_tag_helper_spec.rb +43 -0
  53. data/spec/helpers/label_helper_spec.rb +23 -0
  54. data/spec/helpers/options_helper_spec.rb +47 -0
  55. data/spec/spec_helper.rb +20 -0
  56. data/spec/support/matchers/helpers/alert_helper/render_bs_alert.rb +116 -0
  57. data/spec/support/matchers/helpers/base_helper/render_icon.rb +55 -0
  58. data/spec/support/matchers/helpers/button_helper/render_bs_button_to.rb +135 -0
  59. data/spec/support/matchers/helpers/button_helper/render_inline_button_to.rb +79 -0
  60. data/spec/support/matchers/helpers/form_tag_helper/render_bs_button_tag.rb +136 -0
  61. data/spec/support/matchers/helpers/label_helper/render_bs_label.rb +114 -0
  62. metadata +287 -0
@@ -0,0 +1,55 @@
1
+ RSpec::Matchers.define :render_icon do |icon|
2
+ def options
3
+ @options ||= { invert: false }
4
+ end
5
+
6
+ def icon
7
+ @icon
8
+ end
9
+
10
+ def cls
11
+ cls = "icon-#{icon}"
12
+ cls << " icon-white" if invert?
13
+ cls
14
+ end
15
+
16
+ def expected
17
+ @render_icon_expected ||= "<i class=\"#{cls}\"></i>"
18
+ end
19
+
20
+ def got
21
+ @got ||= helper.icon(icon, invert: options[:invert])
22
+ end
23
+
24
+ def failure_message (is_not)
25
+ ex = is_not ? "expected not" : "expected"
26
+ "#{ex}: #{expected}\n got: #{got}"
27
+ end
28
+
29
+ def invert?
30
+ @invert_set
31
+ end
32
+
33
+ chain :inverted do |invert|
34
+ options[:invert] = invert
35
+ @invert_set = true
36
+ end
37
+
38
+ match do
39
+ @icon = icon
40
+ expected == got
41
+ end
42
+
43
+ failure_message_for_should do
44
+ failure_message(false)
45
+ end
46
+
47
+ failure_message_for_should_not do
48
+ failure_message(true)
49
+ end
50
+
51
+ description do
52
+ ext = invert? ? "inverted " : ""
53
+ "render an icon with the #{ext}style: #{icon}"
54
+ end
55
+ end
@@ -0,0 +1,135 @@
1
+ RSpec::Matchers.define :render_bs_button_to do |text|
2
+ def options
3
+ @options ||= { }
4
+ end
5
+
6
+ def append_style (style)
7
+ " btn-#{style}"
8
+ end
9
+
10
+ def cls
11
+ @cls ||= begin
12
+ cls = "btn"
13
+ cls << " btn-#{options[:style]}" if style?
14
+ cls << " btn-#{options[:size]}" if size?
15
+ cls
16
+ end
17
+ end
18
+
19
+ def text_with_icon
20
+ if icon?
21
+ cls = "icon-#{options[:icon]}"
22
+ cls << " icon-white" if inverted?
23
+ icon = "<i class=\"#{cls}\"></i>"
24
+ default = icon + " " + text
25
+
26
+ if icon_position?
27
+ if options[:icon_position].to_s == "right"
28
+ return text + " " + icon
29
+ end
30
+ end
31
+
32
+ default
33
+ else
34
+ text
35
+ end
36
+ end
37
+
38
+ def expected
39
+ @render_button_expected ||= "<a href=\"#{url}\" class=\"#{cls}\">#{text_with_icon}</a>"
40
+ end
41
+
42
+ def got
43
+ @got ||= helper.bs_button_to(text, url, options)
44
+ end
45
+
46
+ def failure_message (is_not)
47
+ ex = is_not ? "expected not" : "expected"
48
+ "#{ex}: #{expected}\n got: #{got}"
49
+ end
50
+
51
+ def text
52
+ @text
53
+ end
54
+
55
+ def url
56
+ @url || "default_url"
57
+ end
58
+
59
+ def style?
60
+ @style_set
61
+ end
62
+
63
+ def size?
64
+ @size_set
65
+ end
66
+
67
+ def icon?
68
+ @icon_set
69
+ end
70
+
71
+ def inverted?
72
+ @inverted_set
73
+ end
74
+
75
+ def icon_position?
76
+ @icon_position_set
77
+ end
78
+
79
+ chain :to do |url|
80
+ @url = url
81
+ end
82
+
83
+ chain :with_style do |style|
84
+ options[:style] = style
85
+ @style_set = true
86
+ end
87
+
88
+ chain :with_size do |size|
89
+ options[:size] = size
90
+ @size_set = true
91
+ end
92
+
93
+ chain :with_icon do |icon|
94
+ options[:icon] = icon
95
+ @icon_set = true
96
+ end
97
+
98
+ chain :with_icon_inverted do |inverted|
99
+ options[:icon_invert] = inverted
100
+ @inverted_set = true
101
+ end
102
+
103
+ chain :with_icon_position do |icon_position|
104
+ options[:icon_position] = icon_position
105
+ @icon_position_Set = true
106
+ end
107
+
108
+ match do
109
+ @text = text
110
+ expected == got
111
+ end
112
+
113
+ failure_message_for_should do
114
+ failure_message(false)
115
+ end
116
+
117
+ failure_message_for_should_not do
118
+ failure_message(true)
119
+ end
120
+
121
+ description do
122
+ desc = "render a button to '#{url}'"
123
+ descs = []
124
+ descs << "with the style: #{options[:style]}" if style?
125
+ descs << "with the size: #{options[:size]}" if size?
126
+
127
+ ext = inverted? ? "inverted " : ""
128
+
129
+ descs << "with the #{ext}icon: #{options[:icon]}" if icon?
130
+ descs << "with the icon_position: #{options[:icon_position]}" if icon_position?
131
+
132
+ desc << " " if descs.any?
133
+ desc << descs.to_sentence
134
+ end
135
+ end
@@ -0,0 +1,79 @@
1
+ RSpec::Matchers.define :render_inline_button_to do |url, icon|
2
+ def options
3
+ @options ||= { size: "mini" }
4
+ end
5
+
6
+ def cls
7
+ @cls ||= "btn btn-#{options[:size]}"
8
+ end
9
+
10
+ def text_with_icon
11
+ "<i class=\"icon-#{icon}\"></i> "
12
+ end
13
+
14
+ def attributes
15
+ attrs = {
16
+ href: url,
17
+ class: cls
18
+ }
19
+
20
+ attrs = attrs.map do |k, v|
21
+ "#{k}=\"#{v}\""
22
+ end
23
+
24
+ attrs.join(" ")
25
+ end
26
+
27
+ def expected
28
+ @render_remove_button_expected ||= "<a #{attributes}>#{text_with_icon}</a>"
29
+ end
30
+
31
+ def got
32
+ @got ||= helper.bs_inline_button_to(url, icon, options)
33
+ end
34
+
35
+ def failure_message (is_not)
36
+ ex = is_not ? "expected not" : "expected"
37
+ "#{ex}: #{expected}\n got: #{got}"
38
+ end
39
+
40
+ def url
41
+ @url
42
+ end
43
+
44
+ def icon
45
+ @icon
46
+ end
47
+
48
+ def size?
49
+ @size_set
50
+ end
51
+
52
+ chain :with_size do |size|
53
+ options[:size] = size
54
+ @size_set = true
55
+ end
56
+
57
+ match do
58
+ @url = url
59
+ @icon = icon
60
+ expected == got
61
+ end
62
+
63
+ failure_message_for_should do
64
+ failure_message(false)
65
+ end
66
+
67
+ failure_message_for_should_not do
68
+ failure_message(true)
69
+ end
70
+
71
+ description do
72
+ desc = "render an inline button to '#{url}' with the icon: #{icon}"
73
+ descs = []
74
+ descs << "with the size: #{options[:size]}" if size?
75
+
76
+ desc << " " if descs.any?
77
+ desc << descs.to_sentence(two_words_connector: " and ", last_word_connector: " and ")
78
+ end
79
+ end
@@ -0,0 +1,136 @@
1
+ RSpec::Matchers.define :render_bs_button_tag do |text, type|
2
+ def options
3
+ @options ||= { }
4
+ end
5
+
6
+ def append_style (style)
7
+ " btn-#{style}"
8
+ end
9
+
10
+ def cls
11
+ @cls ||= begin
12
+ cls = "btn"
13
+ cls << " btn-#{options[:style]}" if style?
14
+ cls << " btn-#{options[:size]}" if size?
15
+ cls
16
+ end
17
+ end
18
+
19
+ def text_with_icon
20
+ if icon?
21
+ cls = "icon-#{options[:icon]}"
22
+ cls << " icon-white" if inverted?
23
+ icon = "<i class=\"#{cls}\"></i>"
24
+ default = icon + " " + text
25
+
26
+ if icon_position?
27
+ if options[:icon_position].to_s == "right"
28
+ return text + " " + icon
29
+ end
30
+ end
31
+
32
+ default
33
+ else
34
+ text
35
+ end
36
+ end
37
+
38
+ def expected
39
+ @render_button_expected ||= "<button class=\"#{cls}\" name=\"button\" type=\"#{type}\">#{text_with_icon}</button>"
40
+ end
41
+
42
+ def got
43
+ @got ||= helper.bs_button_tag(text, type, options)
44
+ end
45
+
46
+ def failure_message (is_not)
47
+ ex = is_not ? "expected not" : "expected"
48
+ "#{ex}: #{expected}\n got: #{got}"
49
+ end
50
+
51
+ def text
52
+ @text
53
+ end
54
+
55
+ def type
56
+ @type
57
+ end
58
+
59
+ def style?
60
+ @style_set
61
+ end
62
+
63
+ def size?
64
+ @size_set
65
+ end
66
+
67
+ def icon?
68
+ @icon_set
69
+ end
70
+
71
+ def inverted?
72
+ @inverted_set
73
+ end
74
+
75
+ def icon_position?
76
+ @icon_position_set
77
+ end
78
+
79
+ chain :to do |url|
80
+ @url = url
81
+ end
82
+
83
+ chain :with_style do |style|
84
+ options[:style] = style
85
+ @style_set = true
86
+ end
87
+
88
+ chain :with_size do |size|
89
+ options[:size] = size
90
+ @size_set = true
91
+ end
92
+
93
+ chain :with_icon do |icon|
94
+ options[:icon] = icon
95
+ @icon_set = true
96
+ end
97
+
98
+ chain :with_icon_inverted do |inverted|
99
+ options[:icon_invert] = inverted
100
+ @inverted_set = true
101
+ end
102
+
103
+ chain :with_icon_position do |icon_position|
104
+ options[:icon_position] = icon_position
105
+ @icon_position_Set = true
106
+ end
107
+
108
+ match do
109
+ @text = text
110
+ @type = type
111
+ expected == got
112
+ end
113
+
114
+ failure_message_for_should do
115
+ failure_message(false)
116
+ end
117
+
118
+ failure_message_for_should_not do
119
+ failure_message(true)
120
+ end
121
+
122
+ description do
123
+ desc = "render a button with type '#{type}'"
124
+ descs = []
125
+ descs << "with the style: #{options[:style]}" if style?
126
+ descs << "with the size: #{options[:size]}" if size?
127
+
128
+ ext = inverted? ? "inverted " : ""
129
+
130
+ descs << "with the #{ext}icon: #{options[:icon]}" if icon?
131
+ descs << "with the icon_position: #{options[:icon_position]}" if icon_position?
132
+
133
+ desc << " " if descs.any?
134
+ desc << descs.to_sentence(two_words_connector: " and ", last_word_connector: " and ")
135
+ end
136
+ end
@@ -0,0 +1,114 @@
1
+ RSpec::Matchers.define :render_bs_label do |text|
2
+ def options
3
+ @options ||= { }
4
+ end
5
+
6
+ def style
7
+ @style
8
+ end
9
+
10
+ def style?
11
+ @style.present?
12
+ end
13
+
14
+ def custom_class
15
+ @custom_class
16
+ end
17
+
18
+ def custom_class?
19
+ @custom_class.present?
20
+ end
21
+
22
+ def tooltip?
23
+ options.key?(:tooltip)
24
+ end
25
+
26
+ def tooltip_position?
27
+ options.key?(:tooltip_position)
28
+ end
29
+
30
+ def text
31
+ @text
32
+ end
33
+
34
+ def html_cls
35
+ @html_cls ||= custom_class? ? custom_class.to_s : style.to_s
36
+ end
37
+
38
+ def build_html_class
39
+ "label".tap do |c|
40
+ c << " label-#{html_cls}" unless html_cls == "default"
41
+ end
42
+ end
43
+
44
+ def html_attributes
45
+ attrs = { class: build_html_class }
46
+
47
+ if tooltip?
48
+ if tooltip_position?
49
+ attrs[:"data-placement"] = options[:tooltip_position]
50
+ end
51
+
52
+ attrs[:"data-toggle"] = "tooltip"
53
+ attrs[:title] = options[:tooltip]
54
+ end
55
+
56
+ attrs.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
57
+ end
58
+
59
+ def expected
60
+ @render_bs_label_expected ||= begin
61
+ "<span #{html_attributes}>#{text}</span>"
62
+ end
63
+ end
64
+
65
+ def got
66
+ @got ||= helper.bs_label(text, style, options)
67
+ end
68
+
69
+ def failure_message (is_not)
70
+ ex = is_not ? "expected not" : "expected"
71
+ "#{ex}: #{expected}\n got: #{got}"
72
+ end
73
+
74
+ chain :with_style do |style|
75
+ @style = style
76
+ end
77
+
78
+ chain :as_class do |custom_class|
79
+ @custom_class = custom_class
80
+ end
81
+
82
+ chain :with_tooltip do |tooltip|
83
+ options[:tooltip] = tooltip
84
+ end
85
+
86
+ chain :with_tooltip_position do |tooltip_position|
87
+ options[:tooltip_position] = tooltip_position
88
+ end
89
+
90
+ match do
91
+ @text = text
92
+ @style ||= "default"
93
+ expected == got
94
+ end
95
+
96
+ failure_message_for_should do
97
+ failure_message(false)
98
+ end
99
+
100
+ failure_message_for_should_not do
101
+ failure_message(true)
102
+ end
103
+
104
+ description do
105
+ desc = "should return a label with the text '#{text}' and with the #{style} style"
106
+ desc << " as the class #{html_cls}" if custom_class?
107
+ descs = []
108
+ descs << "with the '#{options[:tooltip]}' tooltip" if tooltip?
109
+ descs << "with the '#{options[:tooltip_position]}' tooltip position" if tooltip_position?
110
+
111
+ desc << " " if descs.any?
112
+ desc << descs.to_sentence(two_words_connector: " and ", last_word_connector: " and ")
113
+ end
114
+ end