rack-markdown 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ ## Rack Markdown
2
+
3
+ Serves a markdown file.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ # config.ru
9
+ require 'rack/markdown'
10
+
11
+ run Rack::Markdown.new('path/to/file.markdown')
12
+ ```
13
+
14
+ Then run:
15
+
16
+ ```
17
+ rackup
18
+ ```
19
+
20
+ And visit [localhost:9292](http://localhost:9292).
21
+
22
+ ## Ruby 1.9+
23
+
24
+ If you're using a newer version of Ruby, you'll need to run a [thin](http://code.macournoyer.com/thin/) server instead. There is an [issue](https://github.com/tmm1/pygments.rb/issues/25) with [Pygments](https://github.com/tmm1/pygments.rb).
25
+
26
+ ## Screenshot
27
+
28
+ Yep- it looks almost identical to Github's markdown parser.
29
+
30
+ ![Rack Markdown
31
+ Screenshot](https://dl.dropbox.com/u/5490406/github/rack-markdown-screenshot.png)
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rack', 'markdown')
@@ -0,0 +1,9 @@
1
+ require 'rack'
2
+ require 'pygments.rb'
3
+ require 'redcarpet'
4
+
5
+ class Rack::Markdown; end
6
+
7
+ %w(renderer html css markdown).each do |file|
8
+ require File.join(File.dirname(__FILE__), 'markdown', file)
9
+ end
@@ -0,0 +1,50 @@
1
+ module Rack::Markdown::CSS
2
+ def internal
3
+ <<-CSS
4
+ #outer {
5
+ width: 912px;
6
+ background: #eee;
7
+ padding: 3px;
8
+ border-radius: 3px;
9
+ margin: 0 auto;
10
+ }
11
+
12
+ #inner {
13
+ width: 850px;
14
+ background: white;
15
+ padding: 30px;
16
+ border: 1px solid #cacaca;
17
+ }
18
+
19
+ #title {
20
+ background-image: -webkit-linear-gradient(top, #FAFAFA, #EAEAEA);
21
+ border: 1px solid #cacaca;
22
+ border-bottom: none;
23
+ color: #555;
24
+ font-size: 16px;
25
+ font-weight: bold;
26
+ height: 20px;
27
+ line-height: 20px;
28
+ margin: 0;
29
+ padding: 10px;
30
+ text-shadow: white 0px 1px 0px;
31
+ }
32
+
33
+ #filename {
34
+ padding-left: 16px;
35
+ }
36
+
37
+ #version {
38
+ float: right;
39
+ padding-right: 16px;
40
+ }
41
+ CSS
42
+ end
43
+
44
+ def external
45
+ hrefs = %w(3331384/github.css 3331486/syntax.css).map { |g| "https://raw.github.com/gist/#{g}" }
46
+ links = hrefs.map { |h| "<link rel='stylesheet' type='text/css' href='#{h}' />" }
47
+ links.join
48
+ end
49
+
50
+ end
@@ -0,0 +1,19 @@
1
+ module Rack::Markdown::HTML
2
+
3
+ def html
4
+ "<html><head>#{external}<style>#{internal}</style></head><body>#{body}</body></html>"
5
+ end
6
+
7
+ def body
8
+ <<-HTML
9
+ <div id='outer'>
10
+ <div id='title'>
11
+ <span id='filename'>#{path}</span>
12
+ <span id='version'><a href='https://github.com/cpatuzzo/rack-markdown'>rack-markdown (v#{self.class.version})</a></span>
13
+ </div>
14
+ <div id='inner'>#{rendered}</div>
15
+ </div>
16
+ HTML
17
+ end
18
+
19
+ end
@@ -0,0 +1,28 @@
1
+ class Rack::Markdown
2
+
3
+ attr_reader :path
4
+
5
+ def initialize(path)
6
+ @path = path
7
+ end
8
+
9
+ def call(env)
10
+ [200, { 'Content-Type' => 'text/html' }, [html]]
11
+ end
12
+
13
+ def self.version
14
+ '0.0.1'
15
+ end
16
+
17
+ private
18
+ include HTML, CSS
19
+
20
+ def rendered
21
+ Renderer.render(file_content)
22
+ end
23
+
24
+ def file_content
25
+ ::File.read(path)
26
+ end
27
+
28
+ end
@@ -0,0 +1,20 @@
1
+ class Rack::Markdown::Renderer
2
+ class PygmentsHTML < Redcarpet::Render::HTML
3
+ def block_code(code, language)
4
+ Pygments.highlight(code, :lexer => language)
5
+ end
6
+ end
7
+
8
+ def self.render(text)
9
+ renderer = PygmentsHTML.new(:hard_wrap => true, :filter_html => true)
10
+ options = {
11
+ :autolink => true,
12
+ :no_intra_emphasis => true,
13
+ :fenced_code_blocks => true,
14
+ :lax_html_blocks => true,
15
+ :stikethrough => true,
16
+ :superscript => true
17
+ }
18
+ Redcarpet::Markdown.new(renderer, options).render(text)
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Patuzzo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: pygments.rb
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: redcarpet
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Serves a markdown file
63
+ email: chris@patuzzo.co.uk
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - README.md
69
+ - lib/rack/markdown/css.rb
70
+ - lib/rack/markdown/html.rb
71
+ - lib/rack/markdown/markdown.rb
72
+ - lib/rack/markdown/renderer.rb
73
+ - lib/rack/markdown.rb
74
+ - lib/rack-markdown.rb
75
+ homepage: https://github.com/cpatuzzo/rack-source
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.23
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Rack Markdown
99
+ test_files: []