rails_bootstrap_navbar 0.1.2.beta → 0.1.3.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module RailsBootstrapNavbar
2
- VERSION = "0.1.2.beta"
2
+ VERSION = "0.1.3.beta"
3
3
  end
@@ -43,8 +43,12 @@ module RailsBootstrapNavbar
43
43
  content_tag :li, "", :class => "divider-vertical"
44
44
  end
45
45
 
46
- def menu_text(text=nil, &block)
47
- content_tag :p do
46
+ def menu_text(text=nil, options={}, &block)
47
+ pull = options.delete(:pull)
48
+ pull_class = pull.present? ? "pull-#{pull.to_s}" : nil
49
+ options.append_merge!(:class, pull_class)
50
+ options.append_merge!(:class, "navbar-text")
51
+ content_tag :p, options do
48
52
  text || yield
49
53
  end
50
54
  end
@@ -121,4 +125,19 @@ module RailsBootstrapNavbar
121
125
  content_tag :ul, :class => "dropdown-menu", &block
122
126
  end
123
127
  end
128
+ end
129
+
130
+ class Hash
131
+ # appends a string to a hash key's value after a space character (Good for merging CSS classes in options hashes)
132
+ def append_merge!(key, value)
133
+ # just return self if value is blank
134
+ return self if value.blank?
135
+
136
+ current_value = self[key]
137
+ # just merge if it doesn't already have that key
138
+ self[key] = value and return if current_value.blank?
139
+ # raise error if we're trying to merge into something that isn't a string
140
+ raise ArgumentError, "Can only merge strings" unless current_value.is_a?(String)
141
+ self[key] = [current_value, value].compact.join(" ")
142
+ end
124
143
  end
@@ -102,14 +102,24 @@ describe RailsBootstrapNavbar::ViewHelpers, :type => :helper do
102
102
  end
103
103
 
104
104
  describe "menu_text" do
105
- it "should render text within p tags" do
106
- menu_text("Strapline!").should eql("<p>Strapline!</p>")
105
+ it "should render text within p tags with class 'navbar-text" do
106
+ menu_text("Strapline!").should eql("<p class=\"navbar-text\">Strapline!</p>")
107
+ end
108
+
109
+ it "should be able to be pulled right or left" do
110
+ menu_text("I'm being pulled right", :pull => :right).should eql(
111
+ "<p class=\"pull-right navbar-text\">I'm being pulled right</p>")
112
+ end
113
+
114
+ it "should be able to cope with arbitrary options being passed to the p tag" do
115
+ menu_text("I'm classy!", :class => "classy", :id => "classy_text").should eql(
116
+ "<p class=\"classy navbar-text\" id=\"classy_text\">I'm classy!</p>")
107
117
  end
108
118
 
109
119
  it "should be able to cope with a block too" do
110
120
  menu_text do
111
121
  "I've been rendered programmatically!"
112
- end.should eql("<p>I've been rendered programmatically!</p>")
122
+ end.should eql("<p class=\"navbar-text\">I've been rendered programmatically!</p>")
113
123
  end
114
124
  end
115
125
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_navbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.beta
4
+ version: 0.1.3.beta
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70172493208940 !ruby/object:Gem::Requirement
16
+ requirement: &70330903263900 !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: *70172493208940
24
+ version_requirements: *70330903263900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70172493208340 !ruby/object:Gem::Requirement
27
+ requirement: &70330903259980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70172493208340
35
+ version_requirements: *70330903259980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70172493181760 !ruby/object:Gem::Requirement
38
+ requirement: &70330903258340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 3.0.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70172493181760
46
+ version_requirements: *70330903258340
47
47
  description: A helper method for easy generation of Twitter Bootstrap Navigation menus
48
48
  in Rails
49
49
  email: