sbfaulkner-pygmalion 0.9.2 → 0.9.3
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/lib/pygmalion.rb +14 -14
- data/pygmalion.gemspec +2 -2
- metadata +2 -2
data/lib/pygmalion.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'net/http'
|
2
|
-
require '
|
2
|
+
require 'cgi'
|
3
3
|
require 'active_support'
|
4
4
|
|
5
5
|
module Pygmalion
|
6
|
-
|
6
|
+
PYGMALION_HOST = 'pygments.com'
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
PYGMALION_JSON_PATH = "/json/"
|
9
|
+
PYGMALION_PUSH_PATH = "/push_chunk/"
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
PYGMALION_CHUNK_SIZE = 4000
|
12
|
+
PYGMALION_CHUNK_REGEX = Regexp.new(".{1,#{PYGMALION_CHUNK_SIZE}}", Regexp::MULTILINE)
|
13
13
|
|
14
|
-
|
14
|
+
PYGMALION_DEFAULTS = {
|
15
15
|
:css => 'n',
|
16
16
|
:id => 'pygmalion',
|
17
17
|
:linenos => 'off'
|
@@ -28,8 +28,8 @@ module Pygmalion
|
|
28
28
|
def pygments_query(parameters = {}, code = nil, chunkid = nil)
|
29
29
|
parameters[:code] = code
|
30
30
|
parameters[:chunkid] = chunkid if chunkid
|
31
|
-
parameters = parameters.collect { |k,v| "#{k}=#{
|
32
|
-
query = [ chunkid ?
|
31
|
+
parameters = parameters.collect { |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
|
32
|
+
query = [ chunkid ? PYGMALION_PUSH_PATH : PYGMALION_JSON_PATH ]
|
33
33
|
query << parameters unless parameters.empty?
|
34
34
|
query.join('?')
|
35
35
|
end
|
@@ -49,20 +49,20 @@ module Pygmalion
|
|
49
49
|
language = options.delete(:language)
|
50
50
|
|
51
51
|
# merge provided options into the defaults
|
52
|
-
options =
|
52
|
+
options = PYGMALION_DEFAULTS.merge(options)
|
53
53
|
|
54
54
|
# translate the aforementioned options
|
55
55
|
options[:linenos] = line_numbers ? 'on' : 'off'
|
56
56
|
options[:type] = language
|
57
57
|
|
58
|
-
res = Net::HTTP::start(
|
59
|
-
if self.size <=
|
58
|
+
res = Net::HTTP::start(PYGMALION_HOST) do |http|
|
59
|
+
if self.size <= PYGMALION_CHUNK_SIZE
|
60
60
|
# if code is small enough, use a single request
|
61
61
|
http.get self.class.pygments_query(options, self)
|
62
62
|
else
|
63
63
|
# otherwise break into chunks and push to the server
|
64
64
|
headers = {}
|
65
|
-
self.scan(
|
65
|
+
self.scan(PYGMALION_CHUNK_REGEX).each_with_index do |chunk, chunkid|
|
66
66
|
# TODO: try threads for potential speedup with multiple simultaneous requests if this proves too slow
|
67
67
|
response = http.get self.class.pygments_query(options, chunk, chunkid), headers
|
68
68
|
# the server uses a cookie-based session to deal with chunked requests
|
@@ -73,7 +73,7 @@ module Pygmalion
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
ActiveSupport::JSON.decode(res.body[/\{.*\}/])['output']
|
76
|
+
ActiveSupport::JSON.decode(res.body[/\{.*\}/m])['output']
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
data/pygmalion.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
SPEC = Gem::Specification.new do |s|
|
2
2
|
# identify the gem
|
3
3
|
s.name = "pygmalion"
|
4
|
-
s.version = "0.9.
|
4
|
+
s.version = "0.9.3"
|
5
5
|
s.author = "S. Brent Faulkner"
|
6
6
|
s.email = "brentf@unwwwired.net"
|
7
7
|
s.homepage = "http://www.unwwwired.net"
|
8
8
|
# platform of choice
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
# description of gem
|
11
|
-
s.summary = "
|
11
|
+
s.summary = "Syntax highlighting using the pygments.com \"web service\""
|
12
12
|
s.files = %w(bin/pygmalion lib/pygmalion.rb MIT-LICENSE Rakefile README.markdown pygmalion.gemspec)
|
13
13
|
s.require_path = "lib"
|
14
14
|
s.autorequire = "pygmalion"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbfaulkner-pygmalion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- S. Brent Faulkner
|
@@ -61,6 +61,6 @@ rubyforge_project:
|
|
61
61
|
rubygems_version: 1.2.0
|
62
62
|
signing_key:
|
63
63
|
specification_version: 2
|
64
|
-
summary:
|
64
|
+
summary: Syntax highlighting using the pygments.com "web service"
|
65
65
|
test_files: []
|
66
66
|
|