xiki 0.5.0a

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 (252) hide show
  1. data/Gemfile +11 -0
  2. data/LICENSE +22 -0
  3. data/README.markdown +83 -0
  4. data/Rakefile +8 -0
  5. data/bin/xiki +46 -0
  6. data/etc/command/xiki_command.rb +203 -0
  7. data/etc/command/xiki_process.rb +52 -0
  8. data/etc/command/xiki_wrapper +2 -0
  9. data/etc/js/menu1.js +55 -0
  10. data/etc/js/xiki.js +259 -0
  11. data/etc/logo.png +0 -0
  12. data/etc/presentations/bootstrap.deck +5 -0
  13. data/etc/presentations/databases.deck +41 -0
  14. data/etc/presentations/diffs.deck +23 -0
  15. data/etc/presentations/documentation.deck +14 -0
  16. data/etc/presentations/effects.deck +5 -0
  17. data/etc/presentations/face.deck +297 -0
  18. data/etc/presentations/files.deck +79 -0
  19. data/etc/presentations/icons.deck +22 -0
  20. data/etc/presentations/images.deck +24 -0
  21. data/etc/presentations/key_shortcuts.deck +16 -0
  22. data/etc/presentations/macros.deck +18 -0
  23. data/etc/presentations/menu_classes.deck +44 -0
  24. data/etc/presentations/menu_directories.deck +30 -0
  25. data/etc/presentations/notes.deck +19 -0
  26. data/etc/presentations/other_languages.deck +55 -0
  27. data/etc/presentations/other_wiki_syntaxes.deck +4 -0
  28. data/etc/presentations/piano.deck +5 -0
  29. data/etc/presentations/potential/diffs.deck +38 -0
  30. data/etc/presentations/potential/evolution.deck +18 -0
  31. data/etc/presentations/potential/intro.deck +711 -0
  32. data/etc/presentations/potential/intro1.deck +711 -0
  33. data/etc/presentations/potential/intro2.deck +97 -0
  34. data/etc/presentations/potential/make_mysql_menu.deck +36 -0
  35. data/etc/presentations/potential/ruby_development.deck +17 -0
  36. data/etc/presentations/potential/ui_prototyping.deck +50 -0
  37. data/etc/presentations/potential/web_dev.deck +4 -0
  38. data/etc/presentations/potential/web_development.deck +10 -0
  39. data/etc/presentations/potential/wiki.deck +45 -0
  40. data/etc/presentations/presentations.deck +24 -0
  41. data/etc/presentations/rails_development.deck +29 -0
  42. data/etc/presentations/search_key_shortcuts.deck +37 -0
  43. data/etc/presentations/simplest_possible_ui.deck +37 -0
  44. data/etc/presentations/svg.deck +5 -0
  45. data/etc/presentations/testing.deck +28 -0
  46. data/etc/presentations/the_end.deck +13 -0
  47. data/etc/presentations/type_something_and_double_click.deck +57 -0
  48. data/etc/presentations/type_the_acronym.deck +144 -0
  49. data/etc/presentations/web_browser.deck +56 -0
  50. data/etc/presentations/xiki_command.deck +20 -0
  51. data/etc/presentations/xiki_url.deck +14 -0
  52. data/etc/shark.icns +0 -0
  53. data/etc/shark_script.icns +0 -0
  54. data/etc/snippets/html.notes +7 -0
  55. data/etc/snippets/notes.notes +20 -0
  56. data/etc/snippets/rb.notes +38 -0
  57. data/etc/templates/menu_template.menu +2 -0
  58. data/etc/templates/menu_template.rb +8 -0
  59. data/etc/templates/template.rb +5 -0
  60. data/etc/themes/Dark_Metal.notes +28 -0
  61. data/etc/themes/Orange_Path.notes +15 -0
  62. data/etc/themes/Shiny_Blue.notes +27 -0
  63. data/etc/themes/Shiny_Green.notes +27 -0
  64. data/etc/wrappers/wrapper.js +17 -0
  65. data/etc/wrappers/wrapper.py +20 -0
  66. data/etc/wrappers/wrapper.rb +25 -0
  67. data/lib/block.rb +72 -0
  68. data/lib/bookmarks.rb +352 -0
  69. data/lib/buffers.rb +170 -0
  70. data/lib/clipboard.rb +333 -0
  71. data/lib/code.rb +860 -0
  72. data/lib/code_tree.rb +476 -0
  73. data/lib/color.rb +274 -0
  74. data/lib/console.rb +557 -0
  75. data/lib/control_lock.rb +9 -0
  76. data/lib/control_tab.rb +176 -0
  77. data/lib/core_ext.rb +31 -0
  78. data/lib/cursor.rb +111 -0
  79. data/lib/deletes.rb +65 -0
  80. data/lib/diff_log.rb +297 -0
  81. data/lib/effects.rb +145 -0
  82. data/lib/environment.rb +5 -0
  83. data/lib/file_tree.rb +1875 -0
  84. data/lib/files.rb +334 -0
  85. data/lib/hide.rb +259 -0
  86. data/lib/history.rb +286 -0
  87. data/lib/image.rb +51 -0
  88. data/lib/incrementer.rb +15 -0
  89. data/lib/insert.rb +7 -0
  90. data/lib/irc.rb +22 -0
  91. data/lib/key_bindings.rb +658 -0
  92. data/lib/keys.rb +754 -0
  93. data/lib/launcher.rb +1351 -0
  94. data/lib/line.rb +429 -0
  95. data/lib/links.rb +6 -0
  96. data/lib/location.rb +175 -0
  97. data/lib/macros.rb +48 -0
  98. data/lib/man.rb +19 -0
  99. data/lib/menu.rb +708 -0
  100. data/lib/merb.rb +259 -0
  101. data/lib/message.rb +5 -0
  102. data/lib/meths.rb +56 -0
  103. data/lib/mode.rb +34 -0
  104. data/lib/move.rb +248 -0
  105. data/lib/notes.rb +1000 -0
  106. data/lib/numbers.rb +45 -0
  107. data/lib/ol.rb +203 -0
  108. data/lib/ol_helper.rb +44 -0
  109. data/lib/overlay.rb +167 -0
  110. data/lib/pause_means_space.rb +68 -0
  111. data/lib/php.rb +22 -0
  112. data/lib/projects.rb +21 -0
  113. data/lib/relinquish_exception.rb +2 -0
  114. data/lib/remote.rb +206 -0
  115. data/lib/requirer.rb +46 -0
  116. data/lib/rest_tree.rb +108 -0
  117. data/lib/ruby.rb +57 -0
  118. data/lib/ruby_console.rb +165 -0
  119. data/lib/search.rb +1572 -0
  120. data/lib/search_term.rb +40 -0
  121. data/lib/snippet.rb +68 -0
  122. data/lib/specs.rb +229 -0
  123. data/lib/styles.rb +274 -0
  124. data/lib/svn.rb +682 -0
  125. data/lib/text_util.rb +110 -0
  126. data/lib/tree.rb +1871 -0
  127. data/lib/tree_cursor.rb +87 -0
  128. data/lib/trouble_shooting.rb +27 -0
  129. data/lib/url_tree.rb +11 -0
  130. data/lib/view.rb +1474 -0
  131. data/lib/window.rb +133 -0
  132. data/lib/xiki.rb +404 -0
  133. data/menus/accounts.rb +5 -0
  134. data/menus/address_book.rb +21 -0
  135. data/menus/agenda.rb +28 -0
  136. data/menus/all.rb +5 -0
  137. data/menus/amazon.rb +16 -0
  138. data/menus/app.rb +16 -0
  139. data/menus/applescript.rb +46 -0
  140. data/menus/as.rb +15 -0
  141. data/menus/bookmarklet.rb +63 -0
  142. data/menus/bootstrap.rb +568 -0
  143. data/menus/browse.rb +13 -0
  144. data/menus/browser.rb +78 -0
  145. data/menus/cassandra_db.rb +36 -0
  146. data/menus/chmod.rb +27 -0
  147. data/menus/classes.rb +5 -0
  148. data/menus/coffee_script.rb +35 -0
  149. data/menus/computer.rb +24 -0
  150. data/menus/contacts.rb +5 -0
  151. data/menus/cookies.rb +25 -0
  152. data/menus/couch.rb +184 -0
  153. data/menus/crop.rb +45 -0
  154. data/menus/css.rb +55 -0
  155. data/menus/current.rb +5 -0
  156. data/menus/db.rb +12 -0
  157. data/menus/deck.rb +219 -0
  158. data/menus/dictionary.rb +9 -0
  159. data/menus/dir.rb +8 -0
  160. data/menus/disk.rb +5 -0
  161. data/menus/do.rb +13 -0
  162. data/menus/docs.rb +58 -0
  163. data/menus/dotsies.rb +107 -0
  164. data/menus/edited.rb +18 -0
  165. data/menus/emacs.rb +17 -0
  166. data/menus/enter.rb +13 -0
  167. data/menus/eval.rb +17 -0
  168. data/menus/executable.rb +16 -0
  169. data/menus/filter.rb +46 -0
  170. data/menus/firefox.rb +607 -0
  171. data/menus/foo.rb +30 -0
  172. data/menus/french.rb +7 -0
  173. data/menus/git.rb +185 -0
  174. data/menus/gito.rb +785 -0
  175. data/menus/google.rb +35 -0
  176. data/menus/google_images.rb +11 -0
  177. data/menus/google_patents.rb +10 -0
  178. data/menus/gutenberg.rb +13 -0
  179. data/menus/head.rb +10 -0
  180. data/menus/headings.rb +39 -0
  181. data/menus/html.rb +61 -0
  182. data/menus/icon.rb +40 -0
  183. data/menus/images.menu +2 -0
  184. data/menus/img.rb +15 -0
  185. data/menus/info.rb +9 -0
  186. data/menus/ip.rb +10 -0
  187. data/menus/iterm.rb +36 -0
  188. data/menus/itunes.rb +78 -0
  189. data/menus/javascript.rb +74 -0
  190. data/menus/layout.rb +18 -0
  191. data/menus/local_storage.rb +67 -0
  192. data/menus/ls.rb +19 -0
  193. data/menus/mac.rb +87 -0
  194. data/menus/maps.rb +18 -0
  195. data/menus/matches.rb +18 -0
  196. data/menus/memcache.rb +117 -0
  197. data/menus/mkdir.rb +23 -0
  198. data/menus/mongo.rb +83 -0
  199. data/menus/mysql.rb +294 -0
  200. data/menus/node.rb +88 -0
  201. data/menus/open.rb +19 -0
  202. data/menus/outline.rb +24 -0
  203. data/menus/piano.rb +746 -0
  204. data/menus/postgres.rb +34 -0
  205. data/menus/pre.rb +5 -0
  206. data/menus/python.rb +39 -0
  207. data/menus/rails.rb +160 -0
  208. data/menus/rake.rb +12 -0
  209. data/menus/redmine.rb +168 -0
  210. data/menus/riak_tree.rb +204 -0
  211. data/menus/rss.rb +15 -0
  212. data/menus/safari.rb +11 -0
  213. data/menus/sass.rb +15 -0
  214. data/menus/say.rb +6 -0
  215. data/menus/scale.rb +49 -0
  216. data/menus/serve.rb +78 -0
  217. data/menus/shuffle.rb +24 -0
  218. data/menus/spanish.rb +7 -0
  219. data/menus/standalone.rb +57 -0
  220. data/menus/tail.rb +41 -0
  221. data/menus/technologies.rb +19 -0
  222. data/menus/themes.rb +32 -0
  223. data/menus/thesaurus.rb +13 -0
  224. data/menus/to.rb +24 -0
  225. data/menus/twitter.rb +57 -0
  226. data/menus/wikipedia.rb +34 -0
  227. data/menus/words.rb +11 -0
  228. data/spec/code_tree_spec.rb +59 -0
  229. data/spec/diff_log_spec.rb +40 -0
  230. data/spec/file_tree_spec.rb +102 -0
  231. data/spec/keys_spec.rb +24 -0
  232. data/spec/line_spec.rb +68 -0
  233. data/spec/menu_spec.rb +50 -0
  234. data/spec/ol_spec.rb +98 -0
  235. data/spec/remote_spec.rb +43 -0
  236. data/spec/search_spec.rb +162 -0
  237. data/spec/text_util_spec.rb +119 -0
  238. data/spec/tree_cursor_spec.rb +91 -0
  239. data/spec/tree_spec.rb +955 -0
  240. data/tests/console_test.rb +11 -0
  241. data/tests/couch_db_test.rb +12 -0
  242. data/tests/diff_log_test.rb +43 -0
  243. data/tests/el_mixin.rb +16 -0
  244. data/tests/git_test.rb +95 -0
  245. data/tests/keys_test.rb +19 -0
  246. data/tests/line_test.rb +38 -0
  247. data/tests/merb_test.rb +11 -0
  248. data/tests/redmine_test.rb +50 -0
  249. data/tests/remote_test.rb +31 -0
  250. data/tests/rest_tree_test.rb +70 -0
  251. data/xiki.gemspec +37 -0
  252. metadata +332 -0
@@ -0,0 +1,13 @@
1
+ class Browse
2
+ def self.menu file=nil, heading=nil, *content
3
+
4
+ return "| Pass a bookmark and then use this menu to browse headings\n| in the file, such as:\n|\n@ browse/$t/" if file == "docs"
5
+
6
+ return View.prompt "Type a bookmark of a .notes file." if file.nil? # If no file, say it's required
7
+
8
+ # Add dollar sign if not there
9
+ file = "$#{file}" unless file =~ /^\$/
10
+
11
+ Notes.drill "#{file}", heading, *content
12
+ end
13
+ end
@@ -0,0 +1,78 @@
1
+ class Browser
2
+ def self.menu
3
+ "
4
+ - .url/
5
+ - .reload/
6
+ - .tabs/
7
+ - api/
8
+ | This class lets you choose a default browser.
9
+ |
10
+ | Calls to Browser.url etc. will be delegated to the default browser.
11
+ - docs/
12
+ > Keys
13
+ | do+load+browser: Reload the browser.
14
+ |
15
+ > See
16
+ | Many things have yet to be pulled out of firefox.rb and made generic.
17
+ << firefox/
18
+ |
19
+ "
20
+ end
21
+
22
+ def self.url url, options={}
23
+ Firefox.url url, options
24
+ end
25
+
26
+
27
+ def self.html html
28
+ Firefox.html html
29
+ end
30
+
31
+ def self.js txt, options={}
32
+ Firefox.run txt, options
33
+ end
34
+
35
+
36
+ def self.open_in_browser
37
+
38
+ if Keys.prefix_u # Open as http://xiki/...
39
+
40
+ return self.url "http://xiki/#{Tree.path}"
41
+ end
42
+
43
+ file = FileTree.tree_path_or_this_file
44
+
45
+ return Browser.html Markdown.render(View.txt) if View.extension == "markdown" # If .markdown, render it
46
+
47
+ mappings = Menu.menu_to_hash "/Users/craig/menus/url_mappings.menu"
48
+
49
+ result = nil
50
+ mappings.each do |k, v|
51
+ break file.sub!(v, "#{k}/") if file.start_with? v
52
+ end
53
+
54
+ # If path starts with any of the mappings, apply mapping
55
+
56
+ if file =~ /^\// # If no ^/, must be a url, so use http://
57
+ file = "file://#{file}"
58
+ else
59
+ file = "http://#{file}"
60
+ file.sub! /\/index.html/, '/'
61
+ end
62
+
63
+ self.url file
64
+ end
65
+
66
+ def self.tabs
67
+ Firefox.tabs
68
+ end
69
+
70
+ def self.url *args
71
+ Firefox.url args.join "/"
72
+ end
73
+
74
+ def self.reload
75
+ Firefox.reload
76
+ end
77
+
78
+ end
@@ -0,0 +1,36 @@
1
+ gem 'cassandra'
2
+ require 'cassandra'
3
+
4
+ require "launcher"
5
+
6
+ # Cassandras structure:
7
+ # keyspace ->* table family ->* key (->* super column) ->* column
8
+ class CassandraDb
9
+
10
+ @@connections = {}
11
+
12
+ def self.conn keyspace
13
+ @@connections[keyspace] ||= Cassandra.new(keyspace, '127.0.0.1:9160')
14
+ end
15
+
16
+ def self.insert keyspace, column_family, key, columns
17
+ conn = self.conn keyspace
18
+ conn.insert column_family, key, columns
19
+ end
20
+
21
+ def self.get keyspace, column_family, key, columns=nil
22
+ conn = self.conn keyspace
23
+ conn.get column_family, key, columns
24
+ end
25
+
26
+ def self.menu
27
+ "
28
+ + .start/
29
+ - TODO: implement!
30
+ + .statements/
31
+ CassandraDb.insert 'Animals', :Ant, 'Steve', {'bbbb' => 'bbb'}
32
+ CassandraDb.get 'Animals', :Ant, 'Steve'
33
+ "
34
+ end
35
+
36
+ end
@@ -0,0 +1,27 @@
1
+ class Chmod
2
+ def self.menu mode=nil
3
+
4
+ path = Tree.file :require=>1
5
+
6
+ if ! mode
7
+ base_10_number = File.stat(path).mode
8
+ mode = sprintf("%o", base_10_number)[/...$/]
9
+ return "
10
+ - original) #{mode}/
11
+ > Suggestions:
12
+ - no restrictions) 777/
13
+ - normal) 644/
14
+ - executable) 755/
15
+ - only owner) 600/
16
+ "
17
+ end
18
+
19
+ # Arg passed, so do chmod
20
+
21
+ command = "chmod #{mode} \"#{path}\""
22
+ command = "sudo #{command}" if ! File.writable? path
23
+
24
+ Console.run command, :dir=>path
25
+
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ class Classes
2
+ def self.menu *args
3
+ Menu["ruby/classes/#{args.join '/'}"]
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+ class CoffeeScript
2
+
3
+ # Called by keyboard shortcut
4
+ def self.run_block
5
+ # Get block contents
6
+ txt, left, right = View.txt_per_prefix #:prefix=>Keys.prefix
7
+
8
+ result = self.to_js txt
9
+ # Insert result at end of block
10
+ orig = Location.new
11
+ View.cursor = right
12
+ Line.to_left
13
+ View.insert ">>\n#{result}\n\n"
14
+ orig.go
15
+ end
16
+
17
+ def self.to_js txt
18
+
19
+ path = "/tmp/tmp.coffee"
20
+
21
+ # If txt is file path, us it
22
+ if txt !~ /\n/ && txt =~ /\.coffee$/
23
+ path = txt
24
+ else
25
+ File.open(path, "w") { |f| f << txt } # Write to temp file
26
+ end
27
+
28
+ # Call js
29
+ result = Console.run "coffee -pc \"#{path}\"", :sync=>true
30
+ result.split("\n")[1..-2].join("\n")
31
+ end
32
+
33
+ end
34
+
35
+ Keys.do_as_coffee { CoffeeScript.run_block }
@@ -0,0 +1,24 @@
1
+ # Is just a menu now, since it's all delegation
2
+
3
+
4
+ class Computer
5
+
6
+ def self.menu
7
+ "
8
+ - .ip/
9
+ - @processes/
10
+ "
11
+ end
12
+
13
+ def self.ip
14
+ # return "| 192.168.5.231"
15
+
16
+ txt = `ifconfig`
17
+ inet = txt.grep(/\binet\b/)
18
+
19
+ return "| #{inet[0][/[\d.]+/]}\n- apparently you\'re not connected to the internet?!" if inet.length < 2
20
+
21
+ "| #{inet[1][/[\d.]+/]}"
22
+ end
23
+
24
+ end
@@ -0,0 +1,5 @@
1
+ class Contacts
2
+ def self.menu *args
3
+ Notes.drill '$c', *args
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ class Cookies
2
+ def self.menu key=nil, val=nil
3
+
4
+ txt = Firefox.run "document.cookie"
5
+ hash = txt.split('; ').inject({}) do |acc, e|
6
+ k, v = e.match(/(.*?)=(.*)/)[1..2]
7
+ acc[k] = v
8
+ acc
9
+ end
10
+
11
+ # If no args, show all keys
12
+
13
+ if key.nil?
14
+ return hash.keys.sort.map{|k| "- #{k}/\n"}.join
15
+ end
16
+
17
+ # If just key, show its value
18
+ if val.nil?
19
+ return "| #{hash[key]}"
20
+ end
21
+
22
+ ".flash - updated!"
23
+
24
+ end
25
+ end
@@ -0,0 +1,184 @@
1
+ gem 'couchrest'
2
+ require 'couchrest'
3
+
4
+ class Couch
5
+ @@server = 'http://localhost:5984'
6
+
7
+ def self.menu
8
+ "
9
+ - .start/
10
+ - @db/
11
+ - .admin url/
12
+ "
13
+ end
14
+
15
+ def self.start
16
+ buffer = '*couchdb'
17
+ return ".flash - *couchdb already open!" if View.buffer_open? buffer
18
+
19
+ Console.run('sudo couchdb', :buffer=>buffer)
20
+ end
21
+
22
+ def self.admin_url
23
+ View.url "#{@@server}/_utils"
24
+ nil
25
+ end
26
+
27
+ def self.databases db=nil
28
+ if db.nil? # If no db yet, list all
29
+ txt = Net::HTTP.get(URI.parse("#{@@server}/_all_dbs"))
30
+ dbs = JSON[txt]
31
+
32
+ return dbs.map{|i| "#{i}/"}
33
+ end
34
+
35
+ "
36
+ + .docs/
37
+ + .views/
38
+ + .all_docs/
39
+ + .delete/
40
+ + .rest_tree/
41
+ + .crud/
42
+ "
43
+ end
44
+
45
+ def self.rest_tree db
46
+ %Q[
47
+ - GET #{@@server}/#{db}
48
+ + create db: PUT
49
+ + delete db: DELETE
50
+ + all: _all_docs/
51
+ - bulk add: _bulk_docs/
52
+ POST
53
+ {"docs":[
54
+ {"_id":"a", "txt":"Aye"},
55
+ {"_id":"b", "txt":"Bee"},
56
+ ]}
57
+ - bar/
58
+ + PUT {\"txt\":\"hi\"}
59
+ - ?rev=9123589
60
+ + DELETE
61
+ - _view/d1/v1/
62
+ - _design/d1/
63
+ + PUT {"views": {"v1": {"map": "function(doc){ emit(\\\"a\\\", null); }" }}}
64
+ ]
65
+ end
66
+
67
+ def self.delete db, id=nil
68
+
69
+ # If no id, show all id's
70
+ if id.nil?
71
+ all = RestTree.request 'GET', "#{@@server}/#{db}_all_docs", nil
72
+ rows = JSON[all]['rows']
73
+ return rows.map{|i| "#{i['id']}/"}
74
+ end
75
+
76
+ self.escape_slashes id
77
+
78
+ # If id, look it up to get rev
79
+ record = RestTree.request 'GET', "#{@@server}/#{db}#{id}", nil
80
+ rev = JSON[record]['_rev']
81
+ # Delete it
82
+ RestTree.request 'DELETE', "#{@@server}/#{db}#{id}?rev=#{rev}", nil
83
+ end
84
+
85
+ def self.escape_slashes id
86
+ # If id has multiple slashes, escape all but the last
87
+ if id =~ /\/.+\/$/
88
+ id.sub! /\/$/, '' # Remove last slash
89
+ id.gsub!('/', '%2F') unless id =~ /^_design/ # Escape slashes
90
+ id.sub! /$/, '/' # Put last back
91
+ end
92
+ end
93
+
94
+ def self.docs db, id=nil, doc=nil
95
+ db.sub! /\/$/, ''
96
+
97
+ # If no id, show all id's
98
+ if id.nil?
99
+ all = RestTree.request 'GET', "#{@@server}/#{db}/_all_docs", nil
100
+
101
+ if all =~ /no_db_file/
102
+ return "| DB not found, create it?\n- .create/"
103
+ end
104
+
105
+ rows = JSON[all]['rows']
106
+
107
+ return "
108
+ | No records in db. Create some?
109
+ a/name: aye
110
+ b/name: bee
111
+ " if rows.empty?
112
+
113
+ return rows.map{|i| "#{i['id']}/"}
114
+ end
115
+
116
+ self.escape_slashes id
117
+
118
+ # If just id, show doc
119
+
120
+ if doc.nil?
121
+
122
+ record = RestTree.request 'GET', "#{@@server}/#{db}/#{id}", nil
123
+ record = JSON[record]
124
+ record = record.to_yaml
125
+ record.sub! /.+\n/, ''
126
+ return record.gsub("\\n", "\n").gsub(/^/, '| ').gsub(/^\| $/, '|')
127
+ end
128
+
129
+ # Doc passed, so save it
130
+
131
+ doc = ENV['txt'].dup
132
+
133
+ # If a record is found, add rev
134
+ record = RestTree.request 'GET', "#{@@server}/#{db}/#{id}", nil
135
+ if record !~ /404 /
136
+ rev = JSON[record]['_rev']
137
+
138
+ # Insert rev after first {, or replace if there already
139
+ if doc =~ /"_rev":"\d+"/
140
+ doc.sub! /("_rev":")\d+(")/, "\\1#{rev}\\2"
141
+ else
142
+ doc.sub! /\{/, "{\"_rev\":\"#{rev}\", "
143
+ end
144
+ end
145
+
146
+ doc = YAML::load doc
147
+ doc = doc.to_json
148
+ # Update it
149
+ res = RestTree.request 'PUT', "#{@@server}/#{db}/#{id}", doc
150
+ ".flash - Updated!"
151
+ end
152
+
153
+ def self.views db
154
+ db.sub! /\/$/, ''
155
+ views = JSON[RestTree.request('GET', "#{@@server}/#{db}/_design/d1", nil)]['views'] rescue(return "- none found!")
156
+
157
+ views.keys.each do |k|
158
+ puts "y Cdb.#{db[/(.+)_/, 1]} :#{k}#, :key=>''"
159
+ end
160
+ end
161
+
162
+ def self.all_docs db
163
+ db = db[/(.+)_/, 1]
164
+ puts "y Cdb.#{db}"
165
+ puts "y Cdb.all :#{db}#, :key=>''"
166
+ puts "- descending: y Cdb.all :#{db}, :skip=>1, :descending=>true"
167
+ end
168
+
169
+ def self.create db
170
+ RestTree.request 'PUT', "#{@@server}/#{db}", nil
171
+ ".flash - created!"
172
+ end
173
+
174
+ def self.crud db
175
+ db = db[/(.+)_/, 1]
176
+ puts "y Cdb.#{db} ''"
177
+ puts "- save: y Cdb.#{db}! '', 'txt'=>''"
178
+ puts "- delete: y Cdb.delete :#{db}, ''"
179
+ puts "- search: y Cdb.#{db} :startkey=>'b', :endkey=>'n', :skip=>2, :limit=>3"
180
+ puts "- first: y Cdb.all :#{db}, :limit=>1, :include_docs=>true"
181
+ puts "- last: y Cdb.all :#{db}, :skip=>1, :limit=>1, :descending=>true, :include_docs=>true"
182
+ end
183
+
184
+ end
@@ -0,0 +1,45 @@
1
+ class Crop
2
+
3
+ def self.menu coords=nil, save=nil
4
+
5
+ dir = Tree.dir :file=>"foo.png"
6
+
7
+ tmp_dir = "/tmp/crop"
8
+ Dir.mkdir tmp_dir if ! File.exists? tmp_dir
9
+
10
+ # If nothing, show coords options
11
+
12
+ return "
13
+ - 40x40+10+10/
14
+ - 200x200+100+100/
15
+ " if ! coords
16
+
17
+ dir, file = File.dirname(dir), File.basename(dir)
18
+ dest = file.sub '.', "_#{coords.sub('+', '_')}."
19
+
20
+ # If just coords, so crop into tmp dir and show
21
+
22
+ if save.nil?
23
+ dest = "#{tmp_dir}/#{dest}"
24
+
25
+ Console.sync %`convert "#{file}" -crop #{coords} "#{dest}"`, :dir=>dir
26
+ Image.>> dest, "_"
27
+ return
28
+ end
29
+
30
+ # Image clicked on, so crop to destination
31
+
32
+ Console.sync %`convert "#{file}" -crop #{coords} "#{dest}"`, :dir=>dir
33
+ Line.previous
34
+ Tree.to_parent
35
+ Tree.kill_under
36
+ indent = Line.indent Line.value(0)
37
+ Line.next
38
+ View.<< "#{indent}- #{dest}\n", :dont_move=>1
39
+
40
+ Effects.glow :fade_in=>1
41
+
42
+ nil
43
+
44
+ end
45
+ end