glorify 0.0.1 → 0.0.2
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/glorify.gemspec +2 -2
- data/lib/glorify.rb +12 -43
- data/lib/glorify/renderer.rb +25 -0
- data/lib/glorify/version.rb +1 -1
- metadata +9 -7
data/glorify.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "glorify/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "glorify"
|
7
7
|
s.version = Sinatra::Glorify::VERSION
|
8
|
-
s.authors = ["Zachary Scott"]
|
8
|
+
s.authors = ["Zachary Scott", "Jonathan Stott"]
|
9
9
|
s.email = ["zachary@zacharyscott.net"]
|
10
10
|
s.homepage = "http://github.com/zzak/glorify"
|
11
11
|
s.summary = %q{Sinatra helper to parse markdown with syntax highlighting like the pros}
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.require_paths = ["lib"]
|
16
16
|
|
17
17
|
s.add_runtime_dependency "sinatra"
|
18
|
-
s.add_runtime_dependency "redcarpet", "~>
|
18
|
+
s.add_runtime_dependency "redcarpet", "~> 2.0"
|
19
19
|
s.add_runtime_dependency "albino"
|
20
20
|
s.add_runtime_dependency "nokogiri"
|
21
21
|
end
|
data/lib/glorify.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
require "sinatra/base"
|
2
2
|
require "glorify/version"
|
3
|
-
require "
|
4
|
-
require "albino"
|
5
|
-
require "nokogiri"
|
6
|
-
require "net/http"
|
3
|
+
require "glorify/renderer"
|
7
4
|
|
8
5
|
module Sinatra
|
9
6
|
module Glorify
|
10
7
|
module Helpers
|
11
8
|
def glorify text
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
rndr = Glorify::Renderer.new(:use_albino => settings.use_albino)
|
10
|
+
Redcarpet::Markdown.new(rndr, settings.glorify_extensions).render(text)
|
11
|
+
end
|
12
|
+
|
17
13
|
def glorify_css
|
18
14
|
<<-css
|
19
15
|
.hll { background-color: #ffffcc }
|
@@ -78,42 +74,15 @@ module Sinatra
|
|
78
74
|
.il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
|
79
75
|
css
|
80
76
|
end
|
81
|
-
|
82
|
-
private
|
83
|
-
def highlighter html
|
84
|
-
doc = Nokogiri::HTML(html)
|
85
|
-
doc.search("//pre[@lang]").each do |pre|
|
86
|
-
pre.replace colorize(pre.text.rstrip, pre[:lang])
|
87
|
-
end
|
88
|
-
doc.search('pre').each do |pre|
|
89
|
-
pre.children.each do |c|
|
90
|
-
c.parent = pre.parent
|
91
|
-
end
|
92
|
-
pre.remove
|
93
|
-
end
|
94
|
-
doc.search('div').each do |div|
|
95
|
-
if div['class'] == 'highlight'
|
96
|
-
div.replace(Nokogiri.make("<pre>#{div.to_html}</pre>"))
|
97
|
-
end
|
98
|
-
end
|
99
|
-
doc.to_s
|
100
|
-
end
|
101
|
-
|
102
|
-
def colorize(code, lang)
|
103
|
-
if(pygmentize?)
|
104
|
-
Albino.colorize(code, lang)
|
105
|
-
else
|
106
|
-
Net::HTTP.post_form(URI.parse('http://pygments.appspot.com/'),
|
107
|
-
{'code'=>code, 'lang'=>lang}).body
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def pygmentize?
|
112
|
-
system 'pygmentize -V'
|
113
|
-
end
|
114
77
|
end
|
115
|
-
|
78
|
+
|
116
79
|
def self.registered(app)
|
80
|
+
app.set :use_albino, proc { system 'pygmentize -V' }
|
81
|
+
app.set :glorify_extensions, { :filter_html => true,
|
82
|
+
:autolink => true,
|
83
|
+
:no_intra_emphasis => true,
|
84
|
+
:fenced_code_blocks => true
|
85
|
+
}
|
117
86
|
app.helpers Glorify::Helpers
|
118
87
|
app.get '/pygments.css' do
|
119
88
|
glorify_css
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "redcarpet"
|
2
|
+
require "albino"
|
3
|
+
require "net/http"
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
module Glorify
|
7
|
+
class Renderer < Redcarpet::Render::HTML
|
8
|
+
attr_reader :use_albino
|
9
|
+
|
10
|
+
def initialize(options={})
|
11
|
+
@use_albino = options.fetch(:use_albino, true)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def block_code(code, lang)
|
16
|
+
if use_albino
|
17
|
+
Albino.colorize(code, lang)
|
18
|
+
else
|
19
|
+
Net::HTTP.post_form(URI.parse('http://pygments.appspot.com/'),
|
20
|
+
{'code'=>code, 'lang'=>lang}).body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/glorify/version.rb
CHANGED
metadata
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glorify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zachary Scott
|
14
|
+
- Jonathan Stott
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2012-01-
|
19
|
+
date: 2012-01-29 00:00:00 Z
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: sinatra
|
@@ -39,11 +40,11 @@ dependencies:
|
|
39
40
|
requirements:
|
40
41
|
- - ~>
|
41
42
|
- !ruby/object:Gem::Version
|
42
|
-
hash:
|
43
|
+
hash: 3
|
43
44
|
segments:
|
44
|
-
-
|
45
|
+
- 2
|
45
46
|
- 0
|
46
|
-
version: "
|
47
|
+
version: "2.0"
|
47
48
|
type: :runtime
|
48
49
|
version_requirements: *id002
|
49
50
|
- !ruby/object:Gem::Dependency
|
@@ -94,6 +95,7 @@ files:
|
|
94
95
|
- example/subclassed_app.rb
|
95
96
|
- glorify.gemspec
|
96
97
|
- lib/glorify.rb
|
98
|
+
- lib/glorify/renderer.rb
|
97
99
|
- lib/glorify/version.rb
|
98
100
|
homepage: http://github.com/zzak/glorify
|
99
101
|
licenses: []
|