trahald 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/config.ru +2 -0
- data/lib/trahald.rb +91 -0
- data/lib/trahald/git.rb +82 -0
- data/lib/trahald/version.rb +3 -0
- data/lib/views/edit.slim +10 -0
- data/lib/views/index.slim +8 -0
- data/lib/views/layout.slim +10 -0
- data/lib/views/list.slim +10 -0
- data/lib/views/page.slim +12 -0
- data/lib/views/raw.slim +1 -0
- data/lib/views/raw_layout.slim +1 -0
- data/lib/views/style.scss +16 -0
- data/spec/git_spec.rb +47 -0
- data/spec/spec_helper.rb +9 -0
- data/trahald.gemspec +28 -0
- metadata +186 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 3100
|
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
|
+
# Trahald
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/3100/trahald.png?branch=master)](https://travis-ci.org/3100/trahald)
|
4
|
+
|
5
|
+
Yet another simple wiki on git.
|
6
|
+
|
7
|
+
You need:
|
8
|
+
|
9
|
+
* git
|
10
|
+
* ruby 1.9.3 (2.0.0 does not work with this wiki by now.)
|
11
|
+
* linux or mac. (now engage in support for windows.)
|
12
|
+
|
13
|
+
This project will not support ruby 1.8.7.
|
14
|
+
it will no longer supported in all senses after June 2013.
|
15
|
+
|
16
|
+
[http://www.ruby-lang.org/en/news/2011/10/06/plans-for-1-8-7/](Plans for 1.8.7 - ruby-lang.org)
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
This is just a library.
|
21
|
+
To use Trahald as your wiki, see [3100/a_trahald](https://github.com/3100/a_trahald).
|
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 'Add 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
data/lib/trahald.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require_relative "trahald/version"
|
3
|
+
require_relative "trahald/git"
|
4
|
+
require 'sinatra/base'
|
5
|
+
|
6
|
+
module Trahald
|
7
|
+
require 'kramdown'
|
8
|
+
require 'json'
|
9
|
+
require 'sass'
|
10
|
+
require 'sinatra/base'
|
11
|
+
require 'slim'
|
12
|
+
require 'uri'
|
13
|
+
|
14
|
+
class App < Sinatra::Base
|
15
|
+
|
16
|
+
configure do
|
17
|
+
dir = Dir::pwd + "/data"
|
18
|
+
Git::init_repo_if_needed dir
|
19
|
+
GIT = Git.new dir
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/' do
|
23
|
+
redirect 'home'
|
24
|
+
end
|
25
|
+
|
26
|
+
get '/list' do
|
27
|
+
@keys = GIT.list
|
28
|
+
slim :list
|
29
|
+
end
|
30
|
+
|
31
|
+
get %r{^/(.+?)/edit$} do
|
32
|
+
puts "edit"
|
33
|
+
puts params[:captures]
|
34
|
+
@name = params[:captures][0]
|
35
|
+
@body = GIT.body(@name)
|
36
|
+
@body = "" unless @body
|
37
|
+
slim :edit
|
38
|
+
end
|
39
|
+
|
40
|
+
get %r{^/(.+?)\.md$} do
|
41
|
+
puts "md"
|
42
|
+
puts params[:captures]
|
43
|
+
@name = params[:captures][0]
|
44
|
+
@body = GIT.body(@name)
|
45
|
+
puts @body
|
46
|
+
if @body
|
47
|
+
slim :raw, :layout => :raw_layout
|
48
|
+
else
|
49
|
+
@body = ""
|
50
|
+
slim :edit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
get %r{^/(.+?)$} do
|
55
|
+
puts params[:captures]
|
56
|
+
@name = params[:captures][0]
|
57
|
+
@body = GIT.body(@name)
|
58
|
+
puts "body:#{@body}"
|
59
|
+
@style = scss :style
|
60
|
+
puts "style:#{@style}"
|
61
|
+
if @body
|
62
|
+
@body = Kramdown::Document.new(@body).to_html
|
63
|
+
slim :page
|
64
|
+
else
|
65
|
+
@body = ""
|
66
|
+
slim :edit
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
post "/edit" do
|
71
|
+
@name = params[:name]
|
72
|
+
@body = params[:body]
|
73
|
+
puts "name,body:#{@name},#{@body}"
|
74
|
+
if params[:comment]
|
75
|
+
@message = params[:comment]
|
76
|
+
else
|
77
|
+
@message = "update"
|
78
|
+
end
|
79
|
+
|
80
|
+
if GIT.add!(@name, @body)
|
81
|
+
GIT.commit!(@message)
|
82
|
+
end
|
83
|
+
|
84
|
+
puts @name
|
85
|
+
redirect "/#{URI.escape(@name)}"
|
86
|
+
end
|
87
|
+
|
88
|
+
run! if $0 == __FILE__
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
data/lib/trahald/git.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Trahald
|
4
|
+
require 'grit'
|
5
|
+
|
6
|
+
class Git
|
7
|
+
def initialize(repo_path, ext="md")
|
8
|
+
@repo_dir = repo_path
|
9
|
+
@ext = ext
|
10
|
+
end
|
11
|
+
|
12
|
+
def add!(name, body)
|
13
|
+
path = "#{@repo_dir}/#{name}.#{@ext}"
|
14
|
+
FileUtils.mkdir_p File.dirname(path)
|
15
|
+
begin
|
16
|
+
File.open(path, 'w'){|f| f.write(body)}
|
17
|
+
Dir.chdir(@repo_dir){
|
18
|
+
repo.add "#{name}.#{@ext}"
|
19
|
+
}
|
20
|
+
true
|
21
|
+
rescue => exception
|
22
|
+
puts exception
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def body(name)
|
28
|
+
first = first_commit
|
29
|
+
return nil unless first
|
30
|
+
|
31
|
+
d = dirs(name)
|
32
|
+
tree = first.tree
|
33
|
+
file = tree / "#{name}.#{@ext}".force_encoding("ASCII-8BIT")
|
34
|
+
return nil unless file
|
35
|
+
file.data.force_encoding("UTF-8")
|
36
|
+
end
|
37
|
+
|
38
|
+
def commit!(message)
|
39
|
+
repo.commit_index(message)
|
40
|
+
end
|
41
|
+
|
42
|
+
def list
|
43
|
+
first = first_commit
|
44
|
+
return [] unless first
|
45
|
+
list = []
|
46
|
+
files('', first.tree, list)
|
47
|
+
list.sort
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.init_repo_if_needed(dir)
|
51
|
+
init_repo(dir) unless FileTest.exist? dir
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def dirs(name)
|
56
|
+
d = name.split(/\/+/)
|
57
|
+
d.pop #pop basename
|
58
|
+
d
|
59
|
+
end
|
60
|
+
|
61
|
+
def first_commit
|
62
|
+
repo.commits.first
|
63
|
+
end
|
64
|
+
|
65
|
+
def files(pos, tree, list)
|
66
|
+
tree.blobs.each{|blob|
|
67
|
+
list.push pos + File.basename(blob.name.force_encoding("UTF-8"), ".#{@ext}")
|
68
|
+
}
|
69
|
+
tree.trees.each{|t|
|
70
|
+
files "#{pos}#{t.name.force_encoding("UTF-8")}/", t, list
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def repo
|
75
|
+
@repo ||= Grit::Repo.new @repo_dir
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.init_repo(dir)
|
79
|
+
Grit::Repo.init dir
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/views/edit.slim
ADDED
data/lib/views/list.slim
ADDED
data/lib/views/page.slim
ADDED
data/lib/views/raw.slim
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
== @body
|
@@ -0,0 +1 @@
|
|
1
|
+
== yield
|
data/spec/git_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe "Trahald::Git" do
|
5
|
+
before(:all) do
|
6
|
+
@dir = File.expand_path(File.dirname(__FILE__) + '/repos_for_spec')
|
7
|
+
@git = Trahald::Git.new(@dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should get new repos if it does not exist." do
|
11
|
+
FileTest.exist?(@dir).should be_false
|
12
|
+
Trahald::Git.init_repo_if_needed @dir
|
13
|
+
FileTest.exist?(@dir).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should enable to add and commit some files." do
|
17
|
+
name1 = "sample"
|
18
|
+
body1 = "# title\n\n* hoge\n* huga\n* 123"
|
19
|
+
name2 = "サンプル"
|
20
|
+
body2 = "# タイトル\n\n* いち\n* に\n* さん"
|
21
|
+
name3 = "サンプル/初夢"
|
22
|
+
body3 = "# タイトル\n\n* 富士\n* 鷹\n* なすび"
|
23
|
+
@git.add!(name1, body1)
|
24
|
+
@git.add!(name2, body2)
|
25
|
+
@git.add!(name3, body3)
|
26
|
+
message = "コミット"
|
27
|
+
|
28
|
+
@git.commit!(message).should be_true
|
29
|
+
@git.body(name1).should == body1
|
30
|
+
@git.body(name2).should == body2
|
31
|
+
@git.body(name3).should == body3
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should enable to output list." do
|
35
|
+
@git.list.should == ['sample', 'サンプル', 'サンプル/初夢']
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:all) do
|
39
|
+
if FileTest.exist? @dir
|
40
|
+
Dir.glob(@dir + '/**/').each{|e|
|
41
|
+
puts e}
|
42
|
+
FileUtils.rm_rf(Dir.glob(@dir + '/**/'))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
data/spec/spec_helper.rb
ADDED
data/trahald.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trahald/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "trahald"
|
8
|
+
gem.version = Trahald::VERSION
|
9
|
+
gem.authors = ["3100"]
|
10
|
+
gem.email = ["sugar16g@gmail.com"]
|
11
|
+
gem.description = %q{a simple wiki on git}
|
12
|
+
gem.summary = %q{a simple wiki on git}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency('grit', '~> 2.5.0')
|
21
|
+
gem.add_dependency('kramdown', '~> 0.14.2')
|
22
|
+
gem.add_dependency('sass', '~>3.2.6')
|
23
|
+
gem.add_dependency('sinatra', '~>1.3.5')
|
24
|
+
gem.add_dependency('slim', '~>1.3.6')
|
25
|
+
|
26
|
+
gem.add_development_dependency('rspec', '~> 2.13.0')
|
27
|
+
gem.add_development_dependency('rake', '~> 10.0.3')
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trahald
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- '3100'
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: grit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.5.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: 2.5.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: kramdown
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.14.2
|
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.14.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: sass
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.2.6
|
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: 3.2.6
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sinatra
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.3.5
|
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: 1.3.5
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: slim
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.3.6
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.3.6
|
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: 2.13.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: 2.13.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 10.0.3
|
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: 10.0.3
|
126
|
+
description: a simple wiki on git
|
127
|
+
email:
|
128
|
+
- sugar16g@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- .travis.yml
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- config.ru
|
140
|
+
- lib/trahald.rb
|
141
|
+
- lib/trahald/git.rb
|
142
|
+
- lib/trahald/version.rb
|
143
|
+
- lib/views/edit.slim
|
144
|
+
- lib/views/index.slim
|
145
|
+
- lib/views/layout.slim
|
146
|
+
- lib/views/list.slim
|
147
|
+
- lib/views/page.slim
|
148
|
+
- lib/views/raw.slim
|
149
|
+
- lib/views/raw_layout.slim
|
150
|
+
- lib/views/style.scss
|
151
|
+
- spec/git_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
- trahald.gemspec
|
154
|
+
homepage: ''
|
155
|
+
licenses: []
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
hash: -182653521
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
segments:
|
176
|
+
- 0
|
177
|
+
hash: -182653521
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 1.8.25
|
181
|
+
signing_key:
|
182
|
+
specification_version: 3
|
183
|
+
summary: a simple wiki on git
|
184
|
+
test_files:
|
185
|
+
- spec/git_spec.rb
|
186
|
+
- spec/spec_helper.rb
|