twitter_bootstrap_markup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in twitter_bootstrap_markup.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # twitter_bootstrap_markup
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'twitter_bootstrap_markup'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install twitter_bootstrap_markup
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,45 @@
1
+ require 'twitter_bootstrap_markup/extension/hash'
2
+ require 'twitter_bootstrap_markup/version'
3
+ require 'twitter_bootstrap_markup/tooltip'
4
+ require 'twitter_bootstrap_markup/popover'
5
+ require 'twitter_bootstrap_markup/side_position'
6
+ require 'twitter_bootstrap_markup/tag'
7
+ require 'twitter_bootstrap_markup/link'
8
+ require 'twitter_bootstrap_markup/button_base'
9
+ require 'twitter_bootstrap_markup/button'
10
+ require 'twitter_bootstrap_markup/submit'
11
+ require 'twitter_bootstrap_markup/link_button'
12
+ require 'twitter_bootstrap_markup/icon'
13
+ require 'twitter_bootstrap_markup/divider'
14
+ require 'twitter_bootstrap_markup/dropdown_button'
15
+ require 'twitter_bootstrap_markup/alert'
16
+ require 'twitter_bootstrap_markup/input'
17
+ require 'twitter_bootstrap_markup/select'
18
+ require 'twitter_bootstrap_markup/add_on'
19
+ require 'twitter_bootstrap_markup/extended_input'
20
+ require 'twitter_bootstrap_markup/help'
21
+ require 'twitter_bootstrap_markup/control_group'
22
+ require 'twitter_bootstrap_markup/form'
23
+ require 'twitter_bootstrap_markup/fieldset'
24
+ require 'twitter_bootstrap_markup/well'
25
+ require 'twitter_bootstrap_markup/brand'
26
+ require 'twitter_bootstrap_markup/nav_header'
27
+ require 'twitter_bootstrap_markup/ul_container'
28
+ require 'twitter_bootstrap_markup/nav_container'
29
+ require 'twitter_bootstrap_markup/nav_list_container'
30
+ require 'twitter_bootstrap_markup/nav_list'
31
+ require 'twitter_bootstrap_markup/nav_bar'
32
+ require 'twitter_bootstrap_markup/nav_tab_container'
33
+ require 'twitter_bootstrap_markup/nav_tab'
34
+ require 'twitter_bootstrap_markup/tab_content'
35
+ require 'twitter_bootstrap_markup/tab'
36
+ require 'twitter_bootstrap_markup/table'
37
+ require 'twitter_bootstrap_markup/label_base'
38
+ require 'twitter_bootstrap_markup/label'
39
+ require 'twitter_bootstrap_markup/badge'
40
+ require 'twitter_bootstrap_markup/page_header'
41
+ require 'twitter_bootstrap_markup/breadcrumb'
42
+ require 'twitter_bootstrap_markup/pagination'
43
+ require 'twitter_bootstrap_markup/progress_bar'
44
+ require 'twitter_bootstrap_markup/grid_row'
45
+ require 'twitter_bootstrap_markup/grid_column'
@@ -0,0 +1,9 @@
1
+ module TwitterBootstrapMarkup
2
+ class AddOn < Tag
3
+
4
+ def initialize(text)
5
+ super(:span, :class => 'add-on') { append text }
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ module TwitterBootstrapMarkup
2
+ class Alert < Tag
3
+ TYPES = [:warning, :info, :success, :danger]
4
+
5
+ def initialize(attributes={}, &block)
6
+ super(:div, attributes.prepend!(:class, 'alert'), &block)
7
+ end
8
+
9
+ TYPES.each do |type|
10
+ define_method type do
11
+ attributes.append!(:class, "alert-#{type}") unless type == :warning
12
+ self
13
+ end
14
+ end
15
+
16
+ def closable
17
+ prepend Tag.new(:button, :class => 'close', 'data-dismiss' => 'alert') { append '&times' }
18
+ self
19
+ end
20
+
21
+ TYPES.each do |type|
22
+ define_singleton_method type do |*args, &block|
23
+ self.new(*args, &block).send(type)
24
+ end
25
+
26
+ define_singleton_method "#{type}_closable" do |*args, &block|
27
+ self.new(*args, &block).send(type).closable
28
+ end
29
+ end
30
+
31
+ def self.closable(*args, &block)
32
+ self.new(*args, &block).closable
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module TwitterBootstrapMarkup
2
+ class Badge < LabelBase
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module TwitterBootstrapMarkup
2
+ class Brand < Tag
3
+
4
+ def initialize(title, url)
5
+ super(:a, :class => 'brand', :href => url) { append title }
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ module TwitterBootstrapMarkup
2
+ class Breadcrumb < Tag
3
+ alias :internal_append :append
4
+
5
+ def initialize(attributes={}, &block)
6
+ super(:ul, attributes.prepend!(:class, 'breadcrumb'), &block)
7
+ end
8
+
9
+ def append(element=nil, &block)
10
+ internal_append Tag.block(:li) { append Divider.breadcrumb } unless children.empty?
11
+
12
+ element = instance_eval(&block) if block_given?
13
+ if element.is_a?(Tag) && element.name == :li
14
+ internal_append element
15
+ else
16
+ internal_append Tag.block(:li) { append element }
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module TwitterBootstrapMarkup
2
+ class Button < ButtonBase
3
+
4
+ def initialize(*args, &block)
5
+ text = args.shift unless block_given?
6
+ attributes = args.shift || {}
7
+
8
+ if block_given?
9
+ super(:button, attributes.prepend!(:class, 'btn'), &block)
10
+ else
11
+ super(:button, attributes.prepend!(:class, 'btn')) { append text }
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,41 @@
1
+ module TwitterBootstrapMarkup
2
+ class ButtonBase < Tag
3
+ TYPES = [:primary, :info, :success, :warning, :danger, :inverse]
4
+ SIZES = [:large, :small, :mini]
5
+
6
+ TYPES.each do |type|
7
+ define_method type do
8
+ attributes.append!(:class, "btn-#{type}")
9
+ self
10
+ end
11
+ end
12
+
13
+ SIZES.each do |size|
14
+ define_method size do
15
+ self.attributes.append!(:class, "btn-#{size}")
16
+ self
17
+ end
18
+ end
19
+
20
+ TYPES.each do |type|
21
+ define_singleton_method(type) do |*args, &block|
22
+ self.new(*args, &block).send(type)
23
+ end
24
+ end
25
+
26
+ SIZES.each do |size|
27
+ define_singleton_method(size) do |*args, &block|
28
+ self.new(*args, &block).send(size)
29
+ end
30
+ end
31
+
32
+ TYPES.each do |type|
33
+ SIZES.each do |size|
34
+ define_singleton_method("#{type}_#{size}") do |*args, &block|
35
+ self.new(*args, &block).send(type).send(size)
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ module TwitterBootstrapMarkup
2
+ class ControlGroup < Tag
3
+ TYPES = [:warning, :error, :success]
4
+
5
+ def initialize(label, attributes={}, &block)
6
+ super(:div, :class => 'control-group') do
7
+ append Tag.block(:label, attributes.prepend!(:class, 'control-label')) { append label }
8
+ append Tag.block(:div, :class => 'controls', &block)
9
+ end
10
+ end
11
+
12
+ TYPES.each do |type|
13
+ define_method type do
14
+ self.attributes.append!(:class, type)
15
+ self
16
+ end
17
+ end
18
+
19
+ TYPES.each do |type|
20
+ define_singleton_method type do |*args, &block|
21
+ self.new(*args, &block).send(type)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module TwitterBootstrapMarkup
2
+ class Divider < Tag
3
+
4
+ def initialize(type)
5
+ case type
6
+ when :horizontal
7
+ super(:li, :class => 'divider') {}
8
+ when :vertical
9
+ super(:li, :class => 'divider-vertical') {}
10
+ when :breadcrumb
11
+ super(:span, :class => 'divider') { append '/' }
12
+ else
13
+ raise "Invalid divider type [#{type}]"
14
+ end
15
+ end
16
+
17
+ def self.horizontal
18
+ self.new :horizontal
19
+ end
20
+
21
+ def self.vertical
22
+ self.new :vertical
23
+ end
24
+
25
+ def self.breadcrumb
26
+ self.new :breadcrumb
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,59 @@
1
+ module TwitterBootstrapMarkup
2
+ class DropdownButton < Tag
3
+ alias :internal_append :append
4
+
5
+ def initialize(text, &block)
6
+ super(:div, :class => 'btn-group') do
7
+ @button = internal_append(Button.new(:class => 'dropdown-toggle', 'data-toggle' => 'dropdown') do
8
+ append "#{text} "
9
+ append Tag.block :span, :class => 'caret'
10
+ end)
11
+ @ul = internal_append Tag.block(:ul, :class => 'dropdown-menu')
12
+ instance_eval &block if block_given?
13
+ end
14
+ end
15
+
16
+ def append(element)
17
+ if element.is_a?(Tag) && element.name == :li
18
+ @ul.append element
19
+ else
20
+ @ul.append Tag.block(:li) { append element }
21
+ end
22
+ end
23
+
24
+ ButtonBase::TYPES.each do |type|
25
+ define_method type do
26
+ @button.send(type)
27
+ self
28
+ end
29
+ end
30
+
31
+ ButtonBase::SIZES.each do |size|
32
+ define_method size do
33
+ @button.send(size)
34
+ self
35
+ end
36
+ end
37
+
38
+ ButtonBase::TYPES.each do |type|
39
+ define_singleton_method(type) do |*args, &block|
40
+ self.new(*args, &block).send(type)
41
+ end
42
+ end
43
+
44
+ ButtonBase::SIZES.each do |size|
45
+ define_singleton_method(size) do |*args, &block|
46
+ self.new(*args, &block).send(size)
47
+ end
48
+ end
49
+
50
+ ButtonBase::TYPES.each do |type|
51
+ ButtonBase::SIZES.each do |size|
52
+ define_singleton_method("#{type}_#{size}") do |*args, &block|
53
+ self.new(*args, &block).send(type).send(size)
54
+ end
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,11 @@
1
+ module TwitterBootstrapMarkup
2
+ class ExtendedInput < Tag
3
+
4
+ def initialize(attributes={}, &block)
5
+ super(:div, attributes, &block)
6
+ attributes.append!(:class, 'input-prepend') unless children.first.is_a?(Input) && children.first.attributes[:type] == :text
7
+ attributes.append!(:class, 'input-append') unless children.last.is_a?(Input) && children.last.attributes[:type] == :text
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class Hash
2
+ def prepend!(key, value)
3
+ self[key] = self.has_key?(key) ? "#{value} #{self[key]}" : value
4
+ self
5
+ end
6
+
7
+ def append!(key, value)
8
+ self[key] = self.has_key?(key) ? "#{self[key]} #{value}" : value
9
+ self
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module TwitterBootstrapMarkup
2
+ class Fieldset < Tag
3
+
4
+ def initialize(*args, &block)
5
+ legend = args[0].is_a?(String) ? args.shift : nil
6
+ attributes = args.shift || {}
7
+
8
+ if block_given?
9
+ super(:fieldset, attributes, &block)
10
+ else
11
+ super(:fieldset, attributes) {}
12
+ end
13
+
14
+ prepend Tag.new(:legend) { append legend } if legend
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module TwitterBootstrapMarkup
2
+ class Form < Tag
3
+ TYPES = [:vertical, :inline, :search, :horizontal]
4
+
5
+ def initialize(attributes={}, &block)
6
+ if block_given?
7
+ super(:form, attributes, &block)
8
+ else
9
+ super(:form, attributes) {}
10
+ end
11
+ end
12
+
13
+ TYPES.each do |type|
14
+ define_method(type) do
15
+ attributes.append!(:class, "form-#{type}") unless type == :vertical
16
+ self
17
+ end
18
+ end
19
+
20
+ TYPES.each do |type|
21
+ define_singleton_method(type) do |*args, &block|
22
+ self.new(*args, &block).send(type)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ module TwitterBootstrapMarkup
2
+ class GridColumn < Tag
3
+
4
+ def initialize(*args, &block)
5
+ size = args.shift
6
+ offset = args.shift if args.first.is_a?(Fixnum)
7
+ attributes = args.shift || {}
8
+ attributes.prepend!(:class, "span#{size}")
9
+ attributes.append!(:class, "offset#{offset}") if offset
10
+ super(:div, attributes, &block)
11
+ end
12
+
13
+ end
14
+ end