sisyphus-rails/README.md

116 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2012-10-01 12:29:36 +00:00
# Sisyphus::Rails
A gem to add gmail like form saving through sisyphus.js
## Installation
Add this line to your application's Gemfile:
gem 'sisyphus-rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sisyphus-rails
2012-10-01 20:55:36 +00:00
For a basic install include the following in your *app/assets/javascripts/application.js* file
2012-10-01 14:37:28 +00:00
//= require sisyphus
2012-10-02 14:47:02 +00:00
To support IE6/7 users include jStorage as well
2012-10-02 14:47:30 +00:00
//= require jstorage
2012-10-03 00:58:57 +00:00
//= require sisyphus
2012-10-02 14:47:02 +00:00
2012-10-03 14:27:12 +00:00
### Create a Configuration File
You can use the built in generator to create a basic *sisyphus.yml* configuration file.
$ rails generate sisyphus:configuration
The file will be placed in *config/*
2012-10-01 20:42:14 +00:00
## How it Works
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.
2012-10-01 20:42:14 +00:00
2012-10-01 20:55:36 +00:00
<script>$(document).ready(function() {$('#sampleform').sisyphus();});</script>
<form id="sampleform">
...
2012-10-01 20:55:36 +00:00
</form>
2012-10-03 14:27:12 +00:00
2012-10-01 12:29:36 +00:00
## Usage
2012-10-01 20:42:14 +00:00
Sisyphus automatically works with all your forms, including custom form builders.
2012-10-03 14:27:12 +00:00
### Exclude a form
2012-10-01 14:37:28 +00:00
2012-10-03 18:45:34 +00:00
To stop Sisyphus from initializing on a form include the *with_sisyphus* option in your form_for. This switch overrides the others
<%= form_for User.new, :with_sisyphus=>false do |f| %>
...
<% end %>
2012-10-01 14:37:28 +00:00
2012-10-03 14:27:12 +00:00
### Exclude/Include a model
2012-10-03 18:45:34 +00:00
To exclude or include a specific model you can enter it in your ENV or the *sisyphus.yml* file. The configuration takes a comma (,) separated string of __lower case__ model names. This switch takes precedence over the global switch.
2012-10-03 14:27:12 +00:00
exclude_models: user
include_models: comment,post
2012-10-03 18:45:34 +00:00
### Exclude/Include everything
2012-10-03 14:27:12 +00:00
2012-10-03 18:45:34 +00:00
You can also set the *sisyphus_enabled* option to true/false in your ENV or the *sisyphus.yml* file to turn Sisyphus on or off by default. If no other switches are set this will be used.
2012-10-03 14:27:12 +00:00
sisyphus_enabled: false
### Putting the switches together
The switches work together to see if a form should be protected by Sisyphus or not. The *sisyphus_enabled* switch will be used if no other switches are set. If the model is specifically excluded (when *sisyphus_enabled* = true) then it will not be protected. Conversley, if the model is specifically included and *sisyphus_enabled* = false it will be protected. The final say is taken by the form option. If *with_sysphus* is set it's value will be used to determine if the form should be protected or not.
2012-10-01 14:37:28 +00:00
## Dependencies
- Rails >= 3.1
- Jquery 1.8+
2012-10-01 12:29:36 +00:00
## TODO
- Tests
2012-10-03 16:45:53 +00:00
2012-10-03 14:48:00 +00:00
- rubydoc.info hosted documentation so the rubygems.org page doesn't look like crap.
2012-10-02 14:47:02 +00:00
- conflict resolution... i.e. you have an object edit form, the fields are populated from the DB but if you have local browser changes they may get overridden. We need a way to resolve conflicts between local and remote data -> could use a jquery based modal dialog to present the diff?
2012-10-03 14:27:12 +00:00
- Model based exclusions/options via activerecord extension? We have config based exclude/includes now
2012-10-03 16:45:53 +00:00
- implement all sisyphus options and any relevant ones in jStorage
- block based options (this would allow us to easily and neatly implement Sisyphus options). The do...end block is passed in but how do we interact with it to get options out? Is this possible in any way?
<%= form_for User.new do |f| %>
<% :sisyphus => flase %>
2012-10-02 14:47:02 +00:00
<% :sisyphus_customKeyPrefix => 'sisy' %>
...
<% end %>
2012-10-03 16:45:53 +00:00
- Move away from form_tag_helper, should be able to do it all from form_helper? Script tag can go at the end anyhow. Why aren't we doing that right now? We don't seem to have access to the same variables that the regular form_for does. Also the options array gets muddied by the FormHelper form_for call -> it removes the [:html] section (we need the id of the form for sisyphus). It would be nice if we could get away with this but there are certain things like the form name that we need to know that aren't easily available in the FormHelper.
2012-10-01 12:29:36 +00:00
## Contributing
If you have time to tackle something off the TODO list before I manage to get around to it then please do!
2012-10-01 12:29:36 +00:00
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
2012-10-02 14:47:02 +00:00
## Included Libraries
2012-10-01 12:29:36 +00:00
2012-10-02 14:47:02 +00:00
https://github.com/rails/jquery-rails
2012-10-01 12:29:36 +00:00
https://github.com/simsalabim/sisyphus
2012-10-02 14:47:02 +00:00
https://github.com/andris9/jStorage
## Resources
http://coding.smashingmagazine.com/2011/12/05/sisyphus-js-client-side-drafts-and-more/