Forum: Ruby tagz-5.0.1 -- processing instruction support

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
324ce80d9dbe9417607192038fb880bf?d=identicon&s=25 Andrew S. Townley (Guest)
on 2009-03-29 12:49
(Received via mailing list)
Hi Ara,

I was actually working on another machine where I had to install tagz.
I noticed this morning when I was trying to do a line-by-line
comparison, that this machine had 5.0.1 instead of 5.0.0.  It appears
that the behavior is fixed by the change between 5.0.0 and 5.0.1.

Given this, I've re-patched 5.0.1 with the PI support (if anyone else
cares), and included it below.

$ ruby a.rb
<list><container><element><child1>hello
world</child1></element></container><container><element><child1>hello
world</child1></element></container></list>

Cheers,

ast

$ diff -u /usr/lib/ruby/gems/1.8/gems/tagz-5.0.1/lib/tagz.rb
tagz-local.rb
--- /usr/lib/ruby/gems/1.8/gems/tagz-5.0.1/lib/tagz.rb  2009-03-28
04:08:17.000000000 +0000
+++ tagz-local.rb  2009-03-28 08:57:43.000000000 +0000
@@ -5,7 +5,7 @@
       Tagz::VERSION = [
         Tagz::VERSION_MAJOR = 5,
         Tagz::VERSION_MINOR = 0,
-        Tagz::VERSION_TEENY = 1
+        Tagz::VERSION_TEENY = 0
       ].join('.')
       def Tagz.version() Tagz::VERSION end
     end
@@ -15,27 +15,7 @@
   # open_tag
   #
     def tagz__ name, *argv, &block
-      options = argv.last.is_a?(Hash) ? argv.pop : {}
-      content = argv
-
-      unless options.empty?
-        attributes = ' ' <<
-          options.map do |key, value|
-            key = XChar.escape key.to_s
-            value = XChar.escape value.to_s
-            if value =~ %r/"/
-              raise ArgumentError, value if value =~ %r/'/
-              value = "'#{ value }'"
-            else
-              raise ArgumentError, value if value =~ %r/"/
-              value = "\"#{ value }\""
-            end
-            [key, value].join('=')
-          end.join(' ')
-      else
-        attributes = ''
-      end
-
+      attributes, content = process_attributes *argv, &block
       tagz.concat "<#{ name }#{ attributes }>"

       if content.empty?
@@ -53,7 +33,6 @@
             tagz << value.to_s unless(tagz.size > size)
             tagz.concat "</#{ name }>"
           end
-
         end
       else
         tagz << content.join
@@ -74,6 +53,13 @@
       tagz.concat "</#{ tag }>"
     end

+  # processing instruction
+  #
+    def tagz_? name, *argv, &block
+      attributes, content = process_attributes *argv, &block
+      tagz.concat "<?#{ name }#{ attributes }?>"
+    end
+
   # access tagz doc and enclose tagz operations
   #
     def tagz document = nil, &block
@@ -100,6 +86,8 @@
     def method_missing m, *a, &b
       strategy =
         case m.to_s
+          when %r/^(.*[^?])_\?$/o
+            :processing_instruction
           when %r/^(.*[^_])_(!)?$/o
             :open_tag
           when %r/^_([^_].*)$/o
@@ -125,6 +113,9 @@
           m, bang = $1, $2
           b ||= lambda{} if bang
           tagz{ tagz__(m, *a, &b) }
+        when :processing_instruction
+          m = $1
+          tagz{ tagz_?(m, *a, &b) }
         when :close_tag
           m = $1
           tagz{ __tagz(m, *a, &b) }
@@ -141,6 +132,33 @@
       end
     end

+    def process_attributes *argv, &block
+      options = argv.last.is_a?(Hash) ? argv.pop : {}
+      content = argv
+
+      attributes = nil
+
+      unless options.empty?
+        attributes = ' ' <<
+          options.map do |key, value|
+            key = XChar.escape key.to_s
+            value = XChar.escape value.to_s
+            if value =~ %r/"/
+              raise ArgumentError, value if value =~ %r/'/
+              value = "'#{ value }'"
+            else
+              raise ArgumentError, value if value =~ %r/"/
+              value = "\"#{ value }\""
+            end
+            [key, value].join('=')
+          end.join(' ')
+      else
+        attributes = ''
+      end
+
+      [ attributes, content ]
+    end
+
     class Document < ::String
       def Document.for other
         Document === other ? other : Document.new(other.to_s)
B1b1d33e0655e841d4fd8467359c58d0?d=identicon&s=25 Yossef Mendelssohn (Guest)
on 2009-03-30 07:01
(Received via mailing list)
On Mar 29, 5:48 am, "Andrew S. Townley" <a...@atownley.org> wrote:
> Hi Ara,
>
> I was actually working on another machine where I had to install tagz.
> I noticed this morning when I was trying to do a line-by-line
> comparison, that this machine had 5.0.1 instead of 5.0.0.  It appears
> that the behavior is fixed by the change between 5.0.0 and 5.0.1.
>
> Given this, I've re-patched 5.0.1 with the PI support (if anyone else
> cares), and included it below.

I love the beauty of open source as much as the next guy, but I'm
thinking this is maybe not the best workflow for this type of
collaboration. A few suggestions for better sharing of patches:

 - Use the rubyforge tracker
 - Get tagz set up on GitHub
 - For god's sake, send patches directly to Ara and only Ara, not to
ruby-talk.
This topic is locked and can not be replied to.