twitter_bootstrap_markup 0.0.1

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 (116) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/README.md +29 -0
  4. data/Rakefile +1 -0
  5. data/lib/twitter_bootstrap_markup.rb +45 -0
  6. data/lib/twitter_bootstrap_markup/add_on.rb +9 -0
  7. data/lib/twitter_bootstrap_markup/alert.rb +35 -0
  8. data/lib/twitter_bootstrap_markup/badge.rb +4 -0
  9. data/lib/twitter_bootstrap_markup/brand.rb +9 -0
  10. data/lib/twitter_bootstrap_markup/breadcrumb.rb +21 -0
  11. data/lib/twitter_bootstrap_markup/button.rb +16 -0
  12. data/lib/twitter_bootstrap_markup/button_base.rb +41 -0
  13. data/lib/twitter_bootstrap_markup/control_group.rb +26 -0
  14. data/lib/twitter_bootstrap_markup/divider.rb +30 -0
  15. data/lib/twitter_bootstrap_markup/dropdown_button.rb +59 -0
  16. data/lib/twitter_bootstrap_markup/extended_input.rb +11 -0
  17. data/lib/twitter_bootstrap_markup/extension/hash.rb +11 -0
  18. data/lib/twitter_bootstrap_markup/fieldset.rb +18 -0
  19. data/lib/twitter_bootstrap_markup/form.rb +27 -0
  20. data/lib/twitter_bootstrap_markup/grid_column.rb +14 -0
  21. data/lib/twitter_bootstrap_markup/grid_row.rb +9 -0
  22. data/lib/twitter_bootstrap_markup/help.rb +24 -0
  23. data/lib/twitter_bootstrap_markup/icon.rb +18 -0
  24. data/lib/twitter_bootstrap_markup/input.rb +31 -0
  25. data/lib/twitter_bootstrap_markup/label.rb +4 -0
  26. data/lib/twitter_bootstrap_markup/label_base.rb +29 -0
  27. data/lib/twitter_bootstrap_markup/link.rb +17 -0
  28. data/lib/twitter_bootstrap_markup/link_button.rb +17 -0
  29. data/lib/twitter_bootstrap_markup/nav_bar.rb +32 -0
  30. data/lib/twitter_bootstrap_markup/nav_container.rb +10 -0
  31. data/lib/twitter_bootstrap_markup/nav_header.rb +9 -0
  32. data/lib/twitter_bootstrap_markup/nav_list.rb +11 -0
  33. data/lib/twitter_bootstrap_markup/nav_list_container.rb +10 -0
  34. data/lib/twitter_bootstrap_markup/nav_tab.rb +10 -0
  35. data/lib/twitter_bootstrap_markup/nav_tab_container.rb +13 -0
  36. data/lib/twitter_bootstrap_markup/page_header.rb +17 -0
  37. data/lib/twitter_bootstrap_markup/pagination.rb +29 -0
  38. data/lib/twitter_bootstrap_markup/popover.rb +20 -0
  39. data/lib/twitter_bootstrap_markup/progress_bar.rb +43 -0
  40. data/lib/twitter_bootstrap_markup/select.rb +67 -0
  41. data/lib/twitter_bootstrap_markup/side_position.rb +15 -0
  42. data/lib/twitter_bootstrap_markup/submit.rb +10 -0
  43. data/lib/twitter_bootstrap_markup/tab.rb +14 -0
  44. data/lib/twitter_bootstrap_markup/tab_content.rb +29 -0
  45. data/lib/twitter_bootstrap_markup/table.rb +28 -0
  46. data/lib/twitter_bootstrap_markup/tag.rb +51 -0
  47. data/lib/twitter_bootstrap_markup/tooltip.rb +19 -0
  48. data/lib/twitter_bootstrap_markup/ul_container.rb +21 -0
  49. data/lib/twitter_bootstrap_markup/version.rb +3 -0
  50. data/lib/twitter_bootstrap_markup/well.rb +27 -0
  51. data/markup/alerts.html +75 -0
  52. data/markup/badges.html +65 -0
  53. data/markup/breadcrumbs.html +59 -0
  54. data/markup/buttons.html +95 -0
  55. data/markup/control_groups.html +77 -0
  56. data/markup/css/bootstrap-responsive.css +815 -0
  57. data/markup/css/bootstrap-responsive.min.css +9 -0
  58. data/markup/css/bootstrap.css +4983 -0
  59. data/markup/css/bootstrap.min.css +9 -0
  60. data/markup/dropdown_buttons.html +248 -0
  61. data/markup/form_fields.html +88 -0
  62. data/markup/forms.html +81 -0
  63. data/markup/grid_system.html +87 -0
  64. data/markup/img/glyphicons-halflings-white.png +0 -0
  65. data/markup/img/glyphicons-halflings.png +0 -0
  66. data/markup/index.html +37 -0
  67. data/markup/js/bootstrap.js +1825 -0
  68. data/markup/js/bootstrap.min.js +6 -0
  69. data/markup/js/jquery-1.7.2.js +9402 -0
  70. data/markup/labels.html +65 -0
  71. data/markup/link_buttons.html +95 -0
  72. data/markup/nav_bars.html +104 -0
  73. data/markup/nav_lists.html +54 -0
  74. data/markup/paginations.html +68 -0
  75. data/markup/popovers.html +56 -0
  76. data/markup/progress_bars.html +93 -0
  77. data/markup/selects.html +124 -0
  78. data/markup/tabs.html +46 -0
  79. data/markup/textboxes.html +95 -0
  80. data/markup/tooltips.html +56 -0
  81. data/spec/add_on_spec.rb +10 -0
  82. data/spec/alert_spec.rb +77 -0
  83. data/spec/badge_spec.rb +29 -0
  84. data/spec/brand_spec.rb +10 -0
  85. data/spec/breadcrumb_spec.rb +32 -0
  86. data/spec/button_spec.rb +52 -0
  87. data/spec/control_group_spec.rb +29 -0
  88. data/spec/divider_spec.rb +17 -0
  89. data/spec/dropdown_button_spec.rb +101 -0
  90. data/spec/fieldset_spec.rb +22 -0
  91. data/spec/form_fields_spec.rb +71 -0
  92. data/spec/form_spec.rb +35 -0
  93. data/spec/grid_system_spec.rb +69 -0
  94. data/spec/help_spec.rb +13 -0
  95. data/spec/icon_spec.rb +18 -0
  96. data/spec/input_spec.rb +11 -0
  97. data/spec/label_spec.rb +29 -0
  98. data/spec/link_button_spec.rb +52 -0
  99. data/spec/link_spec.rb +29 -0
  100. data/spec/nav_bar_spec.rb +27 -0
  101. data/spec/nav_list_spec.rb +27 -0
  102. data/spec/page_header_spec.rb +13 -0
  103. data/spec/pagination_spec.rb +18 -0
  104. data/spec/popover_spec.rb +15 -0
  105. data/spec/progress_bar_spec.rb +53 -0
  106. data/spec/select_spec.rb +61 -0
  107. data/spec/spec_helper.rb +12 -0
  108. data/spec/support/helpers/html_helper.rb +11 -0
  109. data/spec/table_spec.rb +29 -0
  110. data/spec/tabs_spec.rb +22 -0
  111. data/spec/tag_spec.rb +40 -0
  112. data/spec/textbox_spec.rb +60 -0
  113. data/spec/tooltip_spec.rb +15 -0
  114. data/spec/well_spec.rb +17 -0
  115. data/twitter_bootstrap_markup.gemspec +23 -0
  116. metadata +182 -0
@@ -0,0 +1,9 @@
1
+ module TwitterBootstrapMarkup
2
+ class GridRow < Tag
3
+
4
+ def initialize(attributes={}, &block)
5
+ super(:div, attributes.prepend!(:class, 'row'), &block)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module TwitterBootstrapMarkup
2
+ class Help < Tag
3
+
4
+ def initialize(type, text)
5
+ case type
6
+ when :inline
7
+ super(:span, :class => 'help-inline') { append text }
8
+ when :block
9
+ super(:p, :class => 'help-block') { append text }
10
+ else
11
+ raise "Invalid help type [#{type}]"
12
+ end
13
+ end
14
+
15
+ def self.inline(text)
16
+ self.new(:inline, text)
17
+ end
18
+
19
+ def self.block(text)
20
+ self.new(:block, text)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ module TwitterBootstrapMarkup
2
+ class Icon < Tag
3
+
4
+ def initialize(name, attributes={})
5
+ super(:i, attributes.prepend!(:class, "icon-#{name}")) {}
6
+ end
7
+
8
+ def white
9
+ attributes.append!(:class, 'icon-white')
10
+ self
11
+ end
12
+
13
+ def self.white(*args)
14
+ self.new(*args).white
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ module TwitterBootstrapMarkup
2
+ class Input < Tag
3
+ TYPES = [:text, :hidden, :email, :password, :button, :checkbox, :radio]
4
+ SIZES = [:mini, :small, :medium, :large, :xlarge, :xxlarge]
5
+
6
+ def initialize(type, attributes={}, &block)
7
+ super(:input, {:type => type}.merge(attributes), &block)
8
+ end
9
+
10
+ SIZES.each do |size|
11
+ define_method(size) do
12
+ attributes.append!(:class, "input-#{size}")
13
+ self
14
+ end
15
+ end
16
+
17
+ TYPES.each do |type|
18
+ define_singleton_method(type) do |*args, &block|
19
+ self.new(type, *args, &block)
20
+ end
21
+
22
+ SIZES.each do |size|
23
+ define_singleton_method("#{type}_#{size}") do |*args, &block|
24
+ self.new(type, *args, &block).send(size)
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module TwitterBootstrapMarkup
2
+ class Label < LabelBase
3
+ end
4
+ end
@@ -0,0 +1,29 @@
1
+ module TwitterBootstrapMarkup
2
+ class LabelBase < Tag
3
+ TYPES = [:success, :warning, :important, :info, :inverse]
4
+
5
+ def initialize(text)
6
+ super(:span, :class => class_name.downcase) { append text }
7
+ end
8
+
9
+ TYPES.each do |type|
10
+ define_method type do
11
+ attributes.append!(:class, "#{class_name.downcase}-#{type}")
12
+ self
13
+ end
14
+ end
15
+
16
+ TYPES.each do |type|
17
+ define_singleton_method type do |*args, &block|
18
+ self.new(*args, &block).send(type)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def class_name
25
+ self.class.name.split('::').last
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ module TwitterBootstrapMarkup
2
+ class Link < Tag
3
+
4
+ def initialize(*args, &block)
5
+ text = args.shift unless block_given?
6
+ url = args.shift
7
+ attributes = args.shift || {}
8
+
9
+ if block_given?
10
+ super(:a, {:href => url}.merge(attributes), &block)
11
+ else
12
+ super(:a, {:href => url}.merge(attributes || {})) { append text }
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module TwitterBootstrapMarkup
2
+ class LinkButton < ButtonBase
3
+
4
+ def initialize(*args, &block)
5
+ text = args.shift unless block_given?
6
+ url = args.shift
7
+ attributes = args.shift || {}
8
+
9
+ if block_given?
10
+ super(:a, attributes.prepend!(:class, 'btn').merge(:href => url), &block)
11
+ else
12
+ super(:a, attributes.prepend!(:class, 'btn').merge(:href => url)) { append text }
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ module TwitterBootstrapMarkup
2
+ class NavBar < Tag
3
+
4
+ def initialize(attributes={}, &block)
5
+ super(:div, attributes.prepend!(:class, 'navbar')){}
6
+ append do
7
+ Tag.new(:div, :class => 'navbar-inner') do
8
+ append Tag.new(:div, :class => 'container', &block)
9
+ end
10
+ end
11
+ end
12
+
13
+ def top
14
+ attributes.append!(:class, 'navbar-fixed-top')
15
+ self
16
+ end
17
+
18
+ def bottom
19
+ attributes.append!(:class, 'navbar-fixed-bottom')
20
+ self
21
+ end
22
+
23
+ def self.top(*args, &block)
24
+ self.new(*args, &block).top
25
+ end
26
+
27
+ def self.bottom(*args, &block)
28
+ self.new(*args, &block).bottom
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ module TwitterBootstrapMarkup
2
+ class NavContainer < UlContainer
3
+
4
+ def initialize(attributes={}, &block)
5
+ super(attributes.prepend!(:class, 'nav'), &block)
6
+ end
7
+
8
+ end
9
+
10
+ end
@@ -0,0 +1,9 @@
1
+ module TwitterBootstrapMarkup
2
+ class NavHeader < Tag
3
+
4
+ def initialize(text)
5
+ super(:li, :class => 'nav-header') { append text }
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module TwitterBootstrapMarkup
2
+ class NavList < Well
3
+
4
+ def initialize(attributes={}, &block)
5
+ super(attributes.append!(:style, 'padding: 8px 0;')) do
6
+ append NavListContainer.new(&block)
7
+ end
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,10 @@
1
+ module TwitterBootstrapMarkup
2
+ class NavListContainer < NavContainer
3
+
4
+ def initialize(attributes={}, &block)
5
+ super(attributes.append!(:class, 'nav-list'), &block)
6
+ end
7
+
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ module TwitterBootstrapMarkup
2
+ class NavTab < Link
3
+
4
+ def initialize(*args, &block)
5
+ super(*args, &block)
6
+ attributes['data-toggle'] = 'tab'
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module TwitterBootstrapMarkup
2
+ class NavTabContainer < NavContainer
3
+
4
+ def initialize(attributes={}, &block)
5
+ if block_given?
6
+ super(attributes.append!(:class, 'nav-tabs'), &block)
7
+ else
8
+ super(attributes.append!(:class, 'nav-tabs')) {}
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module TwitterBootstrapMarkup
2
+ class PageHeader < Tag
3
+
4
+ def initialize(title, subtitle=nil)
5
+ super(:div, :class => 'page-header') do
6
+ append do
7
+ Tag.block(:h1) do
8
+ append title
9
+ append Tag.block(:small) { append subtitle } if subtitle
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module TwitterBootstrapMarkup
2
+ class Pagination < Tag
3
+
4
+ def initialize(attributes={}, &block)
5
+ super(:div, attributes.prepend!(:class, 'pagination')) do
6
+ append UlContainer.new(&block)
7
+ end
8
+ end
9
+
10
+ def centered
11
+ attributes.append!(:class, 'pagination-centered')
12
+ self
13
+ end
14
+
15
+ def right
16
+ attributes.append!(:class, 'pagination-right')
17
+ self
18
+ end
19
+
20
+ def self.centered(*args, &block)
21
+ self.new(*args, &block).centered
22
+ end
23
+
24
+ def self.right(*args, &block)
25
+ self.new(*args, &block).right
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ module TwitterBootstrapMarkup
2
+ module Popover
3
+ POSITIONS = [:top, :bottom, :left, :right]
4
+
5
+ def popover(title, content)
6
+ popover_right(title, content)
7
+ end
8
+
9
+ POSITIONS.each do |position|
10
+ define_method "popover_#{position}" do |title, content|
11
+ attributes[:rel] = 'popover'
12
+ attributes['data-original-title'] = title
13
+ attributes['data-content'] = content
14
+ attributes['data-placement'] = position
15
+ self
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ module TwitterBootstrapMarkup
2
+ class ProgressBar < Tag
3
+ TYPES = [:info, :success, :danger, :warning]
4
+
5
+ def initialize(percentage=0)
6
+ super(:div, :class => 'progress') do
7
+ append Tag.block(:div, :class => 'bar', :style => "width: #{percentage}%;")
8
+ end
9
+ end
10
+
11
+ def striped
12
+ attributes.append! :class, "progress-striped"
13
+ self
14
+ end
15
+
16
+ def striped_animated
17
+ attributes.append! :class, "progress-striped active"
18
+ self
19
+ end
20
+
21
+ TYPES.each do |type|
22
+ define_method type do
23
+ attributes.append! :class, "progress-#{type}"
24
+ self
25
+ end
26
+ end
27
+
28
+ TYPES.each do |type|
29
+ define_singleton_method type do |*args, &block|
30
+ self.new(*args, &block).send(type)
31
+ end
32
+
33
+ define_singleton_method "#{type}_striped" do |*args, &block|
34
+ self.new(*args, &block).send(type).striped
35
+ end
36
+
37
+ define_singleton_method "#{type}_striped_animated" do |*args, &block|
38
+ self.new(*args, &block).send(type).striped_animated
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,67 @@
1
+ module TwitterBootstrapMarkup
2
+ class Select < Tag
3
+ SIZES = [:mini, :small, :medium, :large, :xlarge, :xxlarge]
4
+
5
+ def initialize(*args, &block)
6
+ @options = args.shift || [] unless block_given?
7
+ attributes = args.shift || {}
8
+ @selected_value = attributes.delete(:selected_value)
9
+ prompt = attributes.delete(:prompt)
10
+
11
+ if block_given?
12
+ super(:select, attributes, &block)
13
+ else
14
+ super(:select, attributes) {}
15
+ append_options
16
+ end
17
+
18
+ prepend Tag.new(:option, :value => '') { append prompt } if prompt
19
+ end
20
+
21
+ SIZES.each do |size|
22
+ define_method(size) do
23
+ attributes.append!(:class, "input-#{size}")
24
+ self
25
+ end
26
+ end
27
+
28
+ SIZES.each do |size|
29
+ define_singleton_method(size) do |*args, &block|
30
+ self.new(*args, &block).send(size)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def append_options
37
+ if @options.is_a? Hash
38
+ append_options_hash @options
39
+ else
40
+ append_options_array @options
41
+ end
42
+ end
43
+
44
+ def append_options_array(options, container=self)
45
+ options.each do |option|
46
+ o = container.append Tag.block(:option, :value => option) { append option }
47
+ o.attributes[:selected] = nil if option.to_s == @selected_value.to_s
48
+ end
49
+ end
50
+
51
+ def append_options_hash(options, container=self)
52
+ options.each do |key, value|
53
+ if value.is_a? Array
54
+ group = append Tag.block(:optgroup, :label => key)
55
+ append_options_array(value, group)
56
+ elsif value.is_a? Hash
57
+ group = append Tag.block(:optgroup, :label => key)
58
+ append_options_hash(value, group)
59
+ else
60
+ o = container.append Tag.block(:option, :value => value) { append key }
61
+ o.attributes[:selected] = nil if value.to_s == @selected_value.to_s
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ end