[#10853] Why limit class def to a constant or colon node? — Charles Oliver Nutter <charles.nutter@...>

Is there a historical reason why I can't do something like these:

12 messages 2007/04/03

[#10933] Cannot build with extra library path if previous version already installed — <noreply@...>

Bugs item #10140, was opened at 2007-04-16 17:32

10 messages 2007/04/16
[#10934] Re: [ ruby-Bugs-10140 ] Cannot build with extra library path if previous version already installed — nobu@... 2007/04/16

Hi,

[#10960] Re: [ ruby-Bugs-10140 ] Cannot build with extra library path if previous version already installed — "Michal Suchanek" <hramrach@...> 2007/04/18

On 4/16/07, nobu@ruby-lang.org <nobu@ruby-lang.org> wrote:

[#10967] Re: [ ruby-Bugs-10140 ] Cannot build with extra library path if previous version already installed — Nobuyoshi Nakada <nobu@...> 2007/04/19

Hi,

[#10970] Re: [ ruby-Bugs-10140 ] Cannot build with extra library path if previous version already installed — "Michal Suchanek" <hramrach@...> 2007/04/19

On 4/19/07, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:> Hi,>> At Wed, 18 Apr 2007 20:21:44 +0900,> Michal Suchanek wrote in [ruby-core:10960]:> > Yes. And this should also apply to extensions. The mkmf tests are now> > fine but the extension is linked with -L/sw/lib before -L../..>> Indeed.>>> Index: configure.in> ===================================================================> --- configure.in (revision 12191)> +++ configure.in (working copy)> @@ -1385,5 +1385,4 @@ if test "$enable_rpath" = yes; then> fi>> -LDFLAGS="-L. $LDFLAGS"> AC_SUBST(ARCHFILE)>This would break the previous fix so I did not even try to apply this ^

[#11003] miniruby loads extensions from already installed ruby — <noreply@...>

Bugs item #10303, was opened at 2007-04-23 10:44

10 messages 2007/04/23

[#11025] gsub with backslash characters in replacement string — "Adam Bozanich" <adam.boz@...>

Hello, spotted this one the other day:

10 messages 2007/04/26

Fwd: lib/cgi.rb: support for multiple CSS class values specified as an array

From: "James Greenfield" <james.greenfield@...>
Date: 2007-04-16 12:21:51 UTC
List: ruby-core #10929
First time submitting a patch so forgive any missteps on my part. This is a
new feature proposal for ruby's CGI class. The basic idea is to support an
array value for 'class' in the attributes for the helper HTML generation
helper methods. My proposed change is more generic than simply supporting an
Array: if the value responds to the "join" method then it is invoked to
produce the final attribute value string.

So:

cgi = CGI.new("html4")
cgi.td('class'=>['first', 'second']) { "hey there" }

would be rendered as

<TD class="first second">hey there</TD>

My motivation is simple. I often want to build up the attributes in multiple
methods or classes which are then passed into the HTML helper method for
final rendering, and I like to use multiple CSS class values for different
aspects of the final page. It's handy to be able to manage the various CSS
classes as a list rather than one big string.

I couldn't find any existing test cases for cgi.rb so I started my own. They
cover (minimally) the before and after behaviour around this change but I'm
happy to flesh them out further based on feedback.

Regards
James Greenfield

----------------------

ChangeLog:
Mon Apr 16 21:01:02 2007  James Greenfield  < james.greenfield@gmail.com>

        * lib/cgi.rb: support for multiple CSS class values specified as an
array.

Patch with testcases:

Index: lib/cgi.rb
===================================================================
--- lib/cgi.rb  (revision 12182)
+++ lib/cgi.rb  (working copy)
@@ -1305,7 +1305,11 @@
             if true == value
               ""
             else
-              '="' + CGI::escapeHTML(value) + '"'
+              if name == 'class'
+                '="' + CGI::escapeHTML( value.respond_to?(:join) ?
value.join(' ') : value) + '"'
+              else
+                '="' + CGI::escapeHTML(value) + '"'
+              end
             end
           }.join + ">"
       END
Index: test/cgi/test_cgi.rb
===================================================================
--- test/cgi/test_cgi.rb        (revision 0)
+++ test/cgi/test_cgi.rb        (revision 0)
@@ -0,0 +1,75 @@
+require 'test/unit'
+
+require 'cgi'
+
+module CGITestSupport
+  def d(data)
+    data
+  end
+end
+
+
+class TestCGI < Test::Unit::TestCase
+  include CGITestSupport
+
+  class << self
+    include CGITestSupport
+  end
+
+public
+
+  def setup
+  end
+
+  def teardown
+  end
+
+  #### CSV::Reader unit test
+
+  def test_without_attributes
+    ENV['REQUEST_METHOD'] = 'POST'
+    ENV['CONTENT_LENGTH'] = '0'
+    cgi = CGI.new('html4')
+
+    test_each_tag(cgi)
+  end
+
+  def test_css_class_as_string
+    ENV['REQUEST_METHOD'] = 'POST'
+    ENV['CONTENT_LENGTH'] = '0'
+    cgi = CGI.new('html4')
+
+    test_each_tag(cgi, 'class'=>'stringvalue') { |fragment, elt|
assert_equal(fragment, "<#{elt} class=\"stringvalue\">content</#{elt}>") }
+  end
+
+  def test_css_class_as_array
+    ENV['REQUEST_METHOD'] = 'POST'
+    ENV['CONTENT_LENGTH'] = '0'
+    cgi = CGI.new('html4')
+
+    test_each_tag(cgi, 'class'=>['string1', 'string2']) { |fragment, elt|
assert_equal(fragment, "<#{elt} class=\"string1 string2\">content</#{elt}>")
}
+  end
+
+  private
+
+  def test_each_tag(cgi, attrs={})
+    # This is not a complete list of elements, just the ones that
+    # behave in a "predictable" way (i.e. don't have default attributes).
+    # In an ideal world we'd test every possible tag.
+    tags = %w[ TT I B BIG SMALL SUB SUP EM STRONG
+          DFN CODE SAMP KBD VAR CITE ADDRESS DIV MAP
+          PRE DL OL UL SELECT table TITLE
+          STYLE SCRIPT H1 H2 H3 H4 H5 H6 BLOCKQUOTE
+          CAPTION ] + %w[HEAD BODY P DT DD LI OPTION tr th td]
+    tags.each do |tag|
+      elt = tag.upcase
+      if (attrs.empty?)
+        fragment = cgi.send(tag.downcase) { "content" }
+        assert_equal(fragment, "<#{elt}>content</#{elt}>")
+      else
+        fragment = cgi.send(tag.downcase, attrs) { "content" }
+        yield(fragment, elt)
+      end
+    end
+  end
+end

Attachments (1)

Index: lib/cgi.rb
===================================================================
--- lib/cgi.rb	(revision 12182)
+++ lib/cgi.rb	(working copy)
@@ -1305,7 +1305,11 @@
             if true == value
               ""
             else
-              '="' + CGI::escapeHTML(value) + '"'
+              if name == 'class'
+                '="' + CGI::escapeHTML(value.respond_to?(:join) ? value.join(' ') : value) + '"'
+              else
+                '="' + CGI::escapeHTML(value) + '"'
+              end
             end
           }.join + ">"
       END
Index: test/cgi/test_cgi.rb
===================================================================
--- test/cgi/test_cgi.rb	(revision 0)
+++ test/cgi/test_cgi.rb	(revision 0)
@@ -0,0 +1,75 @@
+require 'test/unit'
+
+require 'cgi'
+
+module CGITestSupport
+  def d(data)
+    data
+  end
+end
+
+
+class TestCGI < Test::Unit::TestCase
+  include CGITestSupport
+
+  class << self
+    include CGITestSupport
+  end
+
+public
+
+  def setup
+  end
+
+  def teardown
+  end
+
+  #### CSV::Reader unit test
+  
+  def test_without_attributes
+    ENV['REQUEST_METHOD'] = 'POST'
+    ENV['CONTENT_LENGTH'] = '0'
+    cgi = CGI.new('html4')
+
+    test_each_tag(cgi)
+  end
+
+  def test_css_class_as_string
+    ENV['REQUEST_METHOD'] = 'POST'
+    ENV['CONTENT_LENGTH'] = '0'
+    cgi = CGI.new('html4')
+
+    test_each_tag(cgi, 'class'=>'stringvalue') { |fragment, elt| assert_equal(fragment, "<#{elt} class=\"stringvalue\">content</#{elt}>") }
+  end
+
+  def test_css_class_as_array
+    ENV['REQUEST_METHOD'] = 'POST'
+    ENV['CONTENT_LENGTH'] = '0'
+    cgi = CGI.new('html4')
+
+    test_each_tag(cgi, 'class'=>['string1', 'string2']) { |fragment, elt| assert_equal(fragment, "<#{elt} class=\"string1 string2\">content</#{elt}>") }
+  end
+
+  private
+
+  def test_each_tag(cgi, attrs={})
+    # This is not a complete list of elements, just the ones that
+    # behave in a "predictable" way (i.e. don't have default attributes). 
+    # In an ideal world we'd test every possible tag.
+    tags = %w[ TT I B BIG SMALL SUB SUP EM STRONG
+          DFN CODE SAMP KBD VAR CITE ADDRESS DIV MAP
+          PRE DL OL UL SELECT table TITLE
+          STYLE SCRIPT H1 H2 H3 H4 H5 H6 BLOCKQUOTE
+          CAPTION ] + %w[HEAD BODY P DT DD LI OPTION tr th td]
+    tags.each do |tag|
+      elt = tag.upcase
+      if (attrs.empty?)
+        fragment = cgi.send(tag.downcase) { "content" }
+        assert_equal(fragment, "<#{elt}>content</#{elt}>")
+      else
+        fragment = cgi.send(tag.downcase, attrs) { "content" }
+        yield(fragment, elt)
+      end
+    end
+  end
+end

In This Thread

Prev Next