[Streamlined][874] moved wrapper call into column base, added help attr that prints below edit fields

0 views
Skip to first unread message

svn-str...@thinkrelevance.com

unread,
Jun 23, 2008, 9:03:26 PM6/23/08
to streamli...@googlegroups.com

Diff

Modified: edge/streamlined/CHANGELOG (873 => 874)


--- edge/streamlined/CHANGELOG	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/CHANGELOG	2008-06-24 01:03:26 UTC (rev 874)
@@ -1,3 +1,5 @@
+06/23/08 - added Sandro's patch for help text below edit fields [Matthew Bass]
+
 06/16/08 - fixed partial rendering calls that had been missed during RC3 refactoring [Matthew Bass]
 
 05/07/08 - added quick_show_button option for hiding the show button on the list view [Matthew Bass]

Modified: edge/streamlined/files/public/stylesheets/streamlined.css (873 => 874)


--- edge/streamlined/files/public/stylesheets/streamlined.css	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/files/public/stylesheets/streamlined.css	2008-06-24 01:03:26 UTC (rev 874)
@@ -12,6 +12,7 @@
 #ft         { background-color: #7594A1; margin-top: -16px; }
 .clear      { clear:  both;   overflow:  hidden;  width:  1px;   height:  1px;  margin:   0  -1px  -1px  0;   border:  0;  padding:   0;  font-size:  0;  line-height:   0;  }
 #streamlined_breadcrumb { font-size: 80%; font-weight: bold; margin-top: 5px; margin-bottom: 5px;}
+.streamlined_help { font-size: 80%; }
 
 /*----------------------------------*/
 

Modified: edge/streamlined/lib/streamlined/column/active_record.rb (873 => 874)


--- edge/streamlined/lib/streamlined/column/active_record.rb	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/lib/streamlined/column/active_record.rb	2008-06-24 01:03:26 UTC (rev 874)
@@ -104,7 +104,7 @@
       options = custom_value ? html_options.merge(:value => custom_value) : html_options
       result = view.input(model_underscore, name, options)
     end
-    wrap(result)
+    append_help(result)
   end
   alias :render_td_new :render_td_edit
   

Modified: edge/streamlined/lib/streamlined/column/association.rb (873 => 874)


--- edge/streamlined/lib/streamlined/column/association.rb	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/lib/streamlined/column/association.rb	2008-06-24 01:03:26 UTC (rev 874)
@@ -133,7 +133,7 @@
       result = view.select(model_underscore, name_as_id, choices, { :selected => selected_choice }, html_options)
       result += render_quick_add(view) if should_render_quick_add?(view)
     end
-    wrap(result)
+    append_help(result)
   end 
   alias :render_td_new :render_td_edit
   

Modified: edge/streamlined/lib/streamlined/column/base.rb (873 => 874)


--- edge/streamlined/lib/streamlined/column/base.rb	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/lib/streamlined/column/base.rb	2008-06-24 01:03:26 UTC (rev 874)
@@ -6,7 +6,7 @@
   include ERB::Util
   
   attr_accessor :human_name, :link_to, :popup, :parent_model, :wrapper, :additional_column_pairs,
-                :additional_includes, :filter_column
+                :additional_includes, :filter_column, :help
   
   attr_with_default :human_name_explicitly_set, 'false'
   attr_with_default :read_only, 'false'
@@ -112,10 +112,11 @@
   
   def render_td(view, item)
     if read_only
-      render_td_show(view, item)
+      result = render_td_show(view, item)
     else
-      send "render_td_#{view.crud_context}", view, item
+      result = send("render_td_#{view.crud_context}", view, item)
     end
+    wrap(result)
   end
   
   [:show, :edit, :list, :new].each do |meth|
@@ -194,6 +195,12 @@
     end
   end
   
+  def append_help(html)
+    x = Builder::XmlMarkup.new
+    x.div(:class => "streamlined_help") { x << help } unless help.blank?
+    html << x.target!
+  end
+  
   def is_displayable_in_context?(view, item)
     # TODO: extract this nastiness into a class?  Only if we see one more need for objectified crud contexts!!!!!!
     column_answer = case view.crud_context

Modified: edge/streamlined/test/functional/association_functional_test.rb (873 => 874)


--- edge/streamlined/test/functional/association_functional_test.rb	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/test/functional/association_functional_test.rb	2008-06-24 01:03:26 UTC (rev 874)
@@ -88,25 +88,6 @@
     end                                       
     assert_people_quick_add_link(html)                          
   end
-
-  it "render td edit with wrapper set" do
-    stock_controller_and_view              
-    @association = Association.new(Poem.reflect_on_association(:poet), Poem, :inset_table, :count) 
-    @association.wrapper = Proc.new { |c| "<div id='wrapper'>#{c}</div>" }
-    html = @association.render_td_edit(@view, poems(:limerick))
-    assert_select root_node(html), "div" do 
-      assert_select "select[id=poem_poet_id]" do
-        assert_select "option[value=]", "Unassigned"
-        assert_select "option[value=1]", "1"
-        assert_select "option[value=2][selected=selected]", "2"
-      end                                       
-      assert_select "a" do
-        assert_select "[href=?]", %r{/people/quick_add\?.*}  
-        assert_select "[href=?]", %r{.*select_id=poem_poet_id.*}
-        assert_select "[href=?]", %r{.*model_class_name=Poet.*}
-      end                
-    end
-  end 
   
   it "render td edit with options for select" do
     stock_controller_and_view

Modified: edge/streamlined/test/unit/streamlined/column/active_record_test.rb (873 => 874)


--- edge/streamlined/test/unit/streamlined/column/active_record_test.rb	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/test/unit/streamlined/column/active_record_test.rb	2008-06-24 01:03:26 UTC (rev 874)
@@ -89,7 +89,7 @@
   end
   
   it "render td edit" do
-    (view = flexmock).should_receive(:input).with('model', 'column', {}).once
+    (view = mock).expects(:input).with('model', 'column', {}).returns('input').once
     @ar.render_td_edit(view, 'item')
   end
   
@@ -101,14 +101,15 @@
   
   it "render td edit with checkbox" do
     @ar.check_box = true
-    (view = flexmock).should_receive(:check_box).with('model', 'column', {}).once
+    (view = mock).expects(:check_box).with('model', 'column', {}).returns('input').once
     @ar.render_td_edit(view, 'item')
   end
   
-  it "render td edit with wrapper" do
-    @ar.wrapper = Proc.new { |c| "<<<#{c}>>>" }
-    (view = flexmock).should_receive(:input).with('model', 'column', {}).and_return('result').once
-    assert_equal '<<<result>>>', @ar.render_td_edit(view, 'item')
+  it "render td edit with help" do
+    view = stub(:input => "content")
+    @ar.help = "This is an optional field"
+    expected = "content<div class=\"streamlined_help\">This is an optional field</div>"
+    @ar.render_td_edit(view, 'item').should == expected
   end
   
   it "render td edit with html options" do

Modified: edge/streamlined/test/unit/streamlined/column/association_test.rb (873 => 874)


--- edge/streamlined/test/unit/streamlined/column/association_test.rb	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/test/unit/streamlined/column/association_test.rb	2008-06-24 01:03:26 UTC (rev 874)
@@ -156,6 +156,14 @@
     assert_equal "select", @association.render_td_edit(view, item)
   end
   
+  it "render td edit with help" do
+    flexmock(SomeClass).stubs(:custom_options).returns([:foo])
+    @association.options_for_select = :custom_options
+    @association.help = "This is an optional field"
+    expected = "select<div class=\"streamlined_help\">This is an optional field</div>"
+    @association.render_td_edit(*view_and_item_mocks_for_render_td_edit).should == expected
+  end
+  
   private
   def view_and_item_mocks(view_attrs={})
     view = flexmock(:render => 'render', :controller_path => 'controller_path', :link_to_function => 'link')
@@ -164,9 +172,9 @@
   end
 
   def view_and_item_mocks_for_render_td_edit(options={:unassigned_value => 'Unassigned'})
-    item = flexmock(:respond_to? => true, :some_name => nil)
-    (view = flexmock).should_receive(:select).with('model', 'some_name_id', [[options[:unassigned_value], nil], :foo], { :selected => nil }, {}).and_return("select").once
-    flexmock(@association) do |mock|
+    item = flexmock("item", :respond_to? => true, :some_name => nil)
+    (view = flexmock("view")).should_receive(:select).with('model', 'some_name_id', [[options[:unassigned_value], nil], :foo], { :selected => nil }, {}).and_return("select").once
+    flexmock("association", @association) do |mock|
       mock.should_receive(:column_can_be_unassigned?).with(@model, "some_name").and_return(true).once
       mock.should_receive(:has_many? => false).once
       mock.should_receive(:belongs_to? => true).once

Modified: edge/streamlined/test/unit/streamlined/column/base_test.rb (873 => 874)


--- edge/streamlined/test/unit/streamlined/column/base_test.rb	2008-06-16 21:40:10 UTC (rev 873)
+++ edge/streamlined/test/unit/streamlined/column/base_test.rb	2008-06-24 01:03:26 UTC (rev 874)
@@ -74,6 +74,13 @@
                       "The set of render_ methods has changed. Make sure the semantics of renderer= are correct, then fix this test to pass again."
   end
   
+  it "render td with wrapper" do
+    view = stub(:crud_context => :edit)
+    item = stub(:send => "content")
+    @addition.wrapper = Proc.new { |c| "<<<#{c}>>>" }
+    assert_equal '<<<content>>>', @addition.render_td(view, item)
+  end
+  
   it "renderer block that does not yield" do
     @addition.render_wrapper = Proc.new {|old_meth, *args| "#{old_meth.name} rendered!"}
     @addition.renderers.each do |renderer|
Reply all
Reply to author
Forward
0 new messages