public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
update plugins

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2308 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Oct 03 07:36:10 -0700 2006
commit  baf463e5ecab49cf5ef172dfadb46073b6afd48f
tree    24a7f98cb3a5218c36773695f8ba2e9a9f2c6914
parent  b0a9f2176c40d7edf9d35bed2718521ee715225f
...
21
22
23
24
 
25
26
 
27
28
29
30
 
31
32
33
...
21
22
23
 
24
25
 
26
27
28
29
 
30
31
32
33
0
@@ -21,13 +21,13 @@ module ActionView
0
               url = SimplyHelpful::RecordIdentifier.named_route(object, self)
0
           
0
               html_options = if object.new_record?
0
- { :class => "new_#{object_name}", :id => "new_#{object_name}", :method => :post }
0
+ { :class => dom_class(object, :new), :id => dom_id(object), :method => :post }
0
               else
0
- { :class => "edit_#{object_name}", :id => dom_id(object, :edit), :method => :put }
0
+ { :class => dom_class(object, :edit), :id => dom_id(object, :edit), :method => :put }
0
               end
0
           
0
               send(old_method_name,
0
- object_name, object, { :url => url, :html => html_options.update(options[:html] || {}) }, &proc
0
+ object_name, object, options.merge({ :url => url, :html => html_options.update(options[:html] || {}) }), &proc
0
               )
0
           end
0
         end
...
9
10
11
12
 
13
14
15
16
17
 
 
18
19
20
...
22
23
24
25
26
 
 
27
28
29
30
 
 
31
 
 
 
 
 
32
33
...
9
10
11
 
12
13
14
15
 
 
16
17
18
19
20
...
22
23
24
 
 
25
26
27
28
 
 
29
30
31
32
33
34
35
36
37
38
0
@@ -9,12 +9,12 @@ module SimplyHelpful
0
     end
0
 
0
     def partial_path(record_or_class)
0
- klass = record_or_class.is_a?(Class) ? record_or_class : record_or_class.class
0
+ klass = class_from_record_or_class(record_or_class)
0
       "#{klass.name.tableize}/#{klass.name.demodulize.underscore}"
0
     end
0
 
0
- def dom_class(record)
0
- singular_class_name(record)
0
+ def dom_class(record_or_class, prefix = nil)
0
+ [ prefix, singular_class_name(record_or_class) ].compact * '_'
0
     end
0
 
0
     def dom_id(record, prefix = nil)
0
@@ -22,12 +22,17 @@ module SimplyHelpful
0
       [ prefix, singular_class_name(record), record.id ].compact * '_'
0
     end
0
   
0
- def plural_class_name(record)
0
- singular_class_name(record).pluralize
0
+ def plural_class_name(record_or_class)
0
+ singular_class_name(record_or_class).pluralize
0
     end
0
   
0
- def singular_class_name(record)
0
- record.class.name.underscore.tr('/', '_')
0
+ def singular_class_name(record_or_class)
0
+ class_from_record_or_class(record_or_class).name.underscore.tr('/', '_')
0
     end
0
+
0
+ private
0
+ def class_from_record_or_class(record_or_class)
0
+ record_or_class.is_a?(Class) ? record_or_class : record_or_class.class
0
+ end
0
   end
0
 end
...
1
2
 
 
 
 
 
 
 
 
 
 
 
3
4
5
...
28
29
30
31
 
 
 
 
 
 
 
 
 
 
 
 
 
32
33
34
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
39
40
41
 
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
0
@@ -1,5 +1,16 @@
0
 require File.dirname(__FILE__) + '/test_helper'
0
 
0
+class LabelledFormBuilder < ActionView::Helpers::FormBuilder
0
+ (field_helpers - %w(hidden_field)).each do |selector|
0
+ src = <<-END_SRC
0
+ def #{selector}(field, *args, &proc)
0
+ "<label for='\#{field}'>\#{field.to_s.humanize}:</label> " + super + "<br/>"
0
+ end
0
+ END_SRC
0
+ class_eval src, __FILE__, __LINE__
0
+ end
0
+end
0
+
0
 class FormHelperExtensionsTest < Test::Unit::TestCase
0
   include ActionView::Helpers::FormHelper
0
   include ActionView::Helpers::FormTagHelper
0
@@ -28,7 +39,19 @@ class FormHelperExtensionsTest < Test::Unit::TestCase
0
     expected = "<form action='#{posts_url}' class='new_post' id='create-post' method='post'></form>"
0
     assert_dom_equal expected, _erbout
0
   end
0
-
0
+ def test_form_for_with_record_identification_with_custom_builder
0
+ _erbout = ''
0
+ form_for(@record, :builder => LabelledFormBuilder) do |f|
0
+ _erbout.concat(f.text_field(:name))
0
+ end
0
+
0
+ expected = "<form action='#{posts_url}' class='new_post' id='new_post' method='post'>" +
0
+ "<label for='name'>Name:</label>" +
0
+ " <input type='text' size='30' name='post[name]' id='post_name' value='new post' /><br />" +
0
+ "</form>"
0
+ assert_dom_equal expected, _erbout
0
+ end
0
+
0
   def test_form_for_with_record_identification_without_html_options
0
     _erbout = ''
0
     form_for(@record) {}
...
4
5
6
7
 
 
8
9
10
...
36
37
38
 
 
 
 
39
40
41
42
43
 
 
 
 
44
45
46
47
 
 
 
 
48
49
50
...
53
54
55
56
 
 
57
58
59
...
4
5
6
 
7
8
9
10
11
...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
66
67
68
 
69
70
71
72
73
0
@@ -4,7 +4,8 @@ class RecordIdentifierTest < Test::Unit::TestCase
0
   include SimplyHelpful
0
 
0
   def setup
0
- @record = Post.new
0
+ @klass = Post
0
+ @record = @klass.new
0
     @singular = 'post'
0
     @plural = 'posts'
0
   end
0
@@ -36,15 +37,27 @@ class RecordIdentifierTest < Test::Unit::TestCase
0
   def test_dom_class
0
     assert_equal @singular, dom_class(@record)
0
   end
0
+
0
+ def test_dom_class_with_prefix
0
+ assert_equal "custom_prefix_#{@singular}", dom_class(@record, :custom_prefix)
0
+ end
0
 
0
   def test_singular_class_name
0
     assert_equal @singular, singular_class_name(@record)
0
   end
0
 
0
+ def test_singular_class_name_for_class
0
+ assert_equal @singular, singular_class_name(@klass)
0
+ end
0
+
0
   def test_plural_class_name
0
     assert_equal @plural, plural_class_name(@record)
0
   end
0
 
0
+ def test_plural_class_name_for_class
0
+ assert_equal @plural, plural_class_name(@klass)
0
+ end
0
+
0
   private
0
     def method_missing(method, *args)
0
       RecordIdentifier.send(method, *args)
0
@@ -53,7 +66,8 @@ end
0
 
0
 class NestedRecordIdentifierTest < RecordIdentifierTest
0
   def setup
0
- @record = Post::Nested.new
0
+ @klass = Post::Nested
0
+ @record = @klass.new
0
     @singular = 'post_nested'
0
     @plural = 'post_nesteds'
0
   end

Comments

    No one has commented yet.