From 9c40ce1ff434621e73c3e41649302b000d0aed30 Mon Sep 17 00:00:00 2001 From: David Parry Date: Tue, 6 Mar 2012 11:01:45 +1100 Subject: [PATCH] Had to refactor out the haml_helper because I couldn't get it to load. Feel dirty. --- Gemfile.lock | 12 ++++++++++++ lib/formtastic-bootstrap/helpers/buttons_helper.rb | 8 +++++--- lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb | 9 ++++++--- spec/helpers/buttons_helper_spec.rb | 6 +++--- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 795b3352..b3fc3218 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,9 +40,18 @@ GEM builder (3.0.0) diff-lcs (1.1.3) erubis (2.7.0) + ffi (1.0.11) formtastic (2.0.2) rails (~> 3.0) git (1.2.5) + guard (1.0.0) + ffi (>= 0.5.0) + thor (~> 0.14.6) + guard-rspec (0.6.0) + guard (>= 0.10.0) + guard-spork (0.5.2) + guard (>= 0.10.0) + spork (>= 0.8.4) hike (1.2.1) i18n (0.6.0) jeweler (1.6.4) @@ -102,6 +111,7 @@ GEM rspec_tag_matchers (1.0.0) nokogiri (>= 1.4.0) rspec-rails (>= 1.2.6) + spork (0.9.0) sprockets (2.0.3) hike (~> 1.2) rack (~> 1.0) @@ -120,6 +130,8 @@ DEPENDENCIES bundler formtastic formtastic-bootstrap! + guard-rspec + guard-spork jeweler rcov rspec diff --git a/lib/formtastic-bootstrap/helpers/buttons_helper.rb b/lib/formtastic-bootstrap/helpers/buttons_helper.rb index fbbe22b0..2f646e60 100644 --- a/lib/formtastic-bootstrap/helpers/buttons_helper.rb +++ b/lib/formtastic-bootstrap/helpers/buttons_helper.rb @@ -1,9 +1,7 @@ module FormtasticBootstrap module Helpers module ButtonsHelper - include Formtastic::Helpers::ButtonsHelper - include FormtasticBootstrap::Helpers::HamlHelper def buttons(*args, &block) @@ -16,7 +14,11 @@ def buttons(*args, &block) if block_given? template.content_tag(:div, html_options) do - contents = capture_block(&block) + contents = if template.respond_to?(:is_haml?) && template.is_haml? + template.capture_haml(&block) + else + template.capture(&block) + end end else args = [:commit] if args.empty? diff --git a/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb b/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb index 92a4f8f4..96f4f8b8 100644 --- a/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +++ b/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb @@ -3,7 +3,6 @@ module Helpers module FieldsetWrapper include Formtastic::Helpers::FieldsetWrapper - include FormtasticBootstrap::Helpers::HamlHelper protected @@ -16,14 +15,18 @@ def field_set_and_list_wrapping(*args, &block) #:nodoc: legend = template.content_tag(:legend, Formtastic::Util.html_safe(legend)) unless legend.blank? if block_given? - contents = capture_block(&block) + contents = if template.respond_to?(:is_haml?) && template.is_haml? + template.capture_haml(&block) + else + template.capture(&block) + end end # Ruby 1.9: String#to_s behavior changed, need to make an explicit join. contents = contents.join if contents.respond_to?(:join) fieldset = template.content_tag(:fieldset, Formtastic::Util.html_safe(legend) << Formtastic::Util.html_safe(contents), - html_options.except(:builder, :parent, :name) + html_options.except(:builder, :parent, :name) ) fieldset diff --git a/spec/helpers/buttons_helper_spec.rb b/spec/helpers/buttons_helper_spec.rb index b6603395..1d35b4a3 100644 --- a/spec/helpers/buttons_helper_spec.rb +++ b/spec/helpers/buttons_helper_spec.rb @@ -133,12 +133,12 @@ end it 'should render a form with a div containing a input for each button arg' do - output_buffer.should have_tag('form > div.actions > input', :count => 1) - output_buffer.should have_tag('form > div.actions > input.commit', :count => 1) + output_buffer.should have_tag('form > div.form-actions > input', :count => 1) + output_buffer.should have_tag('form > div.form-actions > input.commit', :count => 1) end it 'should pass the options down to the div' do - output_buffer.should have_tag('form > div#my-id.actions') + output_buffer.should have_tag('form > div#my-id.form-actions') end end