xiki 0.5.0a → 0.5.1a

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -9,3 +9,5 @@ gem 'net-ssh'
9
9
  gem 'net-ssh'
10
10
  gem 'rspec'
11
11
  gem 'memcached'
12
+ gem 'el4r'
13
+
data/README.markdown CHANGED
@@ -1,8 +1,29 @@
1
- ## Summary
1
+ # Summary
2
2
  This file tells how to install Xiki. See http://xiki.org for a description of Xiki.
3
3
 
4
+ Either install as a gem, or install from github.
4
5
 
5
- __UPDATE DIRECTIONS TO SAY GEM INSTALL BY DEFAULT__
6
+ # Install Xiki
7
+
8
+ ## As a gem
9
+
10
+ $ gem install xiki
11
+
12
+ ## From github
13
+
14
+ $ git clone git@github.com:trogdoro/xiki.git
15
+ $ cd xiki
16
+ $ bundle install --system
17
+ $ cp <xiki dir>/etc/command/xiki_wrapper /usr/local/bin/xiki
18
+ $ chmod 755 /usr/local/bin/xiki
19
+
20
+ # Verify the 'xiki' command works
21
+
22
+ $ xiki
23
+
24
+ # Configure Emacs to use Xiki
25
+
26
+ If you're going to use Xiki with Emacs, do these steps:
6
27
 
7
28
  ## Step 1: Download Emacs
8
29
 
@@ -18,9 +39,8 @@ __UPDATE DIRECTIONS TO SAY GEM INSTALL BY DEFAULT__
18
39
  $ sudo apt-get install emacs
19
40
 
20
41
 
21
- ## Step 2: Install the EmacsRuby (el4r) gem
42
+ ## Step 2: Do extra EmacsRuby (el4r) steps
22
43
 
23
- $ sudo gem install el4r
24
44
  $ gem contents el4r | grep setup.rb # To see which dir to cd to in the next step
25
45
  $ cd /Library/Ruby/Gems/1.8/gems/el4r-1.0.4/
26
46
  $ ruby setup.rb
@@ -28,27 +48,16 @@ __UPDATE DIRECTIONS TO SAY GEM INSTALL BY DEFAULT__
28
48
  $ ruby -S el4r-rctool -p
29
49
  $ sudo ruby -S el4r-rctool -i
30
50
 
31
- ## Step 3: Get Xiki from github
32
- - Option 1: Download as zip
33
- - Click on the 'ZIP' button on http://github.com/trogdoro/xiki
34
- - Option 2: Clone repo
35
- - git clone git@github.com:trogdoro/xiki.git
36
-
37
-
38
- ## Step 4: Require Xiki in EmacsRuby's config
39
- - Sample configuration
40
- - ~/.el4r/init.rb
41
- | $LOAD_PATH.unshift "/projects/xiki/lib"
42
- | require 'xiki'
43
- | Xiki.init
44
- |
45
- | KeyBindings.keys # Use default key bindings
46
- | Styles.use_xiki_color_scheme # Use xiki's color scheme
51
+ ## Step 3: Require Xiki in EmacsRuby's config
52
+ Sample configuration:
47
53
 
54
+ ~/.el4r/init.rb:
55
+ $LOAD_PATH.unshift "/projects/xiki/lib"
56
+ require 'xiki'
57
+ Xiki.init
48
58
 
49
- ## Step 5: Install dependant packages
50
- - In the xiki dir, run:
51
- $ bundle install --system
59
+ KeyBindings.keys # Use default key bindings
60
+ Styles.use_xiki_color_scheme # Use xiki's color scheme
52
61
 
53
62
 
54
63
  ## Trouble-shooting
@@ -84,11 +84,7 @@ class XikiCommand
84
84
 
85
85
  @@initial_request = path
86
86
  xiki_process = "#{xiki_root}/etc/command/xiki_process.rb"
87
- Daemons.run xiki_process, :ARGV=>['start'], :monitor=>false, :multiple=>false #, :app_name=>'xiki'
88
- # Daemons.run '../etc/command/xiki_process.rb', :ARGV=>['start'], :monitor=>false, :multiple=>false #, :app_name=>'xiki'
89
- # Daemons.run 'etc/process/xiki_process.rb', :ARGV=>['start'], :monitor=>false, :multiple=>false #, :app_name=>'xiki'
90
- # Daemons.run '../etc/process/xiki_process.rb', :ARGV=>['start'], :monitor=>false, :multiple=>false #, :app_name=>'xiki'
91
- # Daemons.run 'xiki_daemon.rb', :ARGV=>['start'], :monitor=>false, :multiple=>false #, :app_name=>'xiki'
87
+ Daemons.run xiki_process, :ARGV=>['start'], :monitor=>false, :multiple=>false, :dir_mode=>:normal, :dir=>"/tmp/", :log_dir=>"/tmp/", :log_output=>true
92
88
 
93
89
  # Aparently this line never gets reached
94
90
  "- Started the process, I think."
@@ -99,8 +95,6 @@ class XikiCommand
99
95
 
100
96
  rescue Exception=>e
101
97
  puts "- service couldn't start!"
102
-
103
- #rescue ... <Errno::EACCES: Permission denied - /projects/xiki/etc/command/xiki_process.rb.pid>!
104
98
  end
105
99
  end
106
100
 
@@ -177,7 +171,7 @@ class XikiCommand
177
171
  require 'daemons'
178
172
  xiki_root = File.expand_path "#{File.dirname(__FILE__)}/../.."
179
173
  xiki_process = "#{xiki_root}/etc/command/xiki_process.rb"
180
- Daemons.run(xiki_process, :ARGV=>[action])
174
+ Daemons.run xiki_process, :ARGV=>[action], :dir_mode=>:normal, :dir=>"/tmp/", :log_dir=>"/tmp/", :log_output=>true
181
175
  ""
182
176
  end
183
177
 
data/etc/www/index.rb ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ print "Content-type: text/html\n\n";
4
+
5
+ require "/projects/xiki/lib/ol.rb"
6
+ require "web_server"
7
+ require "cgi"
8
+ WebServer.index
@@ -0,0 +1,353 @@
1
+ class WebServer
2
+
3
+ def self.htmlify txt, options={}
4
+
5
+ return txt if ENV['HTTP_ACCEPT'] !~ /\Atext\/html/ # Only process if request wants html
6
+
7
+ # If starts with <foo or @bootstrap, just render it as html or bootstrap...
8
+
9
+ if txt =~ /\A<\w/
10
+ return txt
11
+ elsif txt =~ /\A@bootstrap\/\n /
12
+
13
+ xiki_dir = File.expand_path "#{File.dirname(__FILE__)}/../.."
14
+
15
+ $:.unshift "#{xiki_dir}/lib"
16
+ ["lib/core_ext", "lib/line", "lib/tree", "menus/bootstrap"].each{|o| require "#{xiki_dir}/#{o}"}
17
+
18
+ txt.slice! /.+\n/
19
+ txt = txt.unindent
20
+
21
+ txt = Bootstrap.process txt
22
+
23
+ return txt
24
+ end
25
+
26
+ # Turn menu text into html...
27
+
28
+ # TODO: should probably maintain indenting?
29
+ txt.gsub! /^ *\| ?/, ''
30
+
31
+ txt.gsub! /^( *)[+-]+ /, "\\1" # Get rid of bullets
32
+ txt.gsub! /> (.+)/, "<h1>\\1</h1>"
33
+
34
+ path = ENV['REQUEST_URI']# =~ /\/$/ ? "" : "#{ENV['REQUEST_URI']}/" # Use relative links if path ends in slash, otherwise use absolute
35
+ path = "#{path}/" if path !~ /\/$/
36
+
37
+ txt.gsub!(/^( *)(.+?)(\/?)$/){
38
+ all = $&
39
+ indent, item, slash = $1, $2, $3
40
+ next all if all =~ /<h/ || all !~ /\/$/
41
+ my_path = path
42
+ my_path = "/" if item.slice!(/^<< /)
43
+ my_path = "/" if item.slice!(/^@ ?/)
44
+ "#{indent}<a href=\"#{my_path}#{item}\">#{item.gsub '_', ' '}</a>"
45
+ } # no slash
46
+
47
+ txt.gsub!(/^ +/){"&nbsp; " * $&.length} # Get rid of bullets
48
+
49
+ txt.gsub!(/.+/){
50
+ all = $&
51
+ next all if all =~ /<h/
52
+ next "<p class='info'>#{all}</p>" if all !~ /^<a/ # Don't end in "/" - just informational
53
+ all
54
+ }
55
+ txt.gsub! /^$/, "<p class='blank'>&nbsp;</p>"
56
+
57
+ print %`
58
+ <style>
59
+ a {
60
+ text-decoration: none;
61
+ }
62
+
63
+ .content a.selected {
64
+ background: -moz-linear-gradient(center top, #58b, #7ad) repeat scroll 0 0 transparent;
65
+ }
66
+ .content a {
67
+ color: #666;
68
+ display: block;
69
+
70
+ border-radius: 2px;
71
+ border: solid 1px;
72
+ border-color: #eee #ddd #bbb #ddd;
73
+ background: -moz-linear-gradient(center top, #fff, #f1f1f1) repeat scroll 0 0 transparent;
74
+ background: -webkit-gradient(linear,center bottom,center top,from(#f1f1f1),to(#fff));
75
+ display: block;
76
+ padding: 10px 16px;
77
+ text-shadow: 0 1px 0 #fff;
78
+ font-weight: bold;
79
+ }
80
+ a:hover {
81
+ background: -moz-linear-gradient(center top, #f8f8f8, #e1e1e1) repeat scroll 0 0 transparent;
82
+ background: -webkit-gradient(linear,center bottom,center top,from(#e1e1e1),to(#f8f8f8));
83
+ }
84
+ body {
85
+ font-family: arial;
86
+ margin: 50px;
87
+ font-size: 15px;
88
+ color: #666;
89
+ line-height: 21px;
90
+ background-color: #f8f8f8;
91
+ }
92
+ p {
93
+ margin: 0;
94
+ }
95
+ .blank {
96
+ line-height: 12px;
97
+ }
98
+ /* Or type some css here (to run in the browser) */
99
+ h1 {
100
+ color: #000;
101
+ font-family: arial;
102
+ font-size: 16px;
103
+ font-weight: bold;
104
+ margin: 11px 0 7px;
105
+ }
106
+ .save {
107
+ margin: 0 20px 10px 20px;
108
+ font-size: 15px;
109
+ }
110
+ form {
111
+ margin: 0;
112
+ }
113
+ textarea {
114
+ border: solid #ccc 1px;
115
+ margin: 2px 20px 13px 20px;
116
+ padding: 7px;
117
+ width: 80%;
118
+ font-size: 15px;
119
+ color: #555;
120
+ height: 150px;
121
+ line-height: 20px;
122
+ }
123
+ .toggle {
124
+ font-size: 13px;
125
+ margin: 15px 20px 0px 20px;
126
+ font-weight: bold;
127
+ }
128
+ .toggle a {
129
+ color: #aaa;
130
+ }
131
+ .info {
132
+ margin: 0 0 6px;
133
+ }
134
+ pre {
135
+ font-weight: bold;
136
+ }
137
+
138
+ </style>
139
+ `
140
+
141
+ puts %`<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>`
142
+
143
+ if ! options[:no_keys]
144
+ print %`
145
+ <script>
146
+ filter_pattern = "";
147
+ started_searching = false;
148
+ $(function(){
149
+
150
+ $(window).focus(function () {
151
+ filter_pattern = "";
152
+
153
+ $('body').css("opacity", 1.0);
154
+ $('p, h1, a').show();
155
+ $('a').removeClass("selected");
156
+ });
157
+
158
+ $('body').keypress(function(e){
159
+ if(e.ctrlKey || e.altKey || e.metaKey) return;
160
+ var char = e.which;
161
+ var letter = String.fromCharCode(char).toLowerCase();
162
+ //console.log(char)
163
+ if(char == 13){
164
+ $("a:visible:eq(0)").click();
165
+ e.stopPropagation();
166
+ return false;
167
+ }
168
+
169
+ if(letter == " "){
170
+ if(started_searching) filter_pattern = "";
171
+ else window.location = "/";
172
+ e.stopPropagation();
173
+ return false;
174
+ }
175
+
176
+ if(! letter.match(/[0-9a-z]/)) return true;
177
+
178
+ started_searching = true;
179
+ filter_pattern += letter;
180
+
181
+ //console.log(filter_pattern);
182
+
183
+ // If more than 100, don't use fade
184
+ var count = $('p, h1, a').filter(':visible').length;
185
+ var fade = count < 50;
186
+
187
+ $('p, h1, a').each(function(i, e){
188
+ e = $(e);
189
+ if(e.is(":hidden")) return;
190
+ var html = e.html().replace(/<.+?>/g, '');
191
+ //console.log(html);
192
+ if(html.toLowerCase().indexOf(filter_pattern) == -1)
193
+ fade ? e.slideUp(400) : e.hide();
194
+ // Get content
195
+ // Remove tags
196
+ // Hide if remaining doesn't match regex (/on/)
197
+ })
198
+
199
+ });
200
+
201
+ $('a').click(function(e){
202
+ var target = $(e.target);
203
+ target.toggleClass("selected");
204
+
205
+ $('body').animate({opacity: 0.0}, {easing: 'swing', duration: 150});
206
+ window.setTimeout(function(){ window.location = target.attr('href'); }, 150);
207
+ return false;
208
+ });
209
+
210
+ })
211
+ </script>
212
+ `
213
+ end
214
+
215
+ "<div class='content'>#{txt}</div>"
216
+ end
217
+
218
+
219
+ def self.usage
220
+ txt = "
221
+ > Summary
222
+ This url displays xiki menus, which come from simple files found in ~/menus/.
223
+
224
+ > Show all menus
225
+ all/
226
+
227
+ > Examples
228
+ ip/
229
+ animals/
230
+ sharks/
231
+ tables/
232
+
233
+ > Create menu
234
+ Just go to the url of a menu that doesn't exist yet:
235
+ unicorn/
236
+
237
+ > Docs
238
+ docs/
239
+ ".sub("\n", '').gsub(/^ /, '')
240
+
241
+ print WebServer.htmlify txt
242
+
243
+ end
244
+
245
+ def self.index
246
+
247
+ no_keys = false
248
+
249
+ if ENV['REQUEST_METHOD'] == "POST"
250
+ cgi = CGI.new
251
+ post_txt = cgi['txt']
252
+
253
+ # Temporary hack
254
+ File.open("/tmp/post_tmp", "w") { |f| f << post_txt }
255
+
256
+ # What's a better way to do this?
257
+ # Pass in pipe, and send to shell command via STDIN
258
+
259
+ end
260
+
261
+ menu = ENV['QUERY_STRING']
262
+
263
+ return self.usage if menu == ""
264
+
265
+ # Run command...
266
+
267
+ command = "xiki #{menu}"
268
+
269
+ txt = `#{command}`
270
+
271
+ # rescue e=>Exception
272
+ # puts "<pre>#{e.message}\n#{e.backtrace}</pre>"
273
+ # Ol << "e: #{e.message}"
274
+ # Ol << "e: #{e.backtrace}"
275
+ # Ol << "If we get the permission problem, provide .notes file that will run command to run xiki command once (message explaining it first)!"
276
+ # end
277
+
278
+ # TODO: return different string when the service is down
279
+
280
+ # Ol << "Extract to new method: suggest_creating!!"
281
+ if txt.empty?
282
+ menu = menu.sub /\/$/, ''
283
+
284
+ no_keys = true
285
+
286
+ if menu =~ /\/./ # If slash that's not at end
287
+ puts "<pre>Nothing returned. Maybe service is down, or maybe menu\njust returned nothing, run xiki command\n\n $ xiki\n"
288
+ else
289
+ puts %`
290
+ <h1>Menu '#{menu}' doesn't exist yet. Create it?</h1>
291
+
292
+ <form action="/create/#{menu}" method="post" id="as_menu">
293
+ <div class='toggle'>
294
+ <span>as text</span>
295
+ | <a href="#" onclick="$('#as_class, #as_menu').toggle(); return false;">as class</a>
296
+ </div>
297
+ <textarea name="txt">
298
+ - Sample item/
299
+ - Another sample item/
300
+ - Yet another/
301
+ </textarea>
302
+ <br>
303
+ <input type="submit" value="save" class="save">
304
+ </form>
305
+
306
+ <form action="/create/#{menu}" method="post" id="as_class" style="display:none;">
307
+ <div class='toggle'>
308
+ <a href="#" onclick="$('#as_class, #as_menu').toggle(); return false;">as text</a>
309
+ | <span>as class</span>
310
+ </div>
311
+ <textarea name="txt">
312
+ class #{self.camel_case menu}
313
+ def self.menu *args
314
+ "Menu was called, with params \#{args.inspect}"
315
+ end
316
+ end
317
+ </textarea>
318
+ <br>
319
+ <input type="submit" value="save" class="save">
320
+ </form>
321
+
322
+ `.gsub(/^ /, '')
323
+ end
324
+ end
325
+
326
+ # Show this again when I figure out how to recognize server being down!
327
+
328
+ # if txt.empty?
329
+ # puts "<pre>Command received no output. Possibly the xiki process
330
+ # isn't running. Run the 'xiki' command in a shell:
331
+
332
+ # $ xiki
333
+
334
+ # </pre>".gsub(/^ /, '')
335
+ # end
336
+
337
+ # Html-ify and print output...
338
+
339
+ txt = self.htmlify txt, :no_keys=>no_keys
340
+ print txt
341
+
342
+ # print "<pre>#{ENV.keys.map{|k| "#{k}: #{ENV[k]}"}.join("\n")}</pre>"
343
+
344
+ rescue Exception=>e
345
+ puts "<pre>#{e.message}\n#{e.backtrace}</pre>"
346
+ end
347
+
348
+ def self.camel_case txt
349
+ return txt if txt !~ /_/ && txt =~ /[A-Z]+.*/
350
+ txt.split('_').map{|e| e.capitalize}.join
351
+ end
352
+
353
+ end
data/lib/launcher.rb CHANGED
@@ -1183,11 +1183,9 @@ class Launcher
1183
1183
  path.sub! /\/$/, ''
1184
1184
  Console.run "rake #{path}", :dir=>dir
1185
1185
  nil
1186
-
1187
1186
  end
1188
1187
 
1189
1188
  def self.reload_menu_dirs
1190
- Ol.stack
1191
1189
  MENU_DIRS.each do |dir|
1192
1190
  next unless File.directory? dir
1193
1191
 
@@ -1318,7 +1316,7 @@ def require_menu file, options={}
1318
1316
  raise "File Not Found" if !File.exists?(file)
1319
1317
  end
1320
1318
 
1321
- stem = file[/(\w+)\./, 1]
1319
+ stem = File.basename(file)[/\A(.*)\.[^.]+\z/, 1]
1322
1320
 
1323
1321
  # As .menu...
1324
1322
 
data/lib/menu.rb CHANGED
@@ -342,6 +342,7 @@ class Menu
342
342
  end
343
343
 
344
344
  def self.call root, rest=nil
345
+ root = root.gsub /[ +]/, '_'
345
346
  menus = Launcher.menus
346
347
  block = menus[0][root] || menus[1][root]
347
348
  return if block.nil?
data/lib/xiki.rb CHANGED
@@ -39,7 +39,7 @@ class Xiki
39
39
  | Double-click on these lines to add the executable 'xiki' command to
40
40
  | your path:
41
41
  |
42
- @$ cp _____/xiki_wrapper /usr/local/bin/xiki
42
+ @$ cp #{Xiki.dir}etc/command/xiki_wrapper /usr/local/bin/xiki
43
43
  @$ chmod 755 /usr/local/bin/xiki
44
44
  |
45
45
  | Then you can type 'xiki' on a command line outside of emacs as a
data/menus/create.rb ADDED
@@ -0,0 +1,17 @@
1
+ class Create
2
+ def self.menu name
3
+
4
+ txt = File.read "/tmp/post_tmp"
5
+
6
+ extension = txt =~ /^class / ? "rb" : "menu"
7
+ file_path = File.expand_path("~/menus/#{name}.#{extension}")
8
+ File.open(file_path, "w") { |f| f << txt }
9
+
10
+ require_menu file_path
11
+
12
+ "
13
+ > Your menu was saved! Now go to it:
14
+ - <a href='/#{name}'>#{name}</a>
15
+ "
16
+ end
17
+ end
data/menus/http.rb ADDED
@@ -0,0 +1,19 @@
1
+ class Http
2
+ def self.menu *args
3
+ url = args.blank? ? nil : args.join('/')
4
+
5
+ # If as+open, just jump to the log
6
+ return View.open Launcher.log_file if Keys.open?
7
+
8
+ # If no url's, list them all
9
+
10
+ if url.blank?
11
+ txt = Launcher.last "http", :exclude_path=>1
12
+ txt.gsub! /^- /, '<< '
13
+ return txt
14
+ end
15
+
16
+ Keys.prefix == :u ? $el.browse_url(url) : Firefox.url(url)
17
+ nil
18
+ end
19
+ end
data/menus/urls.menu ADDED
@@ -0,0 +1 @@
1
+ <<< http/
data/xiki.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "xiki"
8
- s.version = "0.5.0a"
8
+ s.version = "0.5.1a"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Craig Muth"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xiki
3
3
  version: !ruby/object:Gem::Version
4
- hash: -348338586
4
+ hash: -1959472798
5
5
  prerelease: 5
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 0
9
+ - 1
10
10
  - a
11
- version: 0.5.0a
11
+ version: 0.5.1a
12
12
  platform: ruby
13
13
  authors:
14
14
  - Craig Muth
@@ -110,6 +110,8 @@ files:
110
110
  - etc/wrappers/wrapper.js
111
111
  - etc/wrappers/wrapper.py
112
112
  - etc/wrappers/wrapper.rb
113
+ - etc/www/index.rb
114
+ - etc/www/web_server.rb
113
115
  - lib/block.rb
114
116
  - lib/bookmarks.rb
115
117
  - lib/buffers.rb
@@ -196,6 +198,7 @@ files:
196
198
  - menus/contacts.rb
197
199
  - menus/cookies.rb
198
200
  - menus/couch.rb
201
+ - menus/create.rb
199
202
  - menus/crop.rb
200
203
  - menus/css.rb
201
204
  - menus/current.rb
@@ -225,6 +228,7 @@ files:
225
228
  - menus/head.rb
226
229
  - menus/headings.rb
227
230
  - menus/html.rb
231
+ - menus/http.rb
228
232
  - menus/icon.rb
229
233
  - menus/images.menu
230
234
  - menus/img.rb
@@ -269,6 +273,7 @@ files:
269
273
  - menus/thesaurus.rb
270
274
  - menus/to.rb
271
275
  - menus/twitter.rb
276
+ - menus/urls.menu
272
277
  - menus/wikipedia.rb
273
278
  - menus/words.rb
274
279
  - spec/code_tree_spec.rb