page_viewer 0.0.1
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/LICENSE +19 -0
- data/README.md +25 -0
- data/lib/page_viewer/version.rb +3 -0
- data/lib/page_viewer.rb +72 -0
- data/lib/views/index.erb +7 -0
- data/lib/views/layout.erb +67 -0
- data/lib/views/page.erb +1 -0
- data/lib/views/pdf.erb +57 -0
- metadata +117 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 Pete Keen <pete@bugsplat.info>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Page Viewer
|
2
|
+
|
3
|
+
This is a dumb little app for dynamically rendering a directory full of markdown files on a website. It has the following additional features:
|
4
|
+
|
5
|
+
* `_index.md` will be displayed as the index document if it exists. Otherwise a simple directory listing is displayed.
|
6
|
+
* Integrates with [Docverter](http://www.docverter.com) for on-the-fly PDF conversion
|
7
|
+
* Code blocks will get syntax highlighted using Pygments
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'page_viewer', git: 'https://github.com/peterkeen/page_viewer'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Here's an example `config.ru` file:
|
18
|
+
|
19
|
+
```
|
20
|
+
require 'page_viewer'
|
21
|
+
|
22
|
+
PageViewer::App.set :page_root, '/path/to/markdown_files'
|
23
|
+
|
24
|
+
run PageViewer::App
|
25
|
+
```
|
data/lib/page_viewer.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'redcarpet'
|
3
|
+
require 'pygments'
|
4
|
+
require 'docverter'
|
5
|
+
|
6
|
+
module PageViewer
|
7
|
+
|
8
|
+
class HTMLwithPygments < Redcarpet::Render::HTML
|
9
|
+
def block_code(code, language)
|
10
|
+
Pygments.highlight(code, :lexer => language)
|
11
|
+
end
|
12
|
+
|
13
|
+
def postprocess(document)
|
14
|
+
document.gsub(''', "'")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class App < Sinatra::Base
|
19
|
+
|
20
|
+
RENDERER = Redcarpet::Markdown.new(
|
21
|
+
HTMLwithPygments.new(:with_toc_data => true),
|
22
|
+
:fenced_code_blocks => true,
|
23
|
+
:tables => true,
|
24
|
+
)
|
25
|
+
|
26
|
+
before do
|
27
|
+
Docverter.base_url = 'http://c.docverter.com'
|
28
|
+
end
|
29
|
+
|
30
|
+
def page_contents(page)
|
31
|
+
File.read(page_path(page))
|
32
|
+
end
|
33
|
+
|
34
|
+
def page_path(page)
|
35
|
+
File.join(settings.page_root, page + '.md')
|
36
|
+
end
|
37
|
+
|
38
|
+
get '/' do
|
39
|
+
if File.exists?(page_path('_index'))
|
40
|
+
redirect '/_index'
|
41
|
+
else
|
42
|
+
@title = "Index"
|
43
|
+
@files = Dir.glob(page_path('*')).map { |f| File.basename(f, ".md") }.sort
|
44
|
+
erb :index
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
get '/:page.md' do
|
49
|
+
content_type 'text/plain'
|
50
|
+
page_contents(params[:page])
|
51
|
+
end
|
52
|
+
|
53
|
+
get '/:page.pdf' do
|
54
|
+
@content = RENDERER.render(page_contents(params[:page]))
|
55
|
+
@title = params[:page].gsub('_', ' ')
|
56
|
+
pdf = erb :page, :layout => :pdf
|
57
|
+
content_type 'application/pdf'
|
58
|
+
Docverter::Conversion.run do |c|
|
59
|
+
c.from = 'html'
|
60
|
+
c.to = 'pdf'
|
61
|
+
c.content = pdf
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
get '/:page' do
|
66
|
+
@page_name = params[:page]
|
67
|
+
@content = RENDERER.render(page_contents(params[:page]))
|
68
|
+
@title = params[:page].gsub("_", " ")
|
69
|
+
erb :page
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/views/index.erb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title><%= @title %></title>
|
6
|
+
<!-- Le styles -->
|
7
|
+
<link href="/css/bootstrap.css" rel="stylesheet">
|
8
|
+
<style type="text/css">
|
9
|
+
body {
|
10
|
+
padding-top: 20px;
|
11
|
+
padding-bottom: 40px;
|
12
|
+
}
|
13
|
+
|
14
|
+
.container-narrow {
|
15
|
+
margin: 0 auto;
|
16
|
+
max-width: 700px;
|
17
|
+
font-size: 1.25em;
|
18
|
+
line-height: 180%;
|
19
|
+
padding-top: 30px;
|
20
|
+
}
|
21
|
+
|
22
|
+
.container-narrow h1 {
|
23
|
+
border-bottom: 1px solid #CCC;
|
24
|
+
padding-bottom: 10px;
|
25
|
+
}
|
26
|
+
|
27
|
+
.cover {
|
28
|
+
margin-bottom: 3em;
|
29
|
+
}
|
30
|
+
|
31
|
+
.cover .title {
|
32
|
+
font-family: 'Droid Sans', helvetica, arial, sans-serif;
|
33
|
+
border-bottom: 1px solid #CCC;
|
34
|
+
padding-bottom: 10px;
|
35
|
+
font-size: 2em;
|
36
|
+
}
|
37
|
+
|
38
|
+
.cover .subtitle {
|
39
|
+
font-family: 'Droid Sans', helvetica, arial, sans-serif;
|
40
|
+
font-size: 1.5em;
|
41
|
+
}
|
42
|
+
|
43
|
+
.cover .author {
|
44
|
+
font-family: 'Droid Sans', helvetica, arial, sans-serif;
|
45
|
+
font-size: 1.5em;
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
<style type="text/css">
|
49
|
+
<%= Pygments.css %>
|
50
|
+
</style>
|
51
|
+
</head>
|
52
|
+
|
53
|
+
<body>
|
54
|
+
|
55
|
+
<div class="container-narrow">
|
56
|
+
<div class="masthead">
|
57
|
+
<ul class="nav nav-pills pull-right">
|
58
|
+
<li><a href="/">Index</a></li>
|
59
|
+
<li><a href="/<%= @page_name %>.pdf">PDF</a></li>
|
60
|
+
<li><a href="/<%= @page_name %>.md">MD</a></li>
|
61
|
+
</ul>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<%= yield %>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
data/lib/views/page.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<%= @content %>
|
data/lib/views/pdf.erb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang=en>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title><%= @title %></title>
|
6
|
+
<style type="text/css">
|
7
|
+
@page {
|
8
|
+
size: 8in 8.8in;
|
9
|
+
margin: 15%;
|
10
|
+
|
11
|
+
@bottom-left {
|
12
|
+
font-size: 60%;
|
13
|
+
padding-left: 1em;
|
14
|
+
content: "<%= @title %>";
|
15
|
+
}
|
16
|
+
|
17
|
+
@bottom-right {
|
18
|
+
font-size: 60%;
|
19
|
+
content: counter(page);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
.cover {
|
24
|
+
page-break-after: always;
|
25
|
+
}
|
26
|
+
|
27
|
+
.cover .title {
|
28
|
+
font-family: helvetica, arial, sans-serif;
|
29
|
+
border-bottom: 1px solid #CCC;
|
30
|
+
padding-bottom: 0.5em;
|
31
|
+
font-size: 2em;
|
32
|
+
}
|
33
|
+
|
34
|
+
.cover .subtitle {
|
35
|
+
font-family: helvetica, arial, sans-serif;
|
36
|
+
font-size: 1.5em;
|
37
|
+
}
|
38
|
+
|
39
|
+
.cover .author {
|
40
|
+
font-family: 'Droid Sans', helvetica, arial, sans-serif;
|
41
|
+
font-size: 1.5em;
|
42
|
+
padding-top: 1em;
|
43
|
+
}
|
44
|
+
<%= Pygments.css %>
|
45
|
+
</style>
|
46
|
+
</head>
|
47
|
+
<body>
|
48
|
+
|
49
|
+
<div id="container">
|
50
|
+
<div id="content-container">
|
51
|
+
<div id="content">
|
52
|
+
<%= yield %>
|
53
|
+
</div>
|
54
|
+
</div>
|
55
|
+
</div>
|
56
|
+
</body>
|
57
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: page_viewer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pete Keen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.2
|
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: 1.4.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: docverter
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.7
|
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.0.7
|
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: 2.3.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: 2.3.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pygments.rb
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.4.2
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.4.2
|
78
|
+
description: Displays a directory full of markdown files in a web app
|
79
|
+
email:
|
80
|
+
- pete@petekeen.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- lib/page_viewer/version.rb
|
86
|
+
- lib/page_viewer.rb
|
87
|
+
- lib/views/index.erb
|
88
|
+
- lib/views/layout.erb
|
89
|
+
- lib/views/page.erb
|
90
|
+
- lib/views/pdf.erb
|
91
|
+
- LICENSE
|
92
|
+
- README.md
|
93
|
+
homepage: http://www.petekeen.com
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.23
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: A Simple Markdown Viewer
|
117
|
+
test_files: []
|