glorify 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,8 +2,11 @@
2
2
 
3
3
  Sinatra helper to parse markdown with syntax highlighting like the pros
4
4
 
5
- Renders via redcarpet with syntax highlighting thanks to [pygments.rb](https://github.com/tmm1/pygments.rb). Able to use
6
- fenced code blocks like github, and includes a default pygments stylesheet.
5
+ Renders markdown via redcarpet with syntax highlighting thanks to
6
+ [pygments.rb](https://github.com/tmm1/pygments.rb).
7
+
8
+ Able to use fenced code blocks like github, and includes a default pygments
9
+ stylesheet.
7
10
 
8
11
  ## install
9
12
 
@@ -19,28 +22,36 @@ gem 'sinatra'
19
22
  gem 'glorify'
20
23
  ```
21
24
 
22
- ## usage
25
+ ## using `Glorify::Template`
26
+
27
+ glorify comes with a tilt template for rendering markdown.
28
+
29
+ this allows you to override the default markdown renderer and use redcarpet2
30
+ with pygments.rb to highlight any code blocks within your view.
23
31
 
24
- given the following `markdown` example
32
+ in order to do this, you will need to prefer the template class.
25
33
 
26
- # a sip of glory
34
+ ```ruby
35
+ Tilt.prefer Sinatra::Glorify::Template
36
+ ```
27
37
 
28
- providing a sinatra helper, glorify lets you parse markdown with ease.
38
+ then any views that render `markdown` will use Glorify::Template instead.
29
39
 
30
- you can even parse code blocks, in any language you'd like. just like you can
31
- with github flavored markdown. because glorify uses much of the same technology
32
- as github, you can highlight code from nearly any language, without any extra
33
- dependencies.
40
+ ```ruby
41
+ register Sinatra::Glorify
42
+ get '/' do
43
+ markdown :a_view_with_code_blocks
44
+ end
45
+ ```
34
46
 
35
- the snippet below will render a bit of some ruby with syntax highlighting.
47
+ ## using the helper
36
48
 
37
- ```ruby
38
- ['toast', 'cheese', 'wine'].each { |food| print food.capitalize }
39
- ```
49
+ if you want to stick with your current renderer and just render some code
50
+ blocks within your view, use the `glorify` helper method.
40
51
 
41
52
  ### classical app
42
53
 
43
- simply `require 'glorify'` to use with a classic style sinatra app.
54
+ simply `require 'glorify'` to use the helper with a classic style sinatra app.
44
55
 
45
56
  ```ruby
46
57
  require 'sinatra'
@@ -85,6 +96,9 @@ this is just a simple `erb` template, but you get the idea.
85
96
  </html>
86
97
  ```
87
98
 
99
+ the default pygments stylesheet that comes with glorify is available at the
100
+ `/pygments.css` route
101
+
88
102
  ### on heroku
89
103
 
90
104
  to make this work on heroku you'll have to use python2.6
@@ -0,0 +1,21 @@
1
+ $: << File.expand_path(".") + '/lib'
2
+ require 'sinatra'
3
+ require 'glorify'
4
+ require 'erb'
5
+
6
+ set :markdown, :layout_engine => :erb
7
+ set :views, File.dirname(__FILE__)
8
+ Tilt.prefer Sinatra::Glorify::Template
9
+
10
+ get "/" do
11
+ markdown :README
12
+ end
13
+
14
+ __END__
15
+ @@layout
16
+ <html>
17
+ <head>
18
+ <link href="/pygments.css" media="screen" rel="stylesheet" type="text/css">
19
+ </head>
20
+ <body><%= yield %></body>
21
+ </html>
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
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}
12
- s.description = %q{Renders via redcarpet with syntax highlighting thanks to pygments.rb. Able to use fenced code blocks like github, and includes a default pygments stylesheet.}
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
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.require_paths = ["lib"]
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "minitest"
23
23
  s.add_development_dependency "rack-test"
24
24
  s.add_development_dependency "rake"
25
+ s.add_development_dependency "w3c_validators"
25
26
  end
@@ -1,29 +1,30 @@
1
1
  require "sinatra/base"
2
2
  require "glorify/css"
3
+ require "glorify/extensions"
3
4
  require "glorify/version"
4
5
  require "glorify/renderer"
6
+ require "glorify/template"
5
7
 
6
8
  module Sinatra
7
9
  module Glorify
8
10
  module Helpers
9
11
  def glorify text
10
- rndr = Glorify::Renderer.new
11
- Redcarpet::Markdown.new(rndr, settings.glorify_extensions).render(text)
12
+ Redcarpet::Markdown.new(Glorify::Renderer.new,
13
+ Glorify::EXTENSIONS).render(text)
12
14
  end
13
15
  end
14
16
 
15
17
  def self.registered(app)
16
- app.set :glorify_extensions, { :filter_html => true,
17
- :autolink => true,
18
- :no_intra_emphasis => true,
19
- :fenced_code_blocks => true
20
- }
18
+ app.set :glorify_extensions, Glorify::EXTENSIONS
21
19
  app.helpers Glorify::Helpers
20
+
22
21
  app.get '/pygments.css' do
22
+ content_type 'text/css'
23
23
  glorify_css
24
24
  end
25
25
  end
26
26
  end
27
27
 
28
+ Tilt.register Glorify::Template, 'markdown', 'mkd', 'md'
28
29
  register Glorify
29
30
  end
@@ -0,0 +1,9 @@
1
+ module Sinatra
2
+ module Glorify
3
+ EXTENSIONS = { :filter_html => true,
4
+ :autolink => true,
5
+ :no_intra_emphasis => true,
6
+ :fenced_code_blocks => true
7
+ }
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require 'redcarpet' unless defined? Redcarpet
2
+ require 'tilt/template'
3
+
4
+ module Sinatra
5
+ module Glorify
6
+ class Template < Tilt::Template
7
+ def prepare
8
+ @engine = Redcarpet::Markdown.new(Glorify::Renderer.new,
9
+ Glorify::EXTENSIONS)
10
+ @output = nil
11
+ end
12
+
13
+ def evaluate(scope, locals, &block)
14
+ @output ||= @engine.render(data)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Glorify
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ ```puts "Hello, world!"```
@@ -0,0 +1 @@
1
+ # a sip of glory
@@ -0,0 +1,5 @@
1
+ ```ruby
2
+ def in_ruby?
3
+ return apples.all? { |a| a.to_s == 'ruby' }
4
+ end
5
+ ```
@@ -8,7 +8,8 @@ describe Sinatra::Glorify do
8
8
 
9
9
  it "should parse a header" do
10
10
  mock_app do
11
- get('/') { erb :header }
11
+ Tilt.prefer Sinatra::Glorify::Template
12
+ get('/') { markdown :header }
12
13
  end
13
14
  expected = "<h1>a sip of glory</h1>"
14
15
  get('/')
@@ -18,7 +19,8 @@ describe Sinatra::Glorify do
18
19
 
19
20
  it "should parse code blocks" do
20
21
  mock_app do
21
- get('/') { erb :blocks }
22
+ Tilt.prefer Sinatra::Glorify::Template
23
+ get('/') { markdown :blocks }
22
24
  end
23
25
  expected = "<p><code>puts &quot;Hello, world!&quot;</code></p>"
24
26
  get('/')
@@ -27,17 +29,38 @@ describe Sinatra::Glorify do
27
29
  end
28
30
 
29
31
  it "should parse ruby blocks" do
32
+ mock_app do
33
+ get('/') do
34
+ Tilt.prefer Sinatra::Glorify::Template
35
+ markdown :ruby_blocks
36
+ end
37
+ end
38
+ get('/')
39
+ assert ok?
40
+ refute_empty Nokogiri::HTML(body).search("//div[@class = 'highlight']/pre")
41
+ end
42
+
43
+ it "should parse with a helper" do
30
44
  mock_app do
31
45
  get('/') do
32
46
  @some_code = File.open(
33
47
  File.expand_path('../glorify/some_code.md', __FILE__),
34
48
  "rb"
35
49
  ).read
36
- erb :ruby_blocks
50
+ erb :with_helper
37
51
  end
38
52
  end
39
53
  get('/')
40
54
  assert ok?
41
55
  refute_empty Nokogiri::HTML(body).search("//div[@class = 'highlight']/pre")
42
56
  end
57
+
58
+ it "should include a valid css helper for pygments" do
59
+ mock_app
60
+ get('/pygments.css')
61
+ assert ok?
62
+
63
+ assert_match /text\/css/, content_type
64
+ assert_empty validate_css(body).errors
65
+ end
43
66
  end
@@ -8,6 +8,7 @@ require 'nokogiri'
8
8
  require 'rack/test'
9
9
  require 'sinatra/base'
10
10
  require 'erb'
11
+ require 'w3c_validators'
11
12
 
12
13
  Sinatra::Base.set :environment, :test
13
14
  Sinatra::Base.set :views, File.expand_path('../glorify', __FILE__)
@@ -15,6 +16,7 @@ Sinatra::Base.register Sinatra::Glorify
15
16
 
16
17
  class MiniTest::Spec
17
18
  include Rack::Test::Methods
19
+ include W3CValidators
18
20
 
19
21
  def mock_app(base=Sinatra::Base, &block)
20
22
  @app = Sinatra.new(base, &block)
@@ -31,4 +33,12 @@ class MiniTest::Spec
31
33
  def ok?
32
34
  last_response.ok?
33
35
  end
36
+
37
+ def content_type
38
+ last_response.headers['Content-Type']
39
+ end
40
+
41
+ def validate_css(css)
42
+ CSSValidator.new.validate_text css
43
+ end
34
44
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glorify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Zachary Scott
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-05-22 00:00:00 Z
20
+ date: 2012-06-15 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: sinatra
@@ -118,7 +118,21 @@ dependencies:
118
118
  version: "0"
119
119
  type: :development
120
120
  version_requirements: *id007
121
- description: Renders via redcarpet with syntax highlighting thanks to pygments.rb. Able to use fenced code blocks like github, and includes a default pygments stylesheet.
121
+ - !ruby/object:Gem::Dependency
122
+ name: w3c_validators
123
+ prerelease: false
124
+ requirement: &id008 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ type: :development
134
+ version_requirements: *id008
135
+ description: 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.
122
136
  email:
123
137
  - zachary@zacharyscott.net
124
138
  executables: []
@@ -132,16 +146,19 @@ files:
132
146
  - Gemfile
133
147
  - README.md
134
148
  - Rakefile
149
+ - example.rb
135
150
  - glorify.gemspec
136
151
  - lib/glorify.rb
137
152
  - lib/glorify/css.rb
153
+ - lib/glorify/extensions.rb
138
154
  - lib/glorify/renderer.rb
155
+ - lib/glorify/template.rb
139
156
  - lib/glorify/version.rb
140
- - spec/glorify/blocks.erb
141
- - spec/glorify/header.erb
142
- - spec/glorify/layout.erb
143
- - spec/glorify/ruby_blocks.erb
157
+ - spec/glorify/blocks.md
158
+ - spec/glorify/header.md
159
+ - spec/glorify/ruby_blocks.md
144
160
  - spec/glorify/some_code.md
161
+ - spec/glorify/with_helper.erb
145
162
  - spec/glorify_spec.rb
146
163
  - spec/spec_helper.rb
147
164
  homepage: http://github.com/zzak/glorify
@@ -1 +0,0 @@
1
- <%= glorify('```puts "Hello, world!"```') %>
@@ -1 +0,0 @@
1
- <%= glorify("#a sip of glory") %>
@@ -1 +0,0 @@
1
- <%= yield %>