xiki 0.5.1a → 0.5.3a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/Gemfile +1 -11
  2. data/README.markdown +67 -43
  3. data/bin/xiki +2 -15
  4. data/etc/command/xiki_command.rb +115 -41
  5. data/etc/command/xiki_process.rb +3 -7
  6. data/etc/install/el4r_setup.sh +5 -0
  7. data/etc/themes/Black_BG.notes +8 -0
  8. data/etc/themes/Dark_Metal.notes +0 -6
  9. data/etc/themes/Default.notes +24 -0
  10. data/etc/themes/Fall_Fonts.notes +6 -0
  11. data/etc/themes/Light_Gray_BG_Theme.notes +6 -0
  12. data/etc/themes/Orange_Path.notes +1 -1
  13. data/etc/themes/Pastel_Fonts.notes +6 -0
  14. data/etc/themes/Path_Mode_Line.notes +36 -0
  15. data/etc/themes/Rainbow_Fonts.notes +20 -0
  16. data/etc/themes/Shiny_Blue.notes +14 -18
  17. data/etc/themes/Shiny_Green.notes +0 -6
  18. data/etc/themes/White_BG.notes +5 -0
  19. data/etc/vim/vim_status.notes +32 -0
  20. data/etc/vim/xiki.vim +16 -0
  21. data/etc/wrappers/wrapper.rb +2 -2
  22. data/etc/www/index.rb +1 -1
  23. data/etc/www/public/error.html +47 -0
  24. data/etc/www/sinatra_server.rb +353 -0
  25. data/etc/www/web_server.rb +0 -252
  26. data/lib/xiki.rb +94 -26
  27. data/lib/{block.rb → xiki/block.rb} +0 -0
  28. data/lib/{bookmarks.rb → xiki/bookmarks.rb} +11 -10
  29. data/lib/{buffers.rb → xiki/buffers.rb} +10 -10
  30. data/lib/{clipboard.rb → xiki/clipboard.rb} +2 -2
  31. data/lib/{code.rb → xiki/code.rb} +3 -7
  32. data/lib/{code_tree.rb → xiki/code_tree.rb} +3 -3
  33. data/lib/{color.rb → xiki/color.rb} +4 -14
  34. data/lib/{console.rb → xiki/console.rb} +6 -0
  35. data/lib/{control_lock.rb → xiki/control_lock.rb} +5 -1
  36. data/lib/{control_tab.rb → xiki/control_tab.rb} +3 -1
  37. data/lib/{core_ext.rb → xiki/core_ext.rb} +7 -3
  38. data/lib/{cursor.rb → xiki/cursor.rb} +4 -5
  39. data/lib/{deletes.rb → xiki/deletes.rb} +0 -0
  40. data/lib/{diff_log.rb → xiki/diff_log.rb} +4 -4
  41. data/lib/{effects.rb → xiki/effects.rb} +5 -2
  42. data/lib/{environment.rb → xiki/environment.rb} +0 -0
  43. data/lib/{file_tree.rb → xiki/file_tree.rb} +34 -24
  44. data/lib/{files.rb → xiki/files.rb} +15 -5
  45. data/lib/{hide.rb → xiki/hide.rb} +0 -0
  46. data/lib/{history.rb → xiki/history.rb} +1 -0
  47. data/lib/{image.rb → xiki/image.rb} +0 -0
  48. data/lib/{incrementer.rb → xiki/incrementer.rb} +0 -0
  49. data/lib/{insert.rb → xiki/insert.rb} +0 -0
  50. data/lib/{irc.rb → xiki/irc.rb} +0 -0
  51. data/lib/{key_bindings.rb → xiki/key_bindings.rb} +7 -4
  52. data/lib/{keys.rb → xiki/keys.rb} +32 -36
  53. data/lib/{launcher.rb → xiki/launcher.rb} +42 -23
  54. data/lib/{line.rb → xiki/line.rb} +1 -1
  55. data/lib/{links.rb → xiki/links.rb} +0 -0
  56. data/lib/{location.rb → xiki/location.rb} +0 -0
  57. data/lib/{macros.rb → xiki/macros.rb} +0 -0
  58. data/lib/{man.rb → xiki/man.rb} +0 -0
  59. data/lib/{menu.rb → xiki/menu.rb} +62 -11
  60. data/lib/{merb.rb → xiki/merb.rb} +1 -1
  61. data/lib/{message.rb → xiki/message.rb} +0 -0
  62. data/lib/{meths.rb → xiki/meths.rb} +0 -0
  63. data/lib/{mode.rb → xiki/mode.rb} +0 -0
  64. data/lib/{move.rb → xiki/move.rb} +1 -1
  65. data/lib/{notes.rb → xiki/notes.rb} +41 -37
  66. data/lib/{numbers.rb → xiki/numbers.rb} +0 -0
  67. data/lib/{ol.rb → xiki/ol.rb} +2 -3
  68. data/lib/{ol_helper.rb → xiki/ol_helper.rb} +0 -0
  69. data/lib/{overlay.rb → xiki/overlay.rb} +0 -0
  70. data/lib/{pause_means_space.rb → xiki/pause_means_space.rb} +2 -2
  71. data/lib/{php.rb → xiki/php.rb} +0 -0
  72. data/lib/{projects.rb → xiki/projects.rb} +8 -1
  73. data/lib/{relinquish_exception.rb → xiki/relinquish_exception.rb} +0 -0
  74. data/lib/{remote.rb → xiki/remote.rb} +2 -2
  75. data/lib/{requirer.rb → xiki/requirer.rb} +3 -3
  76. data/lib/{rest_tree.rb → xiki/rest_tree.rb} +0 -0
  77. data/lib/{ruby.rb → xiki/ruby.rb} +0 -0
  78. data/lib/{ruby_console.rb → xiki/ruby_console.rb} +0 -0
  79. data/lib/{search.rb → xiki/search.rb} +7 -8
  80. data/lib/{search_term.rb → xiki/search_term.rb} +0 -0
  81. data/lib/{snippet.rb → xiki/snippet.rb} +0 -0
  82. data/lib/{specs.rb → xiki/specs.rb} +0 -0
  83. data/lib/{styles.rb → xiki/styles.rb} +8 -72
  84. data/lib/{svn.rb → xiki/svn.rb} +0 -0
  85. data/lib/{text_util.rb → xiki/text_util.rb} +2 -2
  86. data/lib/{tree.rb → xiki/tree.rb} +40 -32
  87. data/lib/{tree_cursor.rb → xiki/tree_cursor.rb} +0 -0
  88. data/lib/{trouble_shooting.rb → xiki/trouble_shooting.rb} +0 -0
  89. data/lib/{url_tree.rb → xiki/url_tree.rb} +0 -0
  90. data/lib/{view.rb → xiki/view.rb} +39 -16
  91. data/lib/xiki/vim/line.rb +8 -0
  92. data/lib/xiki/vim/tree.rb +9 -0
  93. data/lib/{window.rb → xiki/window.rb} +0 -0
  94. data/menus/address_book.rb +6 -4
  95. data/menus/agenda.rb +3 -3
  96. data/menus/amazon.rb +2 -2
  97. data/menus/applescript.rb +21 -10
  98. data/menus/black.menu +1 -0
  99. data/menus/bootstrap.rb +2 -7
  100. data/menus/browser.rb +8 -5
  101. data/menus/cassandra_db.rb +2 -2
  102. data/menus/chmod.rb +1 -1
  103. data/menus/conf.rb +5 -0
  104. data/menus/cookies.rb +1 -1
  105. data/menus/css.rb +2 -2
  106. data/menus/deck.rb +1 -1
  107. data/menus/dimensions_config.menu +30 -0
  108. data/menus/dimensions_config.rb +5 -0
  109. data/menus/docs.rb +33 -34
  110. data/menus/dotsies.rb +1 -0
  111. data/menus/emacs.rb +7 -2
  112. data/menus/firefox.rb +25 -25
  113. data/menus/git.rb +1 -1
  114. data/menus/gito.rb +2 -2
  115. data/menus/headings.rb +3 -3
  116. data/menus/ip.rb +2 -4
  117. data/menus/itunes.rb +9 -2
  118. data/menus/javascript.rb +3 -1
  119. data/menus/local_storage.rb +4 -4
  120. data/menus/mac.rb +2 -1
  121. data/menus/maps.rb +2 -2
  122. data/menus/models.rb +31 -0
  123. data/menus/mongo.rb +2 -2
  124. data/menus/piano.rb +47 -23
  125. data/menus/r.rb +57 -0
  126. data/menus/rails.rb +89 -27
  127. data/menus/redmine.rb +1 -1
  128. data/menus/sass.rb +1 -1
  129. data/menus/settings.menu +2 -0
  130. data/menus/technologies.rb +4 -1
  131. data/menus/web_interface.rb +58 -0
  132. data/menus/welcome.menu +18 -0
  133. data/menus/white.menu +1 -0
  134. data/menus/youtube.rb +32 -0
  135. data/spec/code_tree_spec.rb +1 -1
  136. data/spec/diff_log_spec.rb +4 -4
  137. data/spec/file_tree_spec.rb +2 -2
  138. data/spec/line_spec.rb +2 -2
  139. data/spec/menu_spec.rb +5 -5
  140. data/spec/ol_spec.rb +3 -3
  141. data/spec/remote_spec.rb +2 -2
  142. data/spec/search_spec.rb +2 -2
  143. data/spec/text_util_spec.rb +1 -1
  144. data/spec/tree_cursor_spec.rb +3 -3
  145. data/spec/tree_spec.rb +3 -3
  146. data/xiki.gemspec +22 -6
  147. metadata +311 -76
  148. data/menus/dir.rb +0 -8
@@ -14,12 +14,6 @@ Styles.mode_line_inactive(
14
14
  :bold=>false,
15
15
  :fg=>'000'
16
16
  )
17
- Styles.mode_line_dir(
18
- :fg=>"777",
19
- :size=>"0",
20
- :face=>"arial",
21
- :bold=>false
22
- )
23
17
  Styles.mode_line_file(
24
18
  :fg=>"fff",
25
19
  :size=>"0",
@@ -0,0 +1,24 @@
1
+ Themes.use "Black BG"
2
+ Themes.use "Shiny Blue"
3
+ Themes.use "Path Mode Line"
4
+
5
+ $el.el4r_lisp_eval %`
6
+ (progn
7
+ (tool-bar-mode -1) ; Turn off the toolbar
8
+
9
+ (custom-set-variables
10
+ '(tabbar-mode nil) ; No tabs
11
+ '(cua-rectangle-mark-key (kbd "<C-S-return>")) ; No tabs
12
+ ;; '(tabbar-mode t) ; No tabs
13
+ ;; '(show-paren-mode nil)
14
+ )
15
+
16
+ (set-face-attribute 'region nil :background "#333333" :foreground "#ffffff") ;; More mac-like selection color
17
+
18
+ (setq-default
19
+ frame-title-format
20
+ '("%b"))
21
+
22
+ (setq frame-title-format '("%b" ))
23
+ )
24
+ `
@@ -0,0 +1,6 @@
1
+ Styles.define :font_lock_comment_face, :fg=>'65614E' # gray
2
+ Styles.define :font_lock_function_name_face, :fg=>'f32' # red
3
+ Styles.define :font_lock_type_face, :fg=>'c21' # red
4
+ Styles.define :font_lock_variable_name_face, :fg=>'fd0' # yellow
5
+ Styles.define :font_lock_string_face, :fg=>'E6DB74' # red
6
+ Styles.define :font_lock_keyword_face, :fg=>'A5A18E'
@@ -0,0 +1,6 @@
1
+ Styles.define :default, :bg=>'ddd', :fg=>'333'
2
+ Styles.define :fringe, :bg=>'ddd', :fg=>'ddd'
3
+
4
+ # Adjust light colors
5
+ Styles.define :font_lock_variable_name_face, :fg=>'c90' # yellow
6
+ Styles.define :font_lock_comment_face, :fg=>'aaa' # gray
@@ -1,4 +1,4 @@
1
- if Styles.inverse # Black bg
1
+ if Styles.dark_bg? # Black bg
2
2
 
3
3
  Styles.mode_line :bg=>'333', :border=>['666', -1], :face=>'Lucida Grande', :size=>'3', :bold=>false, :fg=>'fff'
4
4
  Styles.mode_line_inactive :bg=>'666', :border=>['888', -1], :face=>'Lucida Grande', :size=>'3', :bold=>false, :fg=>'fff'
@@ -0,0 +1,6 @@
1
+ Styles.define :font_lock_comment_face, :fg=>'555' # gray
2
+ Styles.define :font_lock_function_name_face, :fg=>'f95' # orange
3
+ Styles.define :font_lock_type_face, :fg=>'6c7' # green
4
+ Styles.define :font_lock_variable_name_face, :fg=>'ff6' # yellow
5
+ Styles.define :font_lock_string_face, :fg=>'e76' # red
6
+ Styles.define :font_lock_keyword_face, :fg=>'999'
@@ -0,0 +1,36 @@
1
+ $el.el4r_lisp_eval %`
2
+ (progn
3
+
4
+ (setq-default xiki-status3 nil) (setq-default xiki-status2 nil) (setq-default xiki-status1 nil)
5
+ (setq-default mode-line-format
6
+ (quote
7
+ (
8
+
9
+ " " ; Apparently required
10
+
11
+ (:eval
12
+ (cond
13
+ ((buffer-modified-p)
14
+ (propertize "* " 'face 'mode-line-file))
15
+ (t " ")))
16
+
17
+ mode-line-frame-identification
18
+ " "
19
+ " "
20
+
21
+ (:eval (replace-regexp-in-string "^/projects/memorize/memorize.merb/" "$m/" default-directory)
22
+ )
23
+ (:propertize "%b" face mode-line-file)
24
+
25
+ ":%l" ;; Line number
26
+ " "
27
+
28
+ ;; status1, status2, etc. (in mode line)
29
+ (:propertize xiki-status1 face quote-heading-small)
30
+ (:propertize xiki-status2 face quote-heading-small)
31
+ (:propertize xiki-status3 face dotsies-white)
32
+ )))
33
+ )
34
+ `
35
+
36
+
@@ -0,0 +1,20 @@
1
+ if Styles.dark_bg?
2
+
3
+ Styles.define :font_lock_comment_face, :fg=>'555' # gray
4
+ Styles.define :font_lock_function_name_face, :fg=>'f50' # orange
5
+ Styles.define :font_lock_type_face, :fg=>'0a1' # green
6
+ Styles.define :font_lock_variable_name_face, :fg=>'fd0' # yellow
7
+ Styles.define :font_lock_string_face, :fg=>'e10' # red
8
+ Styles.define :font_lock_keyword_face, :fg=>'999'
9
+
10
+ else
11
+
12
+ Styles.define :font_lock_comment_face, :fg=>'aaa' # gray
13
+ Styles.define :font_lock_function_name_face, :fg=>'f50' # orange
14
+ Styles.define :font_lock_type_face, :fg=>'090', :bold=>nil # green
15
+ Styles.define :font_lock_variable_name_face, :fg=>'00c', :bold=>1 # yellow
16
+ Styles.define :font_lock_string_face, :fg=>'e10', :bold=>nil # red
17
+ Styles.define :font_lock_keyword_face, :fg=>'888', :bold=>1 # blue
18
+
19
+ end
20
+
@@ -1,27 +1,23 @@
1
1
  Styles.mode_line(
2
- :bg=>'5483bf',
3
- :border=>['6593b3', -5, 'released-button'],
4
- :face=>'Lucida Grande',
5
- :size=>'3',
6
- :bold=>false,
7
- :fg=>'fff'
2
+ :bg=>'6483af',
3
+ :border=>['6483af', 3],
4
+ :face=>"arial",
5
+ :bold=>true,
6
+ :size=>'1',
7
+ :fg=>'001122'
8
8
  )
9
+
9
10
  Styles.mode_line_inactive(
10
- :bg=>'bbb',
11
- :border=>['bbbbbb', -1],
12
- :face=>'Lucida Grande',
13
- :bold=>false,
14
- :fg=>'000'
15
- )
16
- Styles.mode_line_dir(
17
- :fg=>"222222",
18
- :size=>"0",
11
+ :bg=>'bbbbbb',
12
+ :border=>['bbbbbb', 3],
19
13
  :face=>"arial",
20
- :bold=>false
14
+ :bold=>true,
15
+ :size=>'1',
16
+ :fg=>'555555'
21
17
  )
18
+
22
19
  Styles.mode_line_file(
23
20
  :fg=>"fff",
24
- :size=>"0",
25
21
  :face=>"arial",
26
- :bold=>false
22
+ :bold=>true
27
23
  )
@@ -13,12 +13,6 @@ Styles.mode_line_inactive(
13
13
  :bold=>false,
14
14
  :fg=>'000'
15
15
  )
16
- Styles.mode_line_dir(
17
- :fg=>"222222",
18
- :size=>"0",
19
- :face=>"arial",
20
- :bold=>false
21
- )
22
16
  Styles.mode_line_file(
23
17
  :fg=>"fff",
24
18
  :size=>"0",
@@ -0,0 +1,5 @@
1
+ $el.set_face_background :trailing_whitespace, "#aaaaaa"
2
+
3
+ Styles.define :default, :bg=>'f8f8f8', :fg=>'000'
4
+ Styles.define :fringe, :bg=>'f8f8f8', :fg=>'f8f8f8'
5
+
@@ -0,0 +1,32 @@
1
+ > Try it out
2
+ - 1) Add this line, and then restart vim
3
+ ~/.vimrc
4
+ | let $XIKI_DIR = "[xiki dir]"
5
+ | source [xiki dir]/etc/vim/xiki.vim
6
+
7
+ - 2) Type "ip" on a blank line and double-click on it
8
+
9
+
10
+ > If your vim version doesn't have ruby enabled
11
+ The standard macvim download has the ruby. Compile vim with the --enable-rubyinterp flag installed.
12
+
13
+
14
+ > What's implemented
15
+ Just double-clicking on one line and shelling out to 'xiki'
16
+ and inserting the results
17
+
18
+
19
+ > What needs to be implemented
20
+ - Making this work for nested paths, like:
21
+ docs/
22
+ - faq/
23
+ - It needs to climb the path and pass it in to the command
24
+ - Making it collapse when the line underneath it is indented lower
25
+ - Making it incrementally search after commands are inserted
26
+ - is there a command in vim to read 1 char from the user?
27
+
28
+
29
+ > Help out
30
+ Join the xiki google group if you want to help implement this.
31
+
32
+ If you're in the bay area, hit me up and we can meet at a coffee shop and pair on wraping it up!
data/etc/vim/xiki.vim ADDED
@@ -0,0 +1,16 @@
1
+ function! XikiLaunch()
2
+ ruby << EOF
3
+ xiki_dir = ENV['XIKI_DIR']
4
+ ['ol', 'vim/line', 'vim/tree'].each {|o| require "#{xiki_dir}/lib/xiki/#{o}"}
5
+ line = Line.value
6
+ indent = line[/^ +/]
7
+ command = "xiki #{line}"
8
+ result = `#{command}`
9
+ Tree << result
10
+ EOF
11
+ endfunction
12
+
13
+ nmap <silent> <2-LeftMouse> :call XikiLaunch()<CR>
14
+ imap <silent> <2-LeftMouse> <C-c>:call XikiLaunch()<CR>i
15
+ imap <silent> <C-CR> <C-c>:call XikiLaunch()<CR>i
16
+ nmap <silent> <C-CR> :call XikiLaunch()<CR>
@@ -1,8 +1,8 @@
1
1
  # Gets shelled out to by xiki to delegate call to a no-dependency .rb file.
2
2
  # Just gets the args passed in and requires and invokes.
3
3
 
4
- # TODO Don't hard-code path
5
- require "/projects/xiki/lib/ol.rb"
4
+ # TODO Don't hard-code path - use __FILE__?
5
+ # require "/projects/xiki/lib/xiki/ol.rb"
6
6
 
7
7
  file = ARGV.shift
8
8
  path = ARGV.shift
data/etc/www/index.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  print "Content-type: text/html\n\n";
4
4
 
5
- require "/projects/xiki/lib/ol.rb"
5
+ require "../../lib/xiki/ol.rb"
6
6
  require "web_server"
7
7
  require "cgi"
8
8
  WebServer.index
@@ -0,0 +1,47 @@
1
+ <style>
2
+ a {
3
+ text-decoration: none;
4
+ }
5
+
6
+ body {
7
+ font-family: arial;
8
+ margin: 50px;
9
+ font-size: 15px;
10
+ color: #666;
11
+ line-height: 21px;
12
+ background-color: #f8f8f8;
13
+ }
14
+ p {
15
+ margin: 0;
16
+ }
17
+ .blank {
18
+ line-height: 12px;
19
+ }
20
+ h1 {
21
+ color: #000;
22
+ font-family: arial;
23
+ font-size: 16px;
24
+ font-weight: bold;
25
+ margin: 11px 0 7px;
26
+ }
27
+ .info {
28
+ margin: 0 0 6px;
29
+ }
30
+ pre {
31
+ font-weight: bold;
32
+ }
33
+ </style>
34
+
35
+ <div class='content'>
36
+ <h1>Start the Xiki sinatra server!</h1>
37
+
38
+ <p class='info'>
39
+ Use the <b>web interface</b> Xiki menu to start it (or install it if necessary).
40
+ </p>
41
+ <p class='blank'>&nbsp;</p>
42
+ <p class='info'>
43
+ (Type <b>web interface</b> on a blank line in your Xiki-enabled
44
+ editor, and double-click on it.)
45
+ </p>
46
+
47
+ </div>
@@ -0,0 +1,353 @@
1
+ require 'sinatra'
2
+ require "/projects/xiki/lib/xiki/ol.rb"
3
+
4
+ set :port, 8161
5
+ set :bind, '127.0.0.1'
6
+
7
+ # TODO: Enable basic auth for security
8
+ # Add menu to let users create a password
9
+ # use Rack::Auth::Basic, "Nope" do |u, p|
10
+ # u == 'foo' && p == 'bar'
11
+ # end
12
+
13
+ get %r{/(.*)} do |path|
14
+ index path
15
+ end
16
+
17
+ def htmlify txt, options={}
18
+
19
+ return txt if request.env['HTTP_ACCEPT'] !~ /\Atext\/html/ # Only process if request wants html
20
+
21
+ # If starts with <foo or @bootstrap, just render it as html or bootstrap...
22
+
23
+ if txt =~ /\A<\w/
24
+ return txt
25
+ elsif txt =~ /\A@bootstrap\/\n /
26
+
27
+ xiki_dir = File.expand_path "#{File.dirname(__FILE__)}/../.."
28
+
29
+ $:.unshift "#{xiki_dir}/lib"
30
+ ["xiki/ol", "xiki/core_ext", "xiki/line", "xiki/tree", "../../menus/bootstrap"].each{|o| require o}
31
+
32
+ txt.slice! /.+\n/
33
+ txt = txt.unindent
34
+
35
+ txt = Bootstrap.process txt
36
+
37
+ return txt
38
+ end
39
+
40
+ # Turn menu text into html...
41
+
42
+ # TODO: should probably maintain indenting?
43
+ txt.gsub! /^ *\| ?/, ''
44
+
45
+ txt.gsub! /^( *)[+-]+ /, "\\1" # Get rid of bullets
46
+ txt.gsub! /> (.+)/, "<h1>\\1</h1>"
47
+
48
+ # Use relative links if path ends in slash, otherwise use absolute
49
+ path = request.env['REQUEST_PATH']
50
+
51
+ path = "#{path}/" if path !~ /\/$/
52
+
53
+ # Make path be "/foo/bar/", if no slash ("/foo/bar")
54
+
55
+ txt.gsub!(/^( *)(.+?)(\/?)$/){
56
+ all = $&
57
+ indent, item, slash = $1, $2, $3
58
+ next all if all =~ /<h/ || all !~ /\/$/
59
+ my_path = path
60
+ my_path = "/" if item.slice!(/^<< /)
61
+ my_path = "/" if item.slice!(/^@ ?/)
62
+ "#{indent}<a href=\"#{my_path}#{item}\">#{item.gsub '_', ' '}</a>"
63
+ } # no slash
64
+
65
+ txt.gsub!(/^ +/){"&nbsp; " * $&.length} # Get rid of bullets
66
+
67
+ txt.gsub!(/.+/){
68
+ all = $&
69
+ next all if all =~ /<h/
70
+ next "<p class='info'>#{all}</p>" if all !~ /^<a/ # Don't end in "/" - just informational
71
+ all
72
+ }
73
+ txt.gsub! /^$/, "<p class='blank'>&nbsp;</p>"
74
+ output = ""
75
+ output << %`
76
+ <style>
77
+ a {
78
+ text-decoration: none;
79
+ }
80
+
81
+ .content a.selected {
82
+ background: -moz-linear-gradient(center top, #58b, #7ad) repeat scroll 0 0 transparent;
83
+ }
84
+ .content a {
85
+ color: #666;
86
+ display: block;
87
+
88
+ border-radius: 2px;
89
+ border: solid 1px;
90
+ border-color: #eee #ddd #bbb #ddd;
91
+ background: -moz-linear-gradient(center top, #fff, #f1f1f1) repeat scroll 0 0 transparent;
92
+ background: -webkit-gradient(linear,center bottom,center top,from(#f1f1f1),to(#fff));
93
+ display: block;
94
+ padding: 10px 16px;
95
+ text-shadow: 0 1px 0 #fff;
96
+ font-weight: bold;
97
+ }
98
+ a:hover {
99
+ background: -moz-linear-gradient(center top, #f8f8f8, #e1e1e1) repeat scroll 0 0 transparent;
100
+ background: -webkit-gradient(linear,center bottom,center top,from(#e1e1e1),to(#f8f8f8));
101
+ }
102
+ body {
103
+ font-family: arial;
104
+ margin: 50px;
105
+ font-size: 15px;
106
+ color: #666;
107
+ line-height: 21px;
108
+ background-color: #f8f8f8;
109
+ }
110
+ p {
111
+ margin: 0;
112
+ }
113
+ .blank {
114
+ line-height: 12px;
115
+ }
116
+ h1 {
117
+ color: #000;
118
+ font-family: arial;
119
+ font-size: 16px;
120
+ font-weight: bold;
121
+ margin: 11px 0 7px;
122
+ }
123
+ .save {
124
+ margin: 0 20px 10px 20px;
125
+ font-size: 15px;
126
+ }
127
+ form {
128
+ margin: 0;
129
+ }
130
+ textarea {
131
+ border: solid #ccc 1px;
132
+ margin: 2px 20px 13px 20px;
133
+ padding: 7px;
134
+ width: 80%;
135
+ font-size: 15px;
136
+ color: #555;
137
+ height: 150px;
138
+ line-height: 20px;
139
+ }
140
+ .toggle {
141
+ font-size: 13px;
142
+ margin: 15px 20px 0px 20px;
143
+ font-weight: bold;
144
+ }
145
+ .toggle a {
146
+ color: #aaa;
147
+ }
148
+ .info {
149
+ margin: 0 0 6px;
150
+ }
151
+ pre {
152
+ font-weight: bold;
153
+ }
154
+
155
+ </style>
156
+ `
157
+
158
+ output << %`<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>`
159
+
160
+ if ! options[:no_keys]
161
+ output << %`
162
+ <script>
163
+ filter_pattern = "";
164
+ started_searching = false;
165
+ $(function(){
166
+
167
+ $(window).focus(function () {
168
+ filter_pattern = "";
169
+ started_searching = false;
170
+
171
+ $('body').css("opacity", 1.0);
172
+ $('p, h1, a').show();
173
+ $('a').removeClass("selected");
174
+ });
175
+
176
+ $('body').keypress(function(e){
177
+ if(e.ctrlKey || e.altKey || e.metaKey) return;
178
+ var char = e.which;
179
+ var letter = String.fromCharCode(char).toLowerCase();
180
+ //console.log(char)
181
+ if(char == 13){
182
+ $("a:visible:eq(0)").click();
183
+ e.stopPropagation();
184
+ return false;
185
+ }
186
+
187
+ if(letter == " "){
188
+ if(started_searching) filter_pattern = "";
189
+ else window.location = "/";
190
+ e.stopPropagation();
191
+ return false;
192
+ }
193
+
194
+ if(! letter.match(/[0-9a-z]/)) return true;
195
+
196
+ started_searching = true;
197
+ filter_pattern += letter;
198
+
199
+ //console.log(filter_pattern);
200
+
201
+ // If more than 100, don't use fade
202
+ var count = $('p, h1, a').filter(':visible').length;
203
+ var fade = count < 50;
204
+
205
+ $('p, h1, a').each(function(i, e){
206
+ e = $(e);
207
+ if(e.is(":hidden")) return;
208
+ var html = e.html().replace(/<.+?>/g, '');
209
+ //console.log(html);
210
+ if(html.toLowerCase().indexOf(filter_pattern) == -1)
211
+ fade ? e.slideUp(400) : e.hide();
212
+ // Get content
213
+ // Remove tags
214
+ // Hide if remaining doesn't match regex (/on/)
215
+ })
216
+
217
+ });
218
+
219
+ $('a').click(function(e){
220
+ var target = $(e.target);
221
+ target.toggleClass("selected");
222
+
223
+ $('body').animate({opacity: 0.0}, {easing: 'swing', duration: 150});
224
+ window.setTimeout(function(){ window.location = target.attr('href'); }, 150);
225
+ return false;
226
+ });
227
+
228
+ })
229
+ </script>
230
+ `
231
+ end
232
+
233
+ "#{output}<div class='content'>#{txt}</div>"
234
+
235
+ end
236
+
237
+
238
+ def usage
239
+ htmlify "
240
+ > Summary
241
+ This url displays xiki menus, which come from simple files found in ~/menus/.
242
+
243
+ > Show all menus
244
+ all/
245
+
246
+ > Examples
247
+ ip/
248
+ animals/
249
+ sharks/
250
+ tables/
251
+
252
+ > Create menu
253
+ Just go to the url of a menu that doesn't exist yet:
254
+ unicorn/
255
+
256
+ > Docs
257
+ docs/
258
+ ".sub("\n", '').gsub(/^ /, '')
259
+ end
260
+
261
+
262
+ def index menu
263
+ no_keys = false
264
+
265
+ if ENV['REQUEST_METHOD'] == "POST"
266
+ cgi = CGI.new
267
+ post_txt = cgi['txt']
268
+
269
+ # Temporary hack
270
+ File.open("/tmp/post_tmp", "w") { |f| f << post_txt }
271
+
272
+ # What's a better way to do this?
273
+ # Pass in pipe, and send to shell command via STDIN
274
+
275
+ end
276
+
277
+ # menu = ENV['QUERY_STRING']
278
+
279
+ return usage if menu == ""
280
+
281
+ # Run command...
282
+
283
+ # command = "/usr/local/bin/xiki #{menu}"
284
+ command = "xiki #{menu}"
285
+ txt = `#{command}`
286
+
287
+ # rescue e=>Exception
288
+ # puts "<pre>#{e.message}\n#{e.backtrace}</pre>"
289
+ # Ol << "e: #{e.message}"
290
+ # Ol << "e: #{e.backtrace}"
291
+ # Ol << "If we get the permission problem, provide .notes file that will run command to run xiki command once (message explaining it first)!"
292
+ # end
293
+
294
+ # TODO: return different string when the service is down
295
+
296
+ # Ol << "Extract to new method: suggest_creating!!"
297
+ if txt.empty?
298
+ menu = menu.sub /\/$/, ''
299
+
300
+ no_keys = true
301
+
302
+ if menu =~ /\/./ # If slash that's not at end
303
+ puts "<pre>Nothing returned. Maybe service is down, or maybe menu\njust returned nothing, run xiki command\n\n $ xiki\n"
304
+ else
305
+ puts %`
306
+ <h1>Menu '#{menu}' doesn't exist yet. Create it?</h1>
307
+
308
+ <form action="/create/#{menu}" method="post" id="as_menu">
309
+ <div class='toggle'>
310
+ <span>as text</span>
311
+ | <a href="#" onclick="$('#as_class, #as_menu').toggle(); return false;">as class</a>
312
+ </div>
313
+ <textarea name="txt">
314
+ - Sample item/
315
+ - Another sample item/
316
+ - Yet another/
317
+ </textarea>
318
+ <br>
319
+ <input type="submit" value="save" class="save">
320
+ </form>
321
+
322
+ <form action="/create/#{menu}" method="post" id="as_class" style="display:none;">
323
+ <div class='toggle'>
324
+ <a href="#" onclick="$('#as_class, #as_menu').toggle(); return false;">as text</a>
325
+ | <span>as class</span>
326
+ </div>
327
+ <textarea name="txt">
328
+ class #{camel_case menu}
329
+ def self.menu *args
330
+ "Menu was called, with params \#{args.inspect}"
331
+ end
332
+ end
333
+ </textarea>
334
+ <br>
335
+ <input type="submit" value="save" class="save">
336
+ </form>
337
+
338
+ `.gsub(/^ /, '')
339
+ end
340
+ end
341
+
342
+ # Html-ify and print output...
343
+
344
+ htmlify txt, :no_keys=>no_keys
345
+
346
+ rescue Exception=>e
347
+ "<pre>#{e.message}\n#{e.backtrace}</pre>"
348
+ end
349
+
350
+ def camel_case txt
351
+ return txt if txt !~ /_/ && txt =~ /[A-Z]+.*/
352
+ txt.split('_').map{|e| e.capitalize}.join
353
+ end