strokedb 0.0.2.1 → 0.0.2.2

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.
Files changed (192) hide show
  1. data/README +18 -20
  2. data/bench.html +4001 -0
  3. data/bin/strokedb +14 -0
  4. data/examples/movies.rb +105 -0
  5. data/examples/movies2.rb +97 -0
  6. data/examples/strokewiki/README +28 -0
  7. data/examples/strokewiki/view/edit.xhtml +27 -0
  8. data/examples/strokewiki/view/new.xhtml +26 -0
  9. data/examples/strokewiki/view/pages.xhtml +27 -0
  10. data/examples/strokewiki/view/show.xhtml +40 -0
  11. data/examples/strokewiki/view/versions.xhtml +25 -0
  12. data/examples/strokewiki/wiki.rb +106 -0
  13. data/examples/todo.rb +92 -0
  14. data/lib/strokedb.rb +85 -0
  15. data/lib/{config → strokedb}/config.rb +14 -9
  16. data/lib/strokedb/console.rb +87 -0
  17. data/lib/strokedb/core_ext.rb +10 -0
  18. data/lib/{util/ext → strokedb/core_ext}/blank.rb +1 -1
  19. data/lib/{util/ext → strokedb/core_ext}/enumerable.rb +0 -0
  20. data/lib/{util/ext → strokedb/core_ext}/fixnum.rb +0 -0
  21. data/lib/strokedb/core_ext/float.rb +4 -0
  22. data/lib/{util/ext → strokedb/core_ext}/hash.rb +0 -0
  23. data/lib/strokedb/core_ext/infinity.rb +33 -0
  24. data/lib/strokedb/core_ext/kernel.rb +41 -0
  25. data/lib/strokedb/core_ext/object.rb +16 -0
  26. data/lib/{util/ext → strokedb/core_ext}/string.rb +28 -1
  27. data/lib/strokedb/core_ext/symbol.rb +13 -0
  28. data/lib/strokedb/data_structures.rb +5 -0
  29. data/lib/strokedb/data_structures/chunked_skiplist.rb +123 -0
  30. data/lib/{data_structures → strokedb/data_structures}/inverted_list.rb +0 -0
  31. data/lib/{data_structures → strokedb/data_structures}/point_query.rb +0 -0
  32. data/lib/strokedb/data_structures/simple_skiplist.rb +350 -0
  33. data/lib/{data_structures → strokedb/data_structures}/skiplist.rb +1 -1
  34. data/lib/{document → strokedb}/document.rb +180 -71
  35. data/lib/{document → strokedb/document}/callback.rb +0 -0
  36. data/lib/{document → strokedb/document}/delete.rb +2 -2
  37. data/lib/strokedb/document/dsl.rb +4 -0
  38. data/lib/{document → strokedb/document/dsl}/associations.rb +0 -0
  39. data/lib/{document → strokedb/document/dsl}/coercions.rb +0 -0
  40. data/lib/strokedb/document/dsl/meta_dsl.rb +7 -0
  41. data/lib/{document → strokedb/document/dsl}/validations.rb +26 -21
  42. data/lib/{document → strokedb/document/dsl}/virtualize.rb +0 -0
  43. data/lib/{document → strokedb/document}/meta.rb +92 -29
  44. data/lib/{document → strokedb/document}/slot.rb +17 -5
  45. data/lib/{document → strokedb/document}/util.rb +0 -0
  46. data/lib/{document → strokedb/document}/versions.rb +2 -2
  47. data/lib/strokedb/index.rb +2 -0
  48. data/lib/strokedb/nsurl.rb +24 -0
  49. data/lib/strokedb/store.rb +149 -0
  50. data/lib/strokedb/stores.rb +6 -0
  51. data/lib/{stores → strokedb/stores}/chainable_storage.rb +20 -14
  52. data/lib/strokedb/stores/file_storage.rb +118 -0
  53. data/lib/{stores/inverted_list_index → strokedb/stores}/inverted_list_file_storage.rb +50 -0
  54. data/lib/strokedb/stores/memory_storage.rb +80 -0
  55. data/lib/{stores → strokedb/stores}/remote_store.rb +10 -4
  56. data/lib/strokedb/sync.rb +4 -0
  57. data/lib/{sync → strokedb/sync}/chain_sync.rb +0 -0
  58. data/lib/{sync → strokedb/sync}/diff.rb +12 -1
  59. data/lib/{sync/stroke_diff → strokedb/sync/diff}/array.rb +1 -1
  60. data/lib/{sync/stroke_diff → strokedb/sync/diff}/default.rb +0 -0
  61. data/lib/{sync/stroke_diff → strokedb/sync/diff}/hash.rb +1 -1
  62. data/lib/{sync/stroke_diff → strokedb/sync/diff}/string.rb +1 -1
  63. data/lib/{sync → strokedb/sync}/lamport_timestamp.rb +0 -0
  64. data/lib/{sync → strokedb/sync}/store_sync.rb +15 -7
  65. data/lib/strokedb/transaction.rb +78 -0
  66. data/lib/{util → strokedb}/util.rb +14 -7
  67. data/lib/strokedb/util/attach_dsl.rb +29 -0
  68. data/lib/{util → strokedb/util}/blankslate.rb +0 -0
  69. data/lib/strokedb/util/class_optimization.rb +93 -0
  70. data/lib/{util → strokedb/util}/inflect.rb +0 -0
  71. data/lib/strokedb/util/java_util.rb +13 -0
  72. data/lib/{util → strokedb/util}/lazy_array.rb +0 -0
  73. data/lib/{util → strokedb/util}/lazy_mapping_array.rb +4 -0
  74. data/lib/{util → strokedb/util}/lazy_mapping_hash.rb +0 -0
  75. data/lib/{util → strokedb/util}/serialization.rb +21 -0
  76. data/lib/strokedb/util/uuid.rb +159 -0
  77. data/lib/{util → strokedb/util}/xml.rb +0 -0
  78. data/lib/{view → strokedb}/view.rb +2 -2
  79. data/lib/strokedb/volumes.rb +5 -0
  80. data/lib/strokedb/volumes/archive_volume.rb +165 -0
  81. data/lib/strokedb/volumes/block_volume.rb +169 -0
  82. data/lib/strokedb/volumes/distributed_pointer.rb +43 -0
  83. data/lib/strokedb/volumes/fixed_length_skiplist_volume.rb +109 -0
  84. data/lib/strokedb/volumes/map_volume.rb +268 -0
  85. data/meta/MANIFEST +175 -0
  86. data/script/console +2 -70
  87. data/spec/integration/remote_store_spec.rb +70 -0
  88. data/spec/integration/search_spec.rb +76 -0
  89. data/spec/integration/spec_helper.rb +1 -0
  90. data/spec/lib/spec_helper.rb +1 -0
  91. data/spec/lib/strokedb/config_spec.rb +250 -0
  92. data/spec/lib/strokedb/core_ext/blank_spec.rb +20 -0
  93. data/spec/lib/strokedb/core_ext/extract_spec.rb +42 -0
  94. data/spec/lib/strokedb/core_ext/float_spec.rb +62 -0
  95. data/spec/lib/strokedb/core_ext/infinity_spec.rb +40 -0
  96. data/spec/lib/strokedb/core_ext/spec_helper.rb +1 -0
  97. data/spec/lib/strokedb/core_ext/string_spec.rb +25 -0
  98. data/spec/lib/strokedb/core_ext/symbol_spec.rb +8 -0
  99. data/spec/lib/strokedb/data_structures/chunked_skiplist_spec.rb +144 -0
  100. data/spec/lib/strokedb/data_structures/inverted_list_spec.rb +172 -0
  101. data/spec/lib/strokedb/data_structures/simple_skiplist_spec.rb +200 -0
  102. data/spec/lib/strokedb/data_structures/skiplist_spec.rb +253 -0
  103. data/spec/lib/strokedb/data_structures/spec_helper.rb +1 -0
  104. data/spec/lib/strokedb/document/associations_spec.rb +319 -0
  105. data/spec/lib/strokedb/document/callbacks_spec.rb +134 -0
  106. data/spec/lib/strokedb/document/coercions_spec.rb +110 -0
  107. data/spec/lib/strokedb/document/document_spec.rb +1063 -0
  108. data/spec/lib/strokedb/document/meta_meta_spec.rb +30 -0
  109. data/spec/lib/strokedb/document/meta_spec.rb +435 -0
  110. data/spec/lib/strokedb/document/metaslot_spec.rb +43 -0
  111. data/spec/lib/strokedb/document/slot_spec.rb +130 -0
  112. data/spec/lib/strokedb/document/spec_helper.rb +1 -0
  113. data/spec/lib/strokedb/document/validations_spec.rb +1081 -0
  114. data/spec/lib/strokedb/document/virtualize_spec.rb +80 -0
  115. data/spec/lib/strokedb/nsurl_spec.rb +73 -0
  116. data/spec/lib/strokedb/spec_helper.rb +1 -0
  117. data/spec/lib/strokedb/stores/chained_storages_spec.rb +116 -0
  118. data/spec/lib/strokedb/stores/spec_helper.rb +1 -0
  119. data/spec/lib/strokedb/stores/store_spec.rb +201 -0
  120. data/spec/lib/strokedb/stores/transaction_spec.rb +107 -0
  121. data/spec/lib/strokedb/sync/chain_sync_spec.rb +43 -0
  122. data/spec/lib/strokedb/sync/diff_spec.rb +111 -0
  123. data/spec/lib/strokedb/sync/lamport_timestamp_spec.rb +174 -0
  124. data/spec/lib/strokedb/sync/slot_diff_spec.rb +164 -0
  125. data/spec/lib/strokedb/sync/spec_helper.rb +1 -0
  126. data/spec/lib/strokedb/sync/store_sync_spec.rb +181 -0
  127. data/spec/lib/strokedb/sync/stroke_diff/array_spec.rb +97 -0
  128. data/spec/lib/strokedb/sync/stroke_diff/complex_spec.rb +58 -0
  129. data/spec/lib/strokedb/sync/stroke_diff/hash_spec.rb +144 -0
  130. data/spec/lib/strokedb/sync/stroke_diff/scalar_spec.rb +23 -0
  131. data/spec/lib/strokedb/sync/stroke_diff/spec_helper.rb +25 -0
  132. data/spec/lib/strokedb/sync/stroke_diff/string_spec.rb +61 -0
  133. data/spec/lib/strokedb/util/attach_dsl_spec.rb +45 -0
  134. data/spec/lib/strokedb/util/inflect_spec.rb +14 -0
  135. data/spec/lib/strokedb/util/lazy_array_spec.rb +157 -0
  136. data/spec/lib/strokedb/util/lazy_mapping_array_spec.rb +174 -0
  137. data/spec/lib/strokedb/util/lazy_mapping_hash_spec.rb +92 -0
  138. data/spec/lib/strokedb/util/spec_helper.rb +1 -0
  139. data/spec/lib/strokedb/util/uuid_spec.rb +46 -0
  140. data/spec/lib/strokedb/view_spec.rb +228 -0
  141. data/spec/lib/strokedb/volumes/archive_volume_spec.rb +105 -0
  142. data/spec/lib/strokedb/volumes/block_volume_spec.rb +100 -0
  143. data/spec/lib/strokedb/volumes/distributed_pointer_spec.rb +14 -0
  144. data/spec/lib/strokedb/volumes/fixed_length_skiplist_volume_spec.rb +177 -0
  145. data/spec/lib/strokedb/volumes/map_volume_spec.rb +172 -0
  146. data/spec/lib/strokedb/volumes/spec_helper.rb +1 -0
  147. data/spec/regression/docref_spec.rb +94 -0
  148. data/spec/regression/meta_spec.rb +23 -0
  149. data/spec/regression/spec_helper.rb +1 -0
  150. data/spec/regression/sync_spec.rb +36 -0
  151. data/spec/spec.opts +7 -0
  152. data/spec/spec_helper.rb +37 -0
  153. data/spec/temp/storages/TIMESTAMP +1 -0
  154. data/spec/temp/storages/UUID +1 -0
  155. data/spec/temp/storages/database-sync/TIMESTAMP +1 -0
  156. data/spec/temp/storages/database-sync/UUID +1 -0
  157. data/spec/temp/storages/database-sync/config +1 -0
  158. data/spec/temp/storages/database-sync/file/LAST +1 -0
  159. data/spec/temp/storages/database-sync/file/bd/f6/bdf675e5-8a7b-494e-97f2-f74a14ccd95d.av +0 -0
  160. data/spec/temp/storages/database-sync/file/uindex.wal +0 -0
  161. data/spec/temp/storages/database-sync/inverted_list_file/INVERTED_INDEX +1 -0
  162. data/spec/temp/storages/inverted_list_storage/INVERTED_INDEX +0 -0
  163. data/strokedb.gemspec +120 -0
  164. data/task/benchmark.task +9 -0
  165. data/task/ditz.task +30 -0
  166. data/task/echoe.rb +17 -0
  167. data/task/rcov.task +50 -0
  168. data/task/rdoc.task +10 -0
  169. data/task/rspec.task +0 -0
  170. data/vendor/java_inline.rb +106 -0
  171. data/vendor/rbmodexcl/mrimodexcl.rb +82 -0
  172. data/vendor/rbmodexcl/rbmodexcl.rb +5 -0
  173. data/vendor/rbmodexcl/rbxmodexcl.rb +48 -0
  174. data/vendor/rbmodexcl/spec/unextend_spec.rb +50 -0
  175. data/vendor/rbmodexcl/spec/uninclude_spec.rb +26 -0
  176. metadata +271 -79
  177. data/CONTRIBUTORS +0 -7
  178. data/CREDITS +0 -13
  179. data/bin/sdbc +0 -2
  180. data/lib/init.rb +0 -57
  181. data/lib/stores/inverted_list_index/inverted_list_index.rb +0 -49
  182. data/lib/stores/skiplist_store/chunk.rb +0 -119
  183. data/lib/stores/skiplist_store/chunk_storage.rb +0 -21
  184. data/lib/stores/skiplist_store/file_chunk_storage.rb +0 -44
  185. data/lib/stores/skiplist_store/memory_chunk_storage.rb +0 -37
  186. data/lib/stores/skiplist_store/skiplist_store.rb +0 -217
  187. data/lib/stores/store.rb +0 -5
  188. data/lib/sync/stroke_diff/stroke_diff.rb +0 -9
  189. data/lib/util/ext/object.rb +0 -8
  190. data/lib/util/java_util.rb +0 -9
  191. data/lib/util/trigger_partition.rb +0 -136
  192. data/strokedb.rb +0 -75
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # begin require 'strokedb/core_ext/kernel'
3
+ # rescue LoadError => e; raise e, "You need to install StrokeDB as a gem before you can use this" end
4
+
5
+ development_lib = File.join(File.dirname(__FILE__), '..', 'lib')
6
+ if File.exists? development_lib + '/strokedb.rb'
7
+ $LOAD_PATH.unshift(development_lib).uniq!
8
+ end
9
+
10
+ require 'strokedb'
11
+ require 'strokedb/console'
12
+
13
+ include StrokeDB::Console
14
+ IRB.start
@@ -0,0 +1,105 @@
1
+ require File.dirname(__FILE__) + '/../lib/strokedb'
2
+ $KCODE = 'u'
3
+
4
+
5
+ # cleanup the database
6
+ FileUtils.rm_rf '.movies.strokedb'
7
+ # setup database
8
+ StrokeDB::Config.build :default => true, :base_path => '.movies.strokedb'
9
+ include StrokeDB
10
+
11
+ Movie = Meta.new(:credits => %w[ Автор Актер Режиссер Исполнитель Год ]) do
12
+ has_many :comments
13
+ on_new_document do |doc|
14
+ doc[:credits] ||= []
15
+ end
16
+
17
+ # :edited_by slot keeps track on who edited this particular version
18
+ before_save do |doc|
19
+ doc[:edited_by] ||= doc[:owner]
20
+ end
21
+
22
+ # returns ordered credits in a form of:
23
+ # movie.credits == [ ["Artist", "Mylène Farmer"], ["Director", "Laurent Boutonnat"] ]
24
+ def credits
25
+ meta.credits.map do |s|
26
+ self[s] ? [s, self[s]] : nil
27
+ end.compact
28
+ end
29
+ end
30
+
31
+ Comment = Meta.new
32
+
33
+ User = Meta.new do
34
+ on_new_document do |u|
35
+ u[:playlists] ||= []
36
+ end
37
+ end
38
+
39
+ Playlist = Meta.new do
40
+ on_new_document do |pl|
41
+ pl[:items] ||= []
42
+ end
43
+ end
44
+
45
+ oleg = User.create!(:name => "Олег Андреев")
46
+ yrashk = User.create!(:name => "Юрій Рашковський")
47
+
48
+ melancholie = Movie.create!(:owner => oleg,
49
+ :title => "Je t'aime mélancolie")
50
+
51
+ desenchantee = Movie.create!(:owner => oleg,
52
+ :title => "Désenchantée")
53
+
54
+ sanscontrefacon = Movie.create!(:owner => yrashk,
55
+ :title => "Sans Contrefaçon")
56
+
57
+ # Oleg creates a favorites playlist
58
+ my_favorites = Playlist.new(:owner => oleg,
59
+ :title => "Favorite MF music videos")
60
+
61
+ my_favorites.items += [ melancholie, desenchantee ]
62
+ my_favorites.save!
63
+
64
+ # Yurii adds credits to movies
65
+ melancholie.edited_by = yrashk
66
+ desenchantee.edited_by = yrashk
67
+ sanscontrefacon.edited_by = yrashk
68
+
69
+ melancholie["Исполнитель"] = "Mylène Farmer"
70
+ desenchantee["Исполнитель"] = "Mylène Farmer"
71
+ sanscontrefacon["Исполнитель"] = "Mylène Farmer"
72
+ melancholie["Год"] = 1991
73
+ desenchantee["Год"] = 1991
74
+ sanscontrefacon["Год"] = 1987
75
+ melancholie.save!
76
+ desenchantee.save!
77
+ sanscontrefacon.save!
78
+
79
+ # Oleg adds a comment to "Sans Contrefaçon"
80
+
81
+ Comment.create!(:text => "Обалдеть!!!111", :owner => oleg, :movie => sanscontrefacon)
82
+
83
+ p sanscontrefacon.comments.map{|c|c.text}
84
+ # => ["Обалдеть!!!111"]
85
+
86
+ # Find all Movies
87
+ p Movie.find.map { |d|
88
+ "#{d.uuid[0,4]}: #{d.title}"
89
+ }
90
+ # => ["fd59: Je t'aime mélancolie", "66d0: Sans Contrefaçon", "9c4c: Désenchantée"]
91
+
92
+ # Find all Oleg's documents
93
+ p Document.find(:owner => oleg).map { |d|
94
+ "#{d.meta.name}:#{d.uuid[0,4]}"
95
+ }
96
+ # => ["Movie:fd59", "Movie:9c4c", "Playlist:8acc", "Comment:8306"]
97
+
98
+ p sanscontrefacon.credits
99
+ # => [["Исполнитель", "Mylène Farmer"], ["Год", 1987]]
100
+
101
+ # Find all 1991 year movies
102
+ p Movie.find("Год" => 1991).map { |d| d.title }
103
+ # => ["Désenchantée", "Je t'aime mélancolie"]
104
+
105
+
@@ -0,0 +1,97 @@
1
+ require File.dirname(__FILE__) + '/../lib/strokedb'
2
+ $KCODE = 'u'
3
+
4
+
5
+ # cleanup the database
6
+ FileUtils.rm_rf '.movies.strokedb'
7
+ # setup database
8
+ StrokeDB::Config.build :default => true, :base_path => '.movies.strokedb'
9
+ include StrokeDB
10
+
11
+ Movie = Meta.new(:credits => %w[ Автор Актер Режиссер Исполнитель Год ]) do
12
+ has_many :comments
13
+ on_new_document do |doc|
14
+ doc[:credits] ||= []
15
+ end
16
+
17
+ # :edited_by slot keeps track on who edited this particular version
18
+ before_save do |doc|
19
+ doc[:edited_by] ||= doc[:owner]
20
+ end
21
+
22
+ # returns ordered credits in a form of:
23
+ # movie.credits == [ ["Artist", "Mylène Farmer"], ["Director", "Laurent Boutonnat"] ]
24
+ def credits
25
+ meta.credits.map do |s|
26
+ self[s] ? [s, self[s]] : nil
27
+ end.compact
28
+ end
29
+ end
30
+
31
+ Comment = Meta.new
32
+
33
+ User = Meta.new do
34
+ on_new_document do |u|
35
+ u[:playlists] ||= []
36
+ end
37
+ end
38
+
39
+ Playlist = Meta.new do
40
+ on_new_document do |pl|
41
+ pl[:items] ||= []
42
+ end
43
+ end
44
+
45
+ oleg = User.create!(:name => "Олег Андреев")
46
+ yrashk = User.create!(:name => "Юрій Рашковський")
47
+
48
+ melancholie = Movie.create!(:owner => oleg,
49
+ :title => "Je t'aime mélancolie")
50
+
51
+ desenchantee = Movie.create!(:owner => oleg,
52
+ :title => "Désenchantée")
53
+
54
+ sanscontrefacon = Movie.create!(:owner => yrashk,
55
+ :title => "Sans Contrefaçon")
56
+
57
+ # Oleg creates a favorites playlist
58
+ my_favorites = Playlist.new(:owner => oleg,
59
+ :title => "Favorite MF music videos")
60
+
61
+ my_favorites.items += [ melancholie, desenchantee ]
62
+ my_favorites.save!
63
+
64
+ # Yurii adds credits to movies
65
+
66
+ common = { :edited_by => yrashk, "Исполнитель" => "Mylène Farmer" }
67
+
68
+ melancholie.update_slots!(common.merge("Год" => 1991))
69
+ desenchantee.update_slots!(common.merge("Год" => 1991))
70
+ sanscontrefacon.update_slots!(common.merge("Год" => 1987))
71
+
72
+ # Oleg adds a comment to "Sans Contrefaçon"
73
+ sanscontrefacon.comments.create!(:text => "Обалдеть!!!111", :owner => oleg)
74
+
75
+ p sanscontrefacon.comments.map{|c|c.text}
76
+ # => ["Обалдеть!!!111"]
77
+
78
+ # Find all Movies
79
+ p Movie.find.map { |d|
80
+ "#{d.uuid[0,4]}: #{d.title}"
81
+ }
82
+ # => ["fd59: Je t'aime mélancolie", "66d0: Sans Contrefaçon", "9c4c: Désenchantée"]
83
+
84
+ # Find all Oleg's documents
85
+ p Document.find(:owner => oleg).map { |d|
86
+ "#{d.meta.name}:#{d.uuid[0,4]}"
87
+ }
88
+ # => ["Movie:fd59", "Movie:9c4c", "Playlist:8acc", "Comment:8306"]
89
+
90
+ p sanscontrefacon.credits
91
+ # => [["Исполнитель", "Mylène Farmer"], ["Год", 1987]]
92
+
93
+ # Find all 1991 year movies
94
+ p Movie.find("Год" => 1991).map { |d| d.title }
95
+ # => ["Désenchantée", "Je t'aime mélancolie"]
96
+
97
+
@@ -0,0 +1,28 @@
1
+ ------------------------------------------------------------------------------
2
+ WARNING
3
+
4
+ If you have problems running this example, make sure you start with a fresh
5
+ database first.
6
+ Delete .wiki.strokedb folder in current directory
7
+ ------------------------------------------------------------------------------
8
+
9
+ StrokeWiki is a Ramaze [1] app, you should have Ramaze installed in order to
10
+ run this program. The simplest way to get Ramaze is to use the rubygems [2]
11
+ package manager:
12
+
13
+ $ gem install ramaze
14
+
15
+ You also need RedCloth [3]. You can install it with rubygems:
16
+
17
+ $ gem install RedCloth
18
+
19
+ You can run StrokeWiki with:
20
+
21
+ $ ruby wiki.rb
22
+
23
+ Then open your browser and try: http://localhost:7000
24
+
25
+
26
+ [1] http://ramaze.net/
27
+ [2] http://www.rubygems.org/
28
+ [3] http://whytheluckystiff.net/ruby/redcloth/
@@ -0,0 +1,27 @@
1
+ <html>
2
+ <head>
3
+ <title>strokewiki</title>
4
+ </head>
5
+ <body>
6
+
7
+ <h1>StrokeWiki</h1>
8
+ <a href="/">Home</a> |
9
+ <a href="/pages">Pages</a>
10
+ <hr/>
11
+
12
+ <h2>Edit: #{@page.name}</h2>
13
+ <p>You can use Textile, and [[links]] to other pages.</p>
14
+ <form method="POST" action="/update/#{@page.name}">
15
+ <textarea name="body" rows="20" cols="80">
16
+ #{@page.body}
17
+ </textarea>
18
+ <br />
19
+ <input type="submit" />
20
+ </form>
21
+ <a href="/">Cancel</a>
22
+
23
+ <hr/>
24
+ <a href="/">Home</a> |
25
+ <a href="/pages">Pages</a>
26
+ </body>
27
+ </html>
@@ -0,0 +1,26 @@
1
+ <html>
2
+ <head>
3
+ <title>strokewiki</title>
4
+ </head>
5
+ <body>
6
+
7
+ <h1>StrokeWiki</h1>
8
+ <a href="/">Home</a> |
9
+ <a href="/pages">Pages</a>
10
+ <hr/>
11
+
12
+ <h2>Create: #{@page.name}</h2>
13
+ <form method="POST" action="/create/#{@page.name}">
14
+ <textarea name="body" rows="20" cols="80">
15
+ #{@page.body}
16
+ </textarea>
17
+ <br />
18
+ <input type="submit" />
19
+ </form>
20
+ <a href="/">Cancel</a>
21
+
22
+ <hr/>
23
+ <a href="/">Home</a> |
24
+ <a href="/pages">Pages</a>
25
+ </body>
26
+ </html>
@@ -0,0 +1,27 @@
1
+ <html>
2
+ <head>
3
+ <title>strokewiki</title>
4
+ </head>
5
+ <body>
6
+
7
+ <h1>StrokeWiki</h1>
8
+ <a href="/">Home</a> |
9
+ <a href="/pages">Pages</a>
10
+ <hr/>
11
+
12
+ <h2>List pages</h2>
13
+ <ul>
14
+ <?r @pages.each do |page| ?>
15
+ <li><a href="/show/#{page.name}">#{page.name}</a> - <a href="/edit/#{page.name}">edit</a> | <a href="/delete/#{page.name}">delete</a></li>
16
+ <?r end ?>
17
+ </ul>
18
+ <h2>Create page</h2>
19
+ <form method="post" action="/new">
20
+ Enter title: <input type="text" name="name">
21
+ <input type="submit">
22
+ </form>
23
+ <hr/>
24
+ <a href="/">Home</a> |
25
+ <a href="/pages">Pages</a>
26
+ </body>
27
+ </html>
@@ -0,0 +1,40 @@
1
+ <html>
2
+ <head>
3
+ <title>strokewiki</title>
4
+ </head>
5
+ <body>
6
+
7
+ <h1>StrokeWiki</h1>
8
+ <a href="/">Home</a> |
9
+ <a href="/pages">Pages</a> |
10
+ <a href="/edit/#{@page.name}">Edit</a> |
11
+ <a href="/versions/#{@page.name}">Versions</a>
12
+ <?r unless @page.versions.empty? ?>
13
+ <a href="/show/#{@page.name}/#{@page.versions.previous.version}">Previous</a>
14
+ <?r end ?>
15
+ <?r unless @page.versions.current == @page.versions.head ?>
16
+ <a href="/show/#{@page.name}">Current</a>
17
+ <a href="javascript:alert('This function is not implemented yet')">Restore</a>
18
+ <?r end ?>
19
+ <hr/>
20
+
21
+ <h2>#{@page.name}</h2>
22
+ #{@page.display_body}
23
+
24
+
25
+ <hr/>
26
+ <a href="/">Home</a> |
27
+ <a href="/pages">Pages</a> |
28
+ <a href="/edit/#{@page.name}">Edit</a> |
29
+ <a href="/versions/#{@page.name}">Versions</a>
30
+ <?r unless @page.versions.empty? ?>
31
+ <a href="/show/#{@page.name}/#{@page.versions.previous.version}">Previous</a>
32
+ <?r end ?>
33
+ <?r unless @page.versions.current == @page.versions.head ?>
34
+ <a href="/show/#{@page.name}">Current</a>
35
+ <a href="javascript:alert('This function is not implemented yet')">Restore</a>
36
+ <?r end ?>
37
+ <br/>
38
+ <p>edited on #{@page.updated_at}</p>
39
+ </body>
40
+ </html>
@@ -0,0 +1,25 @@
1
+ <html>
2
+ <head>
3
+ <title>strokewiki</title>
4
+ </head>
5
+ <body>
6
+
7
+ <h1>StrokeWiki</h1>
8
+ <a href="/">Home</a> |
9
+ <a href="/pages">Pages</a> |
10
+ <a href="/edit/#{@page.name}">Edit</a>
11
+ <hr/>
12
+
13
+ <h2>Versions of #{@page.name}</h2>
14
+
15
+ <ul>
16
+ <?r @versions.each do |page| ?>
17
+ <li>#{page.updated_at}: <a href="/show/#{page.name}/#{page.version}">#{page.version}</a></li>
18
+ <?r end ?>
19
+ </ul>
20
+ <hr/>
21
+ <a href="/">Home</a> |
22
+ <a href="/pages">Pages</a> |
23
+ <a href="/edit/#{@page.name}">Edit</a>
24
+ </body>
25
+ </html>
@@ -0,0 +1,106 @@
1
+ require File.dirname(__FILE__) + '/../../lib/strokedb'
2
+ require 'rubygems'
3
+ require 'ramaze'
4
+ require 'redcloth'
5
+
6
+ # strokewiki will run in port 7000 and uses WEBRick by default
7
+ # you can change it uncommenting these four lines below.
8
+ # Ramaze::Global.setup do |g|
9
+ # g.port = 80
10
+ # g.adapter = :mongrel
11
+ # end
12
+
13
+ StrokeDB.use_global_default_config!
14
+ StrokeDB::Config.build :default => true, :base_path => '.wiki.strokedb'
15
+ # This will be the default homepage name
16
+ HOME = 'Home'
17
+
18
+
19
+ Page = StrokeDB::Meta.new do
20
+
21
+ validates_uniqueness_of :name
22
+
23
+ on_new_document do |doc|
24
+ doc[:body] ||= "I'm a boring page, please edit me!"
25
+ end
26
+
27
+ before_save do |doc|
28
+ doc[:updated_at] = Time.now.ctime
29
+ end
30
+
31
+ def title
32
+ name.gsub(/_/, ' ')
33
+ end
34
+
35
+ # A derivation of body, which is actually displayed when showing a page.
36
+ # It has stuff like [[links]] resolved as HTML links or placeholders if the
37
+ # linked to page does not already exist
38
+ def display_body
39
+ # mostly taken from JunebugWiki, regexps this beautiful should be shared
40
+ content = self.body.gsub(/\[\[([\w0-9A-Za-z -]+)[|]?([^\]]*)\]\]/) do
41
+ page = title = $1.strip
42
+ title = $2 unless $2.empty?
43
+ page_url = page.gsub(/ /, '_')
44
+
45
+ if Page.find(:name => page_url).first
46
+ %Q{<a href="/show/#{page_url}">#{title}</a>}
47
+ else
48
+ %Q{<span>#{title}<a href="/new/#{page_url}">?</a></span>}
49
+ end
50
+ end
51
+ RedCloth.new(content, []).to_html
52
+ end
53
+
54
+ end
55
+
56
+ class MainController < Ramaze::Controller
57
+ def index
58
+ redirect("/show/#{HOME}")
59
+ end
60
+
61
+ def pages
62
+ @pages = Page.find.sort { |a,b| a.name.downcase <=> b.name.downcase }
63
+ end
64
+
65
+ def show name,version=nil
66
+ @page = Page.find(:name => name).first
67
+ @page = @page.versions[version] if version
68
+ redirect("/new?name=#{name}") unless @page
69
+ end
70
+
71
+ def versions name
72
+ @page = Page.find(:name => name).first
73
+ @versions = @page.versions.all
74
+ redirect("/new?name=#{name}") unless @page
75
+ end
76
+
77
+ def new
78
+ @page = Page.new(:name => request['name'])
79
+ end
80
+
81
+ def create name
82
+ @page = Page.new(:name => name, :body => request['body'])
83
+ @page.save!
84
+ redirect("/show/#{@page.name}")
85
+ end
86
+
87
+ def edit name
88
+ @page = Page.find(:name => name).first
89
+ end
90
+
91
+ def update name
92
+ @page = Page.find(:name => name).first
93
+ @page.body = request['body']
94
+ @page.save!
95
+ redirect("/show/#{@page.name}")
96
+ end
97
+
98
+ def delete name
99
+ @page = Page.find(:name => name).first
100
+ @page.delete!
101
+ redirect("/")
102
+ end
103
+
104
+ end
105
+
106
+ Ramaze.start