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: 27199ab432e45252ccda65a1bc2cab65addf2beb
4
- data.tar.gz: 19d6821d5c598a3981e65b264095547befa9f611
3
+ metadata.gz: 49263eedd17719084314811be758b56d4fe037f2
4
+ data.tar.gz: 0cd5d52d2ce5268cc14d73772344ae69b7264150
5
5
  SHA512:
6
- metadata.gz: caf32c60135eb76c61cd2768d52b490931d907cabc8891c2f4215dd76bacc772d77e5843b48cdfc31e8a80b17dc682e2774e4b234776b26c169cbad00234b78f
7
- data.tar.gz: d21f8afb8f2cf4700b94f34be8e213114a342ad8398f7a61df8dcbc8ba1badc90d5e0c6ecb59705a06ec7c7e0b7f1eaafbe7fbda2365b20249790887e17ccfee
6
+ metadata.gz: 1b1982bd451a5d4140cf61f1147c94f942f63080199d0276f6f66d90738f2f11b79f358515bd1b5698531aa9d91c3fbfa1cec781516f49226fa8ff873bc72fa7
7
+ data.tar.gz: fd276e6a4f934a457db264599f0825f9ebd7dd2d2b4956f1d5df326084b7964b61c81dfdeae6cb263cae74d9d740a8471cb0508536e27d933209419214dc91e0
@@ -1,38 +1,59 @@
1
- function fixEncoding(str) {
2
- return encodeURIComponent(str)
3
- .replace(/[!'()*]/g,
4
- function(c) {
5
- return '%' +
6
- c.charCodeAt(0)
7
- .toString(16);
8
- }
9
- );
10
- }
11
-
12
- var captureLink = function() {
13
- var selection = window.getSelection().toString();
14
- var location = window.location.href;
15
- var title = document.title;
16
- var description = document.querySelector('meta[name=description]');
17
- var keywords = document.querySelector('meta[name=keywords]');
18
- var protocol = 'capture';
19
-
20
- if (description) {
21
- description = description.attributes.content.value.toString()
22
- }
23
-
24
- if (keywords) {
25
- keywords.attributes.content.value.toString()
26
- }
27
-
28
- var uri = 'http://localhost:9998/?' +
29
- 'p=' + protocol +
30
- '&l=' + fixEncoding(location) +
31
- '&t=' + fixEncoding(title) +
32
- '&s=' + fixEncoding("description: " + description + "\n\n" + "selection: " + selection + "\n\n")
33
-
34
- window.location = uri;
35
- return uri;
36
- };
37
-
38
- captureLink();
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
- if params.empty?
47
- return [422, 'no params passed']
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
@@ -1,3 +1,3 @@
1
1
  module EmacsOrgProtocolServer
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  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.0
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: 2016-10-07 00:00:00.000000000 Z
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.5.1
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