xiki 0.5.0a

Sign up to get free protection for your applications and to get access to all the features.
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,18 @@
1
+ class Layout
2
+ def self.menu
3
+ %`
4
+ | Keys shortcuts that start with "to+" (ctrl-t) such as to+end.
5
+ - frequent/
6
+ | layout+create: Create a new view
7
+ | layout+hide: Hide this view
8
+ | layout+next: Go to next view
9
+ | layout+previous: Go to previous view
10
+ | layout+kill: Close the current file
11
+ - all/
12
+ | TODO
13
+ |
14
+ > See also
15
+ << view/
16
+ `
17
+ end
18
+ end
@@ -0,0 +1,67 @@
1
+ class LocalStorage
2
+ def self.menu
3
+ "
4
+ - .all/
5
+ - docs/
6
+ > Summary
7
+ | View and manipulate records in the browser's \"Local Storage\" database.
8
+ |
9
+ > Show all records
10
+ << all/
11
+ |
12
+ > Manipulating records
13
+ | save: double-click record contents
14
+ | delete: do+kill+it while on the record (Ctrl-d Ctrl-k Ctrl-i)
15
+ |
16
+ > Delete all keys
17
+ @ js/localStorage.clear()
18
+ "
19
+ end
20
+
21
+ def self.all key=nil, val=nil
22
+ prefix = Keys.prefix :clear=>true
23
+
24
+
25
+ if key.nil? # If nothing passed, show all keys
26
+ js = %`
27
+ var result = [];
28
+ for (var key in localStorage) { result.push(key) }
29
+ JSON.stringify(result);
30
+ `
31
+ txt = Firefox.run js, #:jquery=>1 #, :jquery_extra=>ls_function
32
+ array = JSON[txt]
33
+ return "
34
+ | None found. Create a few test records?
35
+ - a/aa
36
+ - b/bb
37
+ " if array.empty?
38
+ return array.sort.inject("") {|acc, element| "#{acc}- #{element}/\n"}
39
+ end
40
+
41
+ if Keys.delete?
42
+ Firefox.run "localStorage.removeItem(\"#{key}\")" #, :jquery=>1
43
+ Tree.to_parent if val
44
+ Tree.kill_under
45
+ View.flash "- deleted!"
46
+ # TODO: let this behave properly when returning with .flash:
47
+ # Currently it ends up one line off? Because we're treating it like it returned nil - make it treat ^.flash as nill?
48
+ # return ".flash - deleted!"
49
+ Line.delete
50
+ return
51
+ end
52
+
53
+ if val.nil? # If just key passed, show val
54
+ txt = Firefox.run "localStorage[\"#{key}\"]" #, :jquery=>1
55
+ return self.docs if txt.blank? && key =~ /docs\/?/
56
+ return self.api if txt.blank? && key =~ /api\/?/
57
+ return Tree.quote txt
58
+ end
59
+
60
+ Tree.unquote! val
61
+
62
+ val = ENV['txt']
63
+ txt = Firefox.run "localStorage[\"#{key}\"] = #{val.inspect}" #, :jquery=>1
64
+ View.flash "- Saved!"
65
+ end
66
+
67
+ end
@@ -0,0 +1,19 @@
1
+ class Ls
2
+ def self.docs
3
+ "
4
+ > Summary
5
+ | Simple wrapper around the 'ls' shell command. Can be used in trees.
6
+
7
+ > Example usage
8
+ @/tmp/
9
+ @ls
10
+ "
11
+ end
12
+
13
+ def self.menu *args
14
+ return self.docs if args == ['docs']
15
+
16
+ path = Tree.file :require=>1
17
+ Tree.quote Console.sync "ls -lah \"#{path}\"", :dir=>path
18
+ end
19
+ end
@@ -0,0 +1,87 @@
1
+ # Starting and stopping mac
2
+ class Mac
3
+
4
+ def self.menu
5
+ %`
6
+ - Enable mac keyboard shortcuts/
7
+ | Enable macintosh-like keyboard shortcuts, like command-c
8
+ @ Mac.define_keys
9
+ - Important dirs/
10
+ @/Users/
11
+ @/Applications/
12
+ @/Applications/Utilities/
13
+ @ ~/Library/Fonts/
14
+ - api/
15
+ | Define standard mac shortcuts
16
+ @ Mac.define_keys
17
+ `
18
+ end
19
+
20
+ def self.define_keys
21
+ self.keys
22
+ View.flash "- defined Command-C, Command-V, Command-Q, etc."
23
+ end
24
+
25
+ #
26
+ # Use this if you're using aquamacs
27
+ #
28
+ # Put this line in your init.rb file to use the below key mappings.
29
+ #
30
+ # Mac.keys_for_aquamacs
31
+ #
32
+ def self.keys_for_aquamacs
33
+
34
+ return if ! $el.boundp(:osx_key_mode_map)
35
+
36
+ $el.define_key(:osx_key_mode_map, $el.kbd("A-0")) { Styles.font_size 110 }
37
+ $el.define_key(:osx_key_mode_map, $el.kbd("A-=")) { Styles.zoom }
38
+ $el.define_key(:osx_key_mode_map, $el.kbd("A--")) { Styles.zoom :out=>1 }
39
+
40
+ # Changes aquamacs behavior so it opens in same frame. Is there
41
+ # an aquamacs setting for this that could be used instead of redefining
42
+ # key?
43
+ $el.define_key :osx_key_mode_map, $el.kbd("A-n") do
44
+ View.to_buffer "untitled"
45
+ $el.rename_uniquely
46
+ Notes.mode
47
+ View.>> "\n"
48
+ end
49
+
50
+ $el.define_key :osx_key_mode_map, $el.kbd("<A-return>") do
51
+ Launcher.launch_or_hide(:blink=>true)
52
+ end
53
+
54
+ $el.define_key :cua_global_keymap, $el.kbd("<C-return>"), nil # Prohibit cua from monopolizing C-return key
55
+
56
+ end
57
+
58
+ #
59
+ # Use this if you're not using aquamacs
60
+ #
61
+ # Put this line in your init.rb file to use the below key mappings.
62
+ #
63
+ # Mac.keys
64
+ #
65
+ def self.keys
66
+
67
+ # def self.keys
68
+ Keys._Q { $el.save_buffers_kill_emacs } # Command-Q to quit
69
+ Keys._C {
70
+ left, right = View.range
71
+ Effects.blink :left=>left, :right=>right
72
+ $el.kill_ring_save left, right
73
+ } # Command-C
74
+ Keys._V { $el.yank } # Command-V
75
+ Keys._A { View.to_highest; Clipboard.copy_everything } # Command-V
76
+
77
+ Keys._X {
78
+ left, right = View.range
79
+ Effects.blink :left=>left, :right=>right
80
+ $el.kill_region left, right
81
+ }
82
+
83
+ Keys._S { DiffLog.save } # save (or, with prefix, save as) **
84
+
85
+ $el.define_key :global_map, $el.kbd("M-X"), :execute_extended_command
86
+ end
87
+ end
@@ -0,0 +1,18 @@
1
+ require 'view'
2
+ require 'effects'
3
+
4
+ class Maps
5
+
6
+ def self.menu *args
7
+
8
+ # If no arg, prompt to type something
9
+
10
+ return View.prompt "Type something to search on google maps" if args.blank?
11
+
12
+ # If arg, look it up
13
+
14
+ Firefox.url "http://maps.google.com/maps?q=#{ENV['txt'].gsub "\n", ", "}"
15
+ nil
16
+
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ class Matches
2
+ def self.menu *args
3
+
4
+ # If no args, explain what it does
5
+
6
+ if args.empty?
7
+ return View.prompt "Count matches of what?"
8
+ end
9
+
10
+ # If only one arg, have them add some text
11
+
12
+ if args.length == 1
13
+ return Tree << "| Add some text here to matches the matches."
14
+ end
15
+
16
+ txt = ENV['txt'].scan(/#{args[0]}/i).length.to_s
17
+ end
18
+ end
@@ -0,0 +1,117 @@
1
+ gem 'memcached'
2
+ require 'memcached'
3
+ require 'net/telnet'
4
+
5
+ class Memcache
6
+ def self.menu
7
+ txt =
8
+ "
9
+ - .keys/
10
+ - .start/
11
+ "
12
+ txt << "- .server/\n" if View.buffer_open? "*memcached"
13
+ txt
14
+ end
15
+
16
+ def self.start
17
+ buffer = "*memcached"
18
+ if View.buffer_open? buffer # If already open
19
+ View.flash "- '*memcached' is already open!", :times=>4
20
+ return self.server
21
+ end
22
+ Console.run('memcached -vv -p 11211 -m 64', :buffer=>buffer)
23
+ end
24
+
25
+ def self.server
26
+ View.to_after_bar
27
+ View.to_buffer "*memcached"
28
+ nil
29
+ end
30
+
31
+ def self.suggest_if_not_running e
32
+
33
+ if e.message =~ /Connection refused/ || e.message =~ /SystemError: Errno 22:/ || e.message =~ /Errno 22/
34
+
35
+ return "
36
+ | > Not installed
37
+ | Memcached doesn't appear to be installed.
38
+ |
39
+ | > Install instructions
40
+ | On a mac
41
+ @$ port install memcached
42
+ |
43
+ | On ubuntu
44
+ @$ sudo apt-get install memcached
45
+ |
46
+ | > Other platforms and more info
47
+ @http://code.google.com/p/memcached/wiki/NewStart
48
+ |
49
+ " if `which memcached`.empty?
50
+
51
+ return "
52
+ > Not running
53
+ | Memcached doesn't appear to be running.
54
+ - start it) @memcache/start/"
55
+ end
56
+ nil
57
+ end
58
+
59
+ def self.keys *args
60
+
61
+ begin
62
+
63
+ # If nothing passed, show all keys
64
+
65
+ if args.blank?
66
+
67
+ # Hack to get all (usually) keys
68
+ con = Net::Telnet::new("Host"=>"127.0.0.1", "Port"=>11211, "Prompt" => /END/)
69
+ items = con.cmd "stats items\n"
70
+ keys = []
71
+ items.scan(/^STAT items:(\d+):number/).each do |i|
72
+ cachedump = con.cmd "stats cachedump #{i[0]} 1000"
73
+ cachedump.scan(/^ITEM (.+?) /).each {|i| keys << i[0]}
74
+ end
75
+ return "
76
+ | > No keys exist
77
+ | Create some:
78
+ - foo/
79
+ | aa
80
+ - bar/
81
+ | b: bb
82
+ " if keys.empty?
83
+ return keys.map{|k| "#{k}/"}
84
+ end
85
+
86
+ value = args.pop if Line =~ /^ *\|/
87
+ key = args.join "/"
88
+
89
+ # If just key, show the value
90
+
91
+ if value.nil?
92
+ return self.connection.get(key).to_yaml.sub(/\A--- \n?/, '').gsub(/^/, "| ")
93
+ end
94
+
95
+ if Keys.prefix == 0
96
+ self.connection.delete key
97
+ View.flash "- Deleted!"
98
+ return
99
+ end
100
+
101
+ value = YAML::load Tree.siblings(:string=>1)
102
+ self.connection.set key, value
103
+
104
+ View.flash "- Saved!"
105
+
106
+ rescue Exception=>e
107
+ return "- Not found!\n| sample value" if e.message == "Memcached::NotFound"
108
+
109
+ result = self.suggest_if_not_running(e) and return result
110
+ raise e
111
+ end
112
+ end
113
+
114
+ def self.connection
115
+ Memcached.new 'localhost:11211' #, :hash=>:default
116
+ end
117
+ end
@@ -0,0 +1,23 @@
1
+ class Mkdir
2
+
3
+ def self.menu
4
+ trunk = Xiki.trunk
5
+ return "
6
+ > Usage
7
+ | Nest @mkdir under a dir path to create the dir, like this:
8
+ |
9
+ | - /tmp/newdir/
10
+ | - @mkdir
11
+ |
12
+ " if trunk.length <= 1
13
+
14
+ closest_file_path = Tree.closest_dir
15
+
16
+ return View.flash("- Already exists: #{closest_file_path}") if File.exists?(closest_file_path)
17
+
18
+ `mkdir -p "#{closest_file_path}"`
19
+
20
+ return View.flash "- Created: #{closest_file_path}", :times=>3
21
+ end
22
+
23
+ end
@@ -0,0 +1,83 @@
1
+ class Mongo
2
+ def self.menu # bucket=nil
3
+ %`
4
+ - .collections/
5
+ - docs/
6
+ > Create
7
+ @foo.save({_id:"a", txt:"b"})
8
+
9
+ > Show
10
+ @foo.find()
11
+ @foo.find({_id:"a"})
12
+
13
+ > Update
14
+ @foo.update({_id:"a"}, {txt:"bbb"})
15
+
16
+ > Delete
17
+ @foo.remove({_id:"a"})
18
+ `.unindent
19
+ end
20
+
21
+ def self.collections collection=nil
22
+
23
+ collection.sub!(/\/$/, '') if collection
24
+
25
+ # If /, list databases
26
+
27
+ if collection.nil?
28
+ json = self.run 'printjson(db._adminCommand("listDatabases"))'
29
+ o = JSON[json]
30
+ return o["databases"].map{|d| "#{d['name']}/"}
31
+ end
32
+
33
+ self.run("db.#{collection}.find()").gsub(/^/, '| ')
34
+ end
35
+
36
+ def self.run command
37
+ command << ".forEach(printjson)" if command =~ /.find\(/
38
+ txt = `mongo --eval '#{command}'`
39
+
40
+ if txt =~ /couldn't connect to server/
41
+ raise "> Mongo isn't running. Start it?
42
+ @/tmp/
43
+ % mongod
44
+ ".unindent
45
+ end
46
+
47
+ txt.sub /(.+\n){2}/, '' # Delete first 2 lines
48
+
49
+ end
50
+
51
+ def self.init
52
+
53
+ Launcher.add(/^db\./) do |l| # General db... lines
54
+ l.strip!
55
+ txt = self.run l
56
+ Tree.under "#{txt.strip}\n", :escape=>'| ', :no_slash=>1
57
+ end
58
+
59
+ Launcher.add(/^(\w+)\.(save|update)\(/) do |l| # Shortcut for foo.save()
60
+ l.strip!
61
+ l = "db.#{l}"
62
+ txt = self.run l
63
+ Tree.under "done#{txt.strip}\n", :escape=>'| ', :no_slash=>1
64
+ end
65
+
66
+ Launcher.add(/^(\w+)\.find\(/) do |l| # Shortcut for foo.find()
67
+ l.strip!
68
+ l = "db.#{l}"
69
+ txt = self.run l
70
+ Tree.under "#{txt.strip}\n", :escape=>'| ', :no_slash=>1
71
+ end
72
+
73
+ Launcher.add(/^(\w+)\.remove\(/) do |l| # Shortcut for foo.remove()
74
+ l.strip!
75
+ l = "db.#{l}"
76
+ txt = self.run l
77
+ Tree.under "#{txt.strip}\n", :escape=>'| ', :no_slash=>1
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+ Mongo.init