qwikdoc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/CHANGES +3 -0
- data/COPYING +340 -0
- data/Gemfile +3 -0
- data/README.md +10 -0
- data/Rakefile +10 -0
- data/TextFormattingRules +137 -0
- data/TextFormattingRules.ja +143 -0
- data/bin/qwikdoc +34 -0
- data/lib/qwik_doc.rb +15 -0
- data/lib/qwik_doc/hack.rb +184 -0
- data/qwikdoc.gemspec +26 -0
- data/spec/qwik_doc_spec.rb +305 -0
- data/spec/spec_helper.rb +12 -0
- data/vendor/qwik/Makefile +63 -0
- data/vendor/qwik/Rakefile +17 -0
- data/vendor/qwik/act-aa.rb +83 -0
- data/vendor/qwik/act-archive.rb +386 -0
- data/vendor/qwik/act-attach.rb +304 -0
- data/vendor/qwik/act-backup.rb +236 -0
- data/vendor/qwik/act-basic.rb +325 -0
- data/vendor/qwik/act-book.rb +161 -0
- data/vendor/qwik/act-calc.rb +371 -0
- data/vendor/qwik/act-charset.rb +251 -0
- data/vendor/qwik/act-christel.rb +112 -0
- data/vendor/qwik/act-chronology.rb +149 -0
- data/vendor/qwik/act-code.rb +155 -0
- data/vendor/qwik/act-comment.rb +554 -0
- data/vendor/qwik/act-config.rb +49 -0
- data/vendor/qwik/act-counter.rb +125 -0
- data/vendor/qwik/act-day.rb +96 -0
- data/vendor/qwik/act-describe.rb +135 -0
- data/vendor/qwik/act-diary.rb +109 -0
- data/vendor/qwik/act-edit.rb +317 -0
- data/vendor/qwik/act-embed-html.rb +296 -0
- data/vendor/qwik/act-emode.rb +150 -0
- data/vendor/qwik/act-event.rb +187 -0
- data/vendor/qwik/act-file.rb +303 -0
- data/vendor/qwik/act-files.rb +771 -0
- data/vendor/qwik/act-getpass.rb +295 -0
- data/vendor/qwik/act-history.rb +136 -0
- data/vendor/qwik/act-html.rb +204 -0
- data/vendor/qwik/act-httpauth.rb +147 -0
- data/vendor/qwik/act-include.rb +142 -0
- data/vendor/qwik/act-interwiki.rb +189 -0
- data/vendor/qwik/act-isearch.rb +109 -0
- data/vendor/qwik/act-keywords.rb +137 -0
- data/vendor/qwik/act-lang.rb +81 -0
- data/vendor/qwik/act-license.rb +63 -0
- data/vendor/qwik/act-list.rb +287 -0
- data/vendor/qwik/act-login.rb +410 -0
- data/vendor/qwik/act-logout.rb +60 -0
- data/vendor/qwik/act-mail.rb +159 -0
- data/vendor/qwik/act-map.rb +292 -0
- data/vendor/qwik/act-md5.rb +42 -0
- data/vendor/qwik/act-mdlb.rb +741 -0
- data/vendor/qwik/act-media.rb +416 -0
- data/vendor/qwik/act-member.rb +157 -0
- data/vendor/qwik/act-menu.rb +142 -0
- data/vendor/qwik/act-metadata.rb +323 -0
- data/vendor/qwik/act-mlsubmitform.rb +49 -0
- data/vendor/qwik/act-monitor.rb +167 -0
- data/vendor/qwik/act-new.rb +418 -0
- data/vendor/qwik/act-pagelist.rb +248 -0
- data/vendor/qwik/act-password.rb +145 -0
- data/vendor/qwik/act-plan.rb +210 -0
- data/vendor/qwik/act-povray.rb +230 -0
- data/vendor/qwik/act-presen.rb +380 -0
- data/vendor/qwik/act-redirect.rb +133 -0
- data/vendor/qwik/act-ring.rb +1071 -0
- data/vendor/qwik/act-rrefs.rb +255 -0
- data/vendor/qwik/act-ruby.rb +116 -0
- data/vendor/qwik/act-sample.rb +170 -0
- data/vendor/qwik/act-save.rb +295 -0
- data/vendor/qwik/act-schedule.rb +374 -0
- data/vendor/qwik/act-search.rb +180 -0
- data/vendor/qwik/act-searchwords.rb +51 -0
- data/vendor/qwik/act-sendpass.rb +83 -0
- data/vendor/qwik/act-site.rb +89 -0
- data/vendor/qwik/act-sitebackup.rb +419 -0
- data/vendor/qwik/act-sitelog.rb +118 -0
- data/vendor/qwik/act-smil.rb +299 -0
- data/vendor/qwik/act-status.rb +220 -0
- data/vendor/qwik/act-style.rb +608 -0
- data/vendor/qwik/act-table.rb +263 -0
- data/vendor/qwik/act-tableform.rb +241 -0
- data/vendor/qwik/act-tag.rb +103 -0
- data/vendor/qwik/act-text.rb +70 -0
- data/vendor/qwik/act-textarea.rb +164 -0
- data/vendor/qwik/act-theme.rb +346 -0
- data/vendor/qwik/act-toc.rb +112 -0
- data/vendor/qwik/act-typekey.rb +198 -0
- data/vendor/qwik/act-under-const.rb +94 -0
- data/vendor/qwik/act-webservice.rb +321 -0
- data/vendor/qwik/act-wema.rb +558 -0
- data/vendor/qwik/act-wysiwyg.rb +238 -0
- data/vendor/qwik/action.rb +325 -0
- data/vendor/qwik/autoreload.rb +98 -0
- data/vendor/qwik/bench-bench.rb +28 -0
- data/vendor/qwik/bench-emode.rb +47 -0
- data/vendor/qwik/bench-format-xml.rb +70 -0
- data/vendor/qwik/bench-large-table.rb +62 -0
- data/vendor/qwik/bench-md5.rb +14 -0
- data/vendor/qwik/bench-module-session.rb +19 -0
- data/vendor/qwik/bench-page.rb +50 -0
- data/vendor/qwik/bench-s-md5.rb +28 -0
- data/vendor/qwik/bench-session.rb +25 -0
- data/vendor/qwik/bench-textformat.rb +31 -0
- data/vendor/qwik/catalog-factory.rb +91 -0
- data/vendor/qwik/catalog-ja.rb +479 -0
- data/vendor/qwik/catalog-ml-ja.rb +145 -0
- data/vendor/qwik/check-act-monitor.rb +112 -0
- data/vendor/qwik/check-act-monitor2.rb +46 -0
- data/vendor/qwik/check-act-theme.rb +27 -0
- data/vendor/qwik/check-event.rb +112 -0
- data/vendor/qwik/check-event2.rb +55 -0
- data/vendor/qwik/check-htree-rexml.rb +77 -0
- data/vendor/qwik/check-htree.rb +51 -0
- data/vendor/qwik/check-libxml.rb +135 -0
- data/vendor/qwik/check-many-pages.rb +47 -0
- data/vendor/qwik/check-monitor.rb +33 -0
- data/vendor/qwik/check-observer.rb +67 -0
- data/vendor/qwik/check-server.rb +61 -0
- data/vendor/qwik/check-uuencode.rb +33 -0
- data/vendor/qwik/check-webdav.rb +65 -0
- data/vendor/qwik/check-xml-xpath.rb +27 -0
- data/vendor/qwik/common-backtrace.rb +94 -0
- data/vendor/qwik/common-basic.rb +111 -0
- data/vendor/qwik/common-condition.rb +142 -0
- data/vendor/qwik/common-error.rb +48 -0
- data/vendor/qwik/common-gettext.rb +50 -0
- data/vendor/qwik/common-javascript.rb +45 -0
- data/vendor/qwik/common-notice.rb +132 -0
- data/vendor/qwik/common-plain.rb +105 -0
- data/vendor/qwik/common-plugin.rb +111 -0
- data/vendor/qwik/common-res.rb +76 -0
- data/vendor/qwik/common-resolve.rb +92 -0
- data/vendor/qwik/common-send.rb +171 -0
- data/vendor/qwik/common-session.rb +139 -0
- data/vendor/qwik/common-surface.rb +261 -0
- data/vendor/qwik/common-url.rb +90 -0
- data/vendor/qwik/compat/Makefile +12 -0
- data/vendor/qwik/compat/add_load_path.rb +1 -0
- data/vendor/qwik/config.rb +299 -0
- data/vendor/qwik/db-b-backup.rb +142 -0
- data/vendor/qwik/db-backup.rb +184 -0
- data/vendor/qwik/db-berkeley.rb +306 -0
- data/vendor/qwik/db-filesystem.rb +305 -0
- data/vendor/qwik/db-indexer.rb +154 -0
- data/vendor/qwik/db-searchwords.rb +238 -0
- data/vendor/qwik/description-ja.rb +267 -0
- data/vendor/qwik/description.rb +256 -0
- data/vendor/qwik/dev-add-copyright.rb +23 -0
- data/vendor/qwik/dev-backup.rb +24 -0
- data/vendor/qwik/dev-bench.rb +175 -0
- data/vendor/qwik/dev-calctime.rb +52 -0
- data/vendor/qwik/dev-css-compressor.rb +60 -0
- data/vendor/qwik/dev-extract-catalog.rb +102 -0
- data/vendor/qwik/dev-js-compressor.rb +73 -0
- data/vendor/qwik/dev-release.rb +235 -0
- data/vendor/qwik/dev-replace.rb +353 -0
- data/vendor/qwik/dev-sendmail.rb +25 -0
- data/vendor/qwik/farm.rb +283 -0
- data/vendor/qwik/gettext.rb +56 -0
- data/vendor/qwik/group-cond.rb +157 -0
- data/vendor/qwik/group-config.rb +247 -0
- data/vendor/qwik/group-confirm.rb +147 -0
- data/vendor/qwik/group-db.rb +326 -0
- data/vendor/qwik/group-mail.rb +195 -0
- data/vendor/qwik/group-member.rb +307 -0
- data/vendor/qwik/group-sendmail.rb +231 -0
- data/vendor/qwik/group-site.rb +374 -0
- data/vendor/qwik/group-sweep.rb +63 -0
- data/vendor/qwik/group.rb +157 -0
- data/vendor/qwik/helper.rb +6 -0
- data/vendor/qwik/html-generator.rb +104 -0
- data/vendor/qwik/html-to-wabisabi.rb +149 -0
- data/vendor/qwik/htree-diff.rb +87 -0
- data/vendor/qwik/htree-format-xml.rb +57 -0
- data/vendor/qwik/htree-generator.rb +144 -0
- data/vendor/qwik/htree-get.rb +251 -0
- data/vendor/qwik/htree-html-generator.rb +179 -0
- data/vendor/qwik/htree-template.rb +263 -0
- data/vendor/qwik/htree-to-wabisabi.rb +171 -0
- data/vendor/qwik/loadlib.rb +79 -0
- data/vendor/qwik/logger.rb +115 -0
- data/vendor/qwik/mail-body.rb +171 -0
- data/vendor/qwik/mail-header.rb +474 -0
- data/vendor/qwik/mail-multipart.rb +193 -0
- data/vendor/qwik/mail-parse.rb +147 -0
- data/vendor/qwik/mail.rb +341 -0
- data/vendor/qwik/mailaddress.rb +83 -0
- data/vendor/qwik/mdlb-model.rb +81 -0
- data/vendor/qwik/mdlb-sample.rb +324 -0
- data/vendor/qwik/ml-catalog-factory.rb +27 -0
- data/vendor/qwik/ml-exception.rb +15 -0
- data/vendor/qwik/ml-generator.rb +28 -0
- data/vendor/qwik/ml-gettext.rb +137 -0
- data/vendor/qwik/ml-logger.rb +82 -0
- data/vendor/qwik/ml-memory.rb +65 -0
- data/vendor/qwik/ml-msg-validator.rb +86 -0
- data/vendor/qwik/ml-processor.rb +609 -0
- data/vendor/qwik/ml-quickml-server.rb +122 -0
- data/vendor/qwik/ml-sendmail.rb +0 -0
- data/vendor/qwik/ml-server.rb +107 -0
- data/vendor/qwik/ml-session.rb +348 -0
- data/vendor/qwik/ml-sweeper.rb +101 -0
- data/vendor/qwik/mock-logger.rb +65 -0
- data/vendor/qwik/mock-sendmail.rb +78 -0
- data/vendor/qwik/mock-socket.rb +82 -0
- data/vendor/qwik/modulobe.rb +406 -0
- data/vendor/qwik/mongrel-server.rb +72 -0
- data/vendor/qwik/page-files.rb +249 -0
- data/vendor/qwik/page-generate.rb +82 -0
- data/vendor/qwik/page-get.rb +262 -0
- data/vendor/qwik/page-images.rb +168 -0
- data/vendor/qwik/page-put.rb +128 -0
- data/vendor/qwik/page-rrefs.rb +154 -0
- data/vendor/qwik/page-title.rb +0 -0
- data/vendor/qwik/page-wikidb.rb +234 -0
- data/vendor/qwik/page.rb +67 -0
- data/vendor/qwik/pages.rb +444 -0
- data/vendor/qwik/parse-plugin.rb +249 -0
- data/vendor/qwik/parser-emode.rb +116 -0
- data/vendor/qwik/parser-inline.rb +273 -0
- data/vendor/qwik/parser.rb +350 -0
- data/vendor/qwik/password.rb +183 -0
- data/vendor/qwik/periodic.rb +79 -0
- data/vendor/qwik/qp.rb +56 -0
- data/vendor/qwik/qwik-service.rb +341 -0
- data/vendor/qwik/qwik.rb +5 -0
- data/vendor/qwik/qwikweb-adduser.rb +34 -0
- data/vendor/qwik/qwikweb-catalog-validator.rb +110 -0
- data/vendor/qwik/qwikweb-incgen.rb +28 -0
- data/vendor/qwik/qwikweb-makesite.rb +41 -0
- data/vendor/qwik/qwikweb-server.rb +44 -0
- data/vendor/qwik/qwikweb-showpassword.rb +26 -0
- data/vendor/qwik/qwikweb-watchlog.rb +67 -0
- data/vendor/qwik/request-path.rb +304 -0
- data/vendor/qwik/request-ua.rb +76 -0
- data/vendor/qwik/request-webrick.rb +81 -0
- data/vendor/qwik/request.rb +91 -0
- data/vendor/qwik/resolve-tdiary.rb +292 -0
- data/vendor/qwik/resolve.rb +121 -0
- data/vendor/qwik/response.rb +228 -0
- data/vendor/qwik/server-memory.rb +57 -0
- data/vendor/qwik/server-webrick.rb +102 -0
- data/vendor/qwik/server.rb +252 -0
- data/vendor/qwik/site-config.rb +149 -0
- data/vendor/qwik/site-db.rb +136 -0
- data/vendor/qwik/site-event.rb +162 -0
- data/vendor/qwik/site-files.rb +86 -0
- data/vendor/qwik/site-group.rb +103 -0
- data/vendor/qwik/site-index.rb +47 -0
- data/vendor/qwik/site-log.rb +64 -0
- data/vendor/qwik/site-member.rb +230 -0
- data/vendor/qwik/site-monitor.rb +97 -0
- data/vendor/qwik/site-pages.rb +62 -0
- data/vendor/qwik/site-plan.rb +139 -0
- data/vendor/qwik/site-report.rb +282 -0
- data/vendor/qwik/site-resolve.rb +230 -0
- data/vendor/qwik/site-rrefs.rb +18 -0
- data/vendor/qwik/site-search.rb +180 -0
- data/vendor/qwik/site-timeline.rb +153 -0
- data/vendor/qwik/site-url.rb +189 -0
- data/vendor/qwik/site.rb +76 -0
- data/vendor/qwik/smil-time.rb +105 -0
- data/vendor/qwik/smtp-session.rb +331 -0
- data/vendor/qwik/template-generator.rb +149 -0
- data/vendor/qwik/template.rb +85 -0
- data/vendor/qwik/test-common.rb +10 -0
- data/vendor/qwik/test-ml-info.rb +225 -0
- data/vendor/qwik/test-module-ml.rb +142 -0
- data/vendor/qwik/test-module-path.rb +110 -0
- data/vendor/qwik/test-module-public.rb +70 -0
- data/vendor/qwik/test-module-server.rb +98 -0
- data/vendor/qwik/test-module-session.rb +264 -0
- data/vendor/qwik/test-module-suite.rb +91 -0
- data/vendor/qwik/test-ms-applemail.rb +59 -0
- data/vendor/qwik/test-ms-attach.rb +174 -0
- data/vendor/qwik/test-ms-basic.rb +40 -0
- data/vendor/qwik/test-ms-close.rb +35 -0
- data/vendor/qwik/test-ms-confirm.rb +75 -0
- data/vendor/qwik/test-ms-ignore-spam.rb +57 -0
- data/vendor/qwik/test-ms-japanese.rb +97 -0
- data/vendor/qwik/test-ms-jfilename.rb +82 -0
- data/vendor/qwik/test-ms-large.rb +58 -0
- data/vendor/qwik/test-ms-member.rb +103 -0
- data/vendor/qwik/test-ms-multipart.rb +84 -0
- data/vendor/qwik/test-ms-org.rb +129 -0
- data/vendor/qwik/test-ms-plan.rb +130 -0
- data/vendor/qwik/test-ms-post.rb +53 -0
- data/vendor/qwik/test-ms-quopri.rb +76 -0
- data/vendor/qwik/test-sub-quopri.rb +45 -0
- data/vendor/qwik/test-submit-base64.rb +59 -0
- data/vendor/qwik/test-submit-forward.rb +61 -0
- data/vendor/qwik/test-submit-html-mail.rb +52 -0
- data/vendor/qwik/test-submit-japanese.rb +135 -0
- data/vendor/qwik/test-submit-jfilename.rb +144 -0
- data/vendor/qwik/test-submit-uuencode.rb +71 -0
- data/vendor/qwik/test-suite-all.rb +8 -0
- data/vendor/qwik/test-suite-basic.rb +9 -0
- data/vendor/qwik/test-suite-ml.rb +9 -0
- data/vendor/qwik/test-typekey.rb +64 -0
- data/vendor/qwik/testunit.rb +45 -0
- data/vendor/qwik/tokenizer-inline.rb +294 -0
- data/vendor/qwik/tokenizer.rb +332 -0
- data/vendor/qwik/typekey.rb +160 -0
- data/vendor/qwik/util-basic.rb +135 -0
- data/vendor/qwik/util-charset.rb +332 -0
- data/vendor/qwik/util-css.rb +56 -0
- data/vendor/qwik/util-csv-tokenizer.rb +113 -0
- data/vendor/qwik/util-filename.rb +112 -0
- data/vendor/qwik/util-pathname.rb +202 -0
- data/vendor/qwik/util-pid.rb +58 -0
- data/vendor/qwik/util-safe.rb +67 -0
- data/vendor/qwik/util-sendmail.rb +273 -0
- data/vendor/qwik/util-string.rb +203 -0
- data/vendor/qwik/util-time.rb +125 -0
- data/vendor/qwik/util-webrick.rb +176 -0
- data/vendor/qwik/version.rb +11 -0
- data/vendor/qwik/wabisabi-basic.rb +163 -0
- data/vendor/qwik/wabisabi-diff.rb +130 -0
- data/vendor/qwik/wabisabi-format-xml.rb +310 -0
- data/vendor/qwik/wabisabi-generator.rb +262 -0
- data/vendor/qwik/wabisabi-index.rb +174 -0
- data/vendor/qwik/wabisabi-table.rb +212 -0
- data/vendor/qwik/wabisabi-template.rb +295 -0
- data/vendor/qwik/wabisabi-to-htree.rb +111 -0
- data/vendor/qwik/wabisabi-to-wiki.rb +690 -0
- data/vendor/qwik/wabisabi-traverse.rb +207 -0
- data/vendor/qwik/wabisabi-validator.rb +116 -0
- data/vendor/qwik/wabisabi.rb +5 -0
- metadata +416 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved.
|
2
|
+
# This is free software with ABSOLUTELY NO WARRANTY.
|
3
|
+
# You can redistribute it and/or modify it under the terms of the GNU GPL 2.
|
4
|
+
|
5
|
+
$LOAD_PATH << 'compat' unless $LOAD_PATH.include? 'compat'
|
6
|
+
begin
|
7
|
+
require 'diff'
|
8
|
+
rescue LoadError
|
9
|
+
require 'algorithm/diff'
|
10
|
+
end
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
|
13
|
+
require 'qwik/util-string'
|
14
|
+
require 'qwik/htree-generator'
|
15
|
+
|
16
|
+
module Qwik
|
17
|
+
class HTreeDiffHtmlGenerator
|
18
|
+
def initialize(s1, s2)
|
19
|
+
@s1 = s1.gsub(/\r/, "")
|
20
|
+
@s2 = s2.gsub(/\r/, "")
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_txt
|
24
|
+
a1 = @s1.split("\n").collect! {|s| "#{s}\n"}
|
25
|
+
a2 = @s2.split("\n").collect! {|s| "#{s}\n"}
|
26
|
+
Diff.diff(a1, a2)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_xml
|
30
|
+
g = HTree::Generator.new
|
31
|
+
src = @s1.split("\n").collect {|s| "#{s.escapeHTML}" }
|
32
|
+
si = 0
|
33
|
+
di = 0
|
34
|
+
e = []
|
35
|
+
to_txt.each {|action, position, elements|
|
36
|
+
case action
|
37
|
+
when :-
|
38
|
+
while si < position
|
39
|
+
e << HTree::Text.new(src[si])
|
40
|
+
e << g.br
|
41
|
+
si += 1
|
42
|
+
di += 1
|
43
|
+
end
|
44
|
+
si += elements.length
|
45
|
+
elements.each {|l|
|
46
|
+
e << g.del{l.chomp}
|
47
|
+
e << g.br
|
48
|
+
}
|
49
|
+
when :+
|
50
|
+
while di < position
|
51
|
+
e << HTree::Text.new(src[si])
|
52
|
+
e << g.br
|
53
|
+
si += 1
|
54
|
+
di += 1
|
55
|
+
end
|
56
|
+
di += elements.length
|
57
|
+
elements.each {|l|
|
58
|
+
e << g.ins{l.chomp}
|
59
|
+
e << g.br
|
60
|
+
}
|
61
|
+
end
|
62
|
+
}
|
63
|
+
while si < src.length
|
64
|
+
e << HTree::Text.new(src[si])
|
65
|
+
e << g.br
|
66
|
+
si += 1
|
67
|
+
end
|
68
|
+
e
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
if $0 == __FILE__
|
74
|
+
require 'qwik/testunit'
|
75
|
+
require 'qwik/htree-format-xml'
|
76
|
+
$test = true
|
77
|
+
end
|
78
|
+
|
79
|
+
if defined?($test) && $test
|
80
|
+
class TestHTreeDiffHtmlGenerator < Test::Unit::TestCase
|
81
|
+
def test_all
|
82
|
+
dhg = Qwik::HTreeDiffHtmlGenerator.new('a', 'b')
|
83
|
+
ok_eq([[:-, 0, ["a\n"]], [:+, 0, ["b\n"]]], dhg.to_txt)
|
84
|
+
ok_eq("[{elem <del> {text a}}, {emptyelem <br>}, {elem <ins> {text b}}, {emptyelem <br>}]", dhg.to_xml.inspect)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved.
|
2
|
+
# This is free software with ABSOLUTELY NO WARRANTY.
|
3
|
+
# You can redistribute it and/or modify it under the terms of the GNU GPL 2.
|
4
|
+
|
5
|
+
$LOAD_PATH << 'compat' unless $LOAD_PATH.include? 'compat'
|
6
|
+
require 'htree'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
|
9
|
+
|
10
|
+
module HTree
|
11
|
+
module Node
|
12
|
+
def format_xml(i=-1)
|
13
|
+
str = ''
|
14
|
+
display_xml(str)
|
15
|
+
str.gsub!(%r! xmlns=\"http://www.w3.org/1999/xhtml\"!, "")
|
16
|
+
str.gsub!(%r! xmlns=\"\"!, "")
|
17
|
+
if i < 0
|
18
|
+
str.gsub!(/\n>/, ">")
|
19
|
+
str.gsub!(/\n\/>/, "/>")
|
20
|
+
end
|
21
|
+
str
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if $0 == __FILE__
|
27
|
+
require 'qwik/testunit'
|
28
|
+
$test = true
|
29
|
+
end
|
30
|
+
|
31
|
+
if defined?($test) && $test
|
32
|
+
class TestHTree_format_xml < Test::Unit::TestCase
|
33
|
+
def ok(e, s)
|
34
|
+
ok_eq(e, s.format_xml)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_all
|
38
|
+
# check_extract_text
|
39
|
+
e = HTree::Elem.new('a', 't')
|
40
|
+
ok("<a>t</a>", e)
|
41
|
+
ok_eq('t', e.extract_text.to_s)
|
42
|
+
|
43
|
+
e = HTree::Elem.new('b', 's', e, 'u')
|
44
|
+
ok("<b>s<a>t</a>u</b>", e)
|
45
|
+
ok_eq('stu', e.extract_text.to_s)
|
46
|
+
|
47
|
+
# test_htree_format_xml
|
48
|
+
e = HTree::Elem.new('a')
|
49
|
+
ok_eq("<a/>", e.format_xml)
|
50
|
+
ok_eq("<a\n/>", e.format_xml(0))
|
51
|
+
|
52
|
+
e = HTree::Text.new('a')
|
53
|
+
ok_eq('a', e.format_xml)
|
54
|
+
ok_eq('a', e.format_xml(0))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved.
|
2
|
+
# This is free software with ABSOLUTELY NO WARRANTY.
|
3
|
+
# You can redistribute it and/or modify it under the terms of the GNU GPL 2.
|
4
|
+
|
5
|
+
$LOAD_PATH << 'compat' unless $LOAD_PATH.include? 'compat'
|
6
|
+
require 'htree'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
|
9
|
+
|
10
|
+
module HTree
|
11
|
+
module GeneratorModule
|
12
|
+
def method_missing(symbol, *args, &block)
|
13
|
+
make(symbol, *args, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def p(*args, &block)
|
17
|
+
make(:p, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def make(symbol, *args, &block)
|
21
|
+
ar = make_ar(symbol, *args, &block)
|
22
|
+
Elem.new(*ar)
|
23
|
+
end
|
24
|
+
|
25
|
+
def make_ar(symbol, *args, &block)
|
26
|
+
ar = []
|
27
|
+
|
28
|
+
ar << symbol.to_s.gsub(/_/, '-') # tag name
|
29
|
+
|
30
|
+
if 0 < args.length
|
31
|
+
a = add_args(args)
|
32
|
+
ar += a
|
33
|
+
end
|
34
|
+
|
35
|
+
if block
|
36
|
+
y = block.call
|
37
|
+
ar += add_elems(y)
|
38
|
+
end
|
39
|
+
|
40
|
+
ar
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_args(args)
|
44
|
+
args.flatten.map {|arg|
|
45
|
+
symbol_to_hash(arg)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_elems(args)
|
50
|
+
return [] if args.nil?
|
51
|
+
return [args] unless args.kind_of? Array
|
52
|
+
ar = []
|
53
|
+
args.each {|a|
|
54
|
+
next if a.nil?
|
55
|
+
ar << a
|
56
|
+
}
|
57
|
+
ar = [''] if ar.empty?
|
58
|
+
ar
|
59
|
+
end
|
60
|
+
|
61
|
+
def symbol_to_hash(s)
|
62
|
+
h = {}
|
63
|
+
s.each {|k, v|
|
64
|
+
next if v.nil?
|
65
|
+
h[k.to_s] = v.to_s
|
66
|
+
}
|
67
|
+
h
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Generator; include GeneratorModule; end
|
72
|
+
end
|
73
|
+
|
74
|
+
if $0 == __FILE__
|
75
|
+
require 'qwik/testunit'
|
76
|
+
require 'qwik/htree-format-xml'
|
77
|
+
$test = true
|
78
|
+
end
|
79
|
+
|
80
|
+
if defined?($test) && $test
|
81
|
+
class TestHTreeGenerator < Test::Unit::TestCase
|
82
|
+
def ok(e, s)
|
83
|
+
ok_eq(e, s.format_xml)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_all
|
87
|
+
g = HTree::Generator.new
|
88
|
+
|
89
|
+
# test_htree_generator
|
90
|
+
ok("<p/>", g.p)
|
91
|
+
doc = HTree::Doc.new(g.p)
|
92
|
+
ok("<p/>", doc)
|
93
|
+
str = ''
|
94
|
+
doc.display_xml(str)
|
95
|
+
ok_eq("<p\n/>", str)
|
96
|
+
|
97
|
+
ok("<a/>", g.a)
|
98
|
+
ok("<b/>", g.b{})
|
99
|
+
ok("<b></b>", g.b{''})
|
100
|
+
ok('<img src='u'/>', g.img(:src=>'u'))
|
101
|
+
ok("<b>t</b>", g.b{'t'})
|
102
|
+
ok("<p><b>b</b></p>", g.p{g.b{'b'}})
|
103
|
+
ok("<p>t<p>b</p>t</p>", g.p{['t', g.p{'b'}, 't']})
|
104
|
+
ok('<a href='u'>t</a>', g.a(:href=>'u'){'t'})
|
105
|
+
ok('<font size='7'>t</font>', g.font(:size => 7){'t'})
|
106
|
+
|
107
|
+
# test_namespace
|
108
|
+
ok("<b>t</b>", g.make('b'){'t'})
|
109
|
+
ok("<n:b>t</n:b>", g.make("n:b"){'t'})
|
110
|
+
ok('<a href='u'>t</a>', g.make('a', :href=>'u'){'t'})
|
111
|
+
|
112
|
+
html = g.html {[
|
113
|
+
g.head {[
|
114
|
+
g.title {"�^�C�g��"},
|
115
|
+
]},
|
116
|
+
g.body {[
|
117
|
+
g.pre {[g.b {'world'}, 'hello']},
|
118
|
+
g.pre {['This is ', g.b{'bold'}, ' text.']},
|
119
|
+
g.pre {['This is ', g.i{'italic'}, ' text.']},
|
120
|
+
g.p {['This is ', g.a(:href=>'hoge'){'anchor'}, ' text.']},
|
121
|
+
]}
|
122
|
+
]}
|
123
|
+
ok("<html><head><title>�^�C�g��</title></head><body><pre><b>world</b>hello</pre><pre>This is <b>bold</b> text.</pre><pre>This is <i>italic</i> text.</pre><p>This is <a href=\"hoge\">anchor</a> text.</p></body></html>", html)
|
124
|
+
|
125
|
+
# test_with_underbar
|
126
|
+
ok("<ab/>", g.ab)
|
127
|
+
ok("<a-b/>", g.a_b)
|
128
|
+
ok("<a-b/>", g.make("a_b"))
|
129
|
+
ok("<a-b/>", g.make("a-b"))
|
130
|
+
|
131
|
+
# test_ordered_hash
|
132
|
+
ok("<a b=\"c\"/>", g.a({'b'=>'c'}))
|
133
|
+
ok("<a b=\"c\"/>", g.a([{'b'=>'c'}]))
|
134
|
+
ok("<a b=\"c\" d=\"e\"/>", g.a([{'b'=>'c'}, {'d'=>'e'}]))
|
135
|
+
ok("<a b=\"c\" d=\"e\"/>", g.a({'b'=>'c'}, {'d'=>'e'}))
|
136
|
+
|
137
|
+
# test_multi_attr
|
138
|
+
ok("<a href=\"h\" class=\"c\"/>",
|
139
|
+
g.make('a', {:href=>'h'}, {:class=>'c'}))
|
140
|
+
ok("<a class=\"c\" href=\"h\"/>",
|
141
|
+
g.make('a', {:class=>'c'}, {:href=>'h'}))
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved.
|
2
|
+
# This is free software with ABSOLUTELY NO WARRANTY.
|
3
|
+
# You can redistribute it and/or modify it under the terms of the GNU GPL 2.
|
4
|
+
|
5
|
+
$LOAD_PATH << 'compat' unless $LOAD_PATH.include? 'compat'
|
6
|
+
require 'htree'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
|
9
|
+
require 'qwik/htree-template'
|
10
|
+
|
11
|
+
module HTree
|
12
|
+
module Container
|
13
|
+
def split_name_num(name)
|
14
|
+
name = name.sub(%r|(^//)|, '')
|
15
|
+
|
16
|
+
if /^(\w+)\[(\d+)\]$/ =~ name
|
17
|
+
return [$1, $2.to_i]
|
18
|
+
end
|
19
|
+
|
20
|
+
return [name, 1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_nth_element(num=1, *names)
|
24
|
+
i = 1
|
25
|
+
traverse_element(*names) {|e|
|
26
|
+
return e if i == num
|
27
|
+
i += 1
|
28
|
+
}
|
29
|
+
return nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_tag(tag)
|
33
|
+
tag, num = split_name_num(tag)
|
34
|
+
names = html_tags(tag)
|
35
|
+
return find_nth_element(num, *names)
|
36
|
+
end
|
37
|
+
|
38
|
+
def each_in_class(klass)
|
39
|
+
klass, knum = split_name_num(klass)
|
40
|
+
k = 1
|
41
|
+
klass_path = nil
|
42
|
+
make_loc.traverse_element {|l|
|
43
|
+
if klass_path.nil?
|
44
|
+
if l.to_node.get_attr('class') == klass
|
45
|
+
if k == knum
|
46
|
+
klass_path = l.path
|
47
|
+
else
|
48
|
+
k += 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
elsif l.path.include?(klass_path)
|
52
|
+
yield l
|
53
|
+
end
|
54
|
+
}
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_class_tag(klass, tag)
|
59
|
+
tag, num = split_name_num(tag)
|
60
|
+
i = 1
|
61
|
+
each_in_class(klass) {|l|
|
62
|
+
ar = l.path.split('/')
|
63
|
+
e = ar.last
|
64
|
+
if e == tag
|
65
|
+
return l.to_node if i == num
|
66
|
+
i += 1
|
67
|
+
end
|
68
|
+
}
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def each_class(klass) # obsolete
|
73
|
+
return each_has_attr('class', klass, &b)
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_class(klass) # obsolete
|
77
|
+
return get_has_attr('class', klass)
|
78
|
+
end
|
79
|
+
|
80
|
+
def each_has_attr(attr, value)
|
81
|
+
make_loc.traverse_element {|l|
|
82
|
+
if l.to_node.get_attr(attr) == value
|
83
|
+
yield(l.to_node)
|
84
|
+
end
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_has_attr(attr, value)
|
89
|
+
each_has_attr(attr, value) {|l|
|
90
|
+
return l.to_node
|
91
|
+
}
|
92
|
+
return nil
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_a_path(path)
|
96
|
+
if /\A(.*)\[(.+)\]\z/ =~ path
|
97
|
+
tag = $1
|
98
|
+
select = $2
|
99
|
+
if /\A@([a-z]+)='([a-z]+)'\z/ =~ select
|
100
|
+
attr = $1
|
101
|
+
value = $2
|
102
|
+
# if attr == 'class'
|
103
|
+
# return get_class(cont)
|
104
|
+
# end
|
105
|
+
return get_has_attr(attr, value)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
return get_tag(path)
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_path(path)
|
113
|
+
xml = self
|
114
|
+
path.split('/').each {|pa|
|
115
|
+
if 0 < pa.length
|
116
|
+
return nil if xml.nil?
|
117
|
+
xml = xml.get_a_path(pa)
|
118
|
+
end
|
119
|
+
}
|
120
|
+
return xml
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class Elem
|
125
|
+
def attributes_str
|
126
|
+
return hash_to_str(attributes)
|
127
|
+
end
|
128
|
+
|
129
|
+
def hash_to_str(src)
|
130
|
+
h = {}
|
131
|
+
src.each {|k, v| h[k.to_s] = v.to_s }
|
132
|
+
return h
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
if $0 == __FILE__
|
138
|
+
require 'qwik/testunit'
|
139
|
+
require 'qwik/htree-format-xml'
|
140
|
+
$test = true
|
141
|
+
end
|
142
|
+
|
143
|
+
if defined?($test) && $test
|
144
|
+
class TestHTreeGet < Test::Unit::TestCase
|
145
|
+
def ok(e, s)
|
146
|
+
return '' if s.nil?
|
147
|
+
ok_eq(e, s.format_xml)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_all
|
151
|
+
# test_get_tag
|
152
|
+
e = HTree::Elem.new('e')
|
153
|
+
|
154
|
+
# test_split_name_num
|
155
|
+
ok_eq(['sidebar', 1], e.split_name_num('sidebar'))
|
156
|
+
ok_eq(['sidebar', 1], e.split_name_num("sidebar[1]"))
|
157
|
+
ok_eq(['sidebar', 2], e.split_name_num("sidebar[2]"))
|
158
|
+
|
159
|
+
# test_get_tag
|
160
|
+
h = HTree("<a><b><c>")
|
161
|
+
ok("<c/>", h.get_tag('c'))
|
162
|
+
ok("<b><c/></b>", h.get_tag('b'))
|
163
|
+
|
164
|
+
# test_each_in_class
|
165
|
+
h = HTree("<p class='a'><ta/></p><p class='b'><tb/></p><p class='b'><tb2/></p>")
|
166
|
+
h.each_in_class('a') {|l|
|
167
|
+
ok_eq("doc()/p[1]/ta", l.path)
|
168
|
+
ok("<ta/>", l.to_node)
|
169
|
+
}
|
170
|
+
h.each_in_class('b') {|l|
|
171
|
+
ok_eq("doc()/p[2]/tb", l.path)
|
172
|
+
ok("<tb/>", l.to_node)
|
173
|
+
}
|
174
|
+
h.each_in_class("b[2]") {|l|
|
175
|
+
ok_eq("doc()/p[3]/tb2", l.path)
|
176
|
+
ok("<tb2/>", l.to_node)
|
177
|
+
}
|
178
|
+
|
179
|
+
ok("<ta/>", h.get_class_tag('a', 'ta'))
|
180
|
+
ok("<tb/>", h.get_class_tag('b', 'tb'))
|
181
|
+
ok("<tb2/>", h.get_class_tag("b[2]", 'tb2'))
|
182
|
+
|
183
|
+
str = <<'EOS'
|
184
|
+
<html><div class='main'>
|
185
|
+
<div class='day'><h2>bh2</h2></div>
|
186
|
+
<div class='sidebar'><h2>sh2</h2></div>
|
187
|
+
</div></html>
|
188
|
+
EOS
|
189
|
+
h = HTree(str)
|
190
|
+
ok("<html><div class=\"main\">\n<div class=\"day\"><h2>bh2</h2></div>\n<div class=\"sidebar\"><h2>sh2</h2></div>\n</div></html>\n", h)
|
191
|
+
ok("<h2>bh2</h2>", h.get_tag('h2'))
|
192
|
+
ok("<h2>sh2</h2>", h.get_tag("h2[2]"))
|
193
|
+
ok("<h2>bh2</h2>", h.get_class_tag('day', 'h2'))
|
194
|
+
ok("<h2>sh2</h2>", h.get_class_tag('sidebar', 'h2'))
|
195
|
+
|
196
|
+
# test_get_tag2
|
197
|
+
h = HTree("<a><b>tb</b><b>tb2</b><c>")
|
198
|
+
ok("<b>tb</b>", h.get_tag('b'))
|
199
|
+
ok_eq(nil, h.get_tag('nosuchtag'))
|
200
|
+
ok("<b>tb</b>", h.get_tag("b[1]"))
|
201
|
+
ok("<b>tb2</b>", h.get_tag("b[2]"))
|
202
|
+
ok("<b>tb</b>", h.get_tag("//b"))
|
203
|
+
|
204
|
+
# test_xpath
|
205
|
+
str = <<'EOS'
|
206
|
+
<html><div class='main'>
|
207
|
+
<div class='day'><h2>bh2</h2></div>
|
208
|
+
<div class='sidebar'><h2>sh2<b>a</b>sh2a</h2></div>
|
209
|
+
</div></html>
|
210
|
+
EOS
|
211
|
+
h = HTree(str)
|
212
|
+
#ok("<html><div class=\"main\">\n<div class=\"day\"><h2>bh2</h2></div>\n<div class=\"sidebar\"><h2>sh2</h2></div>\n</div></html>\n", h)
|
213
|
+
#ok("<h2>sh2</h2>", h.get_class_tag('sidebar', 'h2'))
|
214
|
+
#ok("<h2>sh2<b>a</b>sh2a</h2>", h.get_class('sidebar'))
|
215
|
+
ok("<div class=\"sidebar\"><h2>sh2<b>a</b>sh2a</h2></div>",
|
216
|
+
h.get_class('sidebar'))
|
217
|
+
ok_instance_of(HTree::Elem, h.get_class('sidebar'))
|
218
|
+
ok("<b>a</b>", h.get_class('sidebar').get_tag('b'))
|
219
|
+
ok("<div class=\"sidebar\"><h2>sh2<b>a</b>sh2a</h2></div>",
|
220
|
+
h.get_a_path("div[@class='sidebar']"))
|
221
|
+
ok("<b>a</b>", h.get_a_path("div[@class='sidebar']").get_a_path('b'))
|
222
|
+
ok("<div class=\"sidebar\"><h2>sh2<b>a</b>sh2a</h2></div>",
|
223
|
+
h.get_path("//div[@class='sidebar']"))
|
224
|
+
ok("<b>a</b>", h.get_path("//div[@class='sidebar']/b"))
|
225
|
+
|
226
|
+
str = <<'EOS'
|
227
|
+
<a href='t1' alt='t2'>t3</a>
|
228
|
+
EOS
|
229
|
+
h = HTree(str)
|
230
|
+
ok_instance_of(HTree::Doc, h)
|
231
|
+
e = h.get_tag('a')
|
232
|
+
ok_instance_of(HTree::Elem, e)
|
233
|
+
ok("<a href=\"t1\" alt=\"t2\">t3</a>", e)
|
234
|
+
#ok_eq({href=>{text 't1'}, alt=>{text 't2'}}, e.attributes)
|
235
|
+
ok_eq({'href'=>'t1', 'alt'=>'t2'}, e.attributes_str)
|
236
|
+
|
237
|
+
# test_xpath_attr
|
238
|
+
str = <<'EOS'
|
239
|
+
<html><div class='main'>
|
240
|
+
<div id='menu'><h2>menuh2</h2></div>
|
241
|
+
</div></html>
|
242
|
+
EOS
|
243
|
+
h = HTree(str)
|
244
|
+
ok("<div id=\"menu\"><h2>menuh2</h2></div>",
|
245
|
+
h.get_has_attr('id', 'menu'))
|
246
|
+
ok_instance_of(HTree::Elem, h.get_has_attr('id', 'menu'))
|
247
|
+
ok("<div id=\"menu\"><h2>menuh2</h2></div>",
|
248
|
+
h.get_path("//div[@id='menu']"))
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|