glorify 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -28
- data/Rakefile +9 -0
- data/glorify.gemspec +3 -2
- data/lib/glorify.rb +14 -7
- data/lib/glorify/css.rb +9 -0
- data/lib/glorify/extensions.rb +3 -0
- data/lib/glorify/helpers.rb +70 -0
- data/lib/glorify/renderer.rb +3 -13
- data/lib/glorify/template.rb +19 -2
- data/lib/glorify/version.rb +2 -1
- metadata +29 -6
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Sinatra::Glorify
|
2
2
|
|
3
3
|
Sinatra helper to parse markdown with syntax highlighting like the pros
|
4
4
|
|
@@ -8,7 +8,7 @@ Renders markdown via redcarpet with syntax highlighting thanks to
|
|
8
8
|
Able to use fenced code blocks like github, and includes a default pygments
|
9
9
|
stylesheet.
|
10
10
|
|
11
|
-
##
|
11
|
+
## Installation
|
12
12
|
|
13
13
|
```bash
|
14
14
|
gem install glorify
|
@@ -22,20 +22,21 @@ gem 'sinatra'
|
|
22
22
|
gem 'glorify'
|
23
23
|
```
|
24
24
|
|
25
|
-
##
|
25
|
+
## Sinatra::Glorify::Template
|
26
26
|
|
27
|
-
|
27
|
+
Sinatra::Glorify comes with a tilt template for rendering markdown.
|
28
28
|
|
29
|
-
|
30
|
-
with pygments.rb to highlight any code blocks within your view.
|
29
|
+
This allows you to override the default markdown renderer and use `redcarpet`
|
30
|
+
with `pygments.rb` to highlight any code blocks within your view.
|
31
31
|
|
32
|
-
|
32
|
+
In order to do this, you will need to prefer the template class.
|
33
33
|
|
34
34
|
```ruby
|
35
35
|
Tilt.prefer Sinatra::Glorify::Template
|
36
36
|
```
|
37
37
|
|
38
|
-
|
38
|
+
Now, any views that render via `markdown` will use Sinatra::Glorify::Template
|
39
|
+
instead.
|
39
40
|
|
40
41
|
```ruby
|
41
42
|
register Sinatra::Glorify
|
@@ -44,14 +45,21 @@ get '/' do
|
|
44
45
|
end
|
45
46
|
```
|
46
47
|
|
47
|
-
##
|
48
|
+
## Sinatra::Glorify::Helpers
|
48
49
|
|
49
|
-
|
50
|
-
blocks within your view, use the
|
50
|
+
If you want to stick with your current renderer and just render some code
|
51
|
+
blocks within your view, use the Sinatra::Glorify::Helpers.glorify helper
|
52
|
+
method.
|
51
53
|
|
52
|
-
|
54
|
+
Depending on the type of application you're building with Sinatra, the manner
|
55
|
+
in which Sinatra::Glorify is used will change.
|
53
56
|
|
54
|
-
|
57
|
+
See the Sinatra documentation on [Modular vs. Classic
|
58
|
+
style](http://www.sinatrarb.com/intro#Modular%20vs.%20Classic%20Style)
|
59
|
+
|
60
|
+
### With a classical app
|
61
|
+
|
62
|
+
Simply `require 'glorify'` to use the helper with a classic style sinatra app.
|
55
63
|
|
56
64
|
```ruby
|
57
65
|
require 'sinatra'
|
@@ -63,10 +71,10 @@ get '/' do
|
|
63
71
|
end
|
64
72
|
```
|
65
73
|
|
66
|
-
### modular app
|
74
|
+
### With a modular app
|
67
75
|
|
68
|
-
|
69
|
-
`require 'glorify'`, to use with a modular style sinatra app.
|
76
|
+
You will need to `register Sinatra::Glorify` in your sub-classed app, along
|
77
|
+
with `require 'glorify'`, to use with a modular style sinatra app.
|
70
78
|
|
71
79
|
```ruby
|
72
80
|
require 'sinatra/base'
|
@@ -81,9 +89,9 @@ class SubclassedApp < Sinatra::Base
|
|
81
89
|
end
|
82
90
|
```
|
83
91
|
|
84
|
-
###
|
92
|
+
### The view
|
85
93
|
|
86
|
-
|
94
|
+
This is just a simple `erb` template, but you get the idea.
|
87
95
|
|
88
96
|
```erb
|
89
97
|
<html>
|
@@ -96,21 +104,18 @@ this is just a simple `erb` template, but you get the idea.
|
|
96
104
|
</html>
|
97
105
|
```
|
98
106
|
|
99
|
-
|
100
|
-
`/pygments.css` route
|
107
|
+
The default pygments stylesheet that comes with glorify is available at the
|
108
|
+
`/pygments.css` route.
|
101
109
|
|
102
|
-
### on heroku
|
103
110
|
|
104
|
-
|
111
|
+
## Still stuck?
|
105
112
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
thanks to @simon for
|
110
|
-
[pointing this out](https://github.com/zzak/glorify/pull/5#r812124)
|
113
|
+
The Sinatra documentation on
|
114
|
+
[extensions](http://www.sinatrarb.com/extensions.html) does a great job of
|
115
|
+
explaining how to use and implement extensions using the Sinatra API.
|
111
116
|
|
112
117
|
|
113
|
-
##
|
118
|
+
## License
|
114
119
|
|
115
120
|
```
|
116
121
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
data/Rakefile
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
3
|
require 'rake/testtask'
|
4
|
+
require 'rdoc/task'
|
4
5
|
|
5
6
|
Rake::TestTask.new do |t|
|
6
7
|
t.pattern = "spec/*_spec.rb"
|
7
8
|
end
|
8
9
|
|
10
|
+
RDoc::Task.new do |rdoc|
|
11
|
+
rdoc.title = "Sinatra::Glorify"
|
12
|
+
rdoc.main = "README.md"
|
13
|
+
rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
|
14
|
+
rdoc.rdoc_dir = "."
|
15
|
+
rdoc.options << "-O"
|
16
|
+
end
|
17
|
+
|
9
18
|
task(:spec => :test)
|
10
19
|
task(:default => :test)
|
data/glorify.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Sinatra::Glorify::VERSION
|
8
8
|
s.authors = ["Zachary Scott", "Jonathan Stott", "Simon Gate"]
|
9
9
|
s.email = ["zachary@zacharyscott.net"]
|
10
|
-
s.homepage = "http://
|
10
|
+
s.homepage = "http://zacharyscott.net/glorify/"
|
11
11
|
s.summary = %q{Sinatra helper to parse markdown with syntax highlighting like the pros}
|
12
12
|
s.description = %q{Renders markdown via redcarpet with syntax highlighting thanks to pygments.rb. Able to use fenced code blocks like github, and includes a default pygments stylesheet.}
|
13
13
|
|
@@ -16,11 +16,12 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_runtime_dependency "sinatra"
|
18
18
|
s.add_runtime_dependency "redcarpet", "~> 2.0"
|
19
|
-
s.add_runtime_dependency "pygments.rb"
|
19
|
+
s.add_runtime_dependency "pygments.rb"
|
20
20
|
s.add_runtime_dependency "nokogiri"
|
21
21
|
|
22
22
|
s.add_development_dependency "minitest"
|
23
23
|
s.add_development_dependency "rack-test"
|
24
24
|
s.add_development_dependency "rake"
|
25
25
|
s.add_development_dependency "w3c_validators"
|
26
|
+
s.add_development_dependency "rdoc", "4.0.0.preview2"
|
26
27
|
end
|
data/lib/glorify.rb
CHANGED
@@ -4,16 +4,23 @@ require "glorify/extensions"
|
|
4
4
|
require "glorify/version"
|
5
5
|
require "glorify/renderer"
|
6
6
|
require "glorify/template"
|
7
|
+
require "glorify/helpers"
|
7
8
|
|
9
|
+
# Sinatra is a microframework for Ruby
|
10
|
+
#
|
11
|
+
# See sinatra on github for more:
|
12
|
+
# http://github.com/sinatra/sinatra
|
8
13
|
module Sinatra
|
14
|
+
# Sinatra helper to parse markdown with syntax highlighting like the pros
|
15
|
+
#
|
16
|
+
# {See the README for more info}[http://github.com/zzak/glorify#readme]
|
9
17
|
module Glorify
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
# Sinatra extension setup to configure the application.
|
19
|
+
#
|
20
|
+
# Uses +settings.glorify_extensions+ for the Sinatra::Glorify::Renderer
|
21
|
+
#
|
22
|
+
# Also, registers the Sinatra::Glorify::Helpers and provides the pygments
|
23
|
+
# stylesheet route using Sinatra::Glorify::Helpers.glorify_css.
|
17
24
|
def self.registered(app)
|
18
25
|
app.set :glorify_extensions, Glorify::EXTENSIONS
|
19
26
|
app.helpers Glorify::Helpers
|
data/lib/glorify/css.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
module Sinatra
|
2
2
|
module Glorify
|
3
3
|
module Helpers
|
4
|
+
# A helper route for your application to provide a pygments friendly
|
5
|
+
# stylesheet.
|
6
|
+
#
|
7
|
+
# Given, your Sinatra application is mounted under +/+
|
8
|
+
#
|
9
|
+
# <link rel="stylesheet" type="text/css" href="/pygments.css" />
|
10
|
+
#
|
11
|
+
# Based off {Trevor Turk's
|
12
|
+
# pygments/default.css}[https://github.com/trevorturk/pygments/blob/master/default.css]
|
4
13
|
def glorify_css
|
5
14
|
<<-css
|
6
15
|
.hll { background-color: #ffffcc }
|
data/lib/glorify/extensions.rb
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module Glorify
|
3
|
+
# If you want to stick with your current renderer and just render some code
|
4
|
+
# blocks within your view, use the Sinatra::Glorify::Helpers.glorify helper
|
5
|
+
# method.
|
6
|
+
#
|
7
|
+
# Depending on the type of application you're building with Sinatra, the manner
|
8
|
+
# in which Sinatra::Glorify is used will change.
|
9
|
+
#
|
10
|
+
# See the Sinatra documentation on {Modular vs. Classic
|
11
|
+
# style}[http://www.sinatrarb.com/intro#Modular%20vs.%20Classic%20Style]
|
12
|
+
#
|
13
|
+
# === With a classical app
|
14
|
+
#
|
15
|
+
# Simply <code>require 'glorify'</code> to use the helper with a classic
|
16
|
+
# style sinatra app.
|
17
|
+
#
|
18
|
+
# require 'sinatra'
|
19
|
+
# require 'glorify'
|
20
|
+
# require 'erb'
|
21
|
+
# get '/' do
|
22
|
+
# @example = File.open("#{File.dirname(__FILE__)}/example.md", "rb").read
|
23
|
+
# erb :index
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# === With a modular app
|
27
|
+
#
|
28
|
+
# You will need to <code>register Sinatra::Glorify</code> in your
|
29
|
+
# sub-classed app, along with <code>require 'glorify'</code>, to use with a
|
30
|
+
# modular style sinatra app.
|
31
|
+
#
|
32
|
+
# require 'sinatra/base'
|
33
|
+
# require 'glorify'
|
34
|
+
# require 'erb'
|
35
|
+
# class SubclassedApp < Sinatra::Base
|
36
|
+
# register Sinatra::Glorify
|
37
|
+
# get '/' do
|
38
|
+
# @example = File.open("#{File.dirname(__FILE__)}/example.md", "rb").read
|
39
|
+
# erb :index
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# === The view
|
44
|
+
#
|
45
|
+
# This is just a simple +erb+ template, but you get the idea.
|
46
|
+
#
|
47
|
+
# <html>
|
48
|
+
# <head>
|
49
|
+
# <link rel="stylesheet" type="text/css" href="/pygments.css" />
|
50
|
+
# </head>
|
51
|
+
# <body>
|
52
|
+
# <%= glorify @example %>
|
53
|
+
# </body>
|
54
|
+
# </html>
|
55
|
+
#
|
56
|
+
# The default pygments stylesheet that comes with glorify is available at the
|
57
|
+
# +/pygments.css+ route.
|
58
|
+
#
|
59
|
+
module Helpers
|
60
|
+
# Convenience method for custom markdown and templates.
|
61
|
+
#
|
62
|
+
# For modular applications you must add <code>register
|
63
|
+
# Sinatra::Helpers</code> to your application.
|
64
|
+
def glorify text
|
65
|
+
Redcarpet::Markdown.new(Glorify::Renderer.new,
|
66
|
+
Glorify::EXTENSIONS).render(text)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/glorify/renderer.rb
CHANGED
@@ -3,20 +3,10 @@ require "pygments.rb"
|
|
3
3
|
|
4
4
|
module Sinatra
|
5
5
|
module Glorify
|
6
|
-
class Renderer < Redcarpet::Render::HTML
|
6
|
+
class Renderer < Redcarpet::Render::HTML # :nodoc:
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
RubyPython.configure :python_exe => python
|
11
|
-
super
|
12
|
-
end
|
13
|
-
|
14
|
-
def block_code(code, lang)
|
15
|
-
begin
|
16
|
-
Pygments.highlight(code, :lexer => lang, :options => {:encoding => "utf-8"})
|
17
|
-
rescue RubyPython::PythonError
|
18
|
-
Pygments.highlight(code, :options => {:encoding => "utf-8"})
|
19
|
-
end
|
8
|
+
def block_code(code, lang) # :nodoc:
|
9
|
+
Pygments.highlight(code, :lexer => lang, :options => {:encoding => "utf-8"})
|
20
10
|
end
|
21
11
|
|
22
12
|
end
|
data/lib/glorify/template.rb
CHANGED
@@ -3,14 +3,31 @@ require 'tilt/template'
|
|
3
3
|
|
4
4
|
module Sinatra
|
5
5
|
module Glorify
|
6
|
+
# Sinatra::Glorify comes with a tilt template for rendering markdown.
|
7
|
+
#
|
8
|
+
# This allows you to override the default markdown renderer and use
|
9
|
+
# +redcarpet+ with +pygments.rb+ to highlight any code blocks within your
|
10
|
+
# view.
|
11
|
+
#
|
12
|
+
# In order to do this, you will need to prefer the template class.
|
13
|
+
#
|
14
|
+
# Tilt.prefer Sinatra::Glorify::Template
|
15
|
+
#
|
16
|
+
# Now, any views that render via +markdown+ will use
|
17
|
+
# Sinatra::Glorify::Template instead.
|
18
|
+
#
|
19
|
+
# register Sinatra::Glorify
|
20
|
+
# get '/' do
|
21
|
+
# markdown :a_view_with_code_blocks
|
22
|
+
# end
|
6
23
|
class Template < Tilt::Template
|
7
|
-
def prepare
|
24
|
+
def prepare # :nodoc:
|
8
25
|
@engine = Redcarpet::Markdown.new(Glorify::Renderer.new,
|
9
26
|
Glorify::EXTENSIONS)
|
10
27
|
@output = nil
|
11
28
|
end
|
12
29
|
|
13
|
-
def evaluate(scope, locals, &block)
|
30
|
+
def evaluate(scope, locals, &block) # :nodoc:
|
14
31
|
@output ||= @engine.render(data)
|
15
32
|
end
|
16
33
|
end
|
data/lib/glorify/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glorify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,17 +50,17 @@ dependencies:
|
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ! '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0
|
55
|
+
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
59
|
none: false
|
60
60
|
requirements:
|
61
|
-
- -
|
61
|
+
- - ! '>='
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 0
|
63
|
+
version: '0'
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: nokogiri
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,6 +141,22 @@ dependencies:
|
|
141
141
|
- - ! '>='
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
|
+
- !ruby/object:Gem::Dependency
|
145
|
+
name: rdoc
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - '='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 4.0.0.preview2
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - '='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 4.0.0.preview2
|
144
160
|
description: Renders markdown via redcarpet with syntax highlighting thanks to pygments.rb.
|
145
161
|
Able to use fenced code blocks like github, and includes a default pygments stylesheet.
|
146
162
|
email:
|
@@ -158,6 +174,7 @@ files:
|
|
158
174
|
- lib/glorify.rb
|
159
175
|
- lib/glorify/css.rb
|
160
176
|
- lib/glorify/extensions.rb
|
177
|
+
- lib/glorify/helpers.rb
|
161
178
|
- lib/glorify/renderer.rb
|
162
179
|
- lib/glorify/template.rb
|
163
180
|
- lib/glorify/version.rb
|
@@ -168,7 +185,7 @@ files:
|
|
168
185
|
- spec/glorify/with_helper.erb
|
169
186
|
- spec/glorify_spec.rb
|
170
187
|
- spec/spec_helper.rb
|
171
|
-
homepage: http://
|
188
|
+
homepage: http://zacharyscott.net/glorify/
|
172
189
|
licenses: []
|
173
190
|
post_install_message:
|
174
191
|
rdoc_options: []
|
@@ -180,12 +197,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
180
197
|
- - ! '>='
|
181
198
|
- !ruby/object:Gem::Version
|
182
199
|
version: '0'
|
200
|
+
segments:
|
201
|
+
- 0
|
202
|
+
hash: -3421297559445645487
|
183
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
204
|
none: false
|
185
205
|
requirements:
|
186
206
|
- - ! '>='
|
187
207
|
- !ruby/object:Gem::Version
|
188
208
|
version: '0'
|
209
|
+
segments:
|
210
|
+
- 0
|
211
|
+
hash: -3421297559445645487
|
189
212
|
requirements: []
|
190
213
|
rubyforge_project:
|
191
214
|
rubygems_version: 1.8.24
|