rack-rdiscount 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README +35 -0
- data/README.markdown +35 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/rack/rdiscount.rb +45 -0
- data/test/config.ru +14 -0
- data/test/test.mdwn +9 -0
- metadata +71 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Savonix Corporation
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Summary
|
2
|
+
-------
|
3
|
+
|
4
|
+
Rack Middleware using RDiscount to transform and filter markdown content.
|
5
|
+
|
6
|
+
|
7
|
+
Status
|
8
|
+
------
|
9
|
+
|
10
|
+
This isn't done yet, but it functions.
|
11
|
+
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
<pre class="sh_ruby">
|
17
|
+
use Rack::RackDiscount, :extension => 'mdwn'
|
18
|
+
</pre>
|
19
|
+
|
20
|
+
Note: extension option does nothing at the moment.
|
21
|
+
|
22
|
+
Legal
|
23
|
+
-----
|
24
|
+
|
25
|
+
Author: Albert Lash
|
26
|
+
Copyright: 2009, Savonix Corporation
|
27
|
+
License: MIT, BSD, GPL2, or GPL3
|
28
|
+
|
29
|
+
Thanks
|
30
|
+
------
|
31
|
+
|
32
|
+
* [Ryan Tomayko](http://tomayko.com/) for RDiscount
|
33
|
+
* [David Parsons](http://www.pell.portland.or.us/~orc/) for Discount
|
34
|
+
* [John Gruber](http://daringfireball.net/) for Markdown
|
35
|
+
* <http://Github.com> for bridging mad gaps.
|
data/README.markdown
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Summary
|
2
|
+
-------
|
3
|
+
|
4
|
+
Rack Middleware using RDiscount to transform and filter markdown content.
|
5
|
+
|
6
|
+
|
7
|
+
Status
|
8
|
+
------
|
9
|
+
|
10
|
+
This isn't done yet, but it functions.
|
11
|
+
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
<pre class="sh_ruby">
|
17
|
+
use Rack::RackDiscount, :extension => 'mdwn'
|
18
|
+
</pre>
|
19
|
+
|
20
|
+
Note: extension option does nothing at the moment.
|
21
|
+
|
22
|
+
Legal
|
23
|
+
-----
|
24
|
+
|
25
|
+
Author: Albert Lash
|
26
|
+
Copyright: 2009, Savonix Corporation
|
27
|
+
License: MIT, BSD, GPL2, or GPL3
|
28
|
+
|
29
|
+
Thanks
|
30
|
+
------
|
31
|
+
|
32
|
+
* [Ryan Tomayko](http://tomayko.com/) for RDiscount
|
33
|
+
* [David Parsons](http://www.pell.portland.or.us/~orc/) for Discount
|
34
|
+
* [John Gruber](http://daringfireball.net/) for Markdown
|
35
|
+
* <http://Github.com> for bridging mad gaps.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rack-rdiscount"
|
8
|
+
gem.summary = %{Markdown rack middleware.}
|
9
|
+
gem.description = %Q{A rack middleware for converting markdown to html.}
|
10
|
+
gem.email = 'albert.lash@docunext.com'
|
11
|
+
gem.homepage = 'http://www.docunext.com/'
|
12
|
+
gem.authors = ['Albert Lash']
|
13
|
+
gem.rubyforge_project = ''
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
17
|
+
rubyforge.doc_task = 'rdoc'
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts 'Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler'
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |test|
|
26
|
+
test.libs << 'lib' << 'test'
|
27
|
+
test.pattern = 'test/**/*_test.rb'
|
28
|
+
test.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rcov/rcovtask'
|
33
|
+
Rcov::RcovTask.new do |test|
|
34
|
+
test.libs << 'test'
|
35
|
+
test.pattern = 'test/**/*_test.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION')
|
47
|
+
version = File.read('VERSION')
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "rack-rewrite #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright: Savonix Corporation, 2009
|
2
|
+
# Author: Albert Lash
|
3
|
+
# License: MIT
|
4
|
+
require "rdiscount"
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
class RackDiscount
|
8
|
+
def initialize(app, options)
|
9
|
+
@my_path_info = String.new
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
status, headers, body = @app.call(env)
|
15
|
+
original_response = Array[status, headers, body]
|
16
|
+
excluded_status = Array[204, 301, 302, 304]
|
17
|
+
return original_response if excluded_status.include?(status) || body.nil?
|
18
|
+
|
19
|
+
return original_response unless headers["Content-Type"].to_s == 'text/plain'
|
20
|
+
mdwn = getResponse(body)
|
21
|
+
|
22
|
+
newbody = '<div id="page-content">' + RDiscount.new(mdwn).to_html + '</div>'
|
23
|
+
# If we've made it this far, we can alter the headers
|
24
|
+
headers.delete('Content-Length')
|
25
|
+
headers['Content-Length'] = newbody.length.to_s
|
26
|
+
headers.delete('Content-Type')
|
27
|
+
headers['Content-Type'] = 'text/html'
|
28
|
+
|
29
|
+
[status, headers, newbody]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def getResponse(body)
|
34
|
+
newbody = []
|
35
|
+
body.each { |part|
|
36
|
+
newbody << part.to_s
|
37
|
+
}
|
38
|
+
return newbody.join('')
|
39
|
+
end
|
40
|
+
def wrap(tag='div')
|
41
|
+
#
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/test/config.ru
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require '../lib/rack-rdiscount'
|
3
|
+
#require '../lib/rack-nolength'
|
4
|
+
#require '../lib/rack-finalcontentlength'
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
#use Rack::FinalContentLength
|
9
|
+
#use Rack::NoLength
|
10
|
+
use Rack::RackDiscount, :extension => 'mdwn'
|
11
|
+
use Rack::Static, :urls => ["/test.html","/test2.html"]
|
12
|
+
|
13
|
+
app = lambda { |env| [200, { 'Content-Type' => 'text/html' }, '**Hello World**'] }
|
14
|
+
run app
|
data/test/test.mdwn
ADDED
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-rdiscount
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Albert Lash
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-01 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A rack middleware for converting markdown to html.
|
22
|
+
email: albert.lash@docunext.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README
|
30
|
+
- README.markdown
|
31
|
+
files:
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
- README.markdown
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- lib/rack/rdiscount.rb
|
38
|
+
- test/config.ru
|
39
|
+
- test/test.mdwn
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://www.docunext.com/
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: ""
|
66
|
+
rubygems_version: 1.3.6
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Markdown rack middleware.
|
70
|
+
test_files: []
|
71
|
+
|