trahald 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/.travis.yml +2 -0
- data/Gemfile +8 -0
- data/README.md +40 -3
- data/lib/trahald.rb +16 -10
- data/lib/trahald/backend-base.rb +30 -0
- data/lib/trahald/git.rb +1 -1
- data/lib/trahald/redis-client.rb +49 -0
- data/lib/trahald/version.rb +1 -1
- data/spec/redis-client_spec.rb +46 -0
- data/trahald.gemspec +0 -1
- metadata +8 -20
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,12 +6,12 @@ Yet another simple wiki on git.
|
|
6
6
|
|
7
7
|
You need:
|
8
8
|
|
9
|
-
* git
|
9
|
+
* git or redis as backend database.
|
10
10
|
* ruby 1.9.3 (2.0.0 does not work with this wiki by now.)
|
11
11
|
* linux or mac. (now engage in support for windows.)
|
12
12
|
|
13
|
-
This project
|
14
|
-
|
13
|
+
This project does not support ruby 1.8.7.
|
14
|
+
It will no longer supported in all senses after June 2013.
|
15
15
|
|
16
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
17
|
|
@@ -20,6 +20,43 @@ it will no longer supported in all senses after June 2013.
|
|
20
20
|
This is just a library.
|
21
21
|
To use Trahald as your wiki, see [3100/a_trahald](https://github.com/3100/a_trahald).
|
22
22
|
|
23
|
+
## In development
|
24
|
+
|
25
|
+
### Preparation
|
26
|
+
|
27
|
+
```
|
28
|
+
bundle install
|
29
|
+
```
|
30
|
+
|
31
|
+
By default, Bundler installs git and redis gems. You can use --without option with these groups:
|
32
|
+
|
33
|
+
* git
|
34
|
+
* redis
|
35
|
+
|
36
|
+
e.g. If you do not need redis gem, add the option:
|
37
|
+
|
38
|
+
```
|
39
|
+
bundle install --without redis
|
40
|
+
```
|
41
|
+
|
42
|
+
### Running App
|
43
|
+
|
44
|
+
```
|
45
|
+
rackup -p $PORT
|
46
|
+
```
|
47
|
+
|
48
|
+
By default, Trahald use git. If you want to use redis alternatively, add -E option:
|
49
|
+
|
50
|
+
```
|
51
|
+
rackup -p $PORT -E "redis"
|
52
|
+
```
|
53
|
+
|
54
|
+
### Test
|
55
|
+
|
56
|
+
```
|
57
|
+
bundle exec rspec
|
58
|
+
```
|
59
|
+
|
23
60
|
## Contributing
|
24
61
|
|
25
62
|
1. Fork it
|
data/lib/trahald.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require_relative "trahald/
|
2
|
+
require_relative "trahald/backend-base"
|
3
3
|
require_relative "trahald/git"
|
4
|
-
|
4
|
+
require_relative "trahald/redis-client"
|
5
|
+
require_relative "trahald/version"
|
5
6
|
|
6
7
|
module Trahald
|
7
8
|
require 'kramdown'
|
@@ -13,10 +14,15 @@ module Trahald
|
|
13
14
|
|
14
15
|
class App < Sinatra::Base
|
15
16
|
|
16
|
-
configure do
|
17
|
+
configure :production, :development, :git do
|
17
18
|
dir = Dir::pwd + "/data"
|
18
19
|
Git::init_repo_if_needed dir
|
19
|
-
|
20
|
+
DB = Git.new dir
|
21
|
+
end
|
22
|
+
|
23
|
+
configure :redis do
|
24
|
+
url = "redis://localhost:6379"
|
25
|
+
DB = RedisClient.new url
|
20
26
|
end
|
21
27
|
|
22
28
|
get '/' do
|
@@ -24,7 +30,7 @@ module Trahald
|
|
24
30
|
end
|
25
31
|
|
26
32
|
get '/list' do
|
27
|
-
@keys =
|
33
|
+
@keys = DB.list
|
28
34
|
slim :list
|
29
35
|
end
|
30
36
|
|
@@ -32,7 +38,7 @@ module Trahald
|
|
32
38
|
puts "edit"
|
33
39
|
puts params[:captures]
|
34
40
|
@name = params[:captures][0]
|
35
|
-
@body =
|
41
|
+
@body = DB.body(@name)
|
36
42
|
@body = "" unless @body
|
37
43
|
slim :edit
|
38
44
|
end
|
@@ -41,7 +47,7 @@ module Trahald
|
|
41
47
|
puts "md"
|
42
48
|
puts params[:captures]
|
43
49
|
@name = params[:captures][0]
|
44
|
-
@body =
|
50
|
+
@body = DB.body(@name)
|
45
51
|
puts @body
|
46
52
|
if @body
|
47
53
|
slim :raw, :layout => :raw_layout
|
@@ -54,7 +60,7 @@ module Trahald
|
|
54
60
|
get %r{^/(.+?)$} do
|
55
61
|
puts params[:captures]
|
56
62
|
@name = params[:captures][0]
|
57
|
-
@body =
|
63
|
+
@body = DB.body(@name)
|
58
64
|
puts "body:#{@body}"
|
59
65
|
@style = scss :style
|
60
66
|
puts "style:#{@style}"
|
@@ -77,8 +83,8 @@ module Trahald
|
|
77
83
|
@message = "update"
|
78
84
|
end
|
79
85
|
|
80
|
-
if
|
81
|
-
|
86
|
+
if DB.add!(@name, @body)
|
87
|
+
DB.commit!(@message)
|
82
88
|
end
|
83
89
|
|
84
90
|
puts @name
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Trahald
|
4
|
+
class BackendBase
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
def add!(name, body)
|
9
|
+
raise "Called abstract method: add!"
|
10
|
+
end
|
11
|
+
|
12
|
+
def body(name)
|
13
|
+
raise "Called abstract method: body"
|
14
|
+
end
|
15
|
+
|
16
|
+
def commit!(message)
|
17
|
+
raise "Called abstract method: commit!"
|
18
|
+
end
|
19
|
+
|
20
|
+
def list
|
21
|
+
raise "Called abstract method: list"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.init_repo_if_needed(dir)
|
25
|
+
raise "Called abstract method: self.init_repo_if_needed"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
data/lib/trahald/git.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Trahald
|
4
|
+
require 'redis'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
class RedisClient < BackendBase
|
8
|
+
def initialize(url)
|
9
|
+
uri = URI.parse url
|
10
|
+
@redis = Redis.new(
|
11
|
+
:host => uri.host,
|
12
|
+
:port => uri.port
|
13
|
+
)
|
14
|
+
|
15
|
+
@params = Hash::new
|
16
|
+
end
|
17
|
+
|
18
|
+
# This method does not set data to Redis DB. To confirm, use commit! after add!.
|
19
|
+
def add!(name, body)
|
20
|
+
@params[name] = body
|
21
|
+
end
|
22
|
+
|
23
|
+
def body(name)
|
24
|
+
@redis.get name
|
25
|
+
end
|
26
|
+
|
27
|
+
# message is not used.
|
28
|
+
def commit!(message)
|
29
|
+
@params.each{|name, body|
|
30
|
+
@redis.set(name, body)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# CAUTION! This method flush data on current db.
|
35
|
+
def flush!
|
36
|
+
@redis.flushdb
|
37
|
+
end
|
38
|
+
|
39
|
+
def list
|
40
|
+
@redis.keys.sort
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.init_repo_if_needed(dir)
|
44
|
+
# do nothing.
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
data/lib/trahald/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe "Trahald::RedisClient" do
|
5
|
+
before(:all) do
|
6
|
+
@url = "redis://localhost:6379/"
|
7
|
+
@redis = Trahald::RedisClient.new(@url)
|
8
|
+
@redis.flush!
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should contains no data at first" do
|
12
|
+
@redis.list.should == []
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should enable to save some data." do
|
16
|
+
name1 = "sample"
|
17
|
+
body1 = "# title\n\n* hoge\n* huga\n* 123"
|
18
|
+
name2 = "サンプル"
|
19
|
+
body2 = "# タイトル\n\n* いち\n* に\n* さん"
|
20
|
+
name3 = "サンプル/初夢"
|
21
|
+
body3 = "# タイトル\n\n* 富士\n* 鷹\n* なすび"
|
22
|
+
@redis.add!(name1, body1)
|
23
|
+
@redis.add!(name2, body2)
|
24
|
+
@redis.add!(name3, body3)
|
25
|
+
message = "コミット"
|
26
|
+
|
27
|
+
@redis.commit!(message).should be_true
|
28
|
+
@redis.body(name1).should == body1
|
29
|
+
@redis.body(name2).should == body2
|
30
|
+
@redis.body(name3).should == body3
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should enable to output list." do
|
34
|
+
@redis.list.should == ['sample', 'サンプル', 'サンプル/初夢']
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should enable to flush data" do
|
38
|
+
@redis.flush!
|
39
|
+
@redis.list.should == []
|
40
|
+
end
|
41
|
+
|
42
|
+
after(:all) do
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
data/trahald.gemspec
CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency('grit', '~> 2.5.0')
|
21
20
|
gem.add_dependency('kramdown', '~> 0.14.2')
|
22
21
|
gem.add_dependency('sass', '~>3.2.6')
|
23
22
|
gem.add_dependency('sinatra', '~>1.3.5')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trahald
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,22 +11,6 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2013-03-06 00:00:00.000000000 Z
|
13
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
14
|
- !ruby/object:Gem::Dependency
|
31
15
|
name: kramdown
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,7 +122,9 @@ files:
|
|
138
122
|
- Rakefile
|
139
123
|
- config.ru
|
140
124
|
- lib/trahald.rb
|
125
|
+
- lib/trahald/backend-base.rb
|
141
126
|
- lib/trahald/git.rb
|
127
|
+
- lib/trahald/redis-client.rb
|
142
128
|
- lib/trahald/version.rb
|
143
129
|
- lib/views/edit.slim
|
144
130
|
- lib/views/index.slim
|
@@ -149,6 +135,7 @@ files:
|
|
149
135
|
- lib/views/raw_layout.slim
|
150
136
|
- lib/views/style.scss
|
151
137
|
- spec/git_spec.rb
|
138
|
+
- spec/redis-client_spec.rb
|
152
139
|
- spec/spec_helper.rb
|
153
140
|
- trahald.gemspec
|
154
141
|
homepage: ''
|
@@ -165,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
152
|
version: '0'
|
166
153
|
segments:
|
167
154
|
- 0
|
168
|
-
hash: -
|
155
|
+
hash: -233894239
|
169
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
157
|
none: false
|
171
158
|
requirements:
|
@@ -174,13 +161,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
161
|
version: '0'
|
175
162
|
segments:
|
176
163
|
- 0
|
177
|
-
hash: -
|
164
|
+
hash: -233894239
|
178
165
|
requirements: []
|
179
166
|
rubyforge_project:
|
180
|
-
rubygems_version: 1.8.
|
167
|
+
rubygems_version: 1.8.24
|
181
168
|
signing_key:
|
182
169
|
specification_version: 3
|
183
170
|
summary: a simple wiki on git
|
184
171
|
test_files:
|
185
172
|
- spec/git_spec.rb
|
173
|
+
- spec/redis-client_spec.rb
|
186
174
|
- spec/spec_helper.rb
|