gitki 0.1.0

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.
Files changed (41) hide show
  1. data/ChangeLog +0 -0
  2. data/README.rdoc +74 -0
  3. data/Rakefile +59 -0
  4. data/app.rb +90 -0
  5. data/bin/gitki +3 -0
  6. data/bin/gitki.ru +13 -0
  7. data/config.ru +3 -0
  8. data/console +13 -0
  9. data/lib/gitki.png +0 -0
  10. data/lib/gitki.rb +116 -0
  11. data/lib/home_template.haml +17 -0
  12. data/lib/navigation_template.haml +4 -0
  13. data/public/background.png +0 -0
  14. data/public/favicon.ico +0 -0
  15. data/setting.yml +3 -0
  16. data/spec/gitki_spec.rb +104 -0
  17. data/vendor/git_store/LICENSE +18 -0
  18. data/vendor/git_store/README.md +147 -0
  19. data/vendor/git_store/Rakefile +35 -0
  20. data/vendor/git_store/TODO +3 -0
  21. data/vendor/git_store/git_store.gemspec +40 -0
  22. data/vendor/git_store/lib/git_store.rb +373 -0
  23. data/vendor/git_store/lib/git_store/blob.rb +32 -0
  24. data/vendor/git_store/lib/git_store/commit.rb +65 -0
  25. data/vendor/git_store/lib/git_store/diff.rb +76 -0
  26. data/vendor/git_store/lib/git_store/handlers.rb +36 -0
  27. data/vendor/git_store/lib/git_store/pack.rb +425 -0
  28. data/vendor/git_store/lib/git_store/tag.rb +40 -0
  29. data/vendor/git_store/lib/git_store/tree.rb +183 -0
  30. data/vendor/git_store/lib/git_store/user.rb +29 -0
  31. data/vendor/git_store/test/bare_store_spec.rb +33 -0
  32. data/vendor/git_store/test/benchmark.rb +30 -0
  33. data/vendor/git_store/test/commit_spec.rb +81 -0
  34. data/vendor/git_store/test/git_store_spec.rb +257 -0
  35. data/vendor/git_store/test/helper.rb +18 -0
  36. data/vendor/git_store/test/tree_spec.rb +92 -0
  37. data/views/layout.haml +23 -0
  38. data/views/page.haml +7 -0
  39. data/views/pages.haml +9 -0
  40. data/views/styles.sass +87 -0
  41. metadata +103 -0
File without changes
@@ -0,0 +1,74 @@
1
+ = gitki
2
+
3
+ == DESCRIPTION:
4
+
5
+ Gitki is a wiki using git to store data.
6
+
7
+ == DEMO:
8
+
9
+ http://gitki.oyguj.org/
10
+
11
+ == SYNOPSIS:
12
+
13
+ Setup:
14
+
15
+ git clone git://github.com/jugyo/gitki.git
16
+ cd gitki
17
+ git submodule update --init
18
+ cd ~
19
+ mkdir gitki.git
20
+ cd gitki.git
21
+ git init --bare
22
+
23
+ Run as standalon server:
24
+
25
+ ./app.rb
26
+
27
+ Run on mod_rails:
28
+
29
+ See
30
+ http://www.sinatrarb.com/book.html#deployment_passenger
31
+
32
+ == CONFIGURATION:
33
+
34
+ setting.yml
35
+
36
+ title: wiki title
37
+ git_store: git repository path to store data (ex ~/gitki.git)
38
+ markup: markup type (textile or markdown)
39
+
40
+ == REQUIREMENTS:
41
+
42
+ * sinatra
43
+ * RedCloth or rdiscount
44
+
45
+ To install them as follows:
46
+
47
+ sudo gem install sinatra RedCloth rdiscount
48
+
49
+ See Also: http://github.com/georgi/git_store/tree/master
50
+
51
+ == LICENSE:
52
+
53
+ (The MIT License)
54
+
55
+ Copyright (c) 2008-2009 jugyo
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining
58
+ a copy of this software and associated documentation files (the
59
+ 'Software'), to deal in the Software without restriction, including
60
+ without limitation the rights to use, copy, modify, merge, publish,
61
+ distribute, sublicense, and/or sell copies of the Software, and to
62
+ permit persons to whom the Software is furnished to do so, subject to
63
+ the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be
66
+ included in all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
69
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
70
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
71
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
72
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
73
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
74
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ require 'spec/rake/spectask'
2
+ require 'rake/clean'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/rdoctask'
5
+
6
+ desc "default task"
7
+ task :default => [:spec]
8
+
9
+ name = 'gitki'
10
+ version = '0.1.0'
11
+
12
+ spec = Gem::Specification.new do |s|
13
+ s.name = name
14
+ s.version = version
15
+ s.summary = "Gitki is a wiki using git to store data."
16
+ s.description = "Gitki is a wiki using git to store data."
17
+ s.files = %w(Rakefile README.rdoc ChangeLog app.rb config.ru console setting.yml) +
18
+ Dir.glob("{lib,spec,bin,public,vendor,views}/**/*")
19
+ s.executables = ["gitki"]
20
+ s.add_dependency("sinatra", ">= 0.9.4")
21
+ s.authors = %w(jugyo)
22
+ s.email = 'jugyo.org@gmail.com'
23
+ s.homepage = 'http://github.com/jugyo/gitki'
24
+ s.rubyforge_project = 'gitki'
25
+ s.has_rdoc = false
26
+ end
27
+
28
+ Rake::GemPackageTask.new(spec) do |p|
29
+ p.need_tar = true
30
+ end
31
+
32
+ task :gemspec do
33
+ filename = "#{name}.gemspec"
34
+ open(filename, 'w') do |f|
35
+ f.write spec.to_ruby
36
+ end
37
+ puts <<-EOS
38
+ Successfully generated gemspec
39
+ Name: #{name}
40
+ Version: #{version}
41
+ File: #{filename}
42
+ EOS
43
+ end
44
+
45
+ task :install => [ :package ] do
46
+ sh %{sudo gem install pkg/#{name}-#{version}.gem}
47
+ end
48
+
49
+ task :uninstall => [ :clean ] do
50
+ sh %{sudo gem uninstall #{name}}
51
+ end
52
+
53
+ desc 'run all specs'
54
+ Spec::Rake::SpecTask.new do |t|
55
+ t.spec_files = FileList['spec/**/*_spec.rb']
56
+ t.spec_opts = ['-c']
57
+ end
58
+
59
+ CLEAN.include ['pkg']
data/app.rb ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'rubygems'
5
+ require 'sinatra'
6
+ require 'mime/types'
7
+ require 'yaml'
8
+ require 'lib/gitki'
9
+ include Gitki
10
+
11
+ configure do
12
+ BASE_DIR = File.expand_path(File.dirname(__FILE__)) unless defined? BASE_DIR
13
+ SETTING = YAML.load(open("#{BASE_DIR}/setting.yml")) unless defined? SETTING
14
+
15
+ SETTING['markup'] ||= 'textile'
16
+ raise 'Invalid markup type.' unless markup_types.include?(SETTING['markup'])
17
+
18
+ set SETTING
19
+ set :haml, {:format => :html5}
20
+ enable :sessions
21
+
22
+ Gitki.setup(SETTING['git_store'])
23
+
24
+ repo_path = File.expand_path SETTING['git_store']
25
+ puts <<-EOS
26
+
27
+ #{'#' * 60}
28
+
29
+ Wiki repository is '#{repo_path}'.
30
+ You can clone it as follows:
31
+
32
+ % git clone <user>@<host>:#{repo_path}
33
+
34
+ #{'#' * 60}
35
+
36
+ EOS
37
+ end
38
+
39
+ before do
40
+ store.refresh!
41
+ content_type "text/html", :charset => "utf-8"
42
+ end
43
+
44
+ get '/css' do
45
+ content_type 'text/css', :charset => 'utf-8'
46
+ sass :styles
47
+ end
48
+
49
+ get '/files/:name' do
50
+ content_type MIME::Types.type_for(params[:name]).first.content_type
51
+ Attachment.find(params[:name])
52
+ end
53
+
54
+ get '/' do
55
+ wiki 'home'
56
+ end
57
+
58
+ get '/pages' do
59
+ @pages = Page.find_all
60
+ haml :pages
61
+ end
62
+
63
+ get '/:name' do
64
+ wiki params[:name]
65
+ end
66
+
67
+ get '/raw/:name' do
68
+ content_type 'text/plain', :charset => 'utf-8'
69
+ Page.find(params[:name]).raw
70
+ end
71
+
72
+ not_found do
73
+ haml '#error-message Not found'
74
+ end
75
+
76
+ helpers do
77
+ def navigation
78
+ markup(Page.find('navigation').body)
79
+ end
80
+
81
+ def markup(text)
82
+ self.__send__(options.markup, text)
83
+ end
84
+
85
+ def wiki(name)
86
+ @name = name
87
+ @page = Page.find(@name) || not_found
88
+ haml :page
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ system 'rackup', File.dirname(__FILE__) + '/gitki.ru'
@@ -0,0 +1,13 @@
1
+ ENV['RACK_ENV'] ||= 'production'
2
+
3
+ pwd = Dir.pwd
4
+ git_dir = File.exists?("#{pwd}/.git") ? "#{pwd}/.git" : pwd
5
+
6
+ SETTING = {
7
+ 'title' => 'Gitki',
8
+ 'git_store' => git_dir,
9
+ 'markup' => 'textile',
10
+ }
11
+ $: << File.dirname(__FILE__) + '/../'
12
+ require 'app'
13
+ run Sinatra::Application
@@ -0,0 +1,3 @@
1
+ ENV['RACK_ENV'] ||= 'production'
2
+ require 'app'
3
+ run Sinatra::Application
data/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.dirname(__FILE__) + '/lib'
4
+
5
+ require 'rubygems'
6
+ require 'irb'
7
+ require 'yaml'
8
+ require 'gitki'
9
+
10
+ SETTING = YAML.load(open("#{File.dirname(__FILE__)}/setting.yml"))
11
+ Gitki.setup(SETTING['git_store'])
12
+ include Gitki
13
+ IRB.start
Binary file
@@ -0,0 +1,116 @@
1
+ # -*- coding: utf-8 -*-
2
+ $: << File.dirname(__FILE__) + '/../vendor/git_store/lib'
3
+
4
+ require 'rubygems'
5
+ require 'git_store'
6
+ require 'redcloth' rescue nil
7
+ require 'rdiscount' rescue nil
8
+
9
+ module Gitki
10
+ class << self
11
+ def setup(git_store_path)
12
+ @@store = GitStore.new(File.expand_path(git_store_path), 'master', true) # use bare repository
13
+ Page.setup('wiki')
14
+ Attachment.setup('files')
15
+ if @@store.objects.empty?
16
+ create_defaults
17
+ end
18
+ end
19
+
20
+ def create_defaults
21
+ @@store[Page.dir + '/home'] = read_file('home_template.haml')
22
+ @@store[Page.dir + '/navigation'] = read_file('navigation_template.haml')
23
+ @@store[Attachment.dir + '/gitki.png'] = read_file('gitki.png')
24
+ @@store.commit 'Created defaults'
25
+ end
26
+
27
+ def read_file(name)
28
+ open(File.dirname(__FILE__) + '/' + name).read
29
+ end
30
+ end
31
+
32
+ def markup_types
33
+ ['html', 'textile', 'markdown']
34
+ end
35
+
36
+ def store
37
+ @@store
38
+ end
39
+
40
+ def textile(text)
41
+ RedCloth.new(text).to_html
42
+ end
43
+
44
+ def markdown(text)
45
+ RDiscount.new(text).to_html
46
+ end
47
+
48
+ def html(text)
49
+ text
50
+ end
51
+
52
+ class Page
53
+ class << self
54
+ attr_reader :dir
55
+ def setup(dir)
56
+ @dir = dir
57
+ end
58
+
59
+ def find_all
60
+ pages = {}
61
+ store[dir].to_hash.each do |name, text|
62
+ pages[name] = self.new(text)
63
+ end
64
+ pages
65
+ end
66
+
67
+ def find(name)
68
+ data = store[store_path(name)]
69
+ if data
70
+ self.new(data)
71
+ else
72
+ nil
73
+ end
74
+ end
75
+
76
+ def store_path(name)
77
+ File.join(dir, name)
78
+ end
79
+ end
80
+
81
+ attr_reader :title, :body, :raw
82
+
83
+ def initialize(raw)
84
+ @raw = raw
85
+ @title, @body = split_title_and_body(raw)
86
+ end
87
+
88
+ private
89
+
90
+ def split_title_and_body(raw)
91
+ return nil if raw.nil? || raw.empty?
92
+ lines = raw.split("\n")
93
+ title = lines.shift
94
+ lines.shift
95
+ body = lines.join("\n")
96
+ [title, body]
97
+ end
98
+ end
99
+
100
+ class Attachment
101
+ class << self
102
+ attr_reader :dir
103
+ def setup(dir)
104
+ @dir = dir
105
+ end
106
+
107
+ def find(name)
108
+ store[store_path(name)]
109
+ end
110
+
111
+ def store_path(name)
112
+ File.join(dir, name)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,17 @@
1
+ Home
2
+
3
+ Gitki is a wiki using git to store data.
4
+
5
+ h3. Source
6
+
7
+ "http://github.com/jugyo/gitki/tree/master":http://github.com/jugyo/gitki/tree/master
8
+
9
+ h3. Examples
10
+
11
+ * list
12
+ * list
13
+
14
+ # list
15
+ # list
16
+
17
+ !/files/gitki.png!
@@ -0,0 +1,4 @@
1
+ Navigation
2
+
3
+ * "Home":/
4
+ * "Pages":/pages
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ title: Gitki!!
2
+ git_store: ~/gitki.git
3
+ markup: textile
@@ -0,0 +1,104 @@
1
+ $: << File.dirname(__FILE__) + '/../'
2
+ require 'lib/gitki'
3
+ require 'tmpdir'
4
+ require 'ruby-debug'
5
+ require 'fileutils'
6
+
7
+ include Gitki
8
+
9
+ describe Gitki do
10
+ REPO = File.join Dir.tmpdir, 'git_store_test'
11
+
12
+ before(:each) do
13
+ FileUtils.rm_rf REPO
14
+ Dir.mkdir REPO
15
+ Dir.chdir(REPO) do |path|
16
+ system 'git', 'init', '--bare'
17
+ end
18
+ end
19
+
20
+ describe 'repository is empty' do
21
+ it 'should create defaults' do
22
+ Gitki.should_receive(:create_defaults)
23
+ Gitki.setup(REPO)
24
+ end
25
+
26
+ it 'should return 2 pages' do
27
+ Gitki.setup(REPO)
28
+
29
+ pages = Page.find_all
30
+ pages.size.should == 2
31
+
32
+ page = Page.find('home')
33
+ page.title.should == "Home"
34
+
35
+ page = Page.find('navigation')
36
+ page.title.should == "Navigation"
37
+ end
38
+
39
+ it 'should return a file' do
40
+ Gitki.setup(REPO)
41
+ file = Attachment.find('gitki.png').should_not be_nil
42
+ end
43
+ end
44
+
45
+ describe 'repository is not empty' do
46
+ before(:each) do
47
+ store = GitStore.new(REPO, 'master', true)
48
+ store['test.txt'] = 'test'
49
+ store.commit 'Added test.txt'
50
+ end
51
+
52
+ it 'should not create defaults' do
53
+ Gitki.should_not_receive(:create_defaults)
54
+ Gitki.setup(REPO)
55
+ end
56
+ end
57
+
58
+ describe Page do
59
+ before(:each) do
60
+ Gitki.setup(REPO)
61
+ @@store.delete('wiki/home')
62
+ @@store.delete('wiki/navigation')
63
+ end
64
+
65
+ describe 'create 2 page' do
66
+ before(:each) do
67
+ @@store[Page.dir + '/foo'] = <<-EOS
68
+ foo
69
+
70
+ foo foo foo
71
+ EOS
72
+ @@store[Page.dir + '/bar'] = <<-EOS
73
+ bar
74
+
75
+ bar bar bar
76
+ EOS
77
+ end
78
+
79
+ it 'should return 2 pages' do
80
+ pages = Page.find_all
81
+ pages.size.should == 2
82
+
83
+ page = pages['foo']
84
+ page.title.should == 'foo'
85
+ page.body.should == 'foo foo foo'
86
+
87
+ page = pages['bar']
88
+ page.title.should == 'bar'
89
+ page.body.should == 'bar bar bar'
90
+ end
91
+ end
92
+ end
93
+
94
+ describe Attachment do
95
+ before(:each) do
96
+ Gitki.setup(REPO)
97
+ Gitki.store['files/test.txt'] = 'test'
98
+ end
99
+
100
+ it 'should get file content' do
101
+ Attachment.find('test.txt').should == 'test'
102
+ end
103
+ end
104
+ end