tiddlywiki_cp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +674 -0
- data/History.txt +4 -0
- data/Manifest.txt +68 -0
- data/README.txt +3 -0
- data/Rakefile +123 -0
- data/bin/tiddlywiki_cp +13 -0
- data/lib/tiddlywiki_cp/converters.rb +36 -0
- data/lib/tiddlywiki_cp/file2file.rb +32 -0
- data/lib/tiddlywiki_cp/file2tiddler.rb +42 -0
- data/lib/tiddlywiki_cp/r4tw.rb +763 -0
- data/lib/tiddlywiki_cp/tiddler2directory.rb +27 -0
- data/lib/tiddlywiki_cp/tiddler2file.rb +41 -0
- data/lib/tiddlywiki_cp/tiddler2tiddlywiki.rb +29 -0
- data/lib/tiddlywiki_cp/tiddler_css.rb +39 -0
- data/lib/tiddlywiki_cp/tiddler_html.rb +39 -0
- data/lib/tiddlywiki_cp/tiddler_js.rb +39 -0
- data/lib/tiddlywiki_cp/tiddlywiki2file.rb +29 -0
- data/lib/tiddlywiki_cp/version.rb +24 -0
- data/lib/tiddlywiki_cp.rb +378 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/test/content/a +0 -0
- data/test/content/a.div +0 -0
- data/test/content/b +0 -0
- data/test/content/e +3 -0
- data/test/content/e.div +1 -0
- data/test/content/html_entities.html +6 -0
- data/test/content/test_fetch.html +6 -0
- data/test/content/universe.html +10522 -0
- data/test/r4tw/addtag.rb +93 -0
- data/test/r4tw/all.rb +29 -0
- data/test/r4tw/createfrom.rb +62 -0
- data/test/r4tw/empties/2.1.3.html +7087 -0
- data/test/r4tw/empties/2.2.0.beta5.html +8726 -0
- data/test/r4tw/fromremote.rb +19 -0
- data/test/r4tw/fromurl.rb +28 -0
- data/test/r4tw/shadows.rb +27 -0
- data/test/r4tw/tiddler.rb +70 -0
- data/test/r4tw/tiddlerfromurl.rb +23 -0
- data/test/r4tw/tiddlywiki.rb +66 -0
- data/test/r4tw/utils.rb +55 -0
- data/test/r4tw/withcontent/2.2.0.beta5.html +8739 -0
- data/test/r4tw/withcontent/22b5index.html +13523 -0
- data/test/r4tw/withcontent/empty2.html +7084 -0
- data/test/r4tw/withcontent/nothing.js +1 -0
- data/test/r4tw/write_all_tiddlers_to.rb +62 -0
- data/test/test_all.rb +8 -0
- data/test/test_helper.rb +36 -0
- data/test/test_tiddler_css.rb +55 -0
- data/test/test_tiddler_html.rb +54 -0
- data/test/test_tiddler_js.rb +56 -0
- data/test/test_tiddlywiki_cp.rb +341 -0
- data/website/files/DefaultTiddlers.tiddler +2 -0
- data/website/files/DefaultTiddlers.tiddler.div +1 -0
- data/website/files/Introduction.tiddler +12 -0
- data/website/files/Introduction.tiddler.div +1 -0
- data/website/files/MainMenu.tiddler +1 -0
- data/website/files/MainMenu.tiddler.div +1 -0
- data/website/files/SiteSubtitle.tiddler +1 -0
- data/website/files/SiteSubtitle.tiddler.div +1 -0
- data/website/files/SiteTitle.tiddler +1 -0
- data/website/files/SiteTitle.tiddler.div +1 -0
- data/website/files/Usage.tiddler +55 -0
- data/website/files/Usage.tiddler.div +1 -0
- data/website/files/WebDAVSavingPlugin.js +234 -0
- data/website/files/WebDAVSavingPlugin.js.div +1 -0
- data/website/index.html +9144 -0
- data/website/index.xml +336 -0
- metadata +116 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
module TiddlywikiCp
|
18
|
+
|
19
|
+
class TiddlyWikiCp
|
20
|
+
|
21
|
+
def tiddler2directory(from, to)
|
22
|
+
tiddler2file(from, TiddlyWikiCp.tiddler2filename(to, from) + ".tiddler")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
module TiddlywikiCp
|
18
|
+
|
19
|
+
class TiddlyWikiCp
|
20
|
+
|
21
|
+
def tiddler2file(from, to)
|
22
|
+
tiddler = uri2tiddlywiki(from).get_tiddler(from.split('#')[1])
|
23
|
+
if to == '-'
|
24
|
+
puts tiddler.text
|
25
|
+
else
|
26
|
+
fields_string = tiddler.to_fields_string(true)
|
27
|
+
fields_string.join(' ').to_file("#{to}.div")
|
28
|
+
tiddler.text.to_file(to)
|
29
|
+
if @options.times
|
30
|
+
if tiddler.modified
|
31
|
+
modified = Time.convertFromYYYYMMDDHHMM(tiddler.modified)
|
32
|
+
File.utime(modified, modified, to)
|
33
|
+
File.utime(modified, modified, "#{to}.div")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
module TiddlywikiCp
|
18
|
+
|
19
|
+
class TiddlyWikiCp
|
20
|
+
|
21
|
+
def tiddler2tiddlywiki(from, to)
|
22
|
+
tiddler = uri2tiddlywiki(from).get_tiddler(from.split('#')[1])
|
23
|
+
tiddlywiki = uri2tiddlywiki(to)
|
24
|
+
tiddlywiki.add_tiddler(tiddler)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
module TiddlywikiCp
|
18
|
+
|
19
|
+
class TiddlyWikiCp
|
20
|
+
|
21
|
+
TIDDLER_CSS = 'css'
|
22
|
+
|
23
|
+
def tiddler_css?(tiddler) #:nodoc:
|
24
|
+
tiddler.name =~ /(StyleSheet|Styles)/ && TIDDLER_CSS
|
25
|
+
end
|
26
|
+
|
27
|
+
def css2directory(from, to)
|
28
|
+
tiddler2file(from, TiddlyWikiCp.tiddler2filename(to, from) + ".css")
|
29
|
+
end
|
30
|
+
|
31
|
+
alias css2file tiddler2file
|
32
|
+
|
33
|
+
alias css2tiddlywiki tiddler2tiddlywiki
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
module TiddlywikiCp
|
18
|
+
|
19
|
+
class TiddlyWikiCp
|
20
|
+
|
21
|
+
TIDDLER_HTML = 'html'
|
22
|
+
|
23
|
+
def tiddler_html?(tiddler) #:nodoc:
|
24
|
+
tiddler.name =~ /Template/ && TIDDLER_HTML
|
25
|
+
end
|
26
|
+
|
27
|
+
def html2directory(from, to)
|
28
|
+
tiddler2file(from, TiddlyWikiCp.tiddler2filename(to, from) + ".html")
|
29
|
+
end
|
30
|
+
|
31
|
+
alias html2file tiddler2file
|
32
|
+
|
33
|
+
alias html2tiddlywiki tiddler2tiddlywiki
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
module TiddlywikiCp
|
18
|
+
|
19
|
+
class TiddlyWikiCp
|
20
|
+
|
21
|
+
TIDDLER_JS = 'js'
|
22
|
+
|
23
|
+
def tiddler_js?(tiddler) #:nodoc:
|
24
|
+
tiddler.tags && tiddler.tags.include?("systemConfig") && TIDDLER_JS
|
25
|
+
end
|
26
|
+
|
27
|
+
def js2directory(from, to)
|
28
|
+
tiddler2file(from, TiddlyWikiCp.tiddler2filename(to, from) + ".js")
|
29
|
+
end
|
30
|
+
|
31
|
+
alias js2file tiddler2file
|
32
|
+
|
33
|
+
alias js2tiddlywiki tiddler2tiddlywiki
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
require 'fileutils'
|
18
|
+
|
19
|
+
module TiddlywikiCp
|
20
|
+
|
21
|
+
class TiddlyWikiCp
|
22
|
+
|
23
|
+
def tiddlywiki2file(from, to)
|
24
|
+
write_uri(to, read_uri(from))
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
#
|
16
|
+
module TiddlywikiCp #:nodoc:
|
17
|
+
module VERSION #:nodoc:
|
18
|
+
MAJOR = 0
|
19
|
+
MINOR = 0
|
20
|
+
TINY = 1
|
21
|
+
|
22
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,378 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
require 'tiddlywiki_cp/r4tw'
|
18
|
+
require 'tiddlywiki_cp/version'
|
19
|
+
require 'tiddlywiki_cp/converters'
|
20
|
+
require 'optparse'
|
21
|
+
require 'ostruct'
|
22
|
+
require 'open-uri'
|
23
|
+
require 'find'
|
24
|
+
|
25
|
+
module TiddlywikiCp
|
26
|
+
|
27
|
+
class TiddlyWikiCp
|
28
|
+
|
29
|
+
CONTAINER_DIRECTORY = 'directory'
|
30
|
+
CONTAINER_FILE = 'file'
|
31
|
+
CONTAINER_TIDDLYWIKI = 'tiddlywiki'
|
32
|
+
CONTAINER_TIDDLER = 'tiddler'
|
33
|
+
|
34
|
+
TIDDLER_DEFAULT = CONTAINER_TIDDLER
|
35
|
+
|
36
|
+
attr_reader :file_cache
|
37
|
+
attr_reader :tiddlywiki_cache
|
38
|
+
attr_accessor :options
|
39
|
+
|
40
|
+
def initialize(*args)
|
41
|
+
reset
|
42
|
+
end
|
43
|
+
|
44
|
+
def reset() #:nodoc:
|
45
|
+
@file_cache = {}
|
46
|
+
@tiddlywiki_cache = {}
|
47
|
+
|
48
|
+
@options = OpenStruct.new
|
49
|
+
@options.verbose = false
|
50
|
+
@options.times = false
|
51
|
+
@options.recursive = false
|
52
|
+
@options.dry_run = false
|
53
|
+
@options.includes = []
|
54
|
+
@options.excludes = []
|
55
|
+
@options.ignores = ['^\.(hg|svn)$', '(#|~|.div)$']
|
56
|
+
end
|
57
|
+
|
58
|
+
def main(argv) #:nodoc:
|
59
|
+
args = argv.clone
|
60
|
+
if parse!(args)
|
61
|
+
run(args)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse!(argv) #:nodoc:
|
66
|
+
reset
|
67
|
+
cmd = File.basename($0, '.*')
|
68
|
+
|
69
|
+
opts = OptionParser.new do |opts|
|
70
|
+
|
71
|
+
opts.banner = "Usage: #{cmd} [options] FROM [FROM ...] TO|-"
|
72
|
+
|
73
|
+
opts.separator ""
|
74
|
+
|
75
|
+
opts.on("-r", "--[no-]recursive",
|
76
|
+
"recurse into directories and tiddlywikies") do |v|
|
77
|
+
@options.recursive = v
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on("-t", "--[no-]times",
|
81
|
+
"preserve modification time") do |v|
|
82
|
+
@options.times = v
|
83
|
+
end
|
84
|
+
|
85
|
+
opts.on("-a", "--all",
|
86
|
+
"implies -rt") do
|
87
|
+
@options.times = true
|
88
|
+
@options.recursive = true
|
89
|
+
end
|
90
|
+
|
91
|
+
opts.on("-i", "--include REGEX",
|
92
|
+
"all files,directories or tiddlers must match regex.",
|
93
|
+
" If specified multiple times, ",
|
94
|
+
" must match at least one of the regex.",
|
95
|
+
" Includes are tested after excludes.") do |regex|
|
96
|
+
@options.includes.push(regex)
|
97
|
+
end
|
98
|
+
|
99
|
+
opts.on("--exclude REGEX",
|
100
|
+
"all files,directories or tiddlers must NOT match regex.",
|
101
|
+
" If specified multiple times, ",
|
102
|
+
" exclude if matches at least one of the regex.",
|
103
|
+
" Includes are tested after excludes.") do |regex|
|
104
|
+
@options.excludes.push(regex)
|
105
|
+
end
|
106
|
+
|
107
|
+
opts.on("-v", "--[no-]verbose", "run verbosely") do |v|
|
108
|
+
@options.verbose = v
|
109
|
+
end
|
110
|
+
|
111
|
+
opts.on("-n", "--[no-]dry-run", "show what would have been transferred") do |v|
|
112
|
+
@options.dry_run = v
|
113
|
+
end
|
114
|
+
|
115
|
+
opts.on("--version", "show version") do
|
116
|
+
puts VERSION::STRING
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
|
120
|
+
opts.on("--help", "show command usage") do
|
121
|
+
puts opts.help
|
122
|
+
return false
|
123
|
+
end
|
124
|
+
|
125
|
+
opts.separator ""
|
126
|
+
opts.separator "Examples:"
|
127
|
+
opts.separator ""
|
128
|
+
opts.separator " mkdir /tmp/a ; #{cmd} -a http://tiddlywiki.com/index.html /tmp/a"
|
129
|
+
opts.separator " copies index.html tiddlers in separate files and preserve times."
|
130
|
+
opts.separator " For each tiddler, a .div file contains the meta information."
|
131
|
+
opts.separator " The files are named after their content:"
|
132
|
+
opts.separator " /tmp/a/HelloThere.tiddler"
|
133
|
+
opts.separator " /tmp/a/HelloThere.tiddler.div"
|
134
|
+
opts.separator " /tmp/a/Plugin.js"
|
135
|
+
opts.separator " /tmp/a/Plugin.js.div"
|
136
|
+
opts.separator " /tmp/a/OwnStyle.css"
|
137
|
+
opts.separator " /tmp/a/OwnStyle.css.div"
|
138
|
+
opts.separator " ..."
|
139
|
+
opts.separator ""
|
140
|
+
opts.separator " #{cmd} 'http://tiddlylab.bidix.info/#WebDAVSavingPlugin' tiddlywiki.html"
|
141
|
+
opts.separator " copies the WebDAVSavingPlugin tiddler in the existing tiddlywiki.html"
|
142
|
+
opts.separator ""
|
143
|
+
opts.separator " #{cmd} http://tiddlywiki.com/index.html /tmp/i.html"
|
144
|
+
opts.separator " copies to a local file "
|
145
|
+
opts.separator ""
|
146
|
+
opts.separator " #{cmd} -t myplugin.js tiddlywiki.html"
|
147
|
+
opts.separator " copies the tiddler in the existing tiddlywiki.html tiddlywiki"
|
148
|
+
opts.separator " and use file system modification time"
|
149
|
+
opts.separator ""
|
150
|
+
opts.separator " #{cmd} 'http://tiddlylab.bidix.info/#WebDAVSavingPlugin' WebDAVSavingPlugin.js"
|
151
|
+
opts.separator " get a local copy of the WebDAVSavingPlugin tiddler"
|
152
|
+
opts.separator ""
|
153
|
+
opts.separator " mkdir A ; #{cmd} -a --include 'WebDAV' --include 'RSS' 'http://tiddlylab.bidix.info/' A"
|
154
|
+
opts.separator " copy all tiddlers with WebDAV or RSS in the url"
|
155
|
+
opts.separator ""
|
156
|
+
opts.separator " mkdir A ; #{cmd} -a --exclude 'SEX' 'http://tiddlylab.bidix.info/' A"
|
157
|
+
opts.separator " copy all tiddlers except those with SEX in the url"
|
158
|
+
opts.separator ""
|
159
|
+
opts.separator " #{cmd} -a A B C tiddlywiki.html"
|
160
|
+
opts.separator " copy all tiddlers found in the A B and C directories to tiddlywiki.html"
|
161
|
+
|
162
|
+
end
|
163
|
+
opts.parse!(argv)
|
164
|
+
return @options
|
165
|
+
end # parse()
|
166
|
+
|
167
|
+
def run(args) #:nodoc:
|
168
|
+
if args.length < 2
|
169
|
+
raise "need at least two arguments"
|
170
|
+
end
|
171
|
+
|
172
|
+
to = args.pop
|
173
|
+
to_container = uri2container(to)
|
174
|
+
to_type = uri2type(to)
|
175
|
+
|
176
|
+
from = args2from(args, @options.recursive)
|
177
|
+
#
|
178
|
+
# more than 2 args but really only 1 because of the pop above
|
179
|
+
#
|
180
|
+
if from.length > 1 && to_container != CONTAINER_TIDDLYWIKI && to_container != CONTAINER_DIRECTORY
|
181
|
+
raise "the destination must be a tiddlywiki or a directory when more than two arguments are given (from = \n" + from.join("\n")
|
182
|
+
end
|
183
|
+
|
184
|
+
from.each { |from|
|
185
|
+
from_type = uri2type(from)
|
186
|
+
method = "#{from_type}2#{to_type}"
|
187
|
+
if @options.dry_run or @options.verbose
|
188
|
+
puts "copy '#{from}' '#{to}'"
|
189
|
+
end
|
190
|
+
if ! @options.dry_run
|
191
|
+
self.send(method.intern, from, to)
|
192
|
+
end
|
193
|
+
}
|
194
|
+
|
195
|
+
#
|
196
|
+
# sync the tiddlywiki destination file system when done
|
197
|
+
#
|
198
|
+
if to_container == CONTAINER_TIDDLYWIKI || to_container == CONTAINER_TIDDLER
|
199
|
+
uri2tiddlywiki(to).to_file(TiddlyWikiCp.without_fragment(to))
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
def args2from(args, recursive) #:nodoc:
|
205
|
+
new_args = []
|
206
|
+
if recursive
|
207
|
+
Find.find(*args) { |uri|
|
208
|
+
if File.exists?(uri) && File.ftype(uri) == 'directory'
|
209
|
+
next
|
210
|
+
end
|
211
|
+
|
212
|
+
if ignore?(uri)
|
213
|
+
next
|
214
|
+
end
|
215
|
+
|
216
|
+
case uri2container(uri)
|
217
|
+
when CONTAINER_FILE
|
218
|
+
if File.exists?(uri)
|
219
|
+
if File.exists?("#{uri}.div")
|
220
|
+
new_args.push(uri)
|
221
|
+
else
|
222
|
+
raise Errno::ENOENT, "#{uri}.div"
|
223
|
+
end
|
224
|
+
else
|
225
|
+
raise Errno::ENOENT, "#{uri}"
|
226
|
+
end
|
227
|
+
|
228
|
+
when CONTAINER_TIDDLYWIKI
|
229
|
+
new_args += uri2tiddlywiki(uri).tiddlers.map{|t| uri + "#" + t.name.gsub('/', '%2F')}
|
230
|
+
|
231
|
+
when CONTAINER_TIDDLER
|
232
|
+
new_args.push(uri)
|
233
|
+
end
|
234
|
+
}
|
235
|
+
else
|
236
|
+
args.each do |uri|
|
237
|
+
case uri2container(uri)
|
238
|
+
when CONTAINER_FILE
|
239
|
+
if File.exists?(uri)
|
240
|
+
if File.exists?("#{uri}.div")
|
241
|
+
new_args.push(uri)
|
242
|
+
else
|
243
|
+
raise Errno::ENOENT, "#{uri}.div"
|
244
|
+
end
|
245
|
+
else
|
246
|
+
raise Errno::ENOENT, "#{uri}"
|
247
|
+
end
|
248
|
+
|
249
|
+
when CONTAINER_TIDDLYWIKI
|
250
|
+
new_args.push(uri)
|
251
|
+
|
252
|
+
when CONTAINER_TIDDLER
|
253
|
+
new_args.push(uri)
|
254
|
+
|
255
|
+
when CONTAINER_DIRECTORY
|
256
|
+
raise "#{uri} is a directory"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
new_args.reject! { |uri| ! accept?(uri) }
|
262
|
+
return new_args
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
def uri2type(uri) #:nodoc:
|
267
|
+
type = uri2container(uri)
|
268
|
+
if type == CONTAINER_TIDDLER
|
269
|
+
print "uri2type '#{uri}' " if @options.verbose
|
270
|
+
fragment = uri.split('#')[1]
|
271
|
+
tiddler = uri2tiddlywiki(uri).get_tiddler(fragment)
|
272
|
+
predicates = methods.select{ |m| m =~ /^tiddler_.*?/ }.sort
|
273
|
+
predicates.each do |p|
|
274
|
+
got_type = self.send(p.intern, tiddler)
|
275
|
+
if got_type
|
276
|
+
type = got_type
|
277
|
+
break
|
278
|
+
else
|
279
|
+
print "." if @options.verbose
|
280
|
+
end
|
281
|
+
end
|
282
|
+
print " #{type}\n" if @options.verbose
|
283
|
+
end
|
284
|
+
return type
|
285
|
+
end
|
286
|
+
|
287
|
+
def uri2container(uri) #:nodoc:
|
288
|
+
begin
|
289
|
+
if File.exists?(uri) && File.ftype(uri) == 'directory'
|
290
|
+
uri_container = CONTAINER_DIRECTORY
|
291
|
+
elsif tiddlywiki? uri
|
292
|
+
if TiddlyWikiCp.tiddler_uri? uri
|
293
|
+
uri_container = CONTAINER_TIDDLER
|
294
|
+
else
|
295
|
+
uri_container = CONTAINER_TIDDLYWIKI
|
296
|
+
end
|
297
|
+
else
|
298
|
+
uri_container = CONTAINER_FILE
|
299
|
+
end
|
300
|
+
rescue OpenURI::HTTPError, Errno::ECONNREFUSED, Errno::ENOENT
|
301
|
+
uri_container = CONTAINER_FILE
|
302
|
+
end
|
303
|
+
print "uri2container '#{uri}' -> #{uri_container}\n" if @options.verbose
|
304
|
+
return uri_container
|
305
|
+
end
|
306
|
+
|
307
|
+
def ignore?(uri)
|
308
|
+
@options.ignores.each do |regex|
|
309
|
+
return true if uri.match(regex)
|
310
|
+
end
|
311
|
+
return false
|
312
|
+
end
|
313
|
+
|
314
|
+
def accept?(uri)
|
315
|
+
@options.excludes.each do |regex|
|
316
|
+
return false if uri.match(regex)
|
317
|
+
end
|
318
|
+
if @options.includes.length > 0
|
319
|
+
@options.includes.each do |regex|
|
320
|
+
return true if uri.match(regex)
|
321
|
+
end
|
322
|
+
return false
|
323
|
+
else
|
324
|
+
return true
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def self.tiddler2filename(directory, uri) #:nodoc:
|
329
|
+
fragment = uri.split('#')[1]
|
330
|
+
if ! fragment
|
331
|
+
raise "missing fragment in #{uri}"
|
332
|
+
end
|
333
|
+
return Pathname.new(directory).join(fragment.gsub('/', '%2F')).to_s
|
334
|
+
end
|
335
|
+
|
336
|
+
def uri2tiddlywiki(uri) #:nodoc:
|
337
|
+
uri = TiddlyWikiCp.without_fragment(uri)
|
338
|
+
if ! @tiddlywiki_cache.has_key?(uri)
|
339
|
+
@tiddlywiki_cache[uri] = TiddlyWiki.new.source_empty(uri)
|
340
|
+
end
|
341
|
+
return @tiddlywiki_cache[uri]
|
342
|
+
end
|
343
|
+
|
344
|
+
def read_uri(uri) #:nodoc:
|
345
|
+
uri = TiddlyWikiCp.without_fragment(uri)
|
346
|
+
|
347
|
+
if ! @file_cache.has_key?(uri)
|
348
|
+
@tiddlywiki_cache.delete(uri)
|
349
|
+
@file_cache[uri] = open(uri).read
|
350
|
+
end
|
351
|
+
return @file_cache[uri]
|
352
|
+
end
|
353
|
+
|
354
|
+
def write_uri(uri, content) #:nodoc:
|
355
|
+
uri = TiddlyWikiCp.without_fragment(uri)
|
356
|
+
@tiddlywiki_cache.delete(uri)
|
357
|
+
|
358
|
+
@file_cache[uri] = content
|
359
|
+
fd = open(uri, "w")
|
360
|
+
fd.write(content)
|
361
|
+
fd.close()
|
362
|
+
end
|
363
|
+
|
364
|
+
def self.without_fragment(uri) #:nodoc:
|
365
|
+
uri.gsub(/#.*/, '')
|
366
|
+
end
|
367
|
+
|
368
|
+
def self.tiddler_uri?(uri) #:nodoc:
|
369
|
+
return uri.include?('#')
|
370
|
+
end
|
371
|
+
|
372
|
+
def tiddlywiki?(uri) #:nodoc:
|
373
|
+
return read_uri(uri) =~ /var version = \{title: "TiddlyWiki"/
|
374
|
+
end # tiddlywiki?
|
375
|
+
|
376
|
+
end # TiddlyWikiCp
|
377
|
+
|
378
|
+
end
|