twitter_bootstrap_markup 0.0.1 → 0.0.2

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.
@@ -2,7 +2,7 @@ module TwitterBootstrapMarkup
2
2
  class AddOn < Tag
3
3
 
4
4
  def initialize(text)
5
- super(:span, :class => 'add-on') { append text }
5
+ super(:span, text, :class => 'add-on')
6
6
  end
7
7
 
8
8
  end
@@ -2,8 +2,9 @@ module TwitterBootstrapMarkup
2
2
  class Alert < Tag
3
3
  TYPES = [:warning, :info, :success, :danger]
4
4
 
5
- def initialize(attributes={}, &block)
6
- super(:div, attributes.prepend!(:class, 'alert'), &block)
5
+ def initialize(*args, &block)
6
+ super(:div, *args, &block)
7
+ attributes.prepend!(:class, 'alert')
7
8
  end
8
9
 
9
10
  TYPES.each do |type|
@@ -2,7 +2,7 @@ module TwitterBootstrapMarkup
2
2
  class Brand < Tag
3
3
 
4
4
  def initialize(title, url)
5
- super(:a, :class => 'brand', :href => url) { append title }
5
+ super(:a, title, :class => 'brand', :href => url)
6
6
  end
7
7
 
8
8
  end
@@ -2,18 +2,19 @@ module TwitterBootstrapMarkup
2
2
  class Breadcrumb < Tag
3
3
  alias :internal_append :append
4
4
 
5
- def initialize(attributes={}, &block)
6
- super(:ul, attributes.prepend!(:class, 'breadcrumb'), &block)
5
+ def initialize(*args, &block)
6
+ super(:ul, *args, &block)
7
+ attributes.prepend!(:class, 'breadcrumb')
7
8
  end
8
9
 
9
10
  def append(element=nil, &block)
10
- internal_append Tag.block(:li) { append Divider.breadcrumb } unless children.empty?
11
+ internal_append Tag.block(:li, Divider.breadcrumb) unless children.empty?
11
12
 
12
13
  element = instance_eval(&block) if block_given?
13
14
  if element.is_a?(Tag) && element.name == :li
14
15
  internal_append element
15
16
  else
16
- internal_append Tag.block(:li) { append element }
17
+ internal_append Tag.block(:li, element)
17
18
  end
18
19
  end
19
20
 
@@ -8,7 +8,7 @@ module TwitterBootstrapMarkup
8
8
  if block_given?
9
9
  super(:button, attributes.prepend!(:class, 'btn'), &block)
10
10
  else
11
- super(:button, attributes.prepend!(:class, 'btn')) { append text }
11
+ super(:button, text, attributes.prepend!(:class, 'btn'))
12
12
  end
13
13
  end
14
14
 
@@ -4,7 +4,7 @@ module TwitterBootstrapMarkup
4
4
 
5
5
  def initialize(label, attributes={}, &block)
6
6
  super(:div, :class => 'control-group') do
7
- append Tag.block(:label, attributes.prepend!(:class, 'control-label')) { append label }
7
+ append Tag.block(:label, label, attributes.prepend!(:class, 'control-label'))
8
8
  append Tag.block(:div, :class => 'controls', &block)
9
9
  end
10
10
  end
@@ -8,7 +8,7 @@ module TwitterBootstrapMarkup
8
8
  when :vertical
9
9
  super(:li, :class => 'divider-vertical') {}
10
10
  when :breadcrumb
11
- super(:span, :class => 'divider') { append '/' }
11
+ super(:span, '/', :class => 'divider') {}
12
12
  else
13
13
  raise "Invalid divider type [#{type}]"
14
14
  end
@@ -17,7 +17,7 @@ module TwitterBootstrapMarkup
17
17
  if element.is_a?(Tag) && element.name == :li
18
18
  @ul.append element
19
19
  else
20
- @ul.append Tag.block(:li) { append element }
20
+ @ul.append Tag.block(:li, element)
21
21
  end
22
22
  end
23
23
 
@@ -11,7 +11,7 @@ module TwitterBootstrapMarkup
11
11
  super(:fieldset, attributes) {}
12
12
  end
13
13
 
14
- prepend Tag.new(:legend) { append legend } if legend
14
+ prepend Tag.new(:legend, legend) if legend
15
15
  end
16
16
 
17
17
  end
@@ -4,9 +4,9 @@ module TwitterBootstrapMarkup
4
4
  def initialize(type, text)
5
5
  case type
6
6
  when :inline
7
- super(:span, :class => 'help-inline') { append text }
7
+ super(:span, text, :class => 'help-inline') {}
8
8
  when :block
9
- super(:p, :class => 'help-block') { append text }
9
+ super(:p, text, :class => 'help-block') {}
10
10
  else
11
11
  raise "Invalid help type [#{type}]"
12
12
  end
@@ -3,7 +3,7 @@ module TwitterBootstrapMarkup
3
3
  TYPES = [:success, :warning, :important, :info, :inverse]
4
4
 
5
5
  def initialize(text)
6
- super(:span, :class => class_name.downcase) { append text }
6
+ super(:span, text, :class => class_name.downcase) {}
7
7
  end
8
8
 
9
9
  TYPES.each do |type|
@@ -9,7 +9,7 @@ module TwitterBootstrapMarkup
9
9
  if block_given?
10
10
  super(:a, {:href => url}.merge(attributes), &block)
11
11
  else
12
- super(:a, {:href => url}.merge(attributes || {})) { append text }
12
+ super(:a, text, {:href => url}.merge(attributes || {})) {}
13
13
  end
14
14
  end
15
15
 
@@ -9,7 +9,7 @@ module TwitterBootstrapMarkup
9
9
  if block_given?
10
10
  super(:a, attributes.prepend!(:class, 'btn').merge(:href => url), &block)
11
11
  else
12
- super(:a, attributes.prepend!(:class, 'btn').merge(:href => url)) { append text }
12
+ super(:a, text, attributes.prepend!(:class, 'btn').merge(:href => url)) {}
13
13
  end
14
14
  end
15
15
 
@@ -2,7 +2,7 @@ module TwitterBootstrapMarkup
2
2
  class NavHeader < Tag
3
3
 
4
4
  def initialize(text)
5
- super(:li, :class => 'nav-header') { append text }
5
+ super(:li, text, :class => 'nav-header') {}
6
6
  end
7
7
 
8
8
  end
@@ -6,7 +6,7 @@ module TwitterBootstrapMarkup
6
6
  append do
7
7
  Tag.block(:h1) do
8
8
  append title
9
- append Tag.block(:small) { append subtitle } if subtitle
9
+ append Tag.block(:small, "&nbsp;&nbsp;#{subtitle}") {} if subtitle
10
10
  end
11
11
  end
12
12
 
@@ -15,7 +15,7 @@ module TwitterBootstrapMarkup
15
15
  append_options
16
16
  end
17
17
 
18
- prepend Tag.new(:option, :value => '') { append prompt } if prompt
18
+ prepend Tag.new(:option, prompt, :value => '') {} if prompt
19
19
  end
20
20
 
21
21
  SIZES.each do |size|
@@ -43,7 +43,7 @@ module TwitterBootstrapMarkup
43
43
 
44
44
  def append_options_array(options, container=self)
45
45
  options.each do |option|
46
- o = container.append Tag.block(:option, :value => option) { append option }
46
+ o = container.append Tag.block(:option, option, :value => option) {}
47
47
  o.attributes[:selected] = nil if option.to_s == @selected_value.to_s
48
48
  end
49
49
  end
@@ -57,7 +57,7 @@ module TwitterBootstrapMarkup
57
57
  group = append Tag.block(:optgroup, :label => key)
58
58
  append_options_hash(value, group)
59
59
  else
60
- o = container.append Tag.block(:option, :value => value) { append key }
60
+ o = container.append Tag.block(:option, key, :value => value) {}
61
61
  o.attributes[:selected] = nil if value.to_s == @selected_value.to_s
62
62
  end
63
63
  end
@@ -22,7 +22,7 @@ module TwitterBootstrapMarkup
22
22
  else
23
23
  attributes = {:class => 'tab-pane', :id => id}
24
24
  attributes.append!(:class, :active) if mode == :active
25
- internal_append Tag.block(:div, attributes) { append element }
25
+ internal_append Tag.block(:div, element, attributes)
26
26
  end
27
27
  end
28
28
  end
@@ -12,8 +12,9 @@ module TwitterBootstrapMarkup
12
12
  end
13
13
 
14
14
  TYPES.each do |type|
15
- define_method type do
15
+ define_method type do |&block|
16
16
  attributes.append!(:class, "table-#{type}")
17
+ instance_eval &block if block
17
18
  self
18
19
  end
19
20
  end
@@ -12,19 +12,21 @@ module TwitterBootstrapMarkup
12
12
  Tag.new(name, attributes)
13
13
  end
14
14
 
15
- def self.block(name, attributes={}, &block)
15
+ def self.block(*args, &block)
16
16
  if block_given?
17
- Tag.new(name, attributes, &block)
17
+ Tag.new(*args, &block)
18
18
  else
19
- Tag.new(name, attributes) {}
19
+ Tag.new(*args) {}
20
20
  end
21
21
  end
22
22
 
23
- def initialize(name, attributes={}, &block)
24
- @name = name
25
- @attributes = attributes
23
+ def initialize(*args, &block)
24
+ @name = args.shift
25
+ content = args.shift unless args.first.is_a?(Hash)
26
+ @attributes = args.shift || {}
26
27
  @children = []
27
- @is_block = block_given?
28
+ @is_block = content || block_given?
29
+ append content if content
28
30
  instance_eval &block if block_given?
29
31
  end
30
32
 
@@ -13,7 +13,7 @@ module TwitterBootstrapMarkup
13
13
  internal_append element
14
14
  else
15
15
  attributes = mode == :active ? {:class => 'active'} : {}
16
- internal_append Tag.block(:li, attributes) { append element }
16
+ internal_append Tag.block(:li, element, attributes)
17
17
  end
18
18
  end
19
19
 
@@ -1,3 +1,3 @@
1
1
  module TwitterBootstrapMarkup
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,8 +1,9 @@
1
1
  module TwitterBootstrapMarkup
2
2
  class Well < Tag
3
3
 
4
- def initialize(attributes={}, &block)
5
- super(:div, attributes.prepend!(:class, 'well'), &block)
4
+ def initialize(*args, &block)
5
+ super(:div, *args, &block)
6
+ attributes.prepend!(:class, 'well')
6
7
  end
7
8
 
8
9
  def small
data/spec/alert_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe Alert do
7
7
  Alert::TYPES.each do |type|
8
8
  it type do
9
9
  tag = Alert.new do
10
- append Tag.block(:strong) { append 'Alert!' }
10
+ append Tag.block :strong, 'Alert!'
11
11
  append 'Message'
12
12
  end
13
13
 
@@ -17,7 +17,7 @@ describe Alert do
17
17
 
18
18
  it 'closable' do
19
19
  tag = Alert.new do
20
- append Tag.block(:strong) { append 'Alert!' }
20
+ append Tag.block :strong, 'Alert!'
21
21
  append 'Message'
22
22
  end
23
23
 
@@ -31,12 +31,12 @@ describe Alert do
31
31
  Alert::TYPES.each do |type|
32
32
  it type do
33
33
  tag1 = Alert.send(type) do
34
- append Tag.block(:strong) { append 'Alert!' }
34
+ append Tag.block :strong, 'Alert!'
35
35
  append 'Message'
36
36
  end
37
37
 
38
38
  tag2 = Alert.new do
39
- append Tag.block(:strong) { append 'Alert!' }
39
+ append Tag.block :strong, 'Alert!'
40
40
  append 'Message'
41
41
  end
42
42
 
@@ -45,12 +45,12 @@ describe Alert do
45
45
 
46
46
  it "#{type}_closable" do
47
47
  tag1 = Alert.send("#{type}_closable") do
48
- append Tag.block(:strong) { append 'Alert!' }
48
+ append Tag.block :strong, 'Alert!'
49
49
  append 'Message'
50
50
  end
51
51
 
52
52
  tag2 = Alert.new do
53
- append Tag.block(:strong) { append 'Alert!' }
53
+ append Tag.block :strong, 'Alert!'
54
54
  append 'Message'
55
55
  end
56
56
 
@@ -60,12 +60,12 @@ describe Alert do
60
60
 
61
61
  it 'closable' do
62
62
  tag1 = Alert.closable do
63
- append Tag.block(:strong) { append 'Alert!' }
63
+ append Tag.block :strong, 'Alert!'
64
64
  append 'Message'
65
65
  end
66
66
 
67
67
  tag2 = Alert.new do
68
- append Tag.block(:strong) { append 'Alert!' }
68
+ append Tag.block :strong, 'Alert!'
69
69
  append 'Message'
70
70
  end
71
71
 
data/spec/link_spec.rb CHANGED
@@ -11,11 +11,11 @@ describe Link do
11
11
  end
12
12
 
13
13
  it 'url and block' do
14
- Link.new('url') { append Tag.block(:strong) { append 'text' } }.to_s.should eq '<a href="url"><strong>text</strong></a>'
14
+ Link.new('url') { append Tag.block(:strong, 'text') }.to_s.should eq '<a href="url"><strong>text</strong></a>'
15
15
  end
16
16
 
17
17
  it 'url and block with aditional attributes' do
18
- Link.new('url', :title => 'link') { append Tag.block(:strong) { append 'text' } }.to_s.should eq '<a href="url" title="link"><strong>text</strong></a>'
18
+ Link.new('url', :title => 'link') { append Tag.block(:strong, 'text') }.to_s.should eq '<a href="url" title="link"><strong>text</strong></a>'
19
19
  end
20
20
 
21
21
  it 'url, image and text' do
@@ -7,7 +7,7 @@ describe PageHeader do
7
7
  end
8
8
 
9
9
  it 'title and subtitle' do
10
- PageHeader.new('Page Title', 'Subtitle').to_s.should eq '<div class="page-header"><h1>Page Title<small>Subtitle</small></h1></div>'
10
+ PageHeader.new('Page Title', 'Subtitle').to_s.should eq '<div class="page-header"><h1>Page Title<small>&nbsp;&nbsp;Subtitle</small></h1></div>'
11
11
  end
12
12
 
13
13
  end
@@ -5,8 +5,8 @@ describe Pagination do
5
5
  [:default, :centered, :right].each do |position|
6
6
  it position do
7
7
  tag = Pagination.send(position == :default ? :new : position) do
8
- append Tag.new(:a) { append 'Prev' }, :active
9
- append Tag.new(:a) { append 1 }, :active
8
+ append Tag.new(:a, 'Prev'), :active
9
+ append Tag.new(:a, 1), :active
10
10
  append Link.new(2, '#')
11
11
  append Link.new('Next', '#')
12
12
  end
data/spec/table_spec.rb CHANGED
@@ -24,6 +24,10 @@ describe Table do
24
24
  end
25
25
  end
26
26
 
27
+ it 'combined' do
28
+ Table.bordered.condensed.striped { append Tag.block(:tr) }.to_s.should eq Table.new { append Tag.block(:tr) }.bordered.condensed.striped.to_s
29
+ end
30
+
27
31
  end
28
32
 
29
33
  end
data/spec/tabs_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Tab' do
3
+ describe Tab do
4
4
 
5
5
  it 'default' do
6
6
  tag = Tab.new do
@@ -8,11 +8,11 @@ describe 'Tab' do
8
8
  nav.append NavTab.new('Tab 2', '#tab2')
9
9
  nav.append NavTab.new('#tab3') { append 'Tab 3' }
10
10
  content.append('tab1', :active) do
11
- Tag.block(:i) { append 'Content for Tab 1' }
11
+ Tag.block :i, 'Content for Tab 1'
12
12
  end
13
13
  content.append 'tab2', 'Content for Tab 2'
14
14
  content.append('tab3') do
15
- Tag.block(:strong) { append 'Content for Tab 3' }
15
+ Tag.block :strong, 'Content for Tab 3'
16
16
  end
17
17
  end
18
18
 
data/spec/tag_spec.rb CHANGED
@@ -26,7 +26,7 @@ describe Tag do
26
26
  end
27
27
 
28
28
  it 'Create text container tag' do
29
- Tag.block(:div, :style => 'width: 100%') { append 'Title' }.to_s.should eq '<div style="width: 100%">Title</div>'
29
+ Tag.block(:div, 'Title', :style => 'width: 100%').to_s.should eq '<div style="width: 100%">Title</div>'
30
30
  end
31
31
 
32
32
  it 'Create tag tree' do
data/spec/well_spec.rb CHANGED
@@ -3,15 +3,15 @@ require 'spec_helper'
3
3
  describe Well do
4
4
 
5
5
  it 'default' do
6
- Well.new{append 'This is a well'}.to_s.should eq '<div class="well">This is a well</div>'
6
+ Well.new('This is a well').to_s.should eq '<div class="well">This is a well</div>'
7
7
  end
8
8
 
9
9
  it 'small' do
10
- Well.small{append 'This is a small well'}.to_s.should eq '<div class="well well-small">This is a small well</div>'
10
+ Well.small('This is a small well').to_s.should eq '<div class="well well-small">This is a small well</div>'
11
11
  end
12
12
 
13
13
  it 'large' do
14
- Well.large{append 'This is a large well'}.to_s.should eq '<div class="well well-large">This is a large well</div>'
14
+ Well.large('This is a large well').to_s.should eq '<div class="well well-large">This is a large well</div>'
15
15
  end
16
16
 
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_bootstrap_markup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000 Z
12
+ date: 2012-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &24630648 !ruby/object:Gem::Requirement
16
+ requirement: &25752036 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *24630648
24
+ version_requirements: *25752036
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &24629736 !ruby/object:Gem::Requirement
27
+ requirement: &25751784 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *24629736
35
+ version_requirements: *25751784
36
36
  description: Object Oriented Twitter Bootstrap Markup
37
37
  email:
38
38
  - gabynaiman@gmail.com