Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit f7f2d55d6b5aba96a142cb63853d4ac03ca597ef @zdennis zdennis committed Aug 5, 2009
@@ -0,0 +1,20 @@
+Copyright (c) 2009 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 README
@@ -0,0 +1,27 @@
+Actionview-fieldsForWithTemplate
+================================
+
+Adds the following view helper for work with nested attributes:
+
+ fields_for_with_template
+
+This requires NumericSequence, available at github.com/mhs/numeric-sequence.
+
+Example
+=======
+
+ <% @provider.schools.build if @provider.schools.reject(&:marked_for_destruction?).empty? -%>
+ <% f.fields_for_with_template :schools do |school_form| %>
+ <%= render :partial => "school", :locals => { :form => school_form } %>
+ <% end %>
+
+This will produce an additional template element containing the body of the fields for, ie:
+
+ <div class="template">
+ ... whatever render :partial => 'school' produced...
+ </div>
+
+It will replace all ids or counters with "NEW_RECORD". You need to supply the JavaScript to handle add, removing, etc, given this.
+
+Copyright (c) 2009 Mutually Human Software, released under the MIT license
+
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the actionview_fields_for_with_template plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the actionview_fields_for_with_template plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Actionview-fieldsForWithTemplate'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,2 @@
+require 'numeric_sequence'
+require 'actionview-fields_for_with_template'
@@ -0,0 +1 @@
+# Install hook code here
@@ -0,0 +1,17 @@
+module ActionView
+ module Helpers
+ class FormBuilder
+ def fields_for_with_template(record_or_name_or_array, *args, &block)
+ options = args.extract_options!
+ options[:child_index] = NumericSequence.new
+ args << options
+ fields_for record_or_name_or_array, *args, &block
+ fields_for record_or_name_or_array, object.send(record_or_name_or_array).new, :child_index => "NEW_RECORD" do |f|
+ @template.concat %|<div class="template" style="display:none">|
+ block.call f
+ @template.concat %|</div>|
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :actionview_fields_for_with_template do
+# # Task goes here
+# end
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class Actionview-fieldsForWithTemplateTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
@@ -0,0 +1 @@
+# Uninstall hook code here

0 comments on commit f7f2d55

Please sign in to comment.