twitter_bootstrap_markup 0.0.2 → 0.0.3

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 (37) hide show
  1. data/lib/twitter_bootstrap_markup.rb +7 -0
  2. data/lib/twitter_bootstrap_markup/alert.rb +1 -1
  3. data/lib/twitter_bootstrap_markup/badge.rb +2 -1
  4. data/lib/twitter_bootstrap_markup/button.rb +2 -1
  5. data/lib/twitter_bootstrap_markup/button_base.rb +27 -23
  6. data/lib/twitter_bootstrap_markup/dropdown_link.rb +30 -0
  7. data/lib/twitter_bootstrap_markup/input.rb +3 -9
  8. data/lib/twitter_bootstrap_markup/input_size.rb +22 -0
  9. data/lib/twitter_bootstrap_markup/label.rb +2 -1
  10. data/lib/twitter_bootstrap_markup/label_base.rb +13 -9
  11. data/lib/twitter_bootstrap_markup/link_button.rb +2 -1
  12. data/lib/twitter_bootstrap_markup/nav_bar.rb +8 -6
  13. data/lib/twitter_bootstrap_markup/nav_list.rb +9 -4
  14. data/lib/twitter_bootstrap_markup/select.rb +2 -14
  15. data/lib/twitter_bootstrap_markup/tag.rb +12 -2
  16. data/lib/twitter_bootstrap_markup/tag_builder.rb +22 -0
  17. data/lib/twitter_bootstrap_markup/textarea.rb +15 -0
  18. data/lib/twitter_bootstrap_markup/ul_container.rb +9 -2
  19. data/lib/twitter_bootstrap_markup/version.rb +1 -1
  20. data/markup/alerts.html +1 -1
  21. data/markup/css/bootstrap.css +3451 -3520
  22. data/markup/css/bootstrap.min.css +719 -1
  23. data/markup/dropdown_links.html +112 -0
  24. data/markup/index.html +14 -12
  25. data/markup/js/bootstrap.js +856 -845
  26. data/markup/js/bootstrap.min.js +3 -2
  27. data/markup/textareas.html +90 -0
  28. data/spec/dropdown_link_spec.rb +48 -0
  29. data/spec/nav_bar_spec.rb +11 -0
  30. data/spec/nav_list_spec.rb +14 -1
  31. data/spec/select_spec.rb +2 -3
  32. data/spec/tag_builder_spec.rb +38 -0
  33. data/spec/tag_spec.rb +12 -0
  34. data/spec/text_area_spec.rb +43 -0
  35. data/spec/textbox_spec.rb +2 -2
  36. data/twitter_bootstrap_markup.gemspec +2 -0
  37. metadata +26 -6
@@ -1,3 +1,5 @@
1
+ require 'active_support/all'
2
+
1
3
  require 'twitter_bootstrap_markup/extension/hash'
2
4
  require 'twitter_bootstrap_markup/version'
3
5
  require 'twitter_bootstrap_markup/tooltip'
@@ -12,7 +14,10 @@ require 'twitter_bootstrap_markup/link_button'
12
14
  require 'twitter_bootstrap_markup/icon'
13
15
  require 'twitter_bootstrap_markup/divider'
14
16
  require 'twitter_bootstrap_markup/dropdown_button'
17
+ require 'twitter_bootstrap_markup/dropdown_link'
15
18
  require 'twitter_bootstrap_markup/alert'
19
+ require 'twitter_bootstrap_markup/input_size'
20
+ require 'twitter_bootstrap_markup/textarea'
16
21
  require 'twitter_bootstrap_markup/input'
17
22
  require 'twitter_bootstrap_markup/select'
18
23
  require 'twitter_bootstrap_markup/add_on'
@@ -43,3 +48,5 @@ require 'twitter_bootstrap_markup/pagination'
43
48
  require 'twitter_bootstrap_markup/progress_bar'
44
49
  require 'twitter_bootstrap_markup/grid_row'
45
50
  require 'twitter_bootstrap_markup/grid_column'
51
+
52
+ require 'twitter_bootstrap_markup/tag_builder'
@@ -15,7 +15,7 @@ module TwitterBootstrapMarkup
15
15
  end
16
16
 
17
17
  def closable
18
- prepend Tag.new(:button, :class => 'close', 'data-dismiss' => 'alert') { append '&times' }
18
+ prepend Tag.new(:a, :class => 'close', 'data-dismiss' => 'alert') { append '&times' }
19
19
  self
20
20
  end
21
21
 
@@ -1,4 +1,5 @@
1
1
  module TwitterBootstrapMarkup
2
- class Badge < LabelBase
2
+ class Badge < Tag
3
+ include LabelBase
3
4
  end
4
5
  end
@@ -1,5 +1,6 @@
1
1
  module TwitterBootstrapMarkup
2
- class Button < ButtonBase
2
+ class Button < Tag
3
+ include ButtonBase
3
4
 
4
5
  def initialize(*args, &block)
5
6
  text = args.shift unless block_given?
@@ -1,40 +1,44 @@
1
1
  module TwitterBootstrapMarkup
2
- class ButtonBase < Tag
2
+ module ButtonBase
3
3
  TYPES = [:primary, :info, :success, :warning, :danger, :inverse]
4
4
  SIZES = [:large, :small, :mini]
5
5
 
6
- TYPES.each do |type|
7
- define_method type do
8
- attributes.append!(:class, "btn-#{type}")
9
- self
10
- end
11
- end
6
+ def self.included(base)
12
7
 
13
- SIZES.each do |size|
14
- define_method size do
15
- self.attributes.append!(:class, "btn-#{size}")
16
- self
8
+ TYPES.each do |type|
9
+ base.send(:define_method, type) do
10
+ attributes.append!(:class, "btn-#{type}")
11
+ self
12
+ end
17
13
  end
18
- end
19
14
 
20
- TYPES.each do |type|
21
- define_singleton_method(type) do |*args, &block|
22
- self.new(*args, &block).send(type)
15
+ SIZES.each do |size|
16
+ base.send(:define_method, size) do
17
+ self.attributes.append!(:class, "btn-#{size}")
18
+ self
19
+ end
23
20
  end
24
- end
25
21
 
26
- SIZES.each do |size|
27
- define_singleton_method(size) do |*args, &block|
28
- self.new(*args, &block).send(size)
22
+ TYPES.each do |type|
23
+ base.send(:define_singleton_method, type) do |*args, &block|
24
+ self.new(*args, &block).send(type)
25
+ end
29
26
  end
30
- end
31
27
 
32
- TYPES.each do |type|
33
28
  SIZES.each do |size|
34
- define_singleton_method("#{type}_#{size}") do |*args, &block|
35
- self.new(*args, &block).send(type).send(size)
29
+ base.send(:define_singleton_method, size) do |*args, &block|
30
+ self.new(*args, &block).send(size)
31
+ end
32
+ end
33
+
34
+ TYPES.each do |type|
35
+ SIZES.each do |size|
36
+ base.send(:define_singleton_method, "#{type}_#{size}") do |*args, &block|
37
+ self.new(*args, &block).send(type).send(size)
38
+ end
36
39
  end
37
40
  end
41
+
38
42
  end
39
43
 
40
44
  end
@@ -0,0 +1,30 @@
1
+ module TwitterBootstrapMarkup
2
+ class DropdownLink < Tag
3
+ alias :internal_append :append
4
+
5
+ def initialize(text, &block)
6
+ super(:div, :class => 'dropdown') do
7
+ internal_append(Link.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, element)
21
+ end
22
+ end
23
+
24
+ def as_nav_item
25
+ @name = :li
26
+ self
27
+ end
28
+
29
+ end
30
+ end
@@ -1,25 +1,19 @@
1
1
  module TwitterBootstrapMarkup
2
2
  class Input < Tag
3
3
  TYPES = [:text, :hidden, :email, :password, :button, :checkbox, :radio]
4
- SIZES = [:mini, :small, :medium, :large, :xlarge, :xxlarge]
4
+
5
+ include InputSize::InstanceMethods
5
6
 
6
7
  def initialize(type, attributes={}, &block)
7
8
  super(:input, {:type => type}.merge(attributes), &block)
8
9
  end
9
10
 
10
- SIZES.each do |size|
11
- define_method(size) do
12
- attributes.append!(:class, "input-#{size}")
13
- self
14
- end
15
- end
16
-
17
11
  TYPES.each do |type|
18
12
  define_singleton_method(type) do |*args, &block|
19
13
  self.new(type, *args, &block)
20
14
  end
21
15
 
22
- SIZES.each do |size|
16
+ InputSize::VALUES.each do |size|
23
17
  define_singleton_method("#{type}_#{size}") do |*args, &block|
24
18
  self.new(type, *args, &block).send(size)
25
19
  end
@@ -0,0 +1,22 @@
1
+ module TwitterBootstrapMarkup
2
+ module InputSize
3
+ VALUES = [:mini, :small, :medium, :large, :xlarge, :xxlarge]
4
+
5
+ module InstanceMethods
6
+ VALUES.each do |size|
7
+ define_method(size) do
8
+ attributes.append!(:class, "input-#{size}")
9
+ self
10
+ end
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ VALUES.each do |size|
16
+ define_method(size) do |*args, &block|
17
+ self.new(*args, &block).send(size)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,5 @@
1
1
  module TwitterBootstrapMarkup
2
- class Label < LabelBase
2
+ class Label < Tag
3
+ include LabelBase
3
4
  end
4
5
  end
@@ -1,22 +1,26 @@
1
1
  module TwitterBootstrapMarkup
2
- class LabelBase < Tag
2
+ module LabelBase
3
3
  TYPES = [:success, :warning, :important, :info, :inverse]
4
4
 
5
5
  def initialize(text)
6
6
  super(:span, text, :class => class_name.downcase) {}
7
7
  end
8
8
 
9
- TYPES.each do |type|
10
- define_method type do
11
- attributes.append!(:class, "#{class_name.downcase}-#{type}")
12
- self
9
+ def self.included(base)
10
+
11
+ TYPES.each do |type|
12
+ base.send(:define_method, type) do
13
+ attributes.append!(:class, "#{class_name.downcase}-#{type}")
14
+ self
15
+ end
13
16
  end
14
- end
15
17
 
16
- TYPES.each do |type|
17
- define_singleton_method type do |*args, &block|
18
- self.new(*args, &block).send(type)
18
+ TYPES.each do |type|
19
+ base.send(:define_singleton_method, type) do |*args, &block|
20
+ self.new(*args, &block).send(type)
21
+ end
19
22
  end
23
+
20
24
  end
21
25
 
22
26
  private
@@ -1,5 +1,6 @@
1
1
  module TwitterBootstrapMarkup
2
- class LinkButton < ButtonBase
2
+ class LinkButton < Tag
3
+ include ButtonBase
3
4
 
4
5
  def initialize(*args, &block)
5
6
  text = args.shift unless block_given?
@@ -1,13 +1,15 @@
1
1
  module TwitterBootstrapMarkup
2
2
  class NavBar < Tag
3
+ alias :internal_append :append
3
4
 
4
5
  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
6
+ super(:div, attributes.prepend!(:class, 'navbar')) {}
7
+ @container = Tag.block(:div, :class => 'container', &block)
8
+ internal_append Tag.block(:div, @container, :class => 'navbar-inner')
9
+ end
10
+
11
+ def append(*args, &block)
12
+ @container.append(*args, &block)
11
13
  end
12
14
 
13
15
  def top
@@ -1,11 +1,16 @@
1
1
  module TwitterBootstrapMarkup
2
2
  class NavList < Well
3
+ alias :internal_append :append
3
4
 
4
5
  def initialize(attributes={}, &block)
5
- super(attributes.append!(:style, 'padding: 8px 0;')) do
6
- append NavListContainer.new(&block)
7
- end
6
+ super(attributes.append!(:style, 'padding: 8px 0;')) {}
7
+ @container = NavListContainer.new(&block)
8
+ internal_append @container
9
+ end
10
+
11
+ def append(*args, &block)
12
+ @container.append(*args, &block)
8
13
  end
9
- end
10
14
 
15
+ end
11
16
  end
@@ -1,6 +1,7 @@
1
1
  module TwitterBootstrapMarkup
2
2
  class Select < Tag
3
- SIZES = [:mini, :small, :medium, :large, :xlarge, :xxlarge]
3
+ extend InputSize::ClassMethods
4
+ include InputSize::InstanceMethods
4
5
 
5
6
  def initialize(*args, &block)
6
7
  @options = args.shift || [] unless block_given?
@@ -18,19 +19,6 @@ module TwitterBootstrapMarkup
18
19
  prepend Tag.new(:option, prompt, :value => '') {} if prompt
19
20
  end
20
21
 
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
22
  private
35
23
 
36
24
  def append_options
@@ -27,11 +27,11 @@ module TwitterBootstrapMarkup
27
27
  @children = []
28
28
  @is_block = content || block_given?
29
29
  append content if content
30
- instance_eval &block if block_given?
30
+ evaluate(&block) if block_given?
31
31
  end
32
32
 
33
33
  def append(element=nil, &block)
34
- element = instance_eval(&block) if block_given?
34
+ element = evaluate(&block) if block_given?
35
35
  @children << element
36
36
  element
37
37
  end
@@ -49,5 +49,15 @@ module TwitterBootstrapMarkup
49
49
  end
50
50
  end
51
51
 
52
+ private
53
+
54
+ def evaluate(&block)
55
+ if block.arity == 0
56
+ element = instance_eval(&block)
57
+ else
58
+ element = block.call(self)
59
+ end
60
+ end
61
+
52
62
  end
53
63
  end
@@ -0,0 +1,22 @@
1
+ module TwitterBootstrapMarkup
2
+ module TagBuilder
3
+
4
+ def self.class_of(constant)
5
+ "TwitterBootstrapMarkup::#{constant}".safe_constantize
6
+ end
7
+
8
+ TwitterBootstrapMarkup.constants.select { |c| class_of(c).is_a?(Class) }.each do |constant|
9
+ tag_class = class_of(constant)
10
+ define_singleton_method constant.to_s.underscore do |*args, &block|
11
+ tag_class.new(*args, &block)
12
+ end
13
+
14
+ (tag_class.methods - Object.methods).each do |method|
15
+ define_singleton_method "#{constant.to_s.underscore}_#{method}" do |*args, &block|
16
+ tag_class.send(method, *args, &block)
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module TwitterBootstrapMarkup
2
+ class Textarea < Tag
3
+ extend InputSize::ClassMethods
4
+ include InputSize::InstanceMethods
5
+
6
+ def initialize(*args, &block)
7
+ if block_given?
8
+ super(:textarea, *args, &block)
9
+ else
10
+ super(:textarea, *args) {}
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -3,12 +3,12 @@ module TwitterBootstrapMarkup
3
3
  alias :internal_append :append
4
4
 
5
5
  def initialize(attributes={}, &block)
6
- super(:ul, attributes, &block)
6
+ super(:ul, attributes, &(block || Proc.new {}))
7
7
  end
8
8
 
9
9
  def append(element=nil, mode=:inactive, &block)
10
10
  element = instance_eval(&block) if block_given?
11
- if element.is_a?(Tag) && element.name == :li
11
+ if is_li? element
12
12
  element.attributes.append!(:class, 'active') if mode == :active
13
13
  internal_append element
14
14
  else
@@ -17,5 +17,12 @@ module TwitterBootstrapMarkup
17
17
  end
18
18
  end
19
19
 
20
+ private
21
+
22
+ def is_li?(element)
23
+ (element.is_a?(Tag) && element.name == :li) ||
24
+ (element.is_a?(String) && ['<li>', '<li '].include?(element.downcase[0..3]))
25
+ end
26
+
20
27
  end
21
28
  end
@@ -1,3 +1,3 @@
1
1
  module TwitterBootstrapMarkup
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/markup/alerts.html CHANGED
@@ -59,7 +59,7 @@
59
59
  <td>Closable</td>
60
60
  <td id="closable">
61
61
  <div class="alert">
62
- <button class="close" data-dismiss="alert">&times</button>
62
+ <a class="close" data-dismiss="alert">&times</a>
63
63
  <strong>Alert!</strong>
64
64
  Message
65
65
  </div>