xiki 0.5.0a
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -0
- data/LICENSE +22 -0
- data/README.markdown +83 -0
- data/Rakefile +8 -0
- data/bin/xiki +46 -0
- data/etc/command/xiki_command.rb +203 -0
- data/etc/command/xiki_process.rb +52 -0
- data/etc/command/xiki_wrapper +2 -0
- data/etc/js/menu1.js +55 -0
- data/etc/js/xiki.js +259 -0
- data/etc/logo.png +0 -0
- data/etc/presentations/bootstrap.deck +5 -0
- data/etc/presentations/databases.deck +41 -0
- data/etc/presentations/diffs.deck +23 -0
- data/etc/presentations/documentation.deck +14 -0
- data/etc/presentations/effects.deck +5 -0
- data/etc/presentations/face.deck +297 -0
- data/etc/presentations/files.deck +79 -0
- data/etc/presentations/icons.deck +22 -0
- data/etc/presentations/images.deck +24 -0
- data/etc/presentations/key_shortcuts.deck +16 -0
- data/etc/presentations/macros.deck +18 -0
- data/etc/presentations/menu_classes.deck +44 -0
- data/etc/presentations/menu_directories.deck +30 -0
- data/etc/presentations/notes.deck +19 -0
- data/etc/presentations/other_languages.deck +55 -0
- data/etc/presentations/other_wiki_syntaxes.deck +4 -0
- data/etc/presentations/piano.deck +5 -0
- data/etc/presentations/potential/diffs.deck +38 -0
- data/etc/presentations/potential/evolution.deck +18 -0
- data/etc/presentations/potential/intro.deck +711 -0
- data/etc/presentations/potential/intro1.deck +711 -0
- data/etc/presentations/potential/intro2.deck +97 -0
- data/etc/presentations/potential/make_mysql_menu.deck +36 -0
- data/etc/presentations/potential/ruby_development.deck +17 -0
- data/etc/presentations/potential/ui_prototyping.deck +50 -0
- data/etc/presentations/potential/web_dev.deck +4 -0
- data/etc/presentations/potential/web_development.deck +10 -0
- data/etc/presentations/potential/wiki.deck +45 -0
- data/etc/presentations/presentations.deck +24 -0
- data/etc/presentations/rails_development.deck +29 -0
- data/etc/presentations/search_key_shortcuts.deck +37 -0
- data/etc/presentations/simplest_possible_ui.deck +37 -0
- data/etc/presentations/svg.deck +5 -0
- data/etc/presentations/testing.deck +28 -0
- data/etc/presentations/the_end.deck +13 -0
- data/etc/presentations/type_something_and_double_click.deck +57 -0
- data/etc/presentations/type_the_acronym.deck +144 -0
- data/etc/presentations/web_browser.deck +56 -0
- data/etc/presentations/xiki_command.deck +20 -0
- data/etc/presentations/xiki_url.deck +14 -0
- data/etc/shark.icns +0 -0
- data/etc/shark_script.icns +0 -0
- data/etc/snippets/html.notes +7 -0
- data/etc/snippets/notes.notes +20 -0
- data/etc/snippets/rb.notes +38 -0
- data/etc/templates/menu_template.menu +2 -0
- data/etc/templates/menu_template.rb +8 -0
- data/etc/templates/template.rb +5 -0
- data/etc/themes/Dark_Metal.notes +28 -0
- data/etc/themes/Orange_Path.notes +15 -0
- data/etc/themes/Shiny_Blue.notes +27 -0
- data/etc/themes/Shiny_Green.notes +27 -0
- data/etc/wrappers/wrapper.js +17 -0
- data/etc/wrappers/wrapper.py +20 -0
- data/etc/wrappers/wrapper.rb +25 -0
- data/lib/block.rb +72 -0
- data/lib/bookmarks.rb +352 -0
- data/lib/buffers.rb +170 -0
- data/lib/clipboard.rb +333 -0
- data/lib/code.rb +860 -0
- data/lib/code_tree.rb +476 -0
- data/lib/color.rb +274 -0
- data/lib/console.rb +557 -0
- data/lib/control_lock.rb +9 -0
- data/lib/control_tab.rb +176 -0
- data/lib/core_ext.rb +31 -0
- data/lib/cursor.rb +111 -0
- data/lib/deletes.rb +65 -0
- data/lib/diff_log.rb +297 -0
- data/lib/effects.rb +145 -0
- data/lib/environment.rb +5 -0
- data/lib/file_tree.rb +1875 -0
- data/lib/files.rb +334 -0
- data/lib/hide.rb +259 -0
- data/lib/history.rb +286 -0
- data/lib/image.rb +51 -0
- data/lib/incrementer.rb +15 -0
- data/lib/insert.rb +7 -0
- data/lib/irc.rb +22 -0
- data/lib/key_bindings.rb +658 -0
- data/lib/keys.rb +754 -0
- data/lib/launcher.rb +1351 -0
- data/lib/line.rb +429 -0
- data/lib/links.rb +6 -0
- data/lib/location.rb +175 -0
- data/lib/macros.rb +48 -0
- data/lib/man.rb +19 -0
- data/lib/menu.rb +708 -0
- data/lib/merb.rb +259 -0
- data/lib/message.rb +5 -0
- data/lib/meths.rb +56 -0
- data/lib/mode.rb +34 -0
- data/lib/move.rb +248 -0
- data/lib/notes.rb +1000 -0
- data/lib/numbers.rb +45 -0
- data/lib/ol.rb +203 -0
- data/lib/ol_helper.rb +44 -0
- data/lib/overlay.rb +167 -0
- data/lib/pause_means_space.rb +68 -0
- data/lib/php.rb +22 -0
- data/lib/projects.rb +21 -0
- data/lib/relinquish_exception.rb +2 -0
- data/lib/remote.rb +206 -0
- data/lib/requirer.rb +46 -0
- data/lib/rest_tree.rb +108 -0
- data/lib/ruby.rb +57 -0
- data/lib/ruby_console.rb +165 -0
- data/lib/search.rb +1572 -0
- data/lib/search_term.rb +40 -0
- data/lib/snippet.rb +68 -0
- data/lib/specs.rb +229 -0
- data/lib/styles.rb +274 -0
- data/lib/svn.rb +682 -0
- data/lib/text_util.rb +110 -0
- data/lib/tree.rb +1871 -0
- data/lib/tree_cursor.rb +87 -0
- data/lib/trouble_shooting.rb +27 -0
- data/lib/url_tree.rb +11 -0
- data/lib/view.rb +1474 -0
- data/lib/window.rb +133 -0
- data/lib/xiki.rb +404 -0
- data/menus/accounts.rb +5 -0
- data/menus/address_book.rb +21 -0
- data/menus/agenda.rb +28 -0
- data/menus/all.rb +5 -0
- data/menus/amazon.rb +16 -0
- data/menus/app.rb +16 -0
- data/menus/applescript.rb +46 -0
- data/menus/as.rb +15 -0
- data/menus/bookmarklet.rb +63 -0
- data/menus/bootstrap.rb +568 -0
- data/menus/browse.rb +13 -0
- data/menus/browser.rb +78 -0
- data/menus/cassandra_db.rb +36 -0
- data/menus/chmod.rb +27 -0
- data/menus/classes.rb +5 -0
- data/menus/coffee_script.rb +35 -0
- data/menus/computer.rb +24 -0
- data/menus/contacts.rb +5 -0
- data/menus/cookies.rb +25 -0
- data/menus/couch.rb +184 -0
- data/menus/crop.rb +45 -0
- data/menus/css.rb +55 -0
- data/menus/current.rb +5 -0
- data/menus/db.rb +12 -0
- data/menus/deck.rb +219 -0
- data/menus/dictionary.rb +9 -0
- data/menus/dir.rb +8 -0
- data/menus/disk.rb +5 -0
- data/menus/do.rb +13 -0
- data/menus/docs.rb +58 -0
- data/menus/dotsies.rb +107 -0
- data/menus/edited.rb +18 -0
- data/menus/emacs.rb +17 -0
- data/menus/enter.rb +13 -0
- data/menus/eval.rb +17 -0
- data/menus/executable.rb +16 -0
- data/menus/filter.rb +46 -0
- data/menus/firefox.rb +607 -0
- data/menus/foo.rb +30 -0
- data/menus/french.rb +7 -0
- data/menus/git.rb +185 -0
- data/menus/gito.rb +785 -0
- data/menus/google.rb +35 -0
- data/menus/google_images.rb +11 -0
- data/menus/google_patents.rb +10 -0
- data/menus/gutenberg.rb +13 -0
- data/menus/head.rb +10 -0
- data/menus/headings.rb +39 -0
- data/menus/html.rb +61 -0
- data/menus/icon.rb +40 -0
- data/menus/images.menu +2 -0
- data/menus/img.rb +15 -0
- data/menus/info.rb +9 -0
- data/menus/ip.rb +10 -0
- data/menus/iterm.rb +36 -0
- data/menus/itunes.rb +78 -0
- data/menus/javascript.rb +74 -0
- data/menus/layout.rb +18 -0
- data/menus/local_storage.rb +67 -0
- data/menus/ls.rb +19 -0
- data/menus/mac.rb +87 -0
- data/menus/maps.rb +18 -0
- data/menus/matches.rb +18 -0
- data/menus/memcache.rb +117 -0
- data/menus/mkdir.rb +23 -0
- data/menus/mongo.rb +83 -0
- data/menus/mysql.rb +294 -0
- data/menus/node.rb +88 -0
- data/menus/open.rb +19 -0
- data/menus/outline.rb +24 -0
- data/menus/piano.rb +746 -0
- data/menus/postgres.rb +34 -0
- data/menus/pre.rb +5 -0
- data/menus/python.rb +39 -0
- data/menus/rails.rb +160 -0
- data/menus/rake.rb +12 -0
- data/menus/redmine.rb +168 -0
- data/menus/riak_tree.rb +204 -0
- data/menus/rss.rb +15 -0
- data/menus/safari.rb +11 -0
- data/menus/sass.rb +15 -0
- data/menus/say.rb +6 -0
- data/menus/scale.rb +49 -0
- data/menus/serve.rb +78 -0
- data/menus/shuffle.rb +24 -0
- data/menus/spanish.rb +7 -0
- data/menus/standalone.rb +57 -0
- data/menus/tail.rb +41 -0
- data/menus/technologies.rb +19 -0
- data/menus/themes.rb +32 -0
- data/menus/thesaurus.rb +13 -0
- data/menus/to.rb +24 -0
- data/menus/twitter.rb +57 -0
- data/menus/wikipedia.rb +34 -0
- data/menus/words.rb +11 -0
- data/spec/code_tree_spec.rb +59 -0
- data/spec/diff_log_spec.rb +40 -0
- data/spec/file_tree_spec.rb +102 -0
- data/spec/keys_spec.rb +24 -0
- data/spec/line_spec.rb +68 -0
- data/spec/menu_spec.rb +50 -0
- data/spec/ol_spec.rb +98 -0
- data/spec/remote_spec.rb +43 -0
- data/spec/search_spec.rb +162 -0
- data/spec/text_util_spec.rb +119 -0
- data/spec/tree_cursor_spec.rb +91 -0
- data/spec/tree_spec.rb +955 -0
- data/tests/console_test.rb +11 -0
- data/tests/couch_db_test.rb +12 -0
- data/tests/diff_log_test.rb +43 -0
- data/tests/el_mixin.rb +16 -0
- data/tests/git_test.rb +95 -0
- data/tests/keys_test.rb +19 -0
- data/tests/line_test.rb +38 -0
- data/tests/merb_test.rb +11 -0
- data/tests/redmine_test.rb +50 -0
- data/tests/remote_test.rb +31 -0
- data/tests/rest_tree_test.rb +70 -0
- data/xiki.gemspec +37 -0
- metadata +332 -0
data/menus/edited.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Edited
|
2
|
+
def self.menu option=nil
|
3
|
+
|
4
|
+
paths = Files.edited_array[0..300]
|
5
|
+
|
6
|
+
# If "tree" option, show in tree form
|
7
|
+
if option == "tree"
|
8
|
+
txt = Tree.paths_to_tree paths
|
9
|
+
txt.gsub! /^- \//, "- @/"
|
10
|
+
return txt
|
11
|
+
end
|
12
|
+
|
13
|
+
# Else, show in array form
|
14
|
+
|
15
|
+
paths.map!{|i| i.sub(/(.+\/)(.+)/, "- @\\1\n - \\2")}
|
16
|
+
paths.join("\n")
|
17
|
+
end
|
18
|
+
end
|
data/menus/emacs.rb
ADDED
data/menus/enter.rb
ADDED
data/menus/eval.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Eval
|
2
|
+
def self.menu *args
|
3
|
+
|
4
|
+
# If any args, just eval them
|
5
|
+
if args.any?
|
6
|
+
return eval args.join("/")
|
7
|
+
end
|
8
|
+
|
9
|
+
left = Line.right + 1
|
10
|
+
ignore, ignore, right = View.block_positions "^>"
|
11
|
+
|
12
|
+
Code.run :right=>right, :left=>left
|
13
|
+
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
data/menus/executable.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class Executable
|
2
|
+
def self.menu
|
3
|
+
|
4
|
+
# If not nested, error
|
5
|
+
return "
|
6
|
+
| Put '@executable' under a menu then run it again. It should be under
|
7
|
+
| the menu you want to create the executable for ou want to create the"
|
8
|
+
|
9
|
+
trunk = Xiki.trunk
|
10
|
+
|
11
|
+
"
|
12
|
+
- cake/
|
13
|
+
- chocolate/
|
14
|
+
"
|
15
|
+
end
|
16
|
+
end
|
data/menus/filter.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
class Filter
|
2
|
+
def self.menu filter=nil, *target
|
3
|
+
|
4
|
+
# Get parent file path!
|
5
|
+
# If none, assume current file
|
6
|
+
|
7
|
+
# For now, just assume it's the current file
|
8
|
+
|
9
|
+
# If nothing passed, tell them to add something
|
10
|
+
return View.prompt "Type something to filter by" if ! filter
|
11
|
+
|
12
|
+
return Tree.children(self.docs, target) if filter == "docs"
|
13
|
+
|
14
|
+
if target.blank? # If just filter, show results
|
15
|
+
return View.txt.grep(/#{filter}/i).join("").gsub(/^/, '| ')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Navigated to a target
|
19
|
+
|
20
|
+
target = Line.value
|
21
|
+
target.sub! /^ *\| /, ''
|
22
|
+
|
23
|
+
View.to_highest
|
24
|
+
Search.forward "^#{target}$"
|
25
|
+
|
26
|
+
Line.to_beginning
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.docs
|
31
|
+
"
|
32
|
+
> Examples
|
33
|
+
| Filter the whole file for the string 'tt'
|
34
|
+
@filter/tt/
|
35
|
+
|
36
|
+
| Filter for NOT the string 'tt'
|
37
|
+
@filter/!/tt/
|
38
|
+
|
39
|
+
| Filter children for the string 'tt'
|
40
|
+
@filter/tt/
|
41
|
+
| Hat
|
42
|
+
| Hatty
|
43
|
+
"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/menus/firefox.rb
ADDED
@@ -0,0 +1,607 @@
|
|
1
|
+
require 'net/telnet'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
gem 'simple-tidy'
|
5
|
+
require 'simple-tidy'
|
6
|
+
gem 'nokogiri-pretty'
|
7
|
+
require 'nokogiri-pretty'
|
8
|
+
|
9
|
+
require "rexml/document"
|
10
|
+
|
11
|
+
class Firefox
|
12
|
+
|
13
|
+
@@log_unique_token = "aa"
|
14
|
+
|
15
|
+
def self.menu
|
16
|
+
%`
|
17
|
+
@html/
|
18
|
+
@js/
|
19
|
+
@dom/
|
20
|
+
- .navigate/
|
21
|
+
- .reload/
|
22
|
+
- .back/
|
23
|
+
- .forward/
|
24
|
+
- .tabs/
|
25
|
+
- load js into a page) .include_jquery_and_utils
|
26
|
+
- see/
|
27
|
+
- @append/
|
28
|
+
- @click/
|
29
|
+
- @blink/
|
30
|
+
- @ffo/
|
31
|
+
- @jso/
|
32
|
+
- @jsp/
|
33
|
+
- @jsc/
|
34
|
+
- api/
|
35
|
+
| p Firefox.value "window.title"
|
36
|
+
| "The Title"
|
37
|
+
| Firefox.run "alert('hey')"
|
38
|
+
- docs/
|
39
|
+
> Js examples
|
40
|
+
@js/p('hi')
|
41
|
+
@js/$('a').blink()
|
42
|
+
@js/p($('a').length)
|
43
|
+
@js/$(':text').toggle()
|
44
|
+
|
|
45
|
+
> Running html in the browser
|
46
|
+
@html/<b>hello</b>
|
47
|
+
|
|
48
|
+
|
|
49
|
+
> Running javascript in the browser
|
50
|
+
| Run some javascript:
|
51
|
+
@js/alert('hi')
|
52
|
+
|
|
53
|
+
| Run and insert output:
|
54
|
+
@jso/document.title
|
55
|
+
|
|
56
|
+
| Run and print output in floating divs:
|
57
|
+
@jsp/document.title
|
58
|
+
|
|
59
|
+
| Run and print output in console:
|
60
|
+
@jsc/document.title
|
61
|
+
|
|
62
|
+
|
|
63
|
+
> Exploring and maniplating the current page
|
64
|
+
| Drill into the dom:
|
65
|
+
@dom/
|
66
|
+
|
|
67
|
+
| Search in the current page for "and":
|
68
|
+
@ff/and/
|
69
|
+
|
|
70
|
+
| Make all a tags blink:
|
71
|
+
@blink/a
|
72
|
+
|
|
73
|
+
| Simulate clicking the "sign up" link:
|
74
|
+
@click/
|
75
|
+
|
|
76
|
+
| Drill into the properties of the window class:
|
77
|
+
@ffo/window/
|
78
|
+
`
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.js txt=nil
|
82
|
+
return Tree.<<("| $('div').toggle(1300) // Type some javascript here (to run in the browser)") if ! txt
|
83
|
+
|
84
|
+
Firefox.run txt #, :jquery=>1
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.coffee txt=nil
|
88
|
+
return View.prompt("Type some coffeescript to run in the browser") if txt.nil?
|
89
|
+
|
90
|
+
txt = CoffeeScript.run_internal txt
|
91
|
+
|
92
|
+
Firefox.run txt #, :jquery=>1
|
93
|
+
".flash - ran in browser!"
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.last_stack_trace
|
97
|
+
Firefox.value('window.content.tmp_stack')
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.reload
|
101
|
+
|
102
|
+
# Clears out OL log
|
103
|
+
Code.open_log_view if Keys.prefix_u && View.buffer_visible?('*ol')
|
104
|
+
|
105
|
+
prefix = Keys.prefix_n :clear=>true
|
106
|
+
if ! prefix
|
107
|
+
Firefox.run("gBrowser.reload()", :browser=>true)
|
108
|
+
elsif prefix == 0
|
109
|
+
# Similar to reload, but field values will reset
|
110
|
+
Firefox.run("document.location = document.location;")
|
111
|
+
else
|
112
|
+
|
113
|
+
tab = prefix - 1
|
114
|
+
if tab == -1 # If 0, close tab
|
115
|
+
self.close_tab
|
116
|
+
else # If number, switch to tab
|
117
|
+
Firefox.run("gBrowser.tabContainer.selectedIndex = #{tab}", :browser=>true)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.close_tab
|
125
|
+
times = Keys.prefix_n :clear=>true
|
126
|
+
(times||1).times do
|
127
|
+
self.run "gBrowser.removeCurrentTab();", :browser=>true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.click
|
132
|
+
link = Keys.input(:prompt=>'Substring of link to click on: ')
|
133
|
+
|
134
|
+
Firefox.run("
|
135
|
+
var a = $('a:contains(#{link}):first');
|
136
|
+
var url = a.attr('href');
|
137
|
+
if(url == '#')
|
138
|
+
a.click();
|
139
|
+
else
|
140
|
+
window.location = url;
|
141
|
+
")
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.back
|
145
|
+
Firefox.run "history.back()"
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.forward
|
149
|
+
Firefox.run "history.forward()"
|
150
|
+
end
|
151
|
+
|
152
|
+
# # Copied from here (and modified):
|
153
|
+
# - /docs/tools/firewatir/firewatir-read-only/FireWatir/
|
154
|
+
# - container.rb
|
155
|
+
# | def read_socket(socket = jssh_socket)
|
156
|
+
def self.read_socket(socket)
|
157
|
+
result = ""
|
158
|
+
data = ""
|
159
|
+
receive = true
|
160
|
+
s = nil
|
161
|
+
while(s == nil) do
|
162
|
+
s = Kernel.select([socket] , nil , nil, 1)
|
163
|
+
end
|
164
|
+
for stream in s[0]
|
165
|
+
data = stream.recv(1024)
|
166
|
+
while(receive)
|
167
|
+
result += data
|
168
|
+
if(result.include?("\n> "))
|
169
|
+
receive = false
|
170
|
+
else
|
171
|
+
data = stream.recv(1024)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
length = result.length
|
177
|
+
|
178
|
+
if length <= 3
|
179
|
+
result = ""
|
180
|
+
elsif(result[0..2] == "\n> ")
|
181
|
+
result = result[3..length-1]
|
182
|
+
else
|
183
|
+
result = result[0..length-4]
|
184
|
+
end
|
185
|
+
if(result[result.length - 3..result.length - 1] == "\n> ")
|
186
|
+
result = result[0..result.length - 4]
|
187
|
+
end
|
188
|
+
if(result[0..2] == "\n> ")
|
189
|
+
result = result[3..result.length - 1]
|
190
|
+
end
|
191
|
+
result
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
def self.run_block
|
198
|
+
|
199
|
+
prefix = Keys.prefix
|
200
|
+
|
201
|
+
# Get block contents
|
202
|
+
txt, left, right = View.txt_per_prefix prefix
|
203
|
+
|
204
|
+
funcs = %q`
|
205
|
+
function p(s) {
|
206
|
+
if(s == null)
|
207
|
+
s = "[blank]";
|
208
|
+
|
209
|
+
try {prepend_index++;}
|
210
|
+
catch(e) { prepend_index = 0; }
|
211
|
+
|
212
|
+
var d = document.createElement('div');
|
213
|
+
document.body.appendChild(d);
|
214
|
+
d.innerHTML = '<div style="top:'+(prepend_index*13)+'px; margin-left:5px; position:absolute; font-size:10px; z-index:1002; color:#000; filter: alpha(opacity=85); -moz-opacity: .85; opacity: .85; background-color:#999;">'+s+'</div>';
|
215
|
+
|
216
|
+
}
|
217
|
+
`
|
218
|
+
|
219
|
+
# If started with <..., treat it as html
|
220
|
+
|
221
|
+
return Browser.html txt if txt =~ /\A\s*</
|
222
|
+
|
223
|
+
Browser.js txt
|
224
|
+
return
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.run txt, options={}
|
228
|
+
|
229
|
+
result = Firefox.mozrepl_command txt, options
|
230
|
+
|
231
|
+
if result =~ /\$ is not defined/ # If no jquery wrap it and try again
|
232
|
+
txt = Javascript.wrap_jquery_load txt
|
233
|
+
result = Firefox.mozrepl_command txt, options
|
234
|
+
elsif result =~ /\bp is not defined\b/ # If no jquery wrap it and try again
|
235
|
+
txt = Javascript.wrap_jquery_load txt, "http://xiki.org/javascripts/util.js"
|
236
|
+
result = Firefox.mozrepl_command txt, options
|
237
|
+
end
|
238
|
+
|
239
|
+
result.sub! /^"(.+)"$/m, "\\1" # Remove quotes
|
240
|
+
|
241
|
+
result
|
242
|
+
|
243
|
+
rescue Errno::ECONNREFUSED
|
244
|
+
|
245
|
+
# If brawser wasn't running, ask if they want to open it
|
246
|
+
|
247
|
+
raise "> Looks like the browser isn\'t open. Open it?\n@app/Firefox/"
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
def self.value txt
|
252
|
+
self.run(txt).sub(/\A"/, "").sub(/"\z/, "")
|
253
|
+
end
|
254
|
+
|
255
|
+
def self.url url=nil, options={}
|
256
|
+
|
257
|
+
return ".prompt Type a url here." if url.empty?
|
258
|
+
|
259
|
+
return $el.browse_url(url) if options[:new]
|
260
|
+
|
261
|
+
reload = "gBrowser.reload();";
|
262
|
+
reload = "" if options[:no_reload];
|
263
|
+
|
264
|
+
js = %`
|
265
|
+
var browsers = gBrowser.browsers;
|
266
|
+
|
267
|
+
if((browsers[gBrowser.tabContainer.selectedIndex]).contentDocument.location.href == "#{url}"){
|
268
|
+
#{reload}
|
269
|
+
false;
|
270
|
+
}else{
|
271
|
+
var found = false;
|
272
|
+
for(var i=0; i < browsers.length; i++) {
|
273
|
+
if(browsers[i].contentDocument.location.href != "#{url}") continue;
|
274
|
+
gBrowser.tabContainer.selectedIndex = i;
|
275
|
+
#{options[:reload] ? reload : ''}
|
276
|
+
found = true;
|
277
|
+
break;
|
278
|
+
}
|
279
|
+
if(! found) (browsers[gBrowser.tabContainer.selectedIndex]).contentDocument.location.href = "#{url}";
|
280
|
+
}
|
281
|
+
|
282
|
+
`.unindent
|
283
|
+
|
284
|
+
result = self.run js, :browser=>true
|
285
|
+
|
286
|
+
nil
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
def self.do_as_html
|
291
|
+
# Grab block
|
292
|
+
txt, left, right = View.txt_per_prefix #:prefix=>Keys.prefix
|
293
|
+
|
294
|
+
self.html txt # Write to temp file
|
295
|
+
end
|
296
|
+
|
297
|
+
def self.html txt=nil
|
298
|
+
|
299
|
+
File.open("/tmp/tmp.html", "w") { |f| f << txt }
|
300
|
+
|
301
|
+
Firefox.url "file:///tmp/tmp.html", :reload=>1
|
302
|
+
|
303
|
+
nil
|
304
|
+
end
|
305
|
+
|
306
|
+
def self.append html=nil
|
307
|
+
if html.nil?
|
308
|
+
View.prompt("Add something to append")
|
309
|
+
return "| "
|
310
|
+
end
|
311
|
+
|
312
|
+
html.gsub! '"', '\\"'
|
313
|
+
html.gsub! "\n", ' '
|
314
|
+
|
315
|
+
code = "$('body').append(\"#{html}\")"
|
316
|
+
result = Firefox.run code #, :jquery=>1
|
317
|
+
nil
|
318
|
+
end
|
319
|
+
|
320
|
+
def self.jso txt=nil
|
321
|
+
return View.prompt("Add some js to output its result") if txt.nil?
|
322
|
+
Firefox.run txt #, :jquery=>1
|
323
|
+
end
|
324
|
+
|
325
|
+
def self.enter_log_javascript_line
|
326
|
+
|
327
|
+
$el.open_line(1) unless Line.blank?
|
328
|
+
|
329
|
+
prefix = Keys.prefix
|
330
|
+
|
331
|
+
if prefix.nil?
|
332
|
+
View.insert "p('js#{@@log_unique_token}');"
|
333
|
+
@@log_unique_token.next!
|
334
|
+
|
335
|
+
elsif prefix == :u
|
336
|
+
View.insert "pp('js#{@@log_unique_token}');"
|
337
|
+
@@log_unique_token.next!
|
338
|
+
|
339
|
+
elsif prefix == :-
|
340
|
+
View.insert "p_stack();"
|
341
|
+
|
342
|
+
elsif Keys.prefix_uu
|
343
|
+
|
344
|
+
txt = Firefox.value('window.content.tmp_stack')
|
345
|
+
matches = txt.scan(/\$pu.+?:\d+/)
|
346
|
+
|
347
|
+
txts = matches.map{|o| "- #{o.gsub(/.+\//, '')}"}
|
348
|
+
paths = matches.map{|o| Bookmarks[o]}
|
349
|
+
|
350
|
+
end
|
351
|
+
|
352
|
+
Line.to_left
|
353
|
+
end
|
354
|
+
|
355
|
+
def self.include_jquery_and_utils
|
356
|
+
|
357
|
+
Firefox.run "
|
358
|
+
var s=document.createElement('script');
|
359
|
+
s.setAttribute('src', 'http://code.jquery.com/jquery.min.js');
|
360
|
+
document.getElementsByTagName('head')[0].appendChild(s);
|
361
|
+
|
362
|
+
var s=document.createElement('script');
|
363
|
+
s.setAttribute('src', 'http://xiki.org/javascripts/util.js');
|
364
|
+
document.getElementsByTagName('head')[0].appendChild(s);
|
365
|
+
".unindent
|
366
|
+
|
367
|
+
nil
|
368
|
+
end
|
369
|
+
|
370
|
+
def self.enter_as_url
|
371
|
+
if Keys.prefix_u
|
372
|
+
self.run "gBrowser.tabContainer.selectedIndex += 1", :browser=>true
|
373
|
+
end
|
374
|
+
|
375
|
+
url = Firefox.value('document.location.toString()')
|
376
|
+
View.insert url.gsub '%20', '+'
|
377
|
+
View.insert("\n") if Keys.prefix_u
|
378
|
+
end
|
379
|
+
|
380
|
+
def self.mozrepl_read s
|
381
|
+
begin
|
382
|
+
timeout(6) do
|
383
|
+
r = ''
|
384
|
+
loop do
|
385
|
+
r << s.readchar.chr
|
386
|
+
break if r =~ /^repl\d*> $/
|
387
|
+
end
|
388
|
+
r.sub /^repl\d*> /, ''
|
389
|
+
end
|
390
|
+
rescue Timeout::Error=>e
|
391
|
+
raise "Seems like mozrepl isnt responding. Is the internet down??"
|
392
|
+
end
|
393
|
+
|
394
|
+
end
|
395
|
+
|
396
|
+
def self.mozrepl_command js, options={}
|
397
|
+
s = TCPSocket::new("localhost", "4242")
|
398
|
+
|
399
|
+
initial_crap = mozrepl_read s
|
400
|
+
repl = initial_crap[/repl\d+/] || 'repl'
|
401
|
+
if options[:tab] # Run js in page on nth tab
|
402
|
+
s.puts("#{repl}.enter(window.gBrowser.getBrowserAtIndex(#{options[:tab]}).contentDocument)\n;")
|
403
|
+
mozrepl_read s
|
404
|
+
elsif options[:browser] # Run js at browser outer level
|
405
|
+
# Do nothing to change context
|
406
|
+
else # Run js in page
|
407
|
+
s.puts("#{repl}.enter(content.wrappedJSObject)\n;")
|
408
|
+
mozrepl_read s
|
409
|
+
end
|
410
|
+
|
411
|
+
s.puts js
|
412
|
+
txt = mozrepl_read s
|
413
|
+
s.close
|
414
|
+
txt.strip
|
415
|
+
end
|
416
|
+
|
417
|
+
|
418
|
+
# TODO Not used any more?
|
419
|
+
def self.log
|
420
|
+
View.open "/Users/craig/.emacs.d/url_log.notes"
|
421
|
+
end
|
422
|
+
|
423
|
+
def self.xul txt
|
424
|
+
Firefox.mozrepl_command txt, :browser=>true
|
425
|
+
end
|
426
|
+
|
427
|
+
|
428
|
+
def self.do_as_xul
|
429
|
+
Block.do_as_something do |txt|
|
430
|
+
Firefox.mozrepl_command txt, :browser=>true
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
def self.tabs *url
|
435
|
+
if url.any?
|
436
|
+
url = Line.value.sub /^[ |]*/, ''
|
437
|
+
self.url url, :new=>Keys.prefix_u
|
438
|
+
return
|
439
|
+
end
|
440
|
+
|
441
|
+
js = '
|
442
|
+
var browsers = gBrowser.browsers;
|
443
|
+
txt = "";
|
444
|
+
for(var i = 0; i < browsers.length; i++)
|
445
|
+
txt += "| "+browsers[i].contentDocument.location.href+"\n";
|
446
|
+
txt
|
447
|
+
'.unindent
|
448
|
+
|
449
|
+
result = Firefox.mozrepl_command js, :browser=>true
|
450
|
+
result.gsub! /\/$/, ''
|
451
|
+
result.sub(/\A"/, '').sub(/"\z/, '')
|
452
|
+
end
|
453
|
+
|
454
|
+
def self.load_jquery_maybe txt=nil #, options={}
|
455
|
+
|
456
|
+
# If text passed, check it and error if complaining about jquery missing
|
457
|
+
|
458
|
+
if txt && txt !~ /( (\$|p) is not defined|blink is not a function)/
|
459
|
+
return nil # Text without error, so don't load
|
460
|
+
end
|
461
|
+
|
462
|
+
self.run "
|
463
|
+
if(! document.getElementById('jqid')){
|
464
|
+
var s=document.createElement('script');
|
465
|
+
s.setAttribute('src', 'http://code.jquery.com/jquery.min.js'); s.setAttribute('id', 'jqid');
|
466
|
+
document.getElementsByTagName('head')[0].appendChild(s);
|
467
|
+
|
468
|
+
var s=document.createElement('script');
|
469
|
+
s.setAttribute('src', 'http://xiki.org/javascripts/util.js');
|
470
|
+
document.getElementsByTagName('head')[0].appendChild(s);
|
471
|
+
}
|
472
|
+
".unindent
|
473
|
+
|
474
|
+
raise ".flash - Added required js libs into page, try again!"
|
475
|
+
end
|
476
|
+
|
477
|
+
def self.object name=nil, key=nil
|
478
|
+
|
479
|
+
if name.nil? || name.empty?
|
480
|
+
return View.prompt "Type the name of an object in firefox"
|
481
|
+
end
|
482
|
+
|
483
|
+
if key.nil?
|
484
|
+
|
485
|
+
result = Firefox.value %`
|
486
|
+
var result = "";
|
487
|
+
for(var key in #{name}) {
|
488
|
+
if(! #{name}.hasOwnProperty(key)) continue;
|
489
|
+
result += key+"\\n";
|
490
|
+
}
|
491
|
+
`.unindent
|
492
|
+
return result.split("\n").sort{|a, b| a.sub(/^_+/, '').downcase <=> b.sub(/^_+/, '').downcase}.join("\n").gsub /.+/, "- \\0/"
|
493
|
+
end
|
494
|
+
|
495
|
+
# Key was passed
|
496
|
+
|
497
|
+
result = Firefox.value "#{name}['#{key}']"
|
498
|
+
|
499
|
+
end
|
500
|
+
|
501
|
+
def self.blink txt
|
502
|
+
return View.prompt("Type a selector to blink in firefox", :times=>5) if txt.nil?
|
503
|
+
selector = Tree.slashless txt
|
504
|
+
|
505
|
+
code = "
|
506
|
+
jQuery.fn.blink = function(times, orig) {
|
507
|
+
for(x=1;x<=2;x++) { jQuery(this).animate({opacity: 0.0}, {easing: 'swing', duration: 200}).animate({opacity: 1.0}, {easing: 'swing', duration: 200}) }
|
508
|
+
return this;
|
509
|
+
}
|
510
|
+
jQuery(\"#{selector}\").blink();
|
511
|
+
"
|
512
|
+
|
513
|
+
txt = Firefox.run code #, :jquery=>1
|
514
|
+
nil
|
515
|
+
end
|
516
|
+
|
517
|
+
end
|
518
|
+
|
519
|
+
Menu.ffo :class=>'Firefox.object'
|
520
|
+
|
521
|
+
Launcher.add(/^#[\w-]+$/) do |line|
|
522
|
+
Line.delete :br
|
523
|
+
View.insert "dom/#{line}/"
|
524
|
+
Launcher.launch
|
525
|
+
end
|
526
|
+
|
527
|
+
Launcher.add(/^\.[\w-]+$/) do |line|
|
528
|
+
Line.delete :br
|
529
|
+
View.insert "dom/#{line}/"
|
530
|
+
Launcher.launch
|
531
|
+
end
|
532
|
+
|
533
|
+
Menu.js do |path|
|
534
|
+
Applescript.run("Firefox", "activate") if Keys.prefix_u
|
535
|
+
Firefox.js Tree.rest(path)
|
536
|
+
nil
|
537
|
+
end
|
538
|
+
|
539
|
+
Menu.coffee do |path|
|
540
|
+
Firefox.coffee Tree.rest(path)
|
541
|
+
nil
|
542
|
+
end
|
543
|
+
|
544
|
+
Menu.jsp do |path|
|
545
|
+
txt = Tree.leaf path
|
546
|
+
txt = txt.strip.sub(/;\z/, '') # Remove any semicolon at end
|
547
|
+
code = "p(#{txt})"
|
548
|
+
result = Firefox.run code #, :jquery=>1
|
549
|
+
nil
|
550
|
+
end
|
551
|
+
|
552
|
+
Menu.blink do |path|
|
553
|
+
Firefox.blink Tree.rest(path)
|
554
|
+
nil
|
555
|
+
end
|
556
|
+
|
557
|
+
Menu.length do |path|
|
558
|
+
txt = Tree.rest(path)
|
559
|
+
|
560
|
+
next View.prompt("Type a jquery selector to show length of result") if txt.nil?
|
561
|
+
txt = "$(\"#{txt}\").length"
|
562
|
+
txt = Firefox.run txt #, :jquery=>1
|
563
|
+
|
564
|
+
# txt = Firefox.jso txt
|
565
|
+
Tree.<< txt, :no_slash=>1
|
566
|
+
nil
|
567
|
+
end
|
568
|
+
|
569
|
+
Menu.jsc do |path| # - (js): js to run in firefox
|
570
|
+
txt = Tree.rest path
|
571
|
+
return View.prompt("Add some js to run and output to firebug console.") if txt.nil?
|
572
|
+
txt = txt.strip.sub(/;\z/, '') # Remove any semicolon at end
|
573
|
+
code = "console.log(#{txt})"
|
574
|
+
Firefox.run code #, :jquery=>1
|
575
|
+
nil
|
576
|
+
end
|
577
|
+
|
578
|
+
Menu.jso do |path| # - (js): js to run in firefox
|
579
|
+
txt = Firefox.jso Tree.rest(path)
|
580
|
+
Tree.<< txt, :no_slash=>1
|
581
|
+
nil
|
582
|
+
end
|
583
|
+
|
584
|
+
Menu.jsi do |path| # - (js): js to run in firefox
|
585
|
+
txt = Tree.rest(path)
|
586
|
+
txt.sub! /;/, ''
|
587
|
+
txt = "JSON.stringify(#{txt})"
|
588
|
+
txt = Firefox.jso txt
|
589
|
+
Tree.<< txt, :no_slash=>1
|
590
|
+
nil
|
591
|
+
end
|
592
|
+
|
593
|
+
|
594
|
+
Menu.xul do |path| # - (js): js to run in firefox
|
595
|
+
Firefox.xul Tree.leaf(path)
|
596
|
+
end
|
597
|
+
|
598
|
+
Menu.click do |path|
|
599
|
+
nth = 0
|
600
|
+
txt = Tree.leaf path
|
601
|
+
Firefox.run("$('a, *[onclick]').filter(':contains(#{txt}):eq(#{nth})').click()") #, :jquery=>1)
|
602
|
+
nil
|
603
|
+
end
|
604
|
+
|
605
|
+
Menu.append do |path|
|
606
|
+
Firefox.append Tree.rest(path)
|
607
|
+
end
|