nwiki 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/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/config.ru +33 -0
- data/lib/nwiki/version.rb +3 -0
- data/lib/nwiki.rb +102 -0
- data/nwiki.gemspec +29 -0
- data/spec/nwiki_spec.rb +5 -0
- data/spec/spec_helper.rb +9 -0
- metadata +222 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3
|
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm: 1.9.3
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 niku
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Nwiki
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nwiki'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nwiki
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/config.ru
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$LOAD_PATH << './lib'
|
3
|
+
require './lib/nwiki'
|
4
|
+
require 'rack/google-analytics'
|
5
|
+
|
6
|
+
ENV['RACK_ENV'] ||= "development"
|
7
|
+
CONF = {
|
8
|
+
data_file_directory: ENV['GIT_REPOSITORY'],
|
9
|
+
feeds_url_prefix: '/feeds',
|
10
|
+
articles_url_prefix: '/articles',
|
11
|
+
site_title: "ヽ(´・肉・`)ノログ",
|
12
|
+
site_description: "How do we fighting without fighting?",
|
13
|
+
site_link: "http://niku.name",
|
14
|
+
site_author: "niku",
|
15
|
+
file_encoding: "UTF-8",
|
16
|
+
}
|
17
|
+
|
18
|
+
if ENV['RACK_ENV'] == "development"
|
19
|
+
use Rack::Reloader
|
20
|
+
use Rack::Lint
|
21
|
+
end
|
22
|
+
|
23
|
+
if tracker = ENV['GOOGLE_ANALYTICS_TRACKER']
|
24
|
+
use Rack::GoogleAnalytics, :tracker => tracker
|
25
|
+
end
|
26
|
+
|
27
|
+
map CONF[:feeds_url_prefix] do
|
28
|
+
run Nwiki::Feeds.new(CONF)
|
29
|
+
end
|
30
|
+
|
31
|
+
map CONF[:articles_url_prefix] do
|
32
|
+
run Nwiki::Articles.new(CONF)
|
33
|
+
end
|
data/lib/nwiki.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'nwiki/version'
|
3
|
+
|
4
|
+
require 'rss'
|
5
|
+
require "grit"
|
6
|
+
require "org-ruby"
|
7
|
+
require "rack/mime"
|
8
|
+
|
9
|
+
module Nwiki
|
10
|
+
class Articles
|
11
|
+
def initialize opt
|
12
|
+
@data_file_directory = opt[:data_file_directory]
|
13
|
+
@articles_url_prefix = opt[:articles_url_prefix]
|
14
|
+
@file_encoding = opt[:file_encoding]
|
15
|
+
@site_title = opt[:site_title].force_encoding(@file_encoding)
|
16
|
+
end
|
17
|
+
|
18
|
+
def call env
|
19
|
+
file_path = convert_file_path(env["PATH_INFO"])
|
20
|
+
return [403, {"Content-Type" => "text/plane"}, ["forbidden."]] if file_path.include? ".."
|
21
|
+
tree = Grit::Repo.new(@data_file_directory).commits.first.tree
|
22
|
+
case result = tree/file_path || tree/(file_path + '.org')
|
23
|
+
when Grit::Tree
|
24
|
+
if env["PATH_INFO"] =~ /\/$/
|
25
|
+
list = "<ul><li><a href=\"../\">../</a></li>" + result.contents.map{ |c|
|
26
|
+
case c
|
27
|
+
when Grit::Tree
|
28
|
+
%Q!<li><a href="#{c.name}/">#{c.name}/</a></li>!
|
29
|
+
when Grit::Blob
|
30
|
+
%Q!<li><a href="#{c.name}">#{c.name}</a></li>!
|
31
|
+
else
|
32
|
+
# TODO
|
33
|
+
end
|
34
|
+
}.sort.join("\n") + "</ul>"
|
35
|
+
[200, {"Content-Type" => "text/html; charset=#{@file_encoding}"}, [wrap_html(@site_title, file_path.force_encoding(@file_encoding)){ list.force_encoding(@file_encoding) }]]
|
36
|
+
else
|
37
|
+
request_path = env["SCRIPT_NAME"] + env["PATH_INFO"]
|
38
|
+
[301, {"Content-Type" => "text/plane; charset=#{@file_encoding}", "Location" => request_path + "/"}, ["redirect."]]
|
39
|
+
end
|
40
|
+
when Grit::Blob
|
41
|
+
extname = File.extname(file_path)
|
42
|
+
if extname == '.org' || extname == ''
|
43
|
+
[200, {"Content-Type" => "text/html; charset=#{@file_encoding}"}, [wrap_html(@site_title, result.name.force_encoding(@file_encoding)){ Orgmode::Parser.new(result.data.force_encoding(@file_encoding), 1).to_html }]]
|
44
|
+
else
|
45
|
+
[200, {"Content-Type" => Rack::Mime.mime_type(File.extname(file_path), 'text/plain')}, [result.data]]
|
46
|
+
end
|
47
|
+
else
|
48
|
+
[404, {"Content-Type" => "text/plane; charset=#{@file_encoding}"}, ["not found."]]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def convert_file_path(str)
|
53
|
+
path = str.
|
54
|
+
gsub(%r!^#{@articles_url_prefix}!, '').
|
55
|
+
gsub(%r!^/!, '')
|
56
|
+
path.empty? ? '/' : URI.unescape(path).force_encoding(@file_encoding)
|
57
|
+
end
|
58
|
+
|
59
|
+
def wrap_html site_title, article_title
|
60
|
+
html = ""
|
61
|
+
html << "<!DOCTYPE html><html><head><title>#{article_title} - #{site_title}</title></head><body><h1>#{site_title}</h1>"
|
62
|
+
html << yield if block_given?
|
63
|
+
html << "</body></html>"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Feeds
|
68
|
+
def initialize opt
|
69
|
+
@data_file_directory = opt[:data_file_directory]
|
70
|
+
@feeds_url_prefix = opt[:feeds_url_prefix]
|
71
|
+
@articles_url_prefix = opt[:articles_url_prefix]
|
72
|
+
@site_title = opt[:site_title]
|
73
|
+
@site_description = opt[:site_description]
|
74
|
+
@site_link = opt[:site_link]
|
75
|
+
@site_author = opt[:site_author]
|
76
|
+
end
|
77
|
+
|
78
|
+
def call env
|
79
|
+
feed = RSS::Maker.make("atom") do |maker|
|
80
|
+
maker.channel.about = @site_link + @feeds_url_prefix
|
81
|
+
maker.channel.title = @site_title
|
82
|
+
maker.channel.description = @site_description
|
83
|
+
maker.channel.link = @site_link
|
84
|
+
maker.channel.author = @site_author
|
85
|
+
maker.channel.date = Time.now
|
86
|
+
maker.items.do_sort = true
|
87
|
+
Grit::Repo.new(@data_file_directory).commits.map{ |history|
|
88
|
+
history.diffs.map{ |diff|
|
89
|
+
next nil if diff.deleted_file # FIXME how do we view deleted file?
|
90
|
+
maker.items.new_item{ |item|
|
91
|
+
path = diff.b_path.force_encoding('utf-8')
|
92
|
+
item.link = "#{@site_link}#{@articles_url_prefix}/#{path}"
|
93
|
+
item.title = File.basename(path)
|
94
|
+
item.date = history.date
|
95
|
+
}
|
96
|
+
}.compact
|
97
|
+
}.flatten
|
98
|
+
end
|
99
|
+
[200, {"Content-Type" => "text/xml"}, [feed.to_s]]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/nwiki.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/nwiki/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['niku']
|
6
|
+
gem.email = ['niku@niku.name']
|
7
|
+
gem.description = %q{Write a gem description}
|
8
|
+
gem.summary = %q{Write a gem summary}
|
9
|
+
gem.homepage = ''
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = 'nwiki'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = Nwiki::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency('rack')
|
19
|
+
gem.add_dependency('sinatra')
|
20
|
+
gem.add_dependency('org-ruby')
|
21
|
+
gem.add_dependency('grit')
|
22
|
+
|
23
|
+
gem.add_development_dependency('rake')
|
24
|
+
gem.add_development_dependency('rspec')
|
25
|
+
gem.add_development_dependency('rack-test')
|
26
|
+
gem.add_development_dependency('guard')
|
27
|
+
gem.add_development_dependency('guard-rspec')
|
28
|
+
gem.add_development_dependency('ruby_gntp')
|
29
|
+
end
|
data/spec/nwiki_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nwiki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- niku
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sinatra
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
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'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: org-ruby
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '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: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: grit
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
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'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rack-test
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: guard-rspec
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: ruby_gntp
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
description: Write a gem description
|
175
|
+
email:
|
176
|
+
- niku@niku.name
|
177
|
+
executables: []
|
178
|
+
extensions: []
|
179
|
+
extra_rdoc_files: []
|
180
|
+
files:
|
181
|
+
- .gitignore
|
182
|
+
- .rspec
|
183
|
+
- .rvmrc
|
184
|
+
- .travis.yml
|
185
|
+
- Gemfile
|
186
|
+
- Guardfile
|
187
|
+
- LICENSE
|
188
|
+
- README.md
|
189
|
+
- Rakefile
|
190
|
+
- config.ru
|
191
|
+
- lib/nwiki.rb
|
192
|
+
- lib/nwiki/version.rb
|
193
|
+
- nwiki.gemspec
|
194
|
+
- spec/nwiki_spec.rb
|
195
|
+
- spec/spec_helper.rb
|
196
|
+
homepage: ''
|
197
|
+
licenses: []
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ! '>='
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
+
none: false
|
210
|
+
requirements:
|
211
|
+
- - ! '>='
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '0'
|
214
|
+
requirements: []
|
215
|
+
rubyforge_project:
|
216
|
+
rubygems_version: 1.8.23
|
217
|
+
signing_key:
|
218
|
+
specification_version: 3
|
219
|
+
summary: Write a gem summary
|
220
|
+
test_files:
|
221
|
+
- spec/nwiki_spec.rb
|
222
|
+
- spec/spec_helper.rb
|