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,174 @@
|
|
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.unshift '..' unless $LOAD_PATH.include? '..'
|
6
|
+
require 'qwik/wabisabi-basic'
|
7
|
+
require 'qwik/wabisabi-traverse'
|
8
|
+
|
9
|
+
module WabisabiIndexModule
|
10
|
+
def set_parent(parent)
|
11
|
+
@parent = parent
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def parent
|
16
|
+
@parent = nil if ! defined?(@parent)
|
17
|
+
return @parent
|
18
|
+
end
|
19
|
+
|
20
|
+
def traverse_with_parent(&b)
|
21
|
+
self.each {|child|
|
22
|
+
next if ! child.is_a?(Array)
|
23
|
+
yield(self, child)
|
24
|
+
child.traverse_with_parent(&b) # Recursive.
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_all_parent
|
29
|
+
self.traverse_with_parent {|parent, child|
|
30
|
+
child.set_parent(parent)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def make_index
|
35
|
+
@tags = Hash.new {|h, k| h[k] = [] }
|
36
|
+
@klass = Hash.new {|h, k| h[k] = [] }
|
37
|
+
|
38
|
+
self.traverse_element {|e|
|
39
|
+
classname = e.attr(:class)
|
40
|
+
if classname
|
41
|
+
@klass[classname] << e
|
42
|
+
end
|
43
|
+
|
44
|
+
name = e.element_name
|
45
|
+
@tags[name] << e
|
46
|
+
}
|
47
|
+
|
48
|
+
self.set_all_parent
|
49
|
+
end
|
50
|
+
|
51
|
+
def index_tag(element_name)
|
52
|
+
return @tags[element_name][0]
|
53
|
+
end
|
54
|
+
|
55
|
+
def index_class(classname)
|
56
|
+
return @klass[classname][0]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Use parent.
|
60
|
+
def index_each_tag(element_name)
|
61
|
+
if ! defined?(@tags)
|
62
|
+
self.make_index
|
63
|
+
end
|
64
|
+
|
65
|
+
tags = @tags[element_name]
|
66
|
+
return if tags.nil?
|
67
|
+
tags.each {|e|
|
68
|
+
result = yield(e)
|
69
|
+
|
70
|
+
parent = e.parent
|
71
|
+
new_parent = []
|
72
|
+
parent.each_with_index {|child, i|
|
73
|
+
if child.object_id == e.object_id
|
74
|
+
if result.nil?
|
75
|
+
# do nothing.
|
76
|
+
else
|
77
|
+
new_parent << result
|
78
|
+
end
|
79
|
+
else
|
80
|
+
new_parent << child
|
81
|
+
end
|
82
|
+
}
|
83
|
+
|
84
|
+
parent.replace(new_parent)
|
85
|
+
}
|
86
|
+
return nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class Array
|
91
|
+
include WabisabiIndexModule
|
92
|
+
end
|
93
|
+
|
94
|
+
if $0 == __FILE__
|
95
|
+
require 'test/unit'
|
96
|
+
$test = true
|
97
|
+
end
|
98
|
+
|
99
|
+
if defined?($test) && $test
|
100
|
+
class TestWabisabiIndex < Test::Unit::TestCase
|
101
|
+
def test_parent
|
102
|
+
child = [:child]
|
103
|
+
parent = [:parent, child]
|
104
|
+
|
105
|
+
# test_parent
|
106
|
+
assert_equal nil, child.parent
|
107
|
+
|
108
|
+
# test_set_parent
|
109
|
+
child.set_parent(parent)
|
110
|
+
assert_equal [:parent, [:child]], child.parent
|
111
|
+
|
112
|
+
# test_traverse_with_parent
|
113
|
+
parent.traverse_with_parent {|p, c|
|
114
|
+
assert_equal [:parent, [:child]], p
|
115
|
+
assert_equal [:child], c
|
116
|
+
}
|
117
|
+
|
118
|
+
# test_set_all_parent
|
119
|
+
parent.set_all_parent
|
120
|
+
assert_equal [:parent, [:child]], child.parent
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_parent_real
|
124
|
+
w = [:html,
|
125
|
+
[:div, {:class=>'main'},
|
126
|
+
[:div, {:class=>'day'},
|
127
|
+
[:h2, 'bh2']],
|
128
|
+
[:div, {:class=>'sidebar'},
|
129
|
+
[:h2, 'sh2',
|
130
|
+
[:b, 'a'], 'sh2a']]]]
|
131
|
+
|
132
|
+
# test_set_all_parent
|
133
|
+
w.set_all_parent
|
134
|
+
|
135
|
+
# test_parent
|
136
|
+
ok_eq(nil, w.parent)
|
137
|
+
ok_eq(w, w[1].parent)
|
138
|
+
ok_eq([:h2, 'sh2', [:b, 'a'], 'sh2a'],
|
139
|
+
w[1][3][2][2].parent)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_all
|
143
|
+
w = [:html, [:div, {:class=>'main'},
|
144
|
+
[:div, {:class=>'day'}, [:h2, 'bh2']],
|
145
|
+
[:div, {:class=>'sidebar'}, [:h2, 'sh2', [:b, 'a'], 'sh2a']]]]
|
146
|
+
|
147
|
+
# test_make_index
|
148
|
+
w.make_index
|
149
|
+
|
150
|
+
# test_index_tag
|
151
|
+
assert_equal [:h2, 'bh2'], w.index_tag(:h2)
|
152
|
+
|
153
|
+
# test_index_class
|
154
|
+
assert_equal [:div, {:class=>'sidebar'}, [:h2, 'sh2', [:b, 'a'], 'sh2a']],
|
155
|
+
w.index_class('sidebar')
|
156
|
+
|
157
|
+
# test_index_each_tag
|
158
|
+
w = [:p, '']
|
159
|
+
w.make_index
|
160
|
+
nw = w.index_each_tag(:a) {|ww|
|
161
|
+
[ww]
|
162
|
+
}
|
163
|
+
|
164
|
+
w = [[:a, '']]
|
165
|
+
w.make_index
|
166
|
+
w.index_each_tag(:a) {|ww|
|
167
|
+
www = ww.dup
|
168
|
+
www[-1] = 't'
|
169
|
+
www
|
170
|
+
}
|
171
|
+
assert_equal [[:a, 't']], w
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,212 @@
|
|
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.unshift '..' unless $LOAD_PATH.include? '..'
|
6
|
+
require 'qwik/wabisabi-basic'
|
7
|
+
|
8
|
+
module Qwik
|
9
|
+
class WabisabiTable
|
10
|
+
def self.error_check(table)
|
11
|
+
each_td(table) {|td, col, row|
|
12
|
+
if 2 < td.length # Error!
|
13
|
+
return true
|
14
|
+
end
|
15
|
+
}
|
16
|
+
return false # No error.
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.prepare(table)
|
20
|
+
fill_empty_td(table)
|
21
|
+
add_new_col(table)
|
22
|
+
add_new_row(table)
|
23
|
+
replace_with_input(table)
|
24
|
+
make_th(table)
|
25
|
+
set_new_col_and_new_row(table)
|
26
|
+
add_new_col_button(table)
|
27
|
+
add_new_row_button(table)
|
28
|
+
return table
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.fill_empty_td(table, max_col=nil)
|
32
|
+
max_col = max_col(table) if max_col.nil?
|
33
|
+
table.each_child_with_index {|tr, row|
|
34
|
+
col_len = tr.children.length
|
35
|
+
if col_len < max_col
|
36
|
+
(max_col - col_len).times {
|
37
|
+
tr << [:td, '']
|
38
|
+
}
|
39
|
+
end
|
40
|
+
}
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.add_new_col(table)
|
45
|
+
each_tr(table) {|tr, row|
|
46
|
+
tr << [:td, '']
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.max_col(table)
|
51
|
+
max_col = 0
|
52
|
+
each_tr(table) {|tr, row|
|
53
|
+
col_len = tr.children.length
|
54
|
+
max_col = col_len if max_col < col_len
|
55
|
+
}
|
56
|
+
return max_col
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.each_tr(table)
|
60
|
+
table.each_child_with_index {|tr, row|
|
61
|
+
yield(tr, row)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.each_td(table)
|
66
|
+
each_tr(table) {|tr, row|
|
67
|
+
tr.each_child_with_index {|td, col|
|
68
|
+
yield(td, col, row)
|
69
|
+
}
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.add_new_row(table, max_col=nil)
|
74
|
+
max_col = max_col(table) if max_col.nil?
|
75
|
+
tr = [:tr]
|
76
|
+
(max_col).times {
|
77
|
+
tr << [:td, '']
|
78
|
+
}
|
79
|
+
table << tr
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.replace_with_input(table)
|
83
|
+
max_len = Array.new(0)
|
84
|
+
each_td(table) {|td, col, row|
|
85
|
+
name = "t_#{col}_#{row}"
|
86
|
+
text = td[1]
|
87
|
+
len = text.length
|
88
|
+
len = 1 if len < 1
|
89
|
+
max_len[col] ||= 0
|
90
|
+
max_len[col] = len if max_len[col] < len
|
91
|
+
td[1] = [:input, {:name=>name, :value=>text}]
|
92
|
+
}
|
93
|
+
each_td(table) {|td, col, row|
|
94
|
+
td[1].set_attr(:size=>max_len[col].to_s)
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.make_th(table)
|
99
|
+
each_td(table) {|td, col, row|
|
100
|
+
td[0] = :th if row == 0 || col == 0
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.set_new_col_and_new_row(table)
|
105
|
+
last_tr = table.last
|
106
|
+
last_tr.set_attr(:class=>'new_row')
|
107
|
+
each_tr(table) {|tr, row|
|
108
|
+
tr.last.set_attr(:class=>'new_col')
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.add_new_col_button(table)
|
113
|
+
first_tr = table.children.first
|
114
|
+
first_tr << [:td, {:class=>'new_col_button'},
|
115
|
+
[:a, {:href=>'javascript:show_new_col();'}, '>>']]
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.add_new_row_button(table)
|
119
|
+
table << [:tr, {:class=>'new_row_button_row'},
|
120
|
+
[:td, {:class=>'new_row_button'},
|
121
|
+
[:a, {:href=>'javascript:show_new_row();'}, 'v']]]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
if $0 == __FILE__
|
127
|
+
require 'qwik/testunit'
|
128
|
+
$test = true
|
129
|
+
end
|
130
|
+
|
131
|
+
if defined?($test) && $test
|
132
|
+
module Qwik
|
133
|
+
class WabisabiTable
|
134
|
+
attr_reader :table # Only for debug.
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class TestWabisabiTable < Test::Unit::TestCase
|
139
|
+
def test_class_method
|
140
|
+
table_1x1 = [:table, [:tr, [:td, '']]]
|
141
|
+
table_2x2 = [:table,
|
142
|
+
[:tr, [:td, ''], [:td, '']],
|
143
|
+
[:tr, [:td, ''], [:td, '']]]
|
144
|
+
table_with_empty = [:table,
|
145
|
+
[:tr, [:td, ''], [:td, '']],
|
146
|
+
[:tr, [:td, '']]]
|
147
|
+
|
148
|
+
c = Qwik::WabisabiTable
|
149
|
+
|
150
|
+
# test_max_col
|
151
|
+
assert_equal 1, c.max_col(table_1x1)
|
152
|
+
assert_equal 2, c.max_col(table_2x2)
|
153
|
+
assert_equal 2, c.max_col(table_with_empty)
|
154
|
+
|
155
|
+
# test_fill_empty_td
|
156
|
+
c.fill_empty_td(table_with_empty)
|
157
|
+
eq([:table, [:tr, [:td, ''], [:td, '']], [:tr, [:td, ''], [:td, '']]],
|
158
|
+
table_with_empty)
|
159
|
+
|
160
|
+
# test_each_tr
|
161
|
+
c.each_tr(table_1x1) {|tr, row|
|
162
|
+
assert_equal :tr, tr[0]
|
163
|
+
assert_instance_of Fixnum, row
|
164
|
+
}
|
165
|
+
|
166
|
+
# test_each_td
|
167
|
+
c.each_td(table_1x1) {|td, col, row|
|
168
|
+
assert_equal :td, td[0]
|
169
|
+
assert_instance_of Fixnum, col
|
170
|
+
assert_instance_of Fixnum, row
|
171
|
+
}
|
172
|
+
# test_add_new_col
|
173
|
+
c.add_new_col(table_1x1)
|
174
|
+
assert_equal [:table, [:tr, [:td, ''], [:td, '']]], table_1x1
|
175
|
+
|
176
|
+
# test_add_new_row
|
177
|
+
c.add_new_row(table_1x1)
|
178
|
+
assert_equal [:table, [:tr, [:td, ''], [:td, '']],
|
179
|
+
[:tr, [:td, ''], [:td, '']]],
|
180
|
+
table_1x1
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_for_schedule
|
184
|
+
table_1x1 = [:table, [:tr, [:td, '']]]
|
185
|
+
|
186
|
+
c = Qwik::WabisabiTable
|
187
|
+
|
188
|
+
c.prepare(table_1x1)
|
189
|
+
assert_equal [:table,
|
190
|
+
[:tr,
|
191
|
+
[:th, [:input, {:size=>'1', :value=>'', :name=>'t_0_0'}]],
|
192
|
+
[:th,
|
193
|
+
{:class=>'new_col'},
|
194
|
+
[:input, {:size=>'1', :value=>'', :name=>'t_1_0'}]],
|
195
|
+
[:td,
|
196
|
+
{:class=>'new_col_button'},
|
197
|
+
[:a, {:href=>'javascript:show_new_col();'}, '>>']]],
|
198
|
+
[:tr,
|
199
|
+
{:class=>'new_row'},
|
200
|
+
[:th, [:input, {:size=>'1', :value=>'', :name=>'t_0_1'}]],
|
201
|
+
[:td,
|
202
|
+
{:class=>'new_col'},
|
203
|
+
[:input, {:size=>'1', :value=>'', :name=>'t_1_1'}]]],
|
204
|
+
[:tr,
|
205
|
+
{:class=>'new_row_button_row'},
|
206
|
+
[:td,
|
207
|
+
{:class=>'new_row_button'},
|
208
|
+
[:a, {:href=>'javascript:show_new_row();'}, 'v']]]],
|
209
|
+
table_1x1
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -0,0 +1,295 @@
|
|
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.unshift '..' unless $LOAD_PATH.include? '..'
|
6
|
+
require 'qwik/wabisabi-basic'
|
7
|
+
|
8
|
+
module WabisabiTemplateModule
|
9
|
+
def deep_copy
|
10
|
+
map {|a|
|
11
|
+
a.is_a?(Array) ? a.deep_copy : a
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def prepare
|
16
|
+
h_class = {}
|
17
|
+
h_id = {}
|
18
|
+
self.each_tag {|e|
|
19
|
+
attr = self.attr
|
20
|
+
next if attr.nil?
|
21
|
+
klass = attr[:class]
|
22
|
+
h_class[klass] = self if klass
|
23
|
+
tag_id = attr[:id]
|
24
|
+
h_id[tag_id] = self if tag_id
|
25
|
+
}
|
26
|
+
@h_class = h_class
|
27
|
+
@h_id = h_id
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_to_class(klass, w)
|
31
|
+
prepare if @h_class
|
32
|
+
e = @h_class[klass]
|
33
|
+
e << w
|
34
|
+
end
|
35
|
+
|
36
|
+
def each_tag(*tags, &block)
|
37
|
+
raise 'block not given' unless block_given?
|
38
|
+
|
39
|
+
ar = []
|
40
|
+
deleted = false
|
41
|
+
self.each {|w|
|
42
|
+
if ! w.is_a?(Array)
|
43
|
+
ar << w
|
44
|
+
next
|
45
|
+
end
|
46
|
+
|
47
|
+
if tags.length == 0 || tags.include?(w[0])
|
48
|
+
y = yield(w)
|
49
|
+
|
50
|
+
if y.nil? # do nothing, go next
|
51
|
+
deleted = true
|
52
|
+
next
|
53
|
+
end
|
54
|
+
|
55
|
+
if y != w # not equal
|
56
|
+
if y.is_a?(Array) && !y[0].is_a?(Symbol)
|
57
|
+
ar += y
|
58
|
+
else
|
59
|
+
ar << y
|
60
|
+
end
|
61
|
+
next
|
62
|
+
else
|
63
|
+
# do nothing, run through
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
ar << w.each_tag(*tags, &block) # recursive
|
68
|
+
}
|
69
|
+
|
70
|
+
if ar[0].is_a?(Symbol) && deleted
|
71
|
+
num = 0
|
72
|
+
ar.each {|a|
|
73
|
+
next if a.is_a?(Symbol) || a.is_a?(Hash)
|
74
|
+
num += 1
|
75
|
+
}
|
76
|
+
if num == 0
|
77
|
+
ar << ''
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
ar
|
82
|
+
end
|
83
|
+
|
84
|
+
def clone_with(*ar)
|
85
|
+
name = self[0]
|
86
|
+
nar = [name]
|
87
|
+
|
88
|
+
offset = 1
|
89
|
+
attr = {}
|
90
|
+
while self[offset].is_a?(Hash)
|
91
|
+
attr.update(self[offset])
|
92
|
+
offset += 1
|
93
|
+
end
|
94
|
+
if 0 < attr.length
|
95
|
+
nar << attr
|
96
|
+
end
|
97
|
+
|
98
|
+
nar += self[offset...self.length].dup
|
99
|
+
ar.each {|e|
|
100
|
+
if e.is_a?(Hash)
|
101
|
+
attr.update(e)
|
102
|
+
elsif e.nil?
|
103
|
+
# do nothing
|
104
|
+
else
|
105
|
+
nar << e
|
106
|
+
end
|
107
|
+
}
|
108
|
+
nar
|
109
|
+
end
|
110
|
+
|
111
|
+
def apply(data)
|
112
|
+
self.each_tag {|e|
|
113
|
+
next e unless e[0].is_a?(Symbol)
|
114
|
+
next e unless e[1].is_a?(Hash)
|
115
|
+
attr = e[1]
|
116
|
+
eid = attr[:id]
|
117
|
+
next e if eid.nil?
|
118
|
+
eid = eid.intern
|
119
|
+
d = data[eid]
|
120
|
+
next nil if d.nil?
|
121
|
+
next e if d == true
|
122
|
+
if d.is_a? Hash
|
123
|
+
next e.clone_with(d)
|
124
|
+
elsif d.is_a? Array
|
125
|
+
next e.clone_with(d)
|
126
|
+
end
|
127
|
+
e.clone_with(d)
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
def remove_comment
|
132
|
+
self.each_tag(:"!--") {|x|
|
133
|
+
nil
|
134
|
+
}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class Array
|
139
|
+
include WabisabiTemplateModule
|
140
|
+
end
|
141
|
+
|
142
|
+
if $0 == __FILE__
|
143
|
+
require 'qwik/testunit'
|
144
|
+
$test = true
|
145
|
+
end
|
146
|
+
|
147
|
+
if defined?($test) && $test
|
148
|
+
class TestWabisabiTemplate < Test::Unit::TestCase
|
149
|
+
def test_all
|
150
|
+
# test_deep_copy
|
151
|
+
o = [:a, [:b, [:c]]]
|
152
|
+
s = o.dup # shallow copy
|
153
|
+
d = o.deep_copy
|
154
|
+
assert_equal s, o
|
155
|
+
assert_equal d, o
|
156
|
+
assert_not_equal s.object_id, o.object_id
|
157
|
+
assert_not_equal d.object_id, o.object_id
|
158
|
+
assert_equal s[0].object_id, o[0].object_id
|
159
|
+
assert_equal d[0].object_id, o[0].object_id
|
160
|
+
assert_equal s[1].object_id, o[1].object_id
|
161
|
+
assert_not_equal d[1].object_id, o[1].object_id
|
162
|
+
assert_equal s[1][1].object_id, o[1][1].object_id
|
163
|
+
assert_not_equal d[1][1].object_id, o[1][1].object_id
|
164
|
+
|
165
|
+
# test_prepare
|
166
|
+
|
167
|
+
# test_each_tag_unit
|
168
|
+
w = [:p, '']
|
169
|
+
nw = w.each_tag(:a){|ww|
|
170
|
+
[ww]
|
171
|
+
}
|
172
|
+
assert_equal [:p, ''], w
|
173
|
+
assert_equal [:p, ''], nw
|
174
|
+
|
175
|
+
w = [[:a, '']]
|
176
|
+
assert_equal [:a, ''], w[0]
|
177
|
+
nw = w.each_tag(:a){|ww|
|
178
|
+
www = ww.dup
|
179
|
+
www[-1] = 't'
|
180
|
+
www
|
181
|
+
}
|
182
|
+
assert_equal [[:a, '']], w
|
183
|
+
assert_equal [[:a, 't']], nw
|
184
|
+
|
185
|
+
# test_set_attr
|
186
|
+
e = [:a, {:href=>'t.html'}, 't']
|
187
|
+
e = e.clone_with(:href=>'s.html')
|
188
|
+
assert_equal [:a, {:href=>'s.html'}, 't'], e
|
189
|
+
e = e.clone_with('s')
|
190
|
+
assert_equal [:a, {:href=>'s.html'}, 't', 's'], e
|
191
|
+
|
192
|
+
# test_each_tag
|
193
|
+
org = [:a, [:b, [:c], [:d], [:c]]]
|
194
|
+
xml = org.each_tag(:c){|e| nil }
|
195
|
+
assert_equal [:a, [:b, [:d]]], xml
|
196
|
+
assert_equal [:a, [:b, [:d]]], xml
|
197
|
+
xml = org.each_tag(:c){|e| e }
|
198
|
+
assert_equal [:a, [:b, [:c], [:d], [:c]]], xml
|
199
|
+
xml = org.each_tag(:c){|e| [:cc] }
|
200
|
+
assert_equal [:a, [:b, [:cc], [:d], [:cc]]], xml
|
201
|
+
xml = org.each_tag(:c){|e| [:dd] }
|
202
|
+
assert_equal [:a, [:b, [:dd], [:d], [:dd]]], xml
|
203
|
+
|
204
|
+
# test_each_tag_with_clone
|
205
|
+
org = [:a, [:b, [:c], [:d], [:c]]]
|
206
|
+
xml = org.each_tag(:c){|e| e.clone_with('test1') }
|
207
|
+
assert_equal [:a, [:b, [:c, 'test1'], [:d], [:c, 'test1']]], xml
|
208
|
+
|
209
|
+
# test_clone
|
210
|
+
e = [:a, {:href=>'1.html'}, 't']
|
211
|
+
xml = e.clone_with('test1')
|
212
|
+
assert_equal [:a, {:href=>'1.html'}, 't', 'test1'], xml
|
213
|
+
xml = e.clone_with(:href=>'n.html')
|
214
|
+
assert_equal [:a, {:href=>'n.html'}, 't'], xml
|
215
|
+
|
216
|
+
# test_textarea
|
217
|
+
org = [[:textarea, '']]
|
218
|
+
xml = org.each_tag(:textarea){|e|
|
219
|
+
e.clone_with('text')
|
220
|
+
}
|
221
|
+
assert_equal [[:textarea, '', 'text']], xml
|
222
|
+
|
223
|
+
# test_textarea_apply
|
224
|
+
org = [[:textarea, {:id=>'contents'}, '']]
|
225
|
+
data = {}
|
226
|
+
data[:contents] = 'text'
|
227
|
+
xml = org.apply(data)
|
228
|
+
assert_equal [[:textarea, {:id=>'contents'}, '', 'text']], xml
|
229
|
+
|
230
|
+
# test_apply
|
231
|
+
org = [:p, [:div, {:id=>'a'}, ''], [:div, {:id=>'b'}, '']]
|
232
|
+
data = {}
|
233
|
+
data[:a] = 'a'
|
234
|
+
data[:b] = [:b]
|
235
|
+
h = org.apply(data)
|
236
|
+
assert_equal [:p, [:div, {:id=>'a'}, '', 'a'],
|
237
|
+
[:div, {:id=>'b'}, '', [:b]]], h
|
238
|
+
|
239
|
+
data = {}
|
240
|
+
data[:a] = nil
|
241
|
+
data[:b] = {:action => 'd.html'}
|
242
|
+
h = org.apply(data)
|
243
|
+
assert_equal [:p, [:div, {:action=>'d.html', :id=>'b'}, '']], h
|
244
|
+
|
245
|
+
data = {}
|
246
|
+
data[:a] = ['a', [:hr]] # OK.
|
247
|
+
data[:b] = nil
|
248
|
+
h = org.apply(data)
|
249
|
+
assert_equal [:p, [:div, {:id=>'a'}, '', ['a', [:hr]]]], h
|
250
|
+
|
251
|
+
# test_replace
|
252
|
+
h = [:a, [:b], [:c]]
|
253
|
+
h2 = h.each_tag {|e| e[0] == :c ? 'text' : e } # insert a text
|
254
|
+
assert_equal [:a, [:b], 'text'], h2
|
255
|
+
h2 = h.each_tag(:nosuch) {|e| nil } # no effect
|
256
|
+
assert_equal [:a, [:b], [:c]], h2
|
257
|
+
h2 = h.each_tag(:b) {|e| e } # no effect
|
258
|
+
assert_equal [:a, [:b], [:c]], h2
|
259
|
+
h2 = h.each_tag(:b) {|e| nil } # delete it
|
260
|
+
assert_equal [:a, [:c]], h2
|
261
|
+
h2 = h.each_tag(:b) {|e| 'text' } # insert a text
|
262
|
+
assert_equal [:a, 'text', [:c]], h2
|
263
|
+
h2 = h.each_tag(:b) {|e| [:d] } # insert a element
|
264
|
+
assert_equal [:a, [:d], [:c]], h2
|
265
|
+
h2 = h.each_tag(:b) {|e| [:d, 'text'] } # insert a element with text
|
266
|
+
assert_equal [:a, [:d, 'text'], [:c]], h2
|
267
|
+
|
268
|
+
h = [:p, [:span, {:id=>'a'}], [:span, {:id=>'b'}]]
|
269
|
+
h2 = h.each_tag(:span){|e| e.attr(:id) } # insert the id as text
|
270
|
+
assert_equal [:p, 'a', 'b'], h2
|
271
|
+
h2 = h.each_tag(:span){|e| e.attr(:id) == 'b' ? e : nil }
|
272
|
+
assert_equal [:p, [:span, {:id=>'b'}]], h2
|
273
|
+
|
274
|
+
h = [[:h2], [:h3], [:h4], [:h5], [:h6]]
|
275
|
+
h2 = h.each_tag(:h3, :h4) {|e| [e[0], e[0].to_s] } # insert a text
|
276
|
+
assert_equal [[:h2], [:h3, 'h3'], [:h4, 'h4'], [:h5], [:h6]], h2
|
277
|
+
h2 = h.each_tag {|e| e[0] == :h5 ? 'text' : e } # insert a text
|
278
|
+
assert_equal [[:h2], [:h3], [:h4], 'text', [:h6]], h2
|
279
|
+
h2 = h.each_tag(:h4) {|e| [[:h3, 'h'], [:hr]] }
|
280
|
+
assert_equal [[:h2], [:h3], [:h3, 'h'], [:hr], [:h5], [:h6]], h2
|
281
|
+
|
282
|
+
h = [[:span, '']]
|
283
|
+
h2 = h.each_tag(:span){|e| [[:h3, 'h'], [:hr]] }
|
284
|
+
assert_equal [[:h3, 'h'], [:hr]], h2
|
285
|
+
h2 = h.each_tag(:span){|e|
|
286
|
+
[[:h3, 'h3'], [:ul, [:li, [:a, {:href=>'1.html'}, '1']]]]
|
287
|
+
}
|
288
|
+
assert_equal [[:h3, 'h3'], [:ul, [:li, [:a, {:href=>'1.html'}, '1']]]],
|
289
|
+
h2
|
290
|
+
|
291
|
+
# test_remove_comment
|
292
|
+
assert_equal [:p, 'a', 'c'], [:p, 'a', [:"!--", 'b'], 'c'].remove_comment
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|