stoor 0.1.9 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,12 +9,10 @@ so that we can constrain access by GitHub Organization Team membership.
9
9
 
10
10
  ## Requirements
11
11
 
12
- Ruby 1.9.2 or greater.
13
-
14
- An operating system other than Windows (because Gollum doesn't work on Windows, because grit doesn't work on Windows . . .).
15
-
16
- Unfortunately, Stoor will no longer work on Ruby 1.8.7, because `gollum-lib` now wants Nokogiri 1.6.0 ([see?](https://github.com/gollum/gollum-lib/commit/eeb0a4a036001c7621d173e7152b91ed02b21ed0#commitcomment-4170065)), and
17
- 1.8.7 isn't supported. That's too bad, because it was nice that this would work on the system Ruby on a Mac.
12
+ * Ruby 1.9.2 or greater. Unfortunately, Stoor will no longer work on Ruby 1.8.7, because `gollum-lib` now wants Nokogiri 1.6.0 ([see?](https://github.com/gollum/gollum-lib/commit/eeb0a4a036001c7621d173e7152b91ed02b21ed0#commitcomment-4170065)), and
13
+ 1.8.7 isn't supported. That's too bad, because it was nice that this would work on the older system Ruby on a Mac.
14
+ * Persistent access to the filesystem (i.e., won't work on Heroku).
15
+ * An operating system other than Windows (because Gollum doesn't work on Windows, because [grit doesn't work on Windows . . .](https://github.com/gollum/gollum#system-requirements)).
18
16
 
19
17
  ## Setup
20
18
 
@@ -46,6 +44,13 @@ If you don't have a repo yet for your wiki . . .
46
44
  git init .
47
45
  stoor
48
46
 
47
+ ### Configuration via environment variables
48
+
49
+ Stoor is configured via environment variables of the form `<name>_<some token>`. `<name>` is taken from the name
50
+ of the directory in which the application resides. If you clone the app or use it as a Gem, it will be: `STOOR`
51
+ If you clone into a directory with a different name (e.g., `stoor2`) it will be: `STOOR2`. This facilitates running
52
+ two instances of Stoor in the same process (see below regarding Apache).
53
+
49
54
  ### Specify the Wiki repo location
50
55
 
51
56
  STOOR_WIKI_PATH=/Users/admin/wiki stoor
@@ -150,6 +155,46 @@ and finally:
150
155
 
151
156
  Now browse your wiki at <http://wiki.local>
152
157
 
158
+ ### Running two instances of Stoor in the same Apache
159
+
160
+ You may want to run two instances of Stoor in the same Apache. For instance, they might both use the same Wiki path,
161
+ but one is set to be read-only, while the other allows edits.
162
+
163
+ To do this, don't set the DocumentRoot to the Gem directory. Intead, clone the repo twice, once into a directory
164
+ such as `stoor1` the other into `stoor2`. Then configure
165
+ the two VirtualHosts with environment variables based on each directory. Something like this:
166
+
167
+ <VirtualHost *:80>
168
+ SetEnv STOOR1_GITHUB_CLIENT_ID 780ec06a331b4f61a345
169
+ SetEnv STOOR1_GITHUB_CLIENT_SECRET f1e5439aff166c34f707747120acbf66ef233fc2
170
+ SetEnv STOOR1_GITHUB_EMAIL_DOMAIN 7fff.com
171
+ SetEnv STOOR1_DOMAIN wiki.local
172
+ SetEnv STOOR1_EXPIRE_AFTER 60
173
+ SetEnv STOOR1_WIKI_PATH /Users/jgn/Dropbox/wiki
174
+ ServerName wiki.local
175
+ DocumentRoot "/Users/jgn/src/stoor1"
176
+ <Directory "/Users/jgn/src/stoor1">
177
+ Allow from all
178
+ Options -MultiViews
179
+ </Directory>
180
+ </VirtualHost>
181
+
182
+ <VirtualHost *:80>
183
+ SetEnv STOOR2_GITHUB_CLIENT_ID 780ec06a331b4f61a345
184
+ SetEnv STOOR2_GITHUB_CLIENT_SECRET f1e5439aff166c34f707747120acbf66ef233fc2
185
+ SetEnv STOOR2_GITHUB_EMAIL_DOMAIN 7fff.com
186
+ SetEnv STOOR2_DOMAIN wiki.local
187
+ SetEnv STOOR2_EXPIRE_AFTER 60
188
+ SetEnv STOOR2_WIKI_PATH /Users/jgn/Dropbox/wiki
189
+ SetEnv STOOR2_READONLY y
190
+ ServerName wiki-readonly.local
191
+ DocumentRoot "/Users/jgn/src/stoor2"
192
+ <Directory "/Users/jgn/src/stoor2">
193
+ Allow from all
194
+ Options -MultiViews
195
+ </Directory>
196
+ </VirtualHost>
197
+
153
198
  ## Links in the Wiki
154
199
 
155
200
  A bit of advice: Use the MediaWiki format for links internal to your wiki. This style is recommended by GitHub (see <https://help.github.com/articles/how-do-i-add-links-to-my-wiki>).
@@ -178,6 +223,8 @@ the displayed paths prefix URLs with an extra `base_path`.)
178
223
 
179
224
  ## Testing
180
225
 
226
+ Ensure that you clone to a directory called `stoor`, because the ENV variables adopt the name of the home directory.
227
+
181
228
  To run the specs, create an application per "GitHub Authorization" above, and take note of the client id and client secret.
182
229
 
183
230
  Then set up Stoor so that you are running with GitHub authorization. Authorize.
data/bin/stoor CHANGED
@@ -2,9 +2,12 @@
2
2
 
3
3
  require 'thin'
4
4
 
5
- config_ru = File.expand_path(File.join(File.dirname(__FILE__), '..', 'config.ru'))
5
+ dirname = File.dirname(__FILE__)
6
+ env_key = dirname.split(File::SEPARATOR).last.upcase
6
7
 
7
- ENV['STOOR_WIKI_PATH'] ||= '.'
8
+ config_ru = File.expand_path(File.join(dirname, '..', 'config.ru'))
9
+
10
+ ENV["#{@env_key}_WIKI_PATH"] ||= '.'
8
11
 
9
12
  ARGV.unshift config_ru
10
13
  ARGV.unshift '-R'
data/config.ru CHANGED
@@ -2,67 +2,47 @@
2
2
 
3
3
  $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
4
4
  require 'rubygems'
5
- require 'logger'
6
5
  require 'bundler/setup'
7
6
  require 'sinatra_auth_github'
8
7
  require 'gollum/app'
9
8
  require 'stoor'
9
+ require 'rack/null_logger'
10
10
 
11
- # Force the NullLogger to be a no-op, since it keeps getting bound into the
12
- # Request instance.
13
- module Rack
14
- class NullLogger
15
- def initialize(app)
16
- @app = app
17
- end
11
+ ENV['RACK_ENV'] ||= 'development'
18
12
 
19
- def call(env)
20
- @app.call(env)
21
- end
22
- end
23
- end
13
+ config = Stoor::Config.new(__FILE__)
24
14
 
25
- ENV['RACK_ENV'] ||= 'development'
15
+ domain = config.env('DOMAIN') || 'localhost'
16
+ secret = config.env('SECRET') || 'stoor'
17
+ expire_after = (config.env('EXPIRE_AFTER') || '3600').to_i
26
18
 
27
- domain = ENV['STOOR_DOMAIN'] || 'localhost'
28
- secret = ENV['STOOR_SECRET'] || 'stoor'
29
- expire_after = (ENV['STOOR_EXPIRE_AFTER'] || '3600').to_i
30
19
 
31
- log_frag = "#{File.dirname(__FILE__)}/log/#{ENV['RACK_ENV']}"
32
- access_logger = Logger.new("#{log_frag}_access.log")
33
- access_logger.instance_eval do
34
- def write(msg); self.send(:<<, msg); end
35
- end
36
- access_logger.level = Logger::INFO
37
- log_stream = File.open("#{log_frag}.log", 'a+')
38
- log_stream.sync = true
20
+ gollum_path = config.env('WIKI_PATH') || File.expand_path(File.dirname(__FILE__))
39
21
 
40
- gollum_path = ENV['STOOR_WIKI_PATH'] || File.expand_path(File.dirname(__FILE__))
41
- repo_exists = true
42
- begin
43
- Gollum::Wiki.new(gollum_path)
44
- rescue Gollum::InvalidGitRepositoryError
45
- repo_exists = false
46
- message = "Sorry, #{gollum_path} is not a git repository; you might try `cd #{gollum_path}; git init .`."
47
- rescue NameError
48
- repo_exists = false
49
- message = "Sorry, #{gollum_path} doesn't exist; set the environment variable STOOR_WIKI_PATH to point to a git repository."
50
- end
22
+ config.dump_env
23
+ config.log "gollum_path = #{gollum_path}"
51
24
 
52
- use Rack::Session::Cookie, :domain => domain, :key => 'rack.session', :secret => secret, :expire_after => expire_after
53
- use Rack::CommonLogger, access_logger
54
- use Stoor::Logger, log_stream, Logger::INFO
55
- if repo_exists
25
+ if message = config.repo_missing?(gollum_path)
26
+ puts message
27
+ run Proc.new { |env| [ 200, { 'Content-Type' => 'text/plain' }, [ message ] ] }
28
+ else
29
+ use Rack::Session::Cookie, :domain => domain, :key => 'rack.session', :secret => secret, :expire_after => expire_after
30
+ use Rack::CommonLogger, config.access_logger
31
+ use Stoor::Logger, config.log_stream, Logger::INFO
32
+
33
+ scopes = [ 'user:email' ]
34
+ scopes << 'user' if config.env('GITHUB_TEAM_ID')
56
35
  Stoor::GithubAuth.set :github_options, {
57
- scopes: 'user:email',
58
- client_id: ENV['STOOR_GITHUB_CLIENT_ID'],
59
- secret: ENV['STOOR_GITHUB_CLIENT_SECRET']
36
+ scopes: scopes.join(','),
37
+ client_id: config.env('GITHUB_CLIENT_ID'),
38
+ secret: config.env('GITHUB_CLIENT_SECRET')
60
39
  }
61
40
  Stoor::GithubAuth.set :stoor_options, {
62
- github_team_id: ENV['STOOR_GITHUB_TEAM_ID'],
63
- github_email_domain: ENV['STOOR_GITHUB_EMAIL_DOMAIN']
41
+ github_team_id: config.env('GITHUB_TEAM_ID'),
42
+ github_email_domain: config.env('GITHUB_EMAIL_DOMAIN')
64
43
  }
65
44
  use Stoor::GithubAuth
45
+
66
46
  use Stoor::GitConfig, gollum_path
67
47
  use Stoor::TransformContent,
68
48
  pass_condition: ->(request) { request.session['gollum.author'].nil? },
@@ -82,12 +62,12 @@ if repo_exists
82
62
  </div>
83
63
  HTML
84
64
  end
85
- if ENV['STOOR_WIDE']
65
+ if config.env('WIDE')
86
66
  use Stoor::TransformContent,
87
67
  regexp: /<body>/,
88
68
  after: '<style type="text/css">#wiki-wrapper { width: 90%; } .markdown-body table { width: 100%; }</style>'
89
69
  end
90
- if ENV['STOOR_READONLY']
70
+ if config.env('READONLY')
91
71
  use Stoor::ReadOnly, '/sorry'
92
72
  use Stoor::TransformContent,
93
73
  regexp: /<body>/,
@@ -105,7 +85,4 @@ if repo_exists
105
85
  Precious::App.set(:default_markup, :markdown)
106
86
  Precious::App.set(:wiki_options, { :universal_toc =>false })
107
87
  run Precious::App
108
- else
109
- run Proc.new { |env| [ 200, { 'Content-Type' => 'text/plain' }, [ message ] ] }
110
- puts message
111
88
  end
@@ -0,0 +1,13 @@
1
+ # Force the NullLogger to be a no-op, since it keeps getting bound into the
2
+ # Request instance.
3
+ module Rack
4
+ class NullLogger
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ @app.call(env)
11
+ end
12
+ end
13
+ end
data/lib/stoor.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'stoor/logger'
2
+ require 'stoor/config'
2
3
  require 'stoor/github_auth'
3
4
  require 'stoor/git_config'
4
5
  require 'stoor/read_only'
@@ -0,0 +1,68 @@
1
+ require 'logger'
2
+
3
+ module Stoor
4
+ class Config
5
+ def initialize(file)
6
+ @file = file
7
+ end
8
+
9
+ def dirname
10
+ @dirname ||= begin
11
+ dirname = File.dirname(@file)
12
+ dirname = `pwd`.chomp if dirname == '.' # Probably being run by Apache
13
+ dirname
14
+ end
15
+ end
16
+
17
+ def env_prefix
18
+ @env_prefix ||= dirname.split(File::SEPARATOR).last.upcase
19
+ end
20
+
21
+ def env(token)
22
+ ENV["#{env_prefix}_#{token}"]
23
+ end
24
+
25
+ def log(m)
26
+ log_stream.write(m + "\n")
27
+ end
28
+
29
+ def log_frag
30
+ @log_frag ||= "#{dirname}/log/#{ENV['RACK_ENV']}"
31
+ end
32
+
33
+ def access_logger
34
+ @access_logger ||= begin
35
+ access_logger = ::Logger.new("#{log_frag}_access.log")
36
+ access_logger.instance_eval do
37
+ def write(msg); self.send(:<<, msg); end
38
+ end
39
+ access_logger.level = ::Logger::INFO
40
+ access_logger
41
+ end
42
+ end
43
+
44
+ def log_stream
45
+ @log_stream ||= begin
46
+ log_stream = File.open("#{log_frag}.log", 'a+')
47
+ log_stream.sync = true
48
+ log_stream
49
+ end
50
+ end
51
+
52
+ def dump_env
53
+ log "#{env_prefix} env"
54
+ ENV.each_pair do |k, v|
55
+ log " #{k}: #{v}" if k =~ /\A#{env_prefix}/
56
+ end
57
+ end
58
+
59
+ def repo_missing?(path)
60
+ Gollum::Wiki.new(path)
61
+ return nil
62
+ rescue Gollum::InvalidGitRepositoryError, Gollum::NoSuchPathError
63
+ return "Sorry, #{path} is not a git repository; you might try `cd #{path}; git init .`."
64
+ rescue NameError
65
+ return "Sorry, #{path} doesn't exist; set the environment variable STOOR_WIKI_PATH to point to a git repository."
66
+ end
67
+ end
68
+ end
data/lib/stoor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stoor
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.11'
3
3
  end
data/stoor.gemspec CHANGED
@@ -17,10 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files spec`.split("\n")
18
18
  s.executables << 'stoor'
19
19
  s.add_dependency 'thin', '~> 1.5.1'
20
- s.add_dependency 'gollum', '~> 2.5.0'
20
+ s.add_dependency 'gollum', '~> 2.5.2'
21
21
  s.add_dependency 'sinatra_auth_github', '~> 1.0.0'
22
- s.add_dependency 'json', '~> 1.8.0'
23
- s.add_dependency 'grit', '~> 2.5.0'
24
22
 
25
23
  s.add_development_dependency 'warden-github', '~> 1.0.0'
26
24
  s.add_development_dependency 'rack-test', '~> 0.6.2'
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - John G. Norman
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-11-01 00:00:00.000000000 Z
12
+ date: 2013-11-09 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: thin
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,20 +30,23 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: gollum
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
33
- version: 2.5.0
37
+ version: 2.5.2
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
40
- version: 2.5.0
45
+ version: 2.5.2
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: sinatra_auth_github
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ~>
46
52
  - !ruby/object:Gem::Version
@@ -48,41 +54,15 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: 1.0.0
55
- - !ruby/object:Gem::Dependency
56
- name: json
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 1.8.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: 1.8.0
69
- - !ruby/object:Gem::Dependency
70
- name: grit
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- version: 2.5.0
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: 2.5.0
83
62
  - !ruby/object:Gem::Dependency
84
63
  name: warden-github
85
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
86
66
  requirements:
87
67
  - - ~>
88
68
  - !ruby/object:Gem::Version
@@ -90,6 +70,7 @@ dependencies:
90
70
  type: :development
91
71
  prerelease: false
92
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
93
74
  requirements:
94
75
  - - ~>
95
76
  - !ruby/object:Gem::Version
@@ -97,6 +78,7 @@ dependencies:
97
78
  - !ruby/object:Gem::Dependency
98
79
  name: rack-test
99
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
100
82
  requirements:
101
83
  - - ~>
102
84
  - !ruby/object:Gem::Version
@@ -104,6 +86,7 @@ dependencies:
104
86
  type: :development
105
87
  prerelease: false
106
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
107
90
  requirements:
108
91
  - - ~>
109
92
  - !ruby/object:Gem::Version
@@ -111,6 +94,7 @@ dependencies:
111
94
  - !ruby/object:Gem::Dependency
112
95
  name: rspec
113
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
114
98
  requirements:
115
99
  - - ~>
116
100
  - !ruby/object:Gem::Version
@@ -118,6 +102,7 @@ dependencies:
118
102
  type: :development
119
103
  prerelease: false
120
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
121
106
  requirements:
122
107
  - - ~>
123
108
  - !ruby/object:Gem::Version
@@ -136,7 +121,9 @@ files:
136
121
  - Rakefile
137
122
  - bin/stoor
138
123
  - config.ru
124
+ - lib/rack/null_logger.rb
139
125
  - lib/stoor.rb
126
+ - lib/stoor/config.rb
140
127
  - lib/stoor/git_config.rb
141
128
  - lib/stoor/github_auth.rb
142
129
  - lib/stoor/logger.rb
@@ -159,27 +146,28 @@ files:
159
146
  homepage: https://github.com/jgn/stoor
160
147
  licenses:
161
148
  - MIT
162
- metadata: {}
163
149
  post_install_message:
164
150
  rdoc_options:
165
151
  - --charset=UTF-8
166
152
  require_paths:
167
153
  - lib
168
154
  required_ruby_version: !ruby/object:Gem::Requirement
155
+ none: false
169
156
  requirements:
170
157
  - - ! '>='
171
158
  - !ruby/object:Gem::Version
172
159
  version: '0'
173
160
  required_rubygems_version: !ruby/object:Gem::Requirement
161
+ none: false
174
162
  requirements:
175
163
  - - ! '>='
176
164
  - !ruby/object:Gem::Version
177
165
  version: '0'
178
166
  requirements: []
179
167
  rubyforge_project:
180
- rubygems_version: 2.1.10
168
+ rubygems_version: 1.8.23
181
169
  signing_key:
182
- specification_version: 4
170
+ specification_version: 3
183
171
  summary: Front-end for Gollum
184
172
  test_files:
185
173
  - spec/lib/stoor/git_config_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZmU2OTA0ZjI4ZjY4MWZlZWI1MTQ0OWE2YTI0MGIyYWQxNDk1Mjk4Ng==
5
- data.tar.gz: !binary |-
6
- YzVhZWM1MGU5Y2NhMGZkNGJiYmM5OGVhMGVhYzZkODYxYWY0ODQxNA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- ZDJmMDE1YjcyY2E4Yzc4MTEyZmE5MTUwMTg5ZmNjNzVhOWEwZmQyZDcxOGJk
10
- M2E5NzVjZWMwM2VhOTRiZTZmNDkwNTIxOTQ2Mzc4MGIyMTNiMzJjODM1MDRi
11
- MmQ3YTE4MGRmZTNkZmVkZjk2MDg4NGZiY2FhNTdlOGU3NGM5ZTg=
12
- data.tar.gz: !binary |-
13
- MTIwNzc0NGJhNzRkYWI5MjMzNDEzYmQ2MWY4N2NkOTgxNjgzMTNlNThlNDVl
14
- NzI3NTBmMWYxMWYwYjJiNzljNmNiYmQ1Yzc1N2U0ZjZiNjkzMTNlYzIwYTgx
15
- MDYwODRlYTU1ZWFlZWFkNTlkOTNkMDRhMWMxZjM5NTIzMjIwNTM=