emacs_org_protocol_server 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49263eedd17719084314811be758b56d4fe037f2
|
4
|
+
data.tar.gz: 0cd5d52d2ce5268cc14d73772344ae69b7264150
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b1982bd451a5d4140cf61f1147c94f942f63080199d0276f6f66d90738f2f11b79f358515bd1b5698531aa9d91c3fbfa1cec781516f49226fa8ff873bc72fa7
|
7
|
+
data.tar.gz: fd276e6a4f934a457db264599f0825f9ebd7dd2d2b4956f1d5df326084b7964b61c81dfdeae6cb263cae74d9d740a8471cb0508536e27d933209419214dc91e0
|
data/javascripts/bookmarklet.js
CHANGED
@@ -1,38 +1,59 @@
|
|
1
|
-
function
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
1
|
+
(function() {
|
2
|
+
var fixEncoding = function(str) {
|
3
|
+
return encodeURIComponent(str)
|
4
|
+
.replace(/[!'()*]/g, function(c) {
|
5
|
+
return '%' +
|
6
|
+
c.charCodeAt(0)
|
7
|
+
.toString(16);
|
8
|
+
});
|
9
|
+
};
|
10
|
+
|
11
|
+
var location = window.location.href;
|
12
|
+
if (location) {
|
13
|
+
location = location.toString();
|
14
|
+
} else {
|
15
|
+
location = '';
|
16
|
+
}
|
17
|
+
|
18
|
+
var title = document.title;
|
19
|
+
if (title) {
|
20
|
+
title = title.toString();
|
21
|
+
} else {
|
22
|
+
title = '';
|
23
|
+
}
|
24
|
+
|
25
|
+
var selection = window.getSelection();
|
26
|
+
if (selection) {
|
27
|
+
selection = selection.toString();
|
28
|
+
} else {
|
29
|
+
selection = '';
|
30
|
+
}
|
31
|
+
|
32
|
+
var description = document.querySelector('meta[name=description]');
|
33
|
+
if (description) {
|
34
|
+
description = description.attributes.content.value.toString();
|
35
|
+
} else {
|
36
|
+
description = '';
|
37
|
+
}
|
38
|
+
|
39
|
+
var keywords = document.querySelector('meta[name=keywords]');
|
40
|
+
if (keywords) {
|
41
|
+
keywords.attributes.content.value.toString();
|
42
|
+
} else {
|
43
|
+
keywords = '';
|
44
|
+
}
|
45
|
+
|
46
|
+
var body = JSON.stringify({
|
47
|
+
'selection': selection,
|
48
|
+
'description': description,
|
49
|
+
'keywords': keywords
|
50
|
+
});
|
51
|
+
|
52
|
+
var uri = 'http://localhost:9998/?' +
|
53
|
+
'&l=' + fixEncoding(location) +
|
54
|
+
'&t=' + fixEncoding(title) +
|
55
|
+
'&b=' + fixEncoding(body);
|
56
|
+
|
57
|
+
window.location = uri;
|
58
|
+
return uri;
|
59
|
+
})();
|
@@ -1,9 +1,11 @@
|
|
1
1
|
require "emacs_org_protocol_server/version"
|
2
2
|
require 'emacs_org_protocol_server/uglify'
|
3
|
+
require 'emacs_org_protocol_server/emacs_client_runner'
|
3
4
|
require 'sinatra/base'
|
4
5
|
require 'uri'
|
5
6
|
require 'yaml'
|
6
7
|
require 'erb'
|
8
|
+
require 'logger'
|
7
9
|
|
8
10
|
module EmacsOrgProtocolServer
|
9
11
|
|
@@ -27,10 +29,11 @@ module EmacsOrgProtocolServer
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
32
|
class OPServ < Sinatra::Application
|
33
33
|
|
34
|
+
set :logger , Logger.new(STDOUT)
|
35
|
+
logger.level = Logger::DEBUG
|
36
|
+
|
34
37
|
settings = Settings.new
|
35
38
|
set :server , settings.server
|
36
39
|
set :port , settings.port
|
@@ -43,24 +46,15 @@ module EmacsOrgProtocolServer
|
|
43
46
|
end
|
44
47
|
|
45
48
|
get '/' do
|
46
|
-
|
47
|
-
|
49
|
+
begin
|
50
|
+
if EmacsOrgProtocolServer::EmacsClientRunner.new(params, settings.emacsclient, logger).run!
|
51
|
+
redirect params['l']
|
52
|
+
else
|
53
|
+
[400, 'bad request']
|
54
|
+
end
|
55
|
+
rescue EmacsOrgProtocolServer::EmacsClientRunner::NoParameters => e
|
56
|
+
return [400, 'bad request']
|
48
57
|
end
|
49
|
-
|
50
|
-
p=params['p'].to_s.downcase
|
51
|
-
if p.match(%r{capture})
|
52
|
-
template='//w'
|
53
|
-
else
|
54
|
-
template=''
|
55
|
-
end
|
56
|
-
l=params['l'].to_s
|
57
|
-
t=params['t'].to_s
|
58
|
-
s=params['s'].to_s
|
59
|
-
|
60
|
-
emacsclient_target = "org-protocol://#{p}:#{template}//#{esc(l)}/#{esc(t)}/#{esc(s)}"
|
61
|
-
cmd = "#{settings.emacsclient} -n '#{emacsclient_target}'"
|
62
|
-
system(cmd)
|
63
|
-
redirect to(params['l'])
|
64
58
|
end
|
65
59
|
|
66
60
|
get '/bookmarklet' do
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module EmacsOrgProtocolServer
|
5
|
+
|
6
|
+
class EmacsClientRunner
|
7
|
+
|
8
|
+
class NoParameters < RuntimeError; end
|
9
|
+
|
10
|
+
attr_accessor :client, :logger, :location, :title, :body
|
11
|
+
|
12
|
+
def initialize(params={}, client=nil, logger=Logger.new(STDERR))
|
13
|
+
raise NoParameters if params.empty?
|
14
|
+
self.logger = logger
|
15
|
+
self.client = client
|
16
|
+
self.location = params['l'].to_s
|
17
|
+
self.title = params['t'].to_s
|
18
|
+
self.body = params['b'].to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def run!
|
22
|
+
emacs_target = URI('org-protocol://capture')
|
23
|
+
query_data = {
|
24
|
+
template: 'w',
|
25
|
+
url: location,
|
26
|
+
title: title,
|
27
|
+
body: body
|
28
|
+
}
|
29
|
+
query_string = URI.encode_www_form(query_data).gsub('+','%20')
|
30
|
+
emacs_target.query = query_string
|
31
|
+
|
32
|
+
cmd = "#{client} -n '#{emacs_target}'"
|
33
|
+
logger.info "emacsclient command: #{cmd}"
|
34
|
+
system(cmd)
|
35
|
+
return ($? == 0)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emacs_org_protocol_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tamara Temple
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- javascripts/bookmarklet.js
|
145
145
|
- javascripts/shortkey.js
|
146
146
|
- lib/emacs_org_protocol_server.rb
|
147
|
+
- lib/emacs_org_protocol_server/emacs_client_runner.rb
|
147
148
|
- lib/emacs_org_protocol_server/uglify.rb
|
148
149
|
- lib/emacs_org_protocol_server/version.rb
|
149
150
|
homepage: https://github.com/tamouse/emacs_org_protocol_server
|
@@ -166,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
167
|
version: '0'
|
167
168
|
requirements: []
|
168
169
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.6.8
|
170
171
|
signing_key:
|
171
172
|
specification_version: 4
|
172
173
|
summary: Simple Sinatra server to call org-protocol with emacsclient
|