[PATCH] tagz-5.0.1 -- processing instruction support

A

Andrew S. Townley

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
:eek:pen_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)
 
Y

Yossef Mendelssohn

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. =A0It 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top