tap-ubiquity 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009, Regents of the University of Colorado.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README ADDED
@@ -0,0 +1,18 @@
1
+ = Tap-Ubiqity
2
+
3
+ A gem making {Tap}[http://tap.rubyforge.org] available in
4
+ {Ubiqity}[http://labs.mozilla.com/2008/08/introducing-ubiquity/]
5
+
6
+ == Installation
7
+
8
+ Tap-Ubiquity is available as a gem on
9
+ RubyForge[http://rubyforge.org/projects/tap]. Use:
10
+
11
+ % gem install tap-ubiquity
12
+
13
+ == Info
14
+
15
+ Copyright (c) 2009, Regents of the University of Colorado.
16
+ Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com], {Biomolecular Structure Program}[http://biomol.uchsc.edu/], {Hansen Lab}[http://hsc-proteomics.uchsc.edu/hansenlab/]
17
+ Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
18
+ Licence:: {MIT-Style}[link:files/MIT-LICENSE.html]
@@ -0,0 +1,45 @@
1
+ require 'tap/controller'
2
+ require 'json'
3
+
4
+ module Tap
5
+ module Ubiquity
6
+
7
+ # ::controller
8
+ class Ubiquity < Tap::Controller
9
+ def index
10
+ link = {:uri => request['uri'], :name => request['name']}
11
+ render 'index.erb', :locals => {:feeds => feeds, :link => link}
12
+ end
13
+
14
+ protected
15
+
16
+ def feeds
17
+ env_names = {}
18
+ server.env.minimap.each do |env_name, env|
19
+ env_names[env] = env_name
20
+ end
21
+
22
+ feeds = []
23
+ server.env.each do |env|
24
+ env_name = env_names[env]
25
+
26
+ env.controllers.minimap.each do |name, constant|
27
+ document = Lazydoc[constant.require_path]
28
+ document.resolve(nil, true) # ?? why is force required ??
29
+ if comment = document[constant.name]['ubiquity']
30
+ action = comment.subject.strip
31
+ action = 'commands' if action.empty?
32
+ feeds << [
33
+ server.uri(name, action),
34
+ "#{env_name}:#{name}",
35
+ comment.content.join("\n").strip
36
+ ]
37
+ end
38
+ end
39
+ end
40
+
41
+ feeds
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,156 @@
1
+ require 'json'
2
+
3
+ module Tap
4
+ module Ubiquity
5
+
6
+ # Utils provides methods for serving ubiquity commands that link back to
7
+ # actions on a controller.
8
+ #
9
+ # :startdoc:::-
10
+ # # ::controller
11
+ # # ::ubiquity
12
+ # class Sample < Tap::Controller
13
+ # include Ubiquity::Utils
14
+ #
15
+ # def commands
16
+ # serve command(:action)
17
+ # end
18
+ #
19
+ # def action
20
+ # input = request['input']
21
+ # request.get? ? "got: #{input}" : "received: #{input}"
22
+ # end
23
+ # end
24
+ # :startdoc:::+
25
+ #
26
+ # Utils expects to be included in a Tap::Controller.
27
+ module Utils
28
+ module_function
29
+
30
+ # Serves the command from the calling method.
31
+ def serve(command)
32
+ if command_request?
33
+ response['Content-Type'] = 'application/x-javascript'
34
+ command
35
+ else
36
+ link = "<link rel='commands' href='#{command_href}' />"
37
+ block_given? ? yield(link) : link
38
+ end
39
+ end
40
+
41
+ # Returns true if the current request indicates the command javascript
42
+ # should be returned by serve (ie the path_info ends with '.js')
43
+ def command_request?
44
+ File.extname(request.path_info) == '.js'
45
+ end
46
+
47
+ # Returns the href that returns the command javascript.
48
+ def command_href
49
+ "#{uri(File.basename(request.path_info))}.js"
50
+ end
51
+
52
+ # Formats a Ubiquity command that calls action with an 'input' parameter
53
+ # containing the currently selected text. If the request is a get, the
54
+ # action results will be set in the preview box. Otherwise the current
55
+ # page is redirected to the action url.
56
+ #
57
+ #-- TODO
58
+ # name should be minipath, not action
59
+ def command(action, attrs={})
60
+ attrs = {:name => action}.merge(attrs)
61
+ %Q{
62
+ var cmd = #{attrs.to_json};
63
+ cmd.takes = {"selection": noun_arb_text};
64
+ cmd.preview = function( pblock, selection ) {
65
+ jQuery.ajax({
66
+ type: 'GET',
67
+ url: '#{uri(action)}',
68
+ data: {input: selection.text},
69
+ success: function(data) {
70
+ pblock.innerHTML = data;
71
+ },
72
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
73
+ pblock.innerHTML = "Could not generate preview: " + errorThrown;
74
+ },
75
+ });
76
+ };
77
+ cmd.execute = function(selection) {
78
+ var document = Application.activeWindow.activeTab.document;
79
+
80
+ var form = document.createElement("form");
81
+ form.setAttribute('action', '#{uri(action)}');
82
+ form.setAttribute('style', 'display:none');
83
+ form.setAttribute('method', 'POST');
84
+
85
+ var input = document.createElement('input');
86
+ input.setAttribute('name', 'input');
87
+ input.setAttribute('type', 'text');
88
+ input.value = selection.text;
89
+ form.appendChild(input);
90
+
91
+ document.body.appendChild(form);
92
+ form.submit();
93
+ };
94
+
95
+ CmdUtils.CreateCommand(cmd);
96
+ }
97
+ end
98
+
99
+ # class Sample < Tap::Controller
100
+ # include Ubiquity::Utils
101
+ #
102
+ # def commands
103
+ # serve js_injection(:action)
104
+ # end
105
+ #
106
+ # def action
107
+ # response['Content-Type'] = 'text/plain'
108
+ # "alert('#{request['input']}')"
109
+ # end
110
+ # end
111
+ #
112
+ def js_injection(action, attrs={}, inject=true)
113
+ attrs = {:name => action}.merge(attrs)
114
+ %Q{
115
+ var cmd = #{attrs.to_json};
116
+ cmd.takes = {"selection": noun_arb_text};
117
+ cmd.preview = function( pblock, selection ) {
118
+ jQuery.ajax({
119
+ type: 'GET',
120
+ url: '#{uri(action)}',
121
+ data: {input: selection.text},
122
+ success: function(data) {
123
+ pblock.innerHTML = data;
124
+ },
125
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
126
+ pblock.innerHTML = "Could not generate preview: " + errorThrown;
127
+ },
128
+ });
129
+ };
130
+ cmd.execute = function(selection) {
131
+ jQuery.ajax({
132
+ type: 'POST',
133
+ url: '#{uri(action)}',
134
+ data: {input: selection.text},
135
+ success: function(data) {
136
+ if(#{inject ? 'true' : 'false'}) {
137
+ var doc = Application.activeWindow.activeTab.document;
138
+ var script = doc.createElement("script");
139
+ script.type = "text/javascript";
140
+ script.innerHTML = data;
141
+ doc.body.appendChild(script);
142
+ } else {
143
+ eval(data);
144
+ }
145
+ },
146
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
147
+ displayMessage("Could not execute: " + errorThrown);
148
+ },
149
+ });
150
+ };
151
+
152
+ CmdUtils.CreateCommand(cmd);}
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "tap-ubiquity"
3
+ s.version = "0.2.0"
4
+ s.author = "Simon Chiang"
5
+ s.email = "simon.a.chiang@gmail.com"
6
+ s.homepage = "http://tap.rubyforge.org/ubiquity/"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.summary = "Making Tap available in Ubiquity"
9
+ s.require_path = "lib"
10
+ s.rubyforge_project = "tap"
11
+ s.add_dependency("tap-server", ">= 0.3.0")
12
+ s.add_dependency("json", ">= 1.1.3")
13
+ s.has_rdoc = true
14
+ s.rdoc_options.concat %W{--main README -S -N --title Tap\sUbiquity}
15
+
16
+ # list extra rdoc files here.
17
+ s.extra_rdoc_files = %W{
18
+ MIT-LICENSE
19
+ README
20
+ }
21
+
22
+ # list the files you want to include here. you can
23
+ # check this manifest using 'rake :print_manifest'
24
+ s.files = %W{
25
+ lib/tap/ubiquity/ubiquity.rb
26
+ lib/tap/ubiquity/utils.rb
27
+ tap-ubiquity.gemspec
28
+ tap.yml
29
+ views/tap/ubiquity/ubiquity/commands.js
30
+ views/tap/ubiquity/ubiquity/index.erb
31
+ }
32
+ end
data/tap.yml ADDED
File without changes
@@ -0,0 +1,88 @@
1
+ var Dispatch = {
2
+
3
+ /* Sends a preview request from the server and sets the preview
4
+ * block innerHTML on success. */
5
+ preview: function(pblock, data) {
6
+ jQuery.ajax({
7
+ type: "GET",
8
+ url: "<%= uri(:dispatch) %>",
9
+ data: data,
10
+ dataType: 'html',
11
+ success: function(html, textStatus) {
12
+ pblock.innerHTML = html;
13
+ },
14
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
15
+ Dispatch.ping("Error generating preview: " + textStatus);
16
+ },
17
+ });
18
+ },
19
+
20
+ /* Sends an execute request to the server. A successful response is a
21
+ * JSON object specifying 'inject' (true or false) and 'script'. The
22
+ * script is injected into the DOM as a <script> tag if inject is true,
23
+ * or evaluated in the context of Ubiquity if inject is false.
24
+ */
25
+ execute: function(data) {
26
+ jQuery.ajax({
27
+ type: "POST",
28
+ url: "<%= uri(:dispatch) %>",
29
+ data: data,
30
+ dataType: 'json',
31
+ success: function(json, textStatus) {
32
+ if(json.inject) {
33
+ var doc = Application.activeWindow.activeTab.document;
34
+ var script = doc.createElement("script");
35
+ script.type = "text/javascript";
36
+ script.innerHTML = json.script;
37
+ doc.body.appendChild(script);
38
+ } else {
39
+ eval(json.script);
40
+ }
41
+ },
42
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
43
+ Dispatch.ping("Error executing command: " + textStatus);
44
+ },
45
+ });
46
+ },
47
+
48
+ /* Pings the server to check if it is active. */
49
+ ping: function(active_msg) {
50
+ jQuery.ajax({
51
+ type: "GET",
52
+ url: "<%= uri(:ping) %>",
53
+ success: function(response, textStatus) {
54
+ displayMessage(active_msg);
55
+ },
56
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
57
+ displayMessage("No server is active at: <%= uri %>");
58
+ },
59
+ });
60
+ },
61
+ };
62
+
63
+ /////////////////////////////////////////////////////////////////////////////
64
+ //
65
+ // Generated Commands
66
+ //
67
+ /////////////////////////////////////////////////////////////////////////////
68
+
69
+ <% commands.each do |cmd| %>
70
+ CmdUtils.CreateCommand({
71
+ name: "<%= cmd[:name] %>",
72
+ description: "<%= cmd[:description] %>",
73
+ help: "<%= cmd[:help] %>",
74
+ takes: {"what": noun_arb_text},
75
+
76
+ data: function(what) {
77
+ return {what: what.text, name: '<%= cmd[:name] %>'};
78
+ },
79
+
80
+ preview: function(pblock, what) {
81
+ Dispatch.preview(pblock, this.data(what));
82
+ },
83
+
84
+ execute: function(what) {
85
+ Dispatch.execute(this.data(what));
86
+ },
87
+ });
88
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <h1>Welcome to Tap!</h1>
2
+
3
+ <p><a href="http://tap.rubyforge.org">Tap</a> interfaces with the web using <a href="">Ubiquity</a>.</p>
4
+ <ul>
5
+ <li>Press 'option' + 'space' to bring up a prompt</li>
6
+ </ul>
7
+
8
+ <% unless feeds.empty? %>
9
+ <p>Subscribe to local feeds by clicking on the links below:</p>
10
+ <ul>
11
+ <% feeds.each do |(uri, name, help)| %>
12
+ <li>
13
+ <a href="<%= uri %>"><%= name %></a>
14
+ <div><%= help %></div>
15
+ </li>
16
+ <% end %>
17
+ </ul>
18
+ <% end %>
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tap-ubiquity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Chiang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-17 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: tap-server
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.3
34
+ version:
35
+ description:
36
+ email: simon.a.chiang@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - MIT-LICENSE
43
+ - README
44
+ files:
45
+ - lib/tap/ubiquity/ubiquity.rb
46
+ - lib/tap/ubiquity/utils.rb
47
+ - tap-ubiquity.gemspec
48
+ - tap.yml
49
+ - views/tap/ubiquity/ubiquity/commands.js
50
+ - views/tap/ubiquity/ubiquity/index.erb
51
+ - MIT-LICENSE
52
+ - README
53
+ has_rdoc: true
54
+ homepage: http://tap.rubyforge.org/ubiquity/
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --main
58
+ - README
59
+ - -S
60
+ - -N
61
+ - --title
62
+ - Tap Ubiquity
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project: tap
80
+ rubygems_version: 1.3.1
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: Making Tap available in Ubiquity
84
+ test_files: []
85
+