Added a default form builder.

The form builder has a bug, it's initialize is called twice so we need to find a better place to put the <script... adding code.
This commit is contained in:
Devon Noonan 2012-10-01 13:08:48 -04:00
parent 2c9ea67146
commit f39a2f1422
5 changed files with 21 additions and 5 deletions

View File

@ -34,6 +34,7 @@ ActionView::Base.default_form_builder = YourFormBuilder
## TODO
- Fix the double script tag issue caused by the initialization of the builder twice, once in form_for and once in fields_for right below it
- Tests
- Multiple library support for jStorage (Prototype, Mootools etc.)
- Support for formtastic and extending other form builders

View File

@ -1,8 +1,11 @@
require "sisyphus-rails/version"
require "sisyphus-rails/engine"
require "sisyphus-rails/form_helper"
module Sisyphus
module Rails
class Engine < ::Rails::Engine
end
end
if defined?(ActionView::Base)
ActionView::Base.default_form_builder = Sisyphus::FormBuilder
end

View File

@ -0,0 +1,4 @@
module Sisyphus
class Engine < ::Rails::Engine
end
end

View File

@ -0,0 +1,8 @@
module Sisyphus
class FormBuilder < ActionView::Helpers::FormBuilder
def initialize(object_name, object, template, options, block=nil)
super
@template.output_buffer << "<script type=\"text/javascript\">$(document).ready(function() {$('##{self.options[:html][:id]}').sisyphus();});</script>".html_safe
end
end
end

View File

@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'sisyphus/rails/version'
require 'sisyphus-rails/version'
Gem::Specification.new do |gem|
gem.name = "sisyphus-rails"