Now takes an option to skip sisyphus processing.

This commit is contained in:
Devon Noonan 2012-10-02 10:13:22 -04:00
parent 810a02bece
commit 008eb76a9b
4 changed files with 37 additions and 11 deletions

View File

@ -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.
<script>$(document).ready(function() {$('#sampleform').sisyphus();});</script>
<form id="sampleform">
...
...
</form>
## 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

View File

@ -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
mattr_accessor :process
end

View File

@ -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

View File

@ -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("<script type=\"text/javascript\">$(document).ready(function() {$('##{options[:id]}').sisyphus();});</script>")
end