nwiki 0.1.11 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.org +2 -0
- data/Gemfile +1 -0
- data/lib/nwiki/frontend/app.rb +77 -1
- data/lib/nwiki/version.rb +1 -1
- data/nwiki.gemspec +2 -0
- data/spec/nwiki/core/git_access_spec.rb +1 -1
- data/spec/nwiki/core/wiki_spec.rb +13 -13
- data/spec/requests/articles_spec.rb +34 -34
- data/spec/spec_helper.rb +0 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8abca602ff4dbae3746a79c53e9252284839cb52
|
4
|
+
data.tar.gz: 2bd3cc5dfeca31cd1009ccf050139ffeff9fb5ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b9c8e0a9532deff6ee79c4f8513aa753c422d86de7bd4b9a837b0200f90feedf3aa964a14f408435b58fa643501c9a2312fe873a9f4f987d4d454105d050752
|
7
|
+
data.tar.gz: a8e93f0e0e12a33985af7f0e8c267f8948659f0bf3c5896abb5cb0315b38538ddfa9dc51f3af5cc9352c823088c9b839f41820534b6201317ab7c81938fe5d02
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.2
|
data/CHANGELOG.org
CHANGED
data/Gemfile
CHANGED
data/lib/nwiki/frontend/app.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require 'rack/rewrite'
|
3
|
+
require 'rack/git'
|
4
|
+
require 'org-ruby'
|
5
|
+
|
2
6
|
require_relative 'app/top'
|
3
7
|
require_relative 'app/feed'
|
4
8
|
require_relative 'app/html'
|
@@ -6,7 +10,73 @@ require_relative 'app/html'
|
|
6
10
|
module Nwiki
|
7
11
|
module Frontend
|
8
12
|
class App
|
13
|
+
def template(wiki, page_title, html)
|
14
|
+
erb = ERB.new <<EOS
|
15
|
+
<!DOCTYPE HTML>
|
16
|
+
<html>
|
17
|
+
<head>
|
18
|
+
<title><%= page_title %><%= wiki.title %></title>
|
19
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
20
|
+
<link rel="alternate" type="application/atom+xml" title="ATOM Feed" href="/articles.xml">
|
21
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
|
22
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
|
23
|
+
</head>
|
24
|
+
<body>
|
25
|
+
<a href="https://github.com/niku/nikulog">
|
26
|
+
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub">
|
27
|
+
</a>
|
28
|
+
<div class="container">
|
29
|
+
<div class="row">
|
30
|
+
<div class="col-md-12"><h1><a href="/articles/"><%= wiki.title %></a></h1></div>
|
31
|
+
</div>
|
32
|
+
<div class="row">
|
33
|
+
<div class="col-md-12"><h2"><small><%= wiki.subtitle %></small></h2></div>
|
34
|
+
</div>
|
35
|
+
<div class="row">
|
36
|
+
<div class="col-md-12">
|
37
|
+
<%= html %>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
|
42
|
+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
|
43
|
+
</body>
|
44
|
+
</html>
|
45
|
+
EOS
|
46
|
+
erb.result(binding).force_encoding("UTF-8")
|
47
|
+
end
|
48
|
+
|
9
49
|
def initialize git_repo_path
|
50
|
+
Rack::Mime::MIME_TYPES.merge!({ ".org" => "text/html" })
|
51
|
+
|
52
|
+
wiki = Core::Wiki.new git_repo_path
|
53
|
+
file_converter = -> (file, env) {
|
54
|
+
path = Rack::Utils.unescape(env["PATH_INFO"])
|
55
|
+
return file if ::File.extname(path) != ".org"
|
56
|
+
file.force_encoding("UTF-8")
|
57
|
+
page_title = path.empty? ? '' : "#{path.gsub(/\.org$/, '').gsub(/^\//, '')} - "
|
58
|
+
html = if ::File.extname(path) == ".org"
|
59
|
+
Orgmode::Parser.new(file, offset: 1).to_html
|
60
|
+
else
|
61
|
+
file
|
62
|
+
end
|
63
|
+
template(wiki, page_title, html)
|
64
|
+
}
|
65
|
+
directory_converter = -> (dirs, env) {
|
66
|
+
path = Rack::Utils.unescape(env["PATH_INFO"])
|
67
|
+
if path == '/'
|
68
|
+
page_title = path.empty? ? '' : "#{path.gsub(/\.org$/, '').gsub(/^\//, '')} - "
|
69
|
+
html = wiki.find_directory("/").to_html
|
70
|
+
template(wiki, page_title, html)
|
71
|
+
else
|
72
|
+
dirs.each { |d| d.force_encoding("UTF-8") }
|
73
|
+
page_title = path.empty? ? '' : "#{path.gsub(/\.org$/, '').gsub(/^\//, '')} - "
|
74
|
+
list = dirs.map { |e| %Q!<li><a href="#{e.gsub(/\.org/, '')}">#{e.gsub(/\.org/, '')}</a></li>! }
|
75
|
+
html = "<ul><li><a href=\"../\">../</a></li>#{list.join}</ul>"
|
76
|
+
template(wiki, page_title, html)
|
77
|
+
end
|
78
|
+
}
|
79
|
+
|
10
80
|
@builder = Rack::Builder.new {
|
11
81
|
map '/' do
|
12
82
|
run Top.new git_repo_path
|
@@ -15,7 +85,13 @@ module Nwiki
|
|
15
85
|
run Feed.new git_repo_path, articles_path: '/articles'
|
16
86
|
end
|
17
87
|
map '/articles' do
|
18
|
-
|
88
|
+
use Rack::Rewrite do
|
89
|
+
rewrite %r{^(.*)$}, '$1.org', if: -> (env) {
|
90
|
+
path = Rack::Utils.unescape(env["PATH_INFO"])
|
91
|
+
path !~ /\/$/ && File.extname(path) !~ /(png|jpg|gif)/
|
92
|
+
}
|
93
|
+
end
|
94
|
+
run Rack::Git::File.new git_repo_path, file_converter: file_converter, directory_converter: directory_converter
|
19
95
|
end
|
20
96
|
}
|
21
97
|
end
|
data/lib/nwiki/version.rb
CHANGED
data/nwiki.gemspec
CHANGED
@@ -27,7 +27,7 @@ module Nwiki
|
|
27
27
|
describe '#all_files' do
|
28
28
|
subject { super().all_files }
|
29
29
|
|
30
|
-
it { expect(subject).to
|
30
|
+
it { expect(subject.size).to eq 5 }
|
31
31
|
it { expect(subject.first).to be_kind_of Entry}
|
32
32
|
it { expect(subject.first.path).to eq 'foo.org'}
|
33
33
|
it { expect(subject.last.path).to eq '1/2/b.org'}
|
@@ -8,39 +8,39 @@ module Nwiki
|
|
8
8
|
subject { described_class.new(path) }
|
9
9
|
|
10
10
|
describe '.parser' do
|
11
|
-
it { described_class.parser.
|
11
|
+
it { expect(described_class.parser).to eq Orgmode::Parser }
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '.canonicalize_path' do
|
15
|
-
it { described_class.canonicalize_path('/foo/bar/').
|
16
|
-
it { described_class.canonicalize_path('/%E6%97%A5%E6%9C%AC%E8%AA%9E').
|
15
|
+
it { expect(described_class.canonicalize_path('/foo/bar/')).to eq 'foo/bar/' }
|
16
|
+
it { expect(described_class.canonicalize_path('/%E6%97%A5%E6%9C%AC%E8%AA%9E')).to eq '日本語' }
|
17
17
|
end
|
18
18
|
|
19
19
|
describe '#find' do
|
20
|
-
it { subject.find('/foo').
|
21
|
-
it { subject.find('/icon.png').
|
22
|
-
it { subject.find('/').
|
23
|
-
it { subject.find('/not_exist_page').
|
24
|
-
it { subject.find('/1/2/a').
|
25
|
-
it { subject.find('/日本語ディレクトリ/わたしだ').
|
20
|
+
it { expect(subject.find('/foo')).to eq Page.new("Foo", "* Foo\n** Bar\n[[icon.png]]\n", Wiki.parser) }
|
21
|
+
it { expect(subject.find('/icon.png')).to be_kind_of File }
|
22
|
+
it { expect(subject.find('/')).to be_kind_of Directory }
|
23
|
+
it { expect(subject.find('/not_exist_page')).to be_nil }
|
24
|
+
it { expect(subject.find('/1/2/a')).to_not be_nil }
|
25
|
+
it { expect(subject.find('/日本語ディレクトリ/わたしだ')).to_not be_nil }
|
26
26
|
end
|
27
27
|
|
28
28
|
describe '#find_directory' do
|
29
|
-
it { subject.find_directory('/').list.
|
29
|
+
it { expect(subject.find_directory('/').list).to eq \
|
30
30
|
["foo", "日本語ディレクトリ/わたしだ", "1/2/a", "1/2/b"]
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
34
|
describe '#title' do
|
35
|
-
it { subject.title.
|
35
|
+
it { expect(subject.title).to eq 'ヽ(´・肉・`)ノログ' }
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '#subtitle' do
|
39
|
-
it { subject.subtitle.
|
39
|
+
it { expect(subject.subtitle).to eq 'How do we fighting without fighting?' }
|
40
40
|
end
|
41
41
|
|
42
42
|
describe '#author' do
|
43
|
-
it { subject.author.
|
43
|
+
it { (expect(subject.author)).to eq 'niku' }
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -17,39 +17,39 @@ module Nwiki
|
|
17
17
|
context 'GET /' do
|
18
18
|
let(:path) { '/' }
|
19
19
|
|
20
|
-
it { subject.
|
21
|
-
it { subject.
|
22
|
-
it { subject.
|
20
|
+
it { expect(subject).to be_ok }
|
21
|
+
it { expect(subject).to match %r!\bヽ(´・肉・`)ノログ\b! }
|
22
|
+
it { expect(subject).to match %r!\bHow do we fighting without fighting?\b! }
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'GET /articles' do
|
26
26
|
let(:path) { '/articles/' }
|
27
27
|
|
28
|
-
it { subject.
|
29
|
-
it { subject.
|
30
|
-
it { subject.
|
31
|
-
it { subject.
|
28
|
+
it { expect(subject).to be_ok }
|
29
|
+
it { expect(subject).to match %r!\bfoo\b! }
|
30
|
+
it { expect(subject).to match %r!\b1\b! }
|
31
|
+
it { expect(subject).to match %r!\b日本語ディレクトリ\b! }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'GET /articles.xml' do
|
35
35
|
let(:path) { '/articles.xml' }
|
36
36
|
|
37
|
-
it { subject.
|
38
|
-
it { subject['Content-Type'].
|
37
|
+
it { expect(subject).to be_ok }
|
38
|
+
it { expect(subject['Content-Type']).to eq 'application/atom+xml; charset=UTF-8' }
|
39
39
|
|
40
40
|
describe 'response body' do
|
41
41
|
subject { RSS::Parser.parse(last_response.body) }
|
42
42
|
it { expect { subject }.to_not raise_error }
|
43
|
-
it {
|
44
|
-
it { subject.link.href.
|
45
|
-
it { subject.title.content.
|
46
|
-
it { subject.subtitle.content.
|
47
|
-
it { subject.author.name.content.
|
48
|
-
it { subject.date.
|
49
|
-
it { subject.id.content.
|
50
|
-
it { subject.items.first.link.href.
|
51
|
-
it { subject.items.first.title.content.
|
52
|
-
it { subject.items.first.date.
|
43
|
+
it { is_expected.to_not be_nil }
|
44
|
+
it { expect(subject.link.href).to eq 'http://example.org/articles.xml' }
|
45
|
+
it { expect(subject.title.content).to eq 'ヽ(´・肉・`)ノログ' }
|
46
|
+
it { expect(subject.subtitle.content).to eq 'How do we fighting without fighting?' }
|
47
|
+
it { expect(subject.author.name.content).to eq 'niku' }
|
48
|
+
it { expect(subject.date).to eq Time.parse('2012-08-09 20:15:07 +0900') }
|
49
|
+
it { expect(subject.id.content).to eq 'http://example.org/articles.xml' }
|
50
|
+
it { expect(subject.items.first.link.href).to eq 'http://example.org/articles/foo' }
|
51
|
+
it { expect(subject.items.first.title.content).to eq 'foo' }
|
52
|
+
it { expect(subject.items.first.date).to eq Time.parse('2012-08-09 20:15:07 +0900') }
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -58,25 +58,25 @@ module Nwiki
|
|
58
58
|
context 'GET /articles/foo' do
|
59
59
|
let(:path) { '/articles/foo' }
|
60
60
|
|
61
|
-
it { subject.
|
62
|
-
it { subject.
|
63
|
-
it { subject.
|
64
|
-
it { subject.
|
61
|
+
it { expect(subject).to be_ok }
|
62
|
+
it { expect(subject).to match %r!<title[^>]*>foo - ヽ(´・肉・`)ノログ</title>!}
|
63
|
+
it { expect(subject).to match %r!<h2[^>]*>Foo</h2>! }
|
64
|
+
it { expect(subject).to match %r!<h3[^>]*>Bar</h3>! }
|
65
65
|
end
|
66
66
|
|
67
67
|
context 'GET /articles/icon.png' do
|
68
68
|
let(:path) { '/articles/icon.png' }
|
69
|
-
it { subject.
|
70
|
-
it { subject['Content-Type'].
|
69
|
+
it { expect(subject).to be_ok }
|
70
|
+
it { expect(subject['Content-Type']).to eq 'image/png' }
|
71
71
|
end
|
72
72
|
|
73
73
|
context 'GET /articles/1/2/' do
|
74
74
|
let(:path) { '/articles/1/2/' }
|
75
75
|
|
76
76
|
pending do 'not implement yet'
|
77
|
-
it { subject.
|
78
|
-
it { subject.
|
79
|
-
it { subject.
|
77
|
+
it { expect(subject).to be_ok }
|
78
|
+
it { expect(subject).to match %r!\ba\b! }
|
79
|
+
it { expect(subject).to match %r!\bb\b! }
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -84,18 +84,18 @@ module Nwiki
|
|
84
84
|
let(:path) { URI.encode '/articles/日本語ディレクトリ/' }
|
85
85
|
|
86
86
|
pending do 'not implement yet'
|
87
|
-
it { subject.
|
88
|
-
it { subject.
|
87
|
+
it { expect(subject).to be_ok }
|
88
|
+
it { expect(subject).to match %r!<h2[^>]*>わたしだ</h2>! }
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
context 'GET /articles/日本語ディレクトリ/わたしだ' do
|
93
93
|
let(:path) { URI.encode '/articles/日本語ディレクトリ/わたしだ' }
|
94
94
|
|
95
|
-
it { subject.
|
96
|
-
it { subject.body.
|
97
|
-
it { subject.body.
|
98
|
-
it { subject.body.
|
95
|
+
it { expect(subject).to be_ok }
|
96
|
+
it { expect(subject.body).to match %r!<title[^>]*>日本語ディレクトリ/わたしだ - ヽ(´・肉・`)ノログ</title>!}
|
97
|
+
it { expect(subject.body).to match %r!<h2[^>]*>お前だったのか</h2>! }
|
98
|
+
it { expect(subject.body).to match %r!<h3[^>]*>気づかなかったな</h3>! }
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nwiki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- niku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-rewrite
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-git
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: org-ruby
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|