Skip to content

Commit a52a99e

Browse files
committed
Added support for button groups - no tests available
1 parent ef8ae7e commit a52a99e

File tree

7 files changed

+69
-3
lines changed

7 files changed

+69
-3
lines changed

Diff for: Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ gemspec
66
gem 'actionpack', '>= 3.0.5'
77

88
group :test do
9+
#gem 'rails'
910
gem 'rspec'
11+
#gem 'rspec-rails'
1012
gem 'autotest'
1113
gem 'autotest-growl'
1214
gem 'capybara', :git => 'https://github.com/jnicklas/capybara.git'
15+
gem 'webrat'
1316
end

Diff for: Gemfile.lock

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GIT
1313
PATH
1414
remote: .
1515
specs:
16-
css3buttons (0.0.1)
16+
css3buttons (0.7.0)
1717
actionpack (>= 3.0.5)
1818

1919
GEM
@@ -72,6 +72,10 @@ GEM
7272
json_pure
7373
rubyzip
7474
tzinfo (0.3.25)
75+
webrat (0.7.2)
76+
nokogiri (>= 1.2.0)
77+
rack (>= 1.0)
78+
rack-test (>= 0.5.3)
7579
xpath (0.1.3)
7680
nokogiri (~> 1.3)
7781

@@ -85,3 +89,4 @@ DEPENDENCIES
8589
capybara!
8690
css3buttons!
8791
rspec
92+
webrat

Diff for: lib/css3buttons.rb

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ module Css3buttons
55
module Helpers
66
autoload :ButtonHelper, 'css3buttons/helpers/button_helper'
77
end
8+
autoload :ButtonGroup, 'css3buttons/button_group'
89
ActionController::Base.helper(Css3buttons::Helpers::ButtonHelper)
910
end

Diff for: lib/css3buttons/button_group.rb

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module Css3buttons
2+
class ButtonGroup
3+
attr_reader :template, :button_count
4+
5+
def initialize(template)
6+
@button_count = 0
7+
@template = template
8+
end
9+
10+
def render(&block)
11+
add_group_classes(template.capture(self, &block)) if block_given?
12+
end
13+
14+
def method_missing(method_name, *args)
15+
name = args[0]
16+
options = args[1] || {}
17+
html_options = args[2] || {}
18+
html_options[:class] ||= ""
19+
html_options[:class] += " __css3buttons_group_#{@button_count}__"
20+
@button_count += 1
21+
@template.send(method_name, name, options, html_options)
22+
end
23+
24+
private
25+
def add_group_classes(html)
26+
(0...@button_count).to_a.each do |index|
27+
if index == 0
28+
html.gsub! /__css3buttons_group_#{index}__/, "left"
29+
elsif index == @button_count - 1
30+
html.gsub! /__css3buttons_group_#{index}__/, "right"
31+
else
32+
html.gsub! /__css3buttons_group_#{index}__/, "middle"
33+
end
34+
end
35+
html
36+
end
37+
end
38+
end

Diff for: lib/css3buttons/helpers/button_helper.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ module Css3buttons
22
module Helpers
33
module ButtonHelper
44
def button_group(&block)
5-
puts "Warning: Css3buttons::Helpers::ButtonHelper.button_group was called but this method is not yet implemented."
6-
end # add the dynamic methods for all button types
5+
group = Css3buttons::ButtonGroup.new(self)
6+
group.render(&block) if block_given?
7+
end
8+
9+
# add the dynamic methods for all button types
710
def self.included(base)
811
qualifiers = ["", "positive", "negative", "pill", "positive_pill", "negative_pill"]
912
icons = ["link", "book","calendar","chat","check","clock","cog","comment","cross","downarrow","fork","heart","home","key","leftarrow","lock","loop","magnifier","mail","move","pen","pin","plus","reload","rightarrow","rss","tag","trash","unlock","uparrow","user"]

Diff for: spec/button_group_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
3+
include ActionView::Helpers::UrlHelper
4+
include Css3buttons::Helpers::ButtonHelper
5+
6+
describe Css3buttons::ButtonGroup do
7+
before :each do
8+
stub_template "posts/_actions.html.erb" => "<= button_group do\nlink_button_to 'show', '/post/345'\nlink_button_to 'edit', '/post/345/edit'\nlink_button_to 'delete', '/post/345'"
9+
end
10+
11+
it "should add a class of first to the first link" do
12+
render
13+
puts rendered
14+
end
15+
end

Diff for: spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'rubygems'
22
require 'bundler/setup'
33

4+
require 'webrat'
45
require 'capybara'
56
require 'css3buttons'
67

0 commit comments

Comments
 (0)