nwiki 0.1.11 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e8a735142fc4d1d0648d7834d8a107b10d88e7b
4
- data.tar.gz: ea67db9c169ca414a63656479339589773d1f2f5
3
+ metadata.gz: 8abca602ff4dbae3746a79c53e9252284839cb52
4
+ data.tar.gz: 2bd3cc5dfeca31cd1009ccf050139ffeff9fb5ea
5
5
  SHA512:
6
- metadata.gz: f41486de0cab432bd602907f7f4eae119c63740c8b7f1b62a60b8e368d56e369994a61e93cbd6f424156fda4e65b61b2d27758f322ae7955b3e8cfd42ca0ebae
7
- data.tar.gz: 8840e56a45880585b5c9c7f2b5955db19059ba660ef5e9747405be4ad447aaf75594d83b815cde2f125ecfaf810caa7bed4070c453e1433e6a99064f80074554
6
+ metadata.gz: 7b9c8e0a9532deff6ee79c4f8513aa753c422d86de7bd4b9a837b0200f90feedf3aa964a14f408435b58fa643501c9a2312fe873a9f4f987d4d454105d050752
7
+ data.tar.gz: a8e93f0e0e12a33985af7f0e8c267f8948659f0bf3c5896abb5cb0315b38538ddfa9dc51f3af5cc9352c823088c9b839f41820534b6201317ab7c81938fe5d02
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.2
data/CHANGELOG.org CHANGED
@@ -1,4 +1,6 @@
1
1
  * CHANGELOG
2
+ ** 0.2.0
3
+ - [improvement] Use rack module (i.e. rack-rewrite, rack-git)
2
4
  ** 0.1.11
3
5
  - [fix] Do not print '-' if page title is empty.
4
6
  ** 0.1.10
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rugged', git: 'git://github.com/libgit2/rugged.git', branch: 'development', submodules: true
7
+ gem 'rack-git', git: 'git@github.com:niku/rack-git.git'
7
8
  gem 'coveralls', require: false
@@ -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
- run Html.new git_repo_path
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
@@ -1,3 +1,3 @@
1
1
  module Nwiki
2
- VERSION = '0.1.11'
2
+ VERSION = '0.2.0'
3
3
  end
data/nwiki.gemspec CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Nwiki::VERSION
17
17
 
18
18
  gem.add_dependency('rack')
19
+ gem.add_dependency('rack-rewrite')
20
+ gem.add_dependency('rack-git')
19
21
  gem.add_dependency('org-ruby')
20
22
 
21
23
  gem.add_development_dependency('rake')
@@ -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 have(5).items }
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.should eq Orgmode::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/').should eq 'foo/bar/' }
16
- it { described_class.canonicalize_path('/%E6%97%A5%E6%9C%AC%E8%AA%9E').should eq '日本語' }
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').should eq Page.new("Foo", "* Foo\n** Bar\n[[icon.png]]\n", Wiki.parser) }
21
- it { subject.find('/icon.png').should be_kind_of File }
22
- it { subject.find('/').should be_kind_of Directory }
23
- it { subject.find('/not_exist_page').should be_nil }
24
- it { subject.find('/1/2/a').should_not be_nil }
25
- it { subject.find('/日本語ディレクトリ/わたしだ').should_not be_nil }
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.should eq \
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.should eq 'ヽ(´・肉・`)ノログ' }
35
+ it { expect(subject.title).to eq 'ヽ(´・肉・`)ノログ' }
36
36
  end
37
37
 
38
38
  describe '#subtitle' do
39
- it { subject.subtitle.should eq 'How do we fighting without fighting?' }
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.should eq 'niku' }
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.should be_ok }
21
- it { subject.should match %r!\bヽ(´・肉・`)ノログ\b! }
22
- it { subject.should match %r!\bHow do we fighting without fighting?\b! }
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.should be_ok }
29
- it { subject.should match %r!\bfoo\b! }
30
- it { subject.should match %r!\b1\b! }
31
- it { subject.should match %r!\b日本語ディレクトリ\b! }
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.should be_ok }
38
- it { subject['Content-Type'].should eq 'application/atom+xml; charset=UTF-8' }
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 { should_not be_nil }
44
- it { subject.link.href.should eq 'http://example.org/articles.xml' }
45
- it { subject.title.content.should eq 'ヽ(´・肉・`)ノログ' }
46
- it { subject.subtitle.content.should eq 'How do we fighting without fighting?' }
47
- it { subject.author.name.content.should eq 'niku' }
48
- it { subject.date.should eq Time.parse('2012-08-09 20:15:07 +0900') }
49
- it { subject.id.content.should eq 'http://example.org/articles.xml' }
50
- it { subject.items.first.link.href.should eq 'http://example.org/articles/foo' }
51
- it { subject.items.first.title.content.should eq 'foo' }
52
- it { subject.items.first.date.should eq Time.parse('2012-08-09 20:15:07 +0900') }
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.should be_ok }
62
- it { subject.should match %r!<title[^>]*>foo - ヽ(´・肉・`)ノログ</title>!}
63
- it { subject.should match %r!<h2[^>]*>Foo</h2>! }
64
- it { subject.should match %r!<h3[^>]*>Bar</h3>! }
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.should be_ok }
70
- it { subject['Content-Type'].should eq 'image/png' }
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.should be_ok }
78
- it { subject.should match %r!\ba\b! }
79
- it { subject.should match %r!\bb\b! }
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.should be_ok }
88
- it { subject.should match %r!<h2[^>]*>わたしだ</h2>! }
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.should be_ok }
96
- it { subject.body.should match %r!<title[^>]*>日本語ディレクトリ/わたしだ - ヽ(´・肉・`)ノログ</title>!}
97
- it { subject.body.should match %r!<h2[^>]*>お前だったのか</h2>! }
98
- it { subject.body.should match %r!<h3[^>]*>気づかなかったな</h3>! }
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
@@ -3,7 +3,6 @@ require 'rack/test'
3
3
  require 'coveralls'
4
4
 
5
5
  RSpec.configure do |config|
6
- config.treat_symbols_as_metadata_keys_with_true_values = true
7
6
  config.run_all_when_everything_filtered = true
8
7
  config.filter_run :focus
9
8
  config.include Rack::Test::Methods
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.1.11
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-05-09 00:00:00.000000000 Z
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