nwiki 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8abca602ff4dbae3746a79c53e9252284839cb52
4
- data.tar.gz: 2bd3cc5dfeca31cd1009ccf050139ffeff9fb5ea
3
+ metadata.gz: 609576afeda6cc82444c04db2af2e13365de24f0
4
+ data.tar.gz: d129328ecf29465291517a2a1ee0696d0d849ce1
5
5
  SHA512:
6
- metadata.gz: 7b9c8e0a9532deff6ee79c4f8513aa753c422d86de7bd4b9a837b0200f90feedf3aa964a14f408435b58fa643501c9a2312fe873a9f4f987d4d454105d050752
7
- data.tar.gz: a8e93f0e0e12a33985af7f0e8c267f8948659f0bf3c5896abb5cb0315b38538ddfa9dc51f3af5cc9352c823088c9b839f41820534b6201317ab7c81938fe5d02
6
+ metadata.gz: 9a581ca3dd2f278ead5a5c48a1872d0139d2131446e92e01fed1599c1cead0cb8ebc142d88eb2130e5642d22487266d884144e56e113edbefc46bd5adccaaa75
7
+ data.tar.gz: f24750c7c0da3439456b6e88e584f5900bc47cf5bf656416253c3a2aced34ad8fd48feac51701ef15a259aaf5ce0424b0c0f799f58d4eb55b4d2ee5d98a91ead
data/CHANGELOG.org CHANGED
@@ -1,4 +1,6 @@
1
1
  * CHANGELOG
2
+ ** 0.2.1
3
+ - Refactoring
2
4
  ** 0.2.0
3
5
  - [improvement] Use rack module (i.e. rack-rewrite, rack-git)
4
6
  ** 0.1.11
data/Gemfile.lock CHANGED
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: git://github.com/libgit2/rugged.git
3
- revision: 7c354728ba7ca560e8fead40a1de7d1508756dea
3
+ revision: 12b8de15ec588d84f89e2527ef1e935e36879ddf
4
4
  branch: development
5
5
  submodules: true
6
6
  specs:
@@ -17,7 +17,7 @@ GIT
17
17
  PATH
18
18
  remote: .
19
19
  specs:
20
- nwiki (0.2.0)
20
+ nwiki (0.2.1)
21
21
  org-ruby
22
22
  rack
23
23
  rack-git
@@ -36,7 +36,7 @@ GEM
36
36
  term-ansicolor
37
37
  thor
38
38
  diff-lcs (1.2.5)
39
- docile (1.1.3)
39
+ docile (1.1.5)
40
40
  ffi (1.9.3)
41
41
  formatador (0.2.5)
42
42
  guard (2.6.1)
@@ -45,22 +45,23 @@ GEM
45
45
  lumberjack (~> 1.0)
46
46
  pry (>= 0.9.12)
47
47
  thor (>= 0.18.1)
48
- guard-rspec (4.2.9)
48
+ guard-rspec (4.2.10)
49
49
  guard (~> 2.1)
50
50
  rspec (>= 2.14, < 4.0)
51
- listen (2.7.7)
51
+ listen (2.7.9)
52
52
  celluloid (>= 0.15.2)
53
53
  rb-fsevent (>= 0.9.3)
54
54
  rb-inotify (>= 0.9)
55
- lumberjack (1.0.6)
55
+ lumberjack (1.0.9)
56
56
  method_source (0.8.2)
57
57
  mime-types (2.3)
58
58
  multi_json (1.10.1)
59
- org-ruby (0.9.6)
60
- rubypants (>= 0.2.0)
61
- pry (0.9.12.6)
62
- coderay (~> 1.0)
63
- method_source (~> 0.8)
59
+ netrc (0.7.7)
60
+ org-ruby (0.9.7)
61
+ rubypants (~> 0.2)
62
+ pry (0.10.0)
63
+ coderay (~> 1.1.0)
64
+ method_source (~> 0.8.1)
64
65
  slop (~> 3.4)
65
66
  rack (1.5.2)
66
67
  rack-rewrite (1.5.0)
@@ -70,20 +71,21 @@ GEM
70
71
  rb-fsevent (0.9.4)
71
72
  rb-inotify (0.9.5)
72
73
  ffi (>= 0.5.0)
73
- rest-client (1.6.7)
74
- mime-types (>= 1.16)
74
+ rest-client (1.7.1)
75
+ mime-types (>= 1.16, < 3.0)
76
+ netrc (~> 0.7)
75
77
  rspec (3.0.0)
76
78
  rspec-core (~> 3.0.0)
77
79
  rspec-expectations (~> 3.0.0)
78
80
  rspec-mocks (~> 3.0.0)
79
- rspec-core (3.0.0)
81
+ rspec-core (3.0.2)
80
82
  rspec-support (~> 3.0.0)
81
- rspec-expectations (3.0.0)
83
+ rspec-expectations (3.0.2)
82
84
  diff-lcs (>= 1.2.0, < 2.0)
83
85
  rspec-support (~> 3.0.0)
84
- rspec-mocks (3.0.1)
86
+ rspec-mocks (3.0.2)
85
87
  rspec-support (~> 3.0.0)
86
- rspec-support (3.0.0)
88
+ rspec-support (3.0.2)
87
89
  ruby_gntp (0.3.4)
88
90
  rubypants (0.2.0)
89
91
  simplecov (0.8.2)
@@ -29,8 +29,8 @@ module Nwiki
29
29
  <title><%= page_title %><%= @wiki.title %></title>
30
30
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
31
31
  <link rel="alternate" type="application/atom+xml" title="ATOM Feed" href="/articles.xml">
32
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
33
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
32
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
33
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
34
34
  </head>
35
35
  <body>
36
36
  <a href="https://github.com/niku/nikulog">
@@ -49,8 +49,8 @@ module Nwiki
49
49
  </div>
50
50
  </div>
51
51
  </div>
52
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
53
- <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
52
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
53
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
54
54
  </body>
55
55
  </html>
56
56
  EOS
@@ -25,8 +25,8 @@ module Nwiki
25
25
  <title><%= @wiki.title %></title>
26
26
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
27
27
  <link rel="alternate" type="application/atom+xml" title="ATOM Feed" href="/articles.xml">
28
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
29
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
28
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
29
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
30
30
  </head>
31
31
  <body>
32
32
  <a href="https://github.com/niku/nikulog">
@@ -45,8 +45,8 @@ module Nwiki
45
45
  </div>
46
46
  </div>
47
47
  </div>
48
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
49
- <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
48
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
49
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
50
50
  </body>
51
51
  </html>
52
52
  EOS
@@ -10,7 +10,9 @@ require_relative 'app/html'
10
10
  module Nwiki
11
11
  module Frontend
12
12
  class App
13
- def template(wiki, page_title, html)
13
+ Rack::Mime::MIME_TYPES.merge!({ ".org" => "text/html" })
14
+
15
+ TEMPLATE = -> (wiki, page_title, html) {
14
16
  erb = ERB.new <<EOS
15
17
  <!DOCTYPE HTML>
16
18
  <html>
@@ -18,8 +20,8 @@ module Nwiki
18
20
  <title><%= page_title %><%= wiki.title %></title>
19
21
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
20
22
  <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
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
24
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
23
25
  </head>
24
26
  <body>
25
27
  <a href="https://github.com/niku/nikulog">
@@ -38,44 +40,42 @@ module Nwiki
38
40
  </div>
39
41
  </div>
40
42
  </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
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
44
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
43
45
  </body>
44
46
  </html>
45
47
  EOS
46
48
  erb.result(binding).force_encoding("UTF-8")
47
- end
49
+ }
48
50
 
49
- def initialize git_repo_path
50
- Rack::Mime::MIME_TYPES.merge!({ ".org" => "text/html" })
51
+ FILE_CONVERTER = -> (wiki, template, file, env) {
52
+ path = Rack::Utils.unescape(env["PATH_INFO"])
53
+ return file unless Nwiki::Utils.orgfile?(path)
54
+ page_title = Nwiki::Utils.page_title(path)
55
+ file.force_encoding("UTF-8")
56
+ html = Orgmode::Parser.new(file, offset: 1).to_html
57
+ template.call(wiki, page_title, html)
58
+ }.curry
59
+
60
+ DIRECTORY_CONVERTER = -> (wiki, template, file, env) {
61
+ path = Rack::Utils.unescape(env["PATH_INFO"])
62
+ if path == '/'
63
+ page_title = Nwiki::Utils.page_title(path)
64
+ html = wiki.find_directory("/").to_html
65
+ template.call(wiki, page_title, html)
66
+ else
67
+ page_title = Nwiki::Utils.page_title(path)
68
+ list = dirs.
69
+ each { |d| d.force_encoding("UTF-8") }.
70
+ map { |e| Nwiki::Utils.strip_org(e) }.
71
+ map { |e| %Q!<li><a href="#{e}">#{e}</a></li>! }
72
+ html = "<ul><li><a href=\"../\">../</a></li>#{list.join}</ul>"
73
+ template.call(wiki, page_title, html)
74
+ end
75
+ }.curry
51
76
 
77
+ def initialize git_repo_path
52
78
  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
79
 
80
80
  @builder = Rack::Builder.new {
81
81
  map '/' do
@@ -91,7 +91,9 @@ EOS
91
91
  path !~ /\/$/ && File.extname(path) !~ /(png|jpg|gif)/
92
92
  }
93
93
  end
94
- run Rack::Git::File.new git_repo_path, file_converter: file_converter, directory_converter: directory_converter
94
+ run Rack::Git::File.new git_repo_path,
95
+ file_converter: FILE_CONVERTER.call(wiki, TEMPLATE),
96
+ directory_converter: DIRECTORY_CONVERTER.call(wiki, TEMPLATE)
95
97
  end
96
98
  }
97
99
  end
@@ -0,0 +1,15 @@
1
+ module Nwiki
2
+ module Utils
3
+ def self.page_title path
4
+ path.empty? ? '' : "#{path.gsub(/\.org$/, '').gsub(/^\//, '')} - "
5
+ end
6
+
7
+ def self.orgfile? path
8
+ ::File.extname(path) == ".org"
9
+ end
10
+
11
+ def strip_org path
12
+ path.gsub(/\.org$/) { '' }
13
+ end
14
+ end
15
+ end
data/lib/nwiki/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nwiki
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/nwiki.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'nwiki/version'
3
+ require 'nwiki/utils'
3
4
  require 'nwiki/core'
4
5
  require 'nwiki/frontend'
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - niku
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-09 00:00:00.000000000 Z
11
+ date: 2014-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -185,6 +185,7 @@ files:
185
185
  - lib/nwiki/frontend/app/feed.rb
186
186
  - lib/nwiki/frontend/app/html.rb
187
187
  - lib/nwiki/frontend/app/top.rb
188
+ - lib/nwiki/utils.rb
188
189
  - lib/nwiki/version.rb
189
190
  - nwiki.gemspec
190
191
  - public/.gitkeep