tiddlywiki_cp 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.5.1 2008-04-07
2
+
3
+ * Apply Markup tiddlers.
4
+
5
+ * Save / restore lang attribute.
6
+
1
7
  == 0.4.1 2008-03-30
2
8
 
3
9
  * 1 major bug fix:
data/Manifest.txt CHANGED
@@ -30,6 +30,7 @@ test/content/ignored#
30
30
  test/content/test_fetch.html
31
31
  test/content/tiddly_version_2_1.txt
32
32
  test/content/tiddly_version_2_2.txt
33
+ test/content/tiddly_version_2_3.txt
33
34
  test/content/universe.html
34
35
  test/r4tw/addtag.rb
35
36
  test/r4tw/all.rb
@@ -68,7 +69,7 @@ website/files/SiteTitle.tiddler
68
69
  website/files/SiteTitle.tiddler.div
69
70
  website/files/Usage.tiddler
70
71
  website/files/Usage.tiddler.div
71
- website/files/WebDAVSavingPlugin.js
72
- website/files/WebDAVSavingPlugin.js.div
72
+ website/files/WebDavPlugin.js
73
+ website/files/WebDavPlugin.js.div
73
74
  website/index.html
74
75
  website/index.xml
data/README.txt CHANGED
@@ -1,3 +1,7 @@
1
1
  README for tiddlywiki_cp
2
2
  ========================
3
3
 
4
+ a ruby gem (http://rubyforge.org/projects/tiddlywikicp/) providing a
5
+ library and a command line interface to copy tiddlywiki tiddlers to
6
+ files and vice versa.
7
+
data/Rakefile CHANGED
@@ -83,6 +83,7 @@ desc 'Generate website files'
83
83
  task :website_generate do
84
84
  sh %{ ( echo '{{{' ; RUBYLIB=lib ruby bin/tiddlywiki_cp --help ; echo '}}}' ) > website/files/Usage.tiddler }
85
85
  sh %{ ( echo '{{{' ; hg log ; echo '}}}' ) > website/files/ChangeLog.tiddler }
86
+ sh %{ cd website ; RUBYLIB=../lib ruby ../bin/tiddlywiki_cp -a files index.html }
86
87
  end
87
88
 
88
89
  desc 'Upload website files to rubyforge'
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # =r4tw
3
3
  # Author:: Simon Baird
4
+ # Copyright (C) 2008 Loic Dachary <loic@dachary.org>
4
5
  # URL:: http://simonbaird.com/r4tw
5
6
  # License:: http://en.wikipedia.org/wiki/MIT_license
6
7
  # r4tw is some ruby classes for manipuating TiddlyWikis and tiddlers.
@@ -129,7 +130,7 @@ class Tiddler
129
130
  '.js' => %[systemConfig],
130
131
  '.html' => %[html],
131
132
  '.css' => %[css],
132
- '.pub' => %[contentPublisher],
133
+ '.pub' => %[systemServer],
133
134
  '.palette' => %[palette],
134
135
  }
135
136
 
@@ -465,13 +466,23 @@ end
465
466
 
466
467
  class TiddlyWiki
467
468
 
468
- attr_accessor :orig_tiddlers, :tiddlers, :raw
469
+ TIDDLER2MARKUP = {
470
+ 'MarkupPreHead' => 'PRE-HEAD',
471
+ 'MarkupPostHead' => 'POST-HEAD',
472
+ 'MarkupPreBody' => 'PRE-BODY',
473
+ 'MarkupPostBody' => 'POST-BODY',
474
+ }
475
+
476
+ @@lang_re = /<html(.*?)\s+xml:lang=['"](\w\w)['"]\s+lang=['"](\w\w)['"]/ms
477
+
478
+ attr_accessor :orig_tiddlers, :tiddlers, :raw, :lang
469
479
 
470
480
  # doesn't do much. probably should allow an empty file param
471
481
  def initialize(use_pre=false)
472
482
  @use_pre = use_pre
473
483
  @tiddlers = []
474
484
  @core_hacks = []
485
+ @lang = 'en'
475
486
  end
476
487
 
477
488
  # this should replace all the add_tiddler_from_blah methods
@@ -490,6 +501,46 @@ class TiddlyWiki
490
501
  end
491
502
  end
492
503
 
504
+ def locale2lang(raw)
505
+ #
506
+ # Inspect systemConfig tiddlers, looking for locale settings
507
+ #
508
+ locale_set_re = /config.locale\s*=/s
509
+ locale_re = /config.locale\s*=\s*['"](\w\w)['"]/ms
510
+ lang = @lang
511
+ @tiddlers.each do |t|
512
+ if t.has_tag('systemConfig')
513
+ text = t.fields['text']
514
+ if text =~ locale_set_re
515
+ matches = text.match(locale_re)
516
+ if matches
517
+ lang = matches[1];
518
+ else
519
+ raise "#{locale_set_re} matches but #{locale_re} does not in #{text}"
520
+ end
521
+ end
522
+ end
523
+ end
524
+ if lang != @lang
525
+ raw.gsub!(@@lang_re, "<html\\1 xml:lang=\"#{lang}\" lang=\"#{lang}\"")
526
+ @lang = lang
527
+ end
528
+ return raw
529
+ end
530
+
531
+ def lang_from_raw()
532
+ matches = @raw.match(@@lang_re)
533
+ if matches
534
+ if matches[2] == matches[3]
535
+ @lang = matches[2]
536
+ else
537
+ raise "#{re} found '#{matches[2]}' and '#{matches[3]}' and expected them to be equal"
538
+ end
539
+ else
540
+ raise "#{re} found no match in ${@raw}"
541
+ end
542
+ end
543
+
493
544
  # initialise a TiddlyWiki from a source file
494
545
  # will treat empty_file as a url if it looks like one
495
546
  # note that it doesn't have to be literally empty
@@ -666,13 +717,27 @@ class TiddlyWiki
666
717
 
667
718
  # output the TiddlyWiki file
668
719
  def to_s
720
+ #
721
+ # Each Markup* tiddler must be copied to the corresponding <!-- .. -START -->
722
+ # section. It will be copied by the regular tiddlywiki save function, but
723
+ # it requires manual intervention.
724
+ #
725
+ @tiddlers.each do |t|
726
+ if TIDDLER2MARKUP[t.name]
727
+ markup = TIDDLER2MARKUP[t.name]
728
+ mstart = "<!--" + markup + "-START-->"
729
+ mend = "<!--" + markup + "-END-->"
730
+ add_core_hack(/#{mstart}.*#{mend}/m, "#{mstart}\n#{t.fields['text']}\n#{mend}")
731
+ end
732
+ end
669
733
  pre_store_hacked = pre_store
670
734
  post_store_hacked = post_store
671
735
  @core_hacks.each do |hack|
672
736
  pre_store_hacked.gsub!(hack[0],hack[1])
673
737
  post_store_hacked.gsub!(hack[0],hack[1])
674
738
  end
675
- "#{pre_store_hacked}#{store_to_s}#{post_store_hacked}"
739
+ all = "#{pre_store_hacked}#{store_to_s}#{post_store_hacked}"
740
+ return locale2lang(all)
676
741
  end
677
742
 
678
743
  # output just the contents of the store
@@ -16,7 +16,7 @@
16
16
  module TiddlywikiCp #:nodoc:
17
17
  module VERSION #:nodoc:
18
18
  MAJOR = 0
19
- MINOR = 4
19
+ MINOR = 5
20
20
  TINY = 1
21
21
 
22
22
  STRING = [MAJOR, MINOR, TINY].join('.')
data/lib/tiddlywiki_cp.rb CHANGED
@@ -158,6 +158,20 @@ module TiddlywikiCp
158
158
  opts.separator ""
159
159
  opts.separator " #{cmd} -a A B C tiddlywiki.html"
160
160
  opts.separator " copy all tiddlers found in the A B and C directories to tiddlywiki.html"
161
+ opts.separator ""
162
+ opts.separator "MarkupPreHead, MarkupPostHead, MarkupPreBody, MarkupPostBody tiddlers:"
163
+ opts.separator ""
164
+ opts.separator " When copying to a tiddlywiki file, the content of these tiddlers "
165
+ opts.separator " are copied to the corresponding HTML zones."
166
+ opts.separator ""
167
+ opts.separator "translations, i18n, l10n, linguo:"
168
+ opts.separator ""
169
+ opts.separator " If a translation plugin such as the one found at "
170
+ opts.separator " http://trac.tiddlywiki.org/wiki/Translations"
171
+ opts.separator " is present, the tiddlywiki to which tiddlers are copied"
172
+ opts.separator " will have its lang and xml:lang attributes updated."
173
+ opts.separator " Saving the tiddlywiki manually does the same."
174
+ opts.separator ""
161
175
 
162
176
  end
163
177
  opts.parse!(argv)
@@ -347,6 +361,7 @@ module TiddlywikiCp
347
361
  tiddlywiki.raw = read_uri(uri)
348
362
  tiddlywiki.instance_eval do
349
363
  use_pre_from_raw
364
+ lang_from_raw
350
365
  @tiddlers = tiddlywiki.tiddler_divs.map do |tiddler_div|
351
366
  Tiddler.new.from_div(tiddler_div, @use_pre)
352
367
  end
@@ -0,0 +1 @@
1
+ var version = {title: "TiddlyWiki", major: 2, minor: 3, revision: 0, date: new Date("Dec 4, 2007"), extensions: {}};
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2007 Loic Dachary <loic@dachary.org>
2
+ # Copyright (C) 2007, 2008 Loic Dachary <loic@dachary.org>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -35,6 +35,60 @@ end
35
35
  class TestTiddlywikiCp < Test::Unit::TestCase
36
36
  include TiddlyBase
37
37
 
38
+ def test_lang_from_raw
39
+ r = TiddlyWiki.new
40
+ assert_equal('en', r.lang)
41
+ #
42
+ # The regexp does not match
43
+ #
44
+ r.raw = ''
45
+ exception = assert_raise RuntimeError do
46
+ r.lang_from_raw
47
+ end
48
+ assert_match(/no match/, exception.message)
49
+ #
50
+ # lang are inconsistent
51
+ #
52
+ r.raw = '<html xml:lang="en" lang="fr"'
53
+ exception = assert_raise RuntimeError do
54
+ r.lang_from_raw
55
+ end
56
+ assert_match(/'en' and 'fr'/, exception.message)
57
+ #
58
+ # success
59
+ #
60
+ r.raw = '<html xml:lang="fr" lang="fr"'
61
+ r.lang_from_raw
62
+ assert_equal('fr', r.lang)
63
+ end
64
+
65
+ def test_locale2lang
66
+ r = TiddlyWiki.new
67
+ r.add_tiddler_from({ 'tiddler' => 'fakefrench',
68
+ 'tags' => ['systemConfig'],
69
+ 'text' => 'config.locale = "fr"' })
70
+ raw = r.locale2lang('<html a="f" xml:lang="en" lang="en" ')
71
+ assert_match(/a="f" xml:lang="fr" lang="fr"/, raw)
72
+ #
73
+ # weird config.locale throw exceptions
74
+ #
75
+ r.get_tiddler('fakefrench').fields['text'] = 'config.locale = "f" + "r"';
76
+ exception = assert_raise RuntimeError do
77
+ r.locale2lang('')
78
+ end
79
+ assert_match(/matches but/, exception.message)
80
+ end
81
+
82
+ def test_locale
83
+ t = TiddlyWikiCp.new
84
+ uri = "#{this_dir(__FILE__)}/content/universe.html"
85
+ tw = t.uri2tiddlywiki("#{uri}")
86
+ tw.add_tiddler_from({ 'tiddler' => 'fakefrench',
87
+ 'tags' => ['systemConfig'],
88
+ 'text' => 'config.locale = "fr"' })
89
+ assert_match(/lang="fr"/s, tw.to_s)
90
+ end
91
+
38
92
  def test_main
39
93
  t = TiddlyWikiCp.new
40
94
  a = "#{this_dir(__FILE__)}/content/a" # existing file without .div
@@ -311,6 +365,7 @@ class TestTiddlywikiCp < Test::Unit::TestCase
311
365
 
312
366
  def test_tiddlywiki?
313
367
  t = TiddlyWikiCp.new
368
+ assert(t.tiddlywiki?("#{this_dir(__FILE__)}/content/tiddly_version_2_3.txt"))
314
369
  assert(t.tiddlywiki?("#{this_dir(__FILE__)}/content/tiddly_version_2_2.txt"))
315
370
  assert(t.tiddlywiki?("#{this_dir(__FILE__)}/content/tiddly_version_2_1.txt"))
316
371
  assert_equal(nil, t.tiddlywiki?("#{this_dir(__FILE__)}/content/html_entities.html"))
@@ -355,12 +410,23 @@ class TestTiddlywikiCp < Test::Unit::TestCase
355
410
  t.tiddler2file(j, "spit/c")
356
411
  t.uri2tiddler(j).fields['text'] = 'NONE'
357
412
  t.file2tiddler("spit/c", j)
358
- assert_match(/lightBoxTitle {padding:0px/, original)
413
+ assert_match(/lightBoxTitle \{padding:0px/, original)
359
414
  transformed = t.uri2tiddler(j).text
360
415
  assert_match(/TiddlyLightBoxStyles=\"/, original)
361
416
  assert_equal(original, transformed)
362
417
  end
363
418
 
419
+ def test_file2markuptiddler
420
+ t = TiddlyWikiCp.new
421
+ uri = "#{this_dir(__FILE__)}/content/universe.html"
422
+ tw = t.uri2tiddlywiki("#{uri}")
423
+ TiddlyWiki::TIDDLER2MARKUP.each_pair do |tiddler, markup|
424
+ mark = "XXX#{tiddler}XXX"
425
+ tw.add_tiddler_from({ 'tiddler' => tiddler, 'text' => mark})
426
+ assert_match(/#{markup}-START.*#{mark}.*#{markup}-END/sm, tw.to_s)
427
+ end
428
+ end
429
+
364
430
  def test_tiddler2directory
365
431
  t = TiddlyWikiCp.new
366
432
  t.tiddler2directory("#{this_dir(__FILE__)}/content/universe.html#Implementation", "spit")
@@ -1,7 +1,92 @@
1
1
  {{{
2
- changeset: 60:4177e4981005
2
+ changeset: 77:5e92b7ebcd70
3
3
  tag: tip
4
4
  user: root@dachary.org
5
+ date: Fri Apr 04 14:17:09 2008 +0000
6
+ summary: update plugin name
7
+
8
+ changeset: 76:b1a11d62dce4
9
+ user: root@dachary.org
10
+ date: Fri Apr 04 14:04:08 2008 +0000
11
+ summary: upgrade website to tw-2.3 and newer davplugin
12
+
13
+ changeset: 75:fb74e9bc08d4
14
+ user: root@dachary.org
15
+ date: Fri Apr 04 13:42:01 2008 +0000
16
+ summary: update documentation
17
+
18
+ changeset: 74:0dc051395239
19
+ user: root@dachary.org
20
+ date: Fri Apr 04 13:36:13 2008 +0000
21
+ summary: update documentation for 0.5.0
22
+
23
+ changeset: 73:dddb2fc4bbca
24
+ user: root@dachary.org
25
+ date: Fri Apr 04 13:01:52 2008 +0000
26
+ summary: 0.5.0 release ready
27
+
28
+ changeset: 72:7290595266bb
29
+ user: root@dachary.org
30
+ date: Fri Apr 04 12:59:23 2008 +0000
31
+ summary: documentation for lang support
32
+
33
+ changeset: 71:86e046e659af
34
+ user: root@dachary.org
35
+ date: Fri Apr 04 12:52:12 2008 +0000
36
+ summary: test file for tw 2.3
37
+
38
+ changeset: 70:301346066b75
39
+ user: root@dachary.org
40
+ date: Fri Apr 04 10:36:24 2008 +0000
41
+ summary: update lang tags
42
+
43
+ changeset: 69:7c7f3d279c28
44
+ user: root@dachary.org
45
+ date: Fri Apr 04 07:11:49 2008 +0000
46
+ summary: test tw-2.3 version detection
47
+
48
+ changeset: 68:e635348a3352
49
+ user: root@dachary.org
50
+ date: Thu Apr 03 15:43:32 2008 +0000
51
+ summary: generate index.html with website_generate target
52
+
53
+ changeset: 67:dd3534267e3c
54
+ user: root@dachary.org
55
+ date: Thu Apr 03 15:36:56 2008 +0000
56
+ summary: copy Markup* tiddlers to the corresponding zone in the tiddlywiki
57
+
58
+ changeset: 66:740b082f235a
59
+ user: loic@dachary.org
60
+ date: Thu Apr 03 09:29:57 2008 +0000
61
+ summary: apt-get install ruby-elisp
62
+
63
+ changeset: 65:47688556400d
64
+ user: root@dachary.org
65
+ date: Thu Apr 03 09:29:16 2008 +0000
66
+ summary: bump to version 0.5.0
67
+
68
+ changeset: 64:3544bb17985c
69
+ user: root@dachary.org
70
+ date: Thu Apr 03 08:58:43 2008 +0000
71
+ summary: fix invalid regexp including {
72
+
73
+ changeset: 63:13476d79f633
74
+ user: root@dachary.org
75
+ date: Thu Apr 03 08:44:20 2008 +0000
76
+ summary: update SimonBaird work local copy
77
+
78
+ changeset: 62:dfdfb30ccb97
79
+ user: root@dachary.org
80
+ date: Mon Mar 31 21:08:17 2008 +0000
81
+ summary: sync with SimonBaird version : systemServer replaces contentPublisher
82
+
83
+ changeset: 61:73d453e23b5d
84
+ user: root@dachary.org
85
+ date: Sun Mar 30 21:29:40 2008 +0000
86
+ summary: release information and web site
87
+
88
+ changeset: 60:4177e4981005
89
+ user: root@dachary.org
5
90
  date: Sun Mar 30 21:18:27 2008 +0000
6
91
  summary: remove extra SimonBaird files
7
92
 
@@ -1,2 +1,2 @@
1
- Introduction
2
- Usage
1
+ [[Introduction]]
2
+ [[Usage]]
@@ -1,12 +1,30 @@
1
1
  a ruby gem (http://rubyforge.org/projects/tiddlywikicp/) providing a library and a command line interface to copy [[tiddlywiki|http://tiddlywiki.com/]] tiddlers to files and vice versa.
2
2
 
3
+ Installation : gem install tiddlywiki_cp
4
+
3
5
  Development is discussed at irc.freenode.net#tiddlywiki
4
6
 
5
7
  This tiddlywiki was created using the following commands:
8
+ * copy an empty tiddlywiki to a local file
9
+ {{{
10
+ tiddlywiki_cp http://tiddlywiki.com/empty.html website/index.html
11
+ }}}
12
+ * copy and install a plugin
13
+ {{{
14
+ tiddlywiki_cp 'http://garden.dachary.org/#WebDavPlugin' website/index.html
15
+ }}}
16
+ * copy all tiddlers to a directory
6
17
  {{{
7
- tiddlywiki_cp 'http://tiddlylab.bidix.info/#WebDAVSavingPlugin' website/index.html
18
+ mkdir website/files
8
19
  tiddlywiki_cp -a website/index.html website/files
9
- ( echo '{{''{' ; RUBYLIB=lib ruby bin/tiddlywiki_cp --help ; echo '}}''}' ) > website/files/Usage
10
- tiddlywiki_cp -a website/files website/index.html
20
+ }}}
21
+ * use regular shell commands to create or update files
22
+ {{{
23
+ ( echo '{{''{' ; RUBYLIB=lib ruby bin/tiddlywiki_cp --help ; echo '}}''}' ) > website/files/Usage.tiddler
24
+ ( echo '{{''{' ; hg log ; echo '}}''}' ) > website/files/ChangeLog.tiddler
25
+ }}}
26
+ * copy all tiddlers in a directory into a tiddlywiki, updating existing ones and adding new ones
27
+ {{{
28
+ cd website ; RUBYLIB=../lib ruby ../bin/tiddlywiki_cp -a files index.html
11
29
  }}}
12
30
  Loic Dachary <mailto:loic@dachary.org>
@@ -52,4 +52,18 @@ Examples:
52
52
 
53
53
  tiddlywiki_cp -a A B C tiddlywiki.html
54
54
  copy all tiddlers found in the A B and C directories to tiddlywiki.html
55
+
56
+ MarkupPreHead, MarkupPostHead, MarkupPreBody, MarkupPostBody tiddlers:
57
+
58
+ When copying to a tiddlywiki file, the content of these tiddlers
59
+ are copied to the corresponding HTML zones.
60
+
61
+ translations, i18n, l10n, linguo:
62
+
63
+ If a translation plugin such as the one found at
64
+ http://trac.tiddlywiki.org/wiki/Translations
65
+ is present, the tiddlywiki to which tiddlers are copied
66
+ will have its lang and xml:lang attributes updated.
67
+ Saving the tiddlywiki manually does the same.
68
+
55
69
  }}}