bootstrap-shoehorn 1.0.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.
Files changed (58) hide show
  1. data/.gitignore +9 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/README.md +336 -0
  6. data/Rakefile +32 -0
  7. data/lib/shoehorn.rb +15 -0
  8. data/lib/shoehorn/components.rb +17 -0
  9. data/lib/shoehorn/components/alert.rb +69 -0
  10. data/lib/shoehorn/components/badge.rb +38 -0
  11. data/lib/shoehorn/components/base.rb +18 -0
  12. data/lib/shoehorn/components/button.rb +72 -0
  13. data/lib/shoehorn/components/dropdown.rb +55 -0
  14. data/lib/shoehorn/components/form.rb +14 -0
  15. data/lib/shoehorn/components/form/input_field.rb +53 -0
  16. data/lib/shoehorn/components/form/label.rb +8 -0
  17. data/lib/shoehorn/components/form_builder.rb +13 -0
  18. data/lib/shoehorn/components/icon.rb +40 -0
  19. data/lib/shoehorn/components/label.rb +39 -0
  20. data/lib/shoehorn/components/modal.rb +62 -0
  21. data/lib/shoehorn/components/navigation.rb +47 -0
  22. data/lib/shoehorn/components/progress_bar.rb +51 -0
  23. data/lib/shoehorn/engine.rb +19 -0
  24. data/lib/shoehorn/helper_collection.rb +58 -0
  25. data/lib/shoehorn/helper_collection_set.rb +18 -0
  26. data/lib/shoehorn/helpers.rb +14 -0
  27. data/lib/shoehorn/helpers/alert_helpers.rb +37 -0
  28. data/lib/shoehorn/helpers/badge_helpers.rb +38 -0
  29. data/lib/shoehorn/helpers/button_helpers.rb +122 -0
  30. data/lib/shoehorn/helpers/form_helpers.rb +11 -0
  31. data/lib/shoehorn/helpers/icon_helpers.rb +34 -0
  32. data/lib/shoehorn/helpers/label_helpers.rb +37 -0
  33. data/lib/shoehorn/helpers/modal_helpers.rb +43 -0
  34. data/lib/shoehorn/helpers/navigation_helpers.rb +32 -0
  35. data/lib/shoehorn/helpers/progress_bar_helpers.rb +25 -0
  36. data/lib/shoehorn/plugins.rb +6 -0
  37. data/lib/shoehorn/plugins/simple_navigation/renderer/bootstrap_topbar_list.rb +72 -0
  38. data/lib/shoehorn/version.rb +3 -0
  39. data/log/development.log +0 -0
  40. data/shoehorn.gemspec +33 -0
  41. data/spec/helpers/alert_helpers_spec.rb +138 -0
  42. data/spec/helpers/button_helpers_spec.rb +102 -0
  43. data/spec/helpers/form_helpers_spec.rb +136 -0
  44. data/spec/helpers/inline_label_helpers_spec.rb +50 -0
  45. data/spec/helpers/modal_helpers_spec.rb +60 -0
  46. data/spec/helpers/navigation_helpers_spec.rb +61 -0
  47. data/spec/helpers/progress_bar_helpers_spec.rb +34 -0
  48. data/spec/integration/action_view_spec.rb +23 -0
  49. data/spec/integration/readme_spec.rb +14 -0
  50. data/spec/plugins/bootstrap_topbar_list_spec.rb +11 -0
  51. data/spec/spec_helper.rb +11 -0
  52. data/spec/support/bootstrap_button_macros.rb +8 -0
  53. data/spec/support/bootstrap_form_macros.rb +8 -0
  54. data/spec/support/bootstrap_modal_macros.rb +8 -0
  55. data/spec/support/bootstrap_navigation_macros.rb +8 -0
  56. data/spec/support/bootstrap_spec_helper.rb +50 -0
  57. data/spec/support/test_environment.rb +23 -0
  58. metadata +265 -0
@@ -0,0 +1,38 @@
1
+ module Shoehorn::Components
2
+ class Badge < Base
3
+ attr_reader :message
4
+
5
+ def initialize(message, options = {})
6
+ super
7
+ @message = message
8
+ end
9
+
10
+ def to_s
11
+ output_buffer << content_tag(:span, message, build_tag_options).html_safe
12
+ super
13
+ end
14
+
15
+ private
16
+ def default_options
17
+ {
18
+ :class => nil,
19
+ :bootstrap_class_prefix => "badge",
20
+ :type => nil,
21
+ :html_options => {}
22
+ }
23
+ end
24
+
25
+ def build_class
26
+ classes = [ options[:class] ]
27
+ classes << options[:bootstrap_class_prefix]
28
+ classes << "#{options[:bootstrap_class_prefix]}-#{options[:type]}" if options[:type]
29
+ classes.join(" ")
30
+ end
31
+
32
+ def build_tag_options
33
+ ops = {:class => build_class}
34
+ ops.reverse_merge(options[:html_options])
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Shoehorn::Components
3
+ class Base
4
+ include ActionView::Helpers::TagHelper
5
+
6
+ attr_accessor :output_buffer, :options, :default_options
7
+
8
+ def initialize(*args)
9
+ @output_buffer = ""
10
+ @options = args.extract_options!.reverse_merge(default_options)
11
+ end
12
+
13
+ def to_s
14
+ @output_buffer.to_s.html_safe
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,72 @@
1
+ module Shoehorn::Components
2
+ class Button < Base
3
+ include ActionView::Helpers::UrlHelper
4
+
5
+ attr_reader :text
6
+
7
+ def initialize(text, link, options = {})
8
+ super
9
+ @text = text
10
+ @link = url_for(link)
11
+ end
12
+
13
+ def to_s
14
+ html_text = ""
15
+ if options[:icon_name]
16
+ html_text << build_icon.html_safe
17
+ else
18
+ html_text << text
19
+ end
20
+ html_text << ' ' << build_caret.html_safe if options[:dropdown]
21
+
22
+ output_buffer << content_tag(:a, html_text.html_safe, build_tag_options).html_safe
23
+ super
24
+ end
25
+
26
+ private
27
+ def default_options
28
+ {
29
+ :class => nil,
30
+ :bootstrap_class_prefix => "btn",
31
+ :type => nil,
32
+ :size => nil,
33
+ :disabled => false,
34
+ :dropdown => false,
35
+ :id => nil,
36
+ :icon_name => nil,
37
+ :icon_white => false,
38
+ :html_options => {}
39
+ }
40
+ end
41
+
42
+ def build_class
43
+ classes = [ options[:class] ]
44
+ classes << options[:bootstrap_class_prefix]
45
+ classes << "#{options[:bootstrap_class_prefix]}-#{options[:type]}" if options[:type]
46
+ classes << "#{options[:bootstrap_class_prefix]}-#{options[:size]}" if options[:size]
47
+ classes << 'dropdown-toggle' if options[:dropdown]
48
+ classes << 'disabled' if options[:disabled]
49
+ classes.join(" ")
50
+ end
51
+
52
+ def build_icon
53
+ if (options[:icon_white] || options[:type].present?)
54
+ options[:icon_white] = true
55
+ end
56
+ Icon.new(:text => text,
57
+ :name => options[:icon_name],
58
+ :icon_white => options[:icon_white]).to_s
59
+ end
60
+
61
+ def build_caret
62
+ content_tag(:span, nil, :class => 'caret')
63
+ end
64
+
65
+ def build_tag_options
66
+ ops = { :href => @link, :class => build_class }
67
+ ops[:"data-toggle"] = 'dropdown' if options[:dropdown]
68
+ ops[:id] = options[:id] if options[:id]
69
+ ops.reverse_merge(options[:html_options])
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,55 @@
1
+ module Shoehorn::Components
2
+ class Dropdown < Base
3
+ attr_reader :collection
4
+
5
+ def initialize(elements, options = {})
6
+ super
7
+ @elements = elements
8
+ end
9
+
10
+ def to_s
11
+ div_options = {:class => build_class}
12
+ output_buffer << content_tag(:div, div_options.reverse_merge(options[:html_options])) do
13
+ html=''
14
+ html << build_dropdown
15
+
16
+ html << content_tag(:ul, :class => 'dropdown-menu') do
17
+ menu = ''
18
+ @elements.each do |e|
19
+ menu << content_tag(:li, e.to_s)
20
+ end
21
+ menu.html_safe
22
+ end
23
+
24
+ html.html_safe
25
+ end
26
+ super
27
+ end
28
+
29
+ private
30
+ def default_options
31
+ {
32
+ :html_options => {}
33
+ }
34
+ end
35
+
36
+ def build_class
37
+ classes = %w(btn-group)
38
+ classes << options[:html_options][:class] if options[:html_options][:class]
39
+ classes.join(" ")
40
+ end
41
+
42
+ def build_dropdown
43
+ html = ''
44
+
45
+ if @elements.size > 0
46
+ dropdown = @elements.shift
47
+ dropdown.options[:dropdown] = true
48
+ html << dropdown.to_s
49
+ end
50
+
51
+ html
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,14 @@
1
+ module Shoehorn::Components
2
+ class Form < Base
3
+ autoload :InputField, 'shoehorn/components/form/input_field'
4
+ autoload :Label, 'shoehorn/components/form/label'
5
+
6
+ include ActionView::Helpers::FormHelper
7
+
8
+ protected
9
+
10
+ def default_options
11
+ {}
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,53 @@
1
+ module Shoehorn::Components
2
+ class Form::InputField < Form
3
+ attr_accessor :input_html, :label_html
4
+
5
+ def initialize(object_name, method, input_html, options = {})
6
+ super(options)
7
+ @input_html = input_html
8
+ @label_html = Label.new(object_name, method, options) if options[:label] || options[:label_text]
9
+ end
10
+
11
+ def to_s
12
+ output_buffer << content_tag(:div, :class => 'control-group') do
13
+ html = ''
14
+ html << label_html.to_s
15
+ html << content_tag(:div, :class => 'controls') do
16
+ build_input_wrapper << build_help_text
17
+ end
18
+ html.html_safe
19
+ end
20
+ super
21
+ end
22
+
23
+ private
24
+
25
+ def build_input_wrapper
26
+ if options[:add_on]
27
+ build_add_on_wrapper
28
+ else
29
+ input_html
30
+ end
31
+ end
32
+
33
+ def build_help_text
34
+ html = ''
35
+ html = content_tag(:p, options[:help_text], :class => 'help-block') if options[:help_text]
36
+ html.html_safe
37
+ end
38
+
39
+ def build_add_on_wrapper
40
+ content_tag(:div, :class => "input-#{options[:add_on][:position] || 'prepend'}") do
41
+ add_on = ''
42
+ add_on << input_html
43
+ add_on << content_tag(:span, :class => 'add-on') do
44
+ add_on_content = ''
45
+ add_on_content << content_tag(:i, '', :class => options[:add_on][:icon]) if options[:add_on][:icon]
46
+ add_on_content << options[:add_on][:text] if options[:add_on][:text]
47
+ add_on_content.html_safe
48
+ end
49
+ add_on.html_safe
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,8 @@
1
+ module Shoehorn::Components
2
+ class Form::Label < Form
3
+ def initialize(object_name, method, options)
4
+ super(options)
5
+ output_buffer << label(object_name, method, options[:label_text], :class => 'control-label')
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module Shoehorn::Components
2
+ class FormBuilder < ActionView::Helpers::FormBuilder
3
+ def text_field(method, options={})
4
+ input_html = super(method, options)
5
+ Form::InputField.new(object_name, method, input_html, options).to_s
6
+ end
7
+
8
+ def password_field(method, options={})
9
+ input_html = super(method, options)
10
+ Form::InputField.new(object_name, method, input_html, options).to_s
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ module Shoehorn::Components
2
+ class Icon < Base
3
+
4
+ def initialize(options = {})
5
+ super
6
+ end
7
+
8
+ def to_s
9
+ output_buffer << content_tag(:i, nil, build_tag_options).html_safe
10
+ output_buffer << ' ' << text if options[:text]
11
+ super
12
+ end
13
+
14
+ private
15
+ def default_options
16
+ {
17
+ :class => nil,
18
+ :bootstrap_class_prefix => "icon",
19
+ :text => nil,
20
+ :name => nil,
21
+ :icon_white => false,
22
+ :html_options => {}
23
+ }
24
+ end
25
+
26
+ def build_class
27
+ classes = [ options[:class] ]
28
+ classes << options[:bootstrap_class_prefix]
29
+ classes << "#{options[:bootstrap_class_prefix]}-#{options[:name]}" if options[:name]
30
+ classes << "#{options[:bootstrap_class_prefix]}-white" if options[:icon_white]
31
+ classes.join(" ")
32
+ end
33
+
34
+ def build_tag_options
35
+ ops = {:class => build_class}
36
+ ops.reverse_merge(options[:html_options])
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,39 @@
1
+ module Shoehorn::Components
2
+ class Label < Base
3
+ attr_reader :message
4
+
5
+ def initialize(message, options = {})
6
+ super
7
+ @message = message
8
+ end
9
+
10
+ def to_s
11
+ output_buffer << content_tag(:span, message, build_tag_options).html_safe
12
+ super
13
+ end
14
+
15
+ private
16
+
17
+ def default_options
18
+ {
19
+ :class => nil,
20
+ :bootstrap_class_prefix => "label",
21
+ :type => nil,
22
+ :html_options => {}
23
+ }
24
+ end
25
+
26
+ def build_class
27
+ classes = [ options[:class] ]
28
+ classes << options[:bootstrap_class_prefix]
29
+ classes << "#{options[:bootstrap_class_prefix]}-#{options[:type]}" if options[:type]
30
+ classes.join(" ")
31
+ end
32
+
33
+ def build_tag_options
34
+ ops = {:class => build_class}
35
+ ops.reverse_merge(options[:html_options])
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,62 @@
1
+ module Shoehorn::Components
2
+ class Modal < Base
3
+ attr_reader :collection
4
+
5
+ def initialize(body_elements, footer_elements, options = {})
6
+ super
7
+ @body_elements = body_elements
8
+ @footer_elements = footer_elements
9
+ end
10
+
11
+ def to_s
12
+ output_buffer << content_tag(:div, :id => options[:id], :class => modal_classes) do
13
+ html=''
14
+ html << build_header
15
+ html << build_body
16
+ html << build_footer
17
+ html.html_safe
18
+ end
19
+ super
20
+ end
21
+
22
+ private
23
+
24
+ def default_options
25
+ {
26
+ :id => 'twitter-bootstrap-modal',
27
+ :fade => false,
28
+ :title => ''
29
+ }
30
+ end
31
+
32
+ def modal_classes
33
+ classes = %w(modal)
34
+ classes.push 'fade' if options[:fade]
35
+ classes.join " "
36
+ end
37
+
38
+ def build_header
39
+ content_tag(:div, :class => "modal-header") do
40
+ content_tag(:a, "&times".html_safe, :class => 'close', :"data-dismiss" => "modal" ) + content_tag(:h3, options[:title])
41
+ end
42
+ end
43
+
44
+ def build_body
45
+ html = ''
46
+ @body_elements.each do |e|
47
+ html << e.to_s
48
+ end
49
+ content_tag(:div, html.html_safe, :class => "modal-body")
50
+ end
51
+
52
+ def build_footer
53
+ html = ''
54
+ @footer_elements.each do |e|
55
+ html << e.to_s
56
+ end
57
+ content_tag(:div, html.html_safe, :class => "modal-footer")
58
+ end
59
+
60
+ end
61
+ end
62
+
@@ -0,0 +1,47 @@
1
+ module Shoehorn::Components
2
+ class Navigation < Base
3
+ attr_reader :collection
4
+
5
+ def initialize(elements, options = {})
6
+ super
7
+ @elements = elements
8
+ end
9
+
10
+ def to_s
11
+ output_buffer << content_tag(:ul, :class => build_class) do
12
+ html = ""
13
+
14
+ @elements.each do |e|
15
+ html_class = build_html_class(e)
16
+ html << content_tag(:li, e.to_s, html_class)
17
+ end
18
+
19
+ html.html_safe
20
+ end
21
+ super
22
+ end
23
+
24
+ private
25
+
26
+ def default_options
27
+ {}
28
+ end
29
+
30
+ def build_html_class(element)
31
+ html_class = {}
32
+ if element.options[:active_nav]
33
+ element.options.reject! { |k| k == :active_nav }
34
+ html_class = { :class => "active" }
35
+ end
36
+ html_class
37
+ end
38
+
39
+ def build_class
40
+ classes = %w( nav )
41
+ classes << "nav-#{ options[:type] || "tabs" }"
42
+ classes << "nav-stacked" if options[:stacked]
43
+ classes.join(" ")
44
+ end
45
+ end
46
+ end
47
+