diff --git a/README.md b/README.md index 81ebd7e..7253961 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,11 @@ For a basic install include the following in your *app/assets/javascripts/applic ## How it Works -Sisyphus uses an aliased form_tag method to automatically put a *<script>...</script>* tag infront of your forms to initialize Sisyphus +Sisyphus uses an aliased form_tag method to automatically put a *<script>...</script>* tag infront of your forms to initialize Sisyphus. It also uses an aliased FormHelper form_for method to read options.
- ... + ...
## Usage @@ -35,6 +35,11 @@ Sisyphus automatically works with all your forms, including custom form builders ### Exclude form +To stop Sisyphus from initializing on a form include the *with_sisyphus* option in your form_for. + + <%= form_for User.new, :with_sisyphus=>false do |f| %> + ... + <% end %> ## Dependencies @@ -44,8 +49,13 @@ Sisyphus automatically works with all your forms, including custom form builders ## TODO - Tests -- Multiple library support for jStorage (Prototype, Mootools etc.) - Model/Object based exclusions +- block based options + + <%= form_for User.new do |f| %> + <% :sisyphus => flase %> + ... + <% end %> ## Contributing diff --git a/lib/sisyphus-rails.rb b/lib/sisyphus-rails.rb index 6652c15..ac49ba8 100644 --- a/lib/sisyphus-rails.rb +++ b/lib/sisyphus-rails.rb @@ -1,12 +1,9 @@ require "sisyphus-rails/version" require "sisyphus-rails/engine" -# require "sisyphus-rails/form_helper" +require "sisyphus-rails/form_helper" require "sisyphus-rails/form_tag_helper" module Sisyphus - -end - -# if defined?(ActionView::Base) -# ActionView::Base.default_form_builder = Sisyphus::FormBuilder -# end \ No newline at end of file + mattr_accessor :process + +end \ No newline at end of file diff --git a/lib/sisyphus-rails/form_helper.rb b/lib/sisyphus-rails/form_helper.rb new file mode 100644 index 0000000..ccfdf37 --- /dev/null +++ b/lib/sisyphus-rails/form_helper.rb @@ -0,0 +1,19 @@ +module ActionView + module Helpers + module FormHelper + def form_for_with_sisyphus(record, options = {}, &proc) + + if options[:with_sisyphus] == false + Sisyphus::process = false + else + Sisyphus::process = true + end + + #strip all the sisyphus options from the options hash before moving on + form_for_without_sisyphus(record, options.reject{|k,v| k =~ /sisyphus(.*)/}, &proc) + end + + alias_method_chain :form_for, :sisyphus + end + end +end \ No newline at end of file diff --git a/lib/sisyphus-rails/form_tag_helper.rb b/lib/sisyphus-rails/form_tag_helper.rb index 01c4213..866f498 100644 --- a/lib/sisyphus-rails/form_tag_helper.rb +++ b/lib/sisyphus-rails/form_tag_helper.rb @@ -5,7 +5,7 @@ module ActionView def form_tag_with_sisyphus(url_for_options = {}, options = {}, &block) buf = ActiveSupport::SafeBuffer.new - if options.has_key?(:id) + if options.has_key?(:id) && Sisyphus::process buf.safe_concat("") end