nwiki 0.0.3 → 0.0.4

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/CHANGELOG.org CHANGED
@@ -1,4 +1,6 @@
1
1
  * CHANGELOG
2
+ ** 0.0.4
3
+ - [feature] view list at root directory
2
4
  ** 0.0.3
3
5
  - Nothing to change
4
6
  ** 0.0.2
@@ -0,0 +1,34 @@
1
+ module Nwiki
2
+ module Core
3
+ class Directory
4
+ class << self
5
+ attr_accessor :encoding
6
+ end
7
+
8
+ attr_reader :list
9
+
10
+ def initialize path, list
11
+ @path = path
12
+ @list = list.
13
+ reject { |e| e =~ /^__nwiki/ }.
14
+ map { |e| e.sub(/\.org$/){ '' } }
15
+ end
16
+
17
+ def title
18
+ @path
19
+ end
20
+
21
+ def encoding
22
+ self.class.encoding
23
+ end
24
+
25
+ def to_html
26
+ '<ul>' + @list.map { |e|
27
+ root = './'
28
+ root << @path if @path != '/'
29
+ %Q!<li><a href="#{root}#{e}">#{e}</a></li>!
30
+ }.join + '</ul>'
31
+ end
32
+ end
33
+ end
34
+ end
@@ -22,9 +22,17 @@ module Nwiki
22
22
 
23
23
  def find path
24
24
  canonicalized_path = self.class.canonicalize_path path
25
+ if canonicalized_path == ''
26
+ find_directory(canonicalized_path)
27
+ else
28
+ find_page_or_file(canonicalized_path)
29
+ end
30
+ end
31
+
32
+ def find_page_or_file path
25
33
  blob_entry = @access
26
34
  .tree('master')
27
- .find { |e| canonicalized_path == e.path.sub(/\.org$/){ '' } }
35
+ .find { |e| path == e.path.sub(/\.org$/){ '' } }
28
36
  return nil unless blob_entry
29
37
  byte_string = blob_entry.blob(@access.repo).data
30
38
  if blob_entry.name =~ /\.org$/
@@ -35,6 +43,12 @@ module Nwiki
35
43
  end
36
44
  end
37
45
 
46
+ def find_directory path
47
+ sha = @access.tree('master')
48
+ Directory.encoding = self.class.repo_filename_encoding
49
+ Directory.new(path, sha.map(&:path))
50
+ end
51
+
38
52
  def name
39
53
  blob_entry = @access
40
54
  .tree('master')
data/lib/nwiki/core.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'nwiki/core/git_access'
2
+ require 'nwiki/core/directory'
2
3
  require 'nwiki/core/file'
3
4
  require 'nwiki/core/page'
4
5
  require 'nwiki/core/wiki'
@@ -12,7 +12,7 @@ module Nwiki
12
12
  path_info = env["PATH_INFO"]
13
13
  page = @wiki.find path_info
14
14
  case page
15
- when Core::Page
15
+ when Core::Page, Core::Directory
16
16
  [200, {"Content-Type" => "text/html; charset=#{page.encoding}"}, [html(page)]]
17
17
  when Core::File
18
18
  [200, {"Content-Type" => page.content_type}, [page.data]]
data/lib/nwiki/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nwiki
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -15,11 +15,18 @@ module Nwiki
15
15
  describe '#find' do
16
16
  it { subject.find('/foo').should eq Page.new("Foo", "* Foo\n** Bar\n[[icon.png]]\n", Wiki.parser) }
17
17
  it { subject.find('/icon.png').should be_kind_of File }
18
+ it { subject.find('/').should be_kind_of Directory }
18
19
  it { subject.find('/not_exist_page').should be_nil }
19
20
  it { subject.find('/1/2/a').should_not be_nil }
20
21
  it { subject.find('/日本語ディレクトリ/わたしだ').should_not be_nil }
21
22
  end
22
23
 
24
+ describe '#find_directory' do
25
+ it { subject.find_directory('/').list.should eq \
26
+ Directory.new('/', ["1/2/a", "1/2/b", "foo", "icon.png", "日本語ディレクトリ/わたしだ"]).list
27
+ }
28
+ end
29
+
23
30
  describe '#name' do
24
31
  it { subject.name.should eq 'ヽ(´・肉・`)ノログ' }
25
32
  end
@@ -17,22 +17,18 @@ module Nwiki
17
17
  describe 'GET /' do
18
18
  let(:path) { '/' }
19
19
 
20
- pending do 'not implement yet'
21
- it { subject.should be_ok }
22
- it { subject.should match %r!\bfoo\b! }
23
- it { subject.should match %r!\b1\b! }
24
- it { subject.should match %r!\b日本語ディレクトリ\b! }
25
- end
20
+ it { subject.should be_ok }
21
+ it { subject.should match %r!\bfoo\b! }
22
+ it { subject.should match %r!\b1\b! }
23
+ it { subject.should match %r!\b日本語ディレクトリ\b! }
26
24
  end
27
25
 
28
26
  describe 'GET /foo' do
29
27
  let(:path) { '/foo' }
30
28
 
31
- pending do 'not implement yet'
32
- it { subject.should be_ok }
33
- it { subject.should match %r!<h2[^>]*>Foo</h2>! }
34
- it { subject.should match %r!<h3[^>]*>Bar</h3>! }
35
- end
29
+ it { subject.should be_ok }
30
+ it { subject.should match %r!<h2[^>]*>Foo</h2>! }
31
+ it { subject.should match %r!<h3[^>]*>Bar</h3>! }
36
32
  end
37
33
 
38
34
  describe 'GET /icon.png' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nwiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-09 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gollum
@@ -207,6 +207,7 @@ files:
207
207
  - config.ru
208
208
  - lib/nwiki.rb
209
209
  - lib/nwiki/core.rb
210
+ - lib/nwiki/core/directory.rb
210
211
  - lib/nwiki/core/file.rb
211
212
  - lib/nwiki/core/git_access.rb
212
213
  - lib/nwiki/core/page.rb
@@ -271,12 +272,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
271
272
  - - ! '>='
272
273
  - !ruby/object:Gem::Version
273
274
  version: '0'
275
+ segments:
276
+ - 0
277
+ hash: 3374850286995081300
274
278
  required_rubygems_version: !ruby/object:Gem::Requirement
275
279
  none: false
276
280
  requirements:
277
281
  - - ! '>='
278
282
  - !ruby/object:Gem::Version
279
283
  version: '0'
284
+ segments:
285
+ - 0
286
+ hash: 3374850286995081300
280
287
  requirements: []
281
288
  rubyforge_project:
282
289
  rubygems_version: 1.8.23