smeagol 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@ Smeagol is a server that can run a read-only version of a
8
8
  to maintain a standalone copy of a Github wiki but you want to update it through
9
9
  the Github interface.
10
10
 
11
- Gollum follows the rules of [Semantic Versioning](http://semver.org/) and uses
11
+ Smeagol follows the rules of [Semantic Versioning](http://semver.org/) and uses
12
12
  [TomDoc](http://tomdoc.org/) for inline documentation.
13
13
 
14
14
 
data/bin/smeagol CHANGED
@@ -1,28 +1,44 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
- require 'bundler/setup'
3
+ require 'daemons'
4
4
  require 'optparse'
5
5
  require 'ostruct'
6
6
  require File.expand_path(File.dirname(__FILE__) + '/../lib/smeagol')
7
7
 
8
+ # Catch signals
9
+ Signal.trap('TERM') do
10
+ Process.kill('KILL', 0)
11
+ end
12
+
8
13
  # Parse options
9
14
  options = Smeagol::OptionParser.parse(ARGV)
10
15
 
16
+ # Show repositories being served
17
+ $stderr.puts "\n Now serving:"
18
+ options.repositories.each do |repository|
19
+ $stderr.puts " #{repository.path} (#{repository.cname})"
20
+ end
21
+ $stderr.puts "\n"
22
+
11
23
  # Run the auto update process
12
24
  if options.git && options.auto_update
13
25
  Thread.new do
14
26
  while true do
15
27
  sleep 86400
16
- Smeagol::Updater.update(options.git, options.gollum_path)
28
+ options.repositories.each do |repository|
29
+ Smeagol::Updater.update(options.git, repository.path)
30
+ end
17
31
  end
18
32
  end
19
33
  end
20
34
 
21
- # Clear the cache
22
- Smeagol::Cache.new(Gollum::Wiki.new(options.gollum_path)).clear()
35
+ # Clear the caches
36
+ options.repositories.each do |repository|
37
+ Smeagol::Cache.new(Gollum::Wiki.new(repository.path)).clear()
38
+ end
23
39
 
24
40
  # Run the web server
25
- Smeagol::App.set(:gollum_path, options.gollum_path)
41
+ Smeagol::App.set(:repositories, options.repositories)
26
42
  Smeagol::App.set(:git, options.git)
27
43
  Smeagol::App.set(:cache_enabled, options.cache_enabled)
28
44
  Smeagol::App.run!(:port => options.port)
data/bin/smeagold ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'daemons'
4
+
5
+ filename = File.expand_path('smeagol', File.dirname(__FILE__))
6
+ Daemons.run(filename)
data/lib/smeagol/app.rb CHANGED
@@ -24,7 +24,7 @@ module Smeagol
24
24
 
25
25
  # Update the gollum repository
26
26
  get '/update' do
27
- if Updater.update(settings.git, settings.gollum_path)
27
+ if Updater.update(settings.git, repository)
28
28
  'ok'
29
29
  else
30
30
  'error'
@@ -37,10 +37,10 @@ module Smeagol
37
37
  name = "Home" if name == ""
38
38
  name = name.gsub(/\/+$/, '')
39
39
  name = File.sanitize_path(name)
40
- file_path = "#{settings.gollum_path}/#{name}"
40
+ file_path = "#{repository.path}/#{name}"
41
41
 
42
42
  # Load the wiki settings
43
- wiki = Smeagol::Wiki.new(settings.gollum_path)
43
+ wiki = Smeagol::Wiki.new(repository.path)
44
44
  cache = Smeagol::Cache.new(wiki)
45
45
 
46
46
  # First check the cache
@@ -78,8 +78,8 @@ module Smeagol
78
78
  # repository if it exists. Otherwise, it uses the default page.mustache file
79
79
  # packaged with the Smeagol library.
80
80
  def page_template
81
- if File.exists?("#{settings.gollum_path}/page.mustache")
82
- IO.read("#{settings.gollum_path}/page.mustache")
81
+ if File.exists?("#{repository.path}/page.mustache")
82
+ IO.read("#{repository.path}/page.mustache")
83
83
  else
84
84
  IO.read(File.join(File.dirname(__FILE__), 'templates/page.mustache'))
85
85
  end
@@ -98,5 +98,19 @@ module Smeagol
98
98
 
99
99
  return 'text/plain'
100
100
  end
101
+
102
+ # Determines the repository to use based on the hostname.
103
+ def repository
104
+ # Match on hostname
105
+ settings.repositories.each do |repository|
106
+ next if repository.cname.nil?
107
+ if repository.cname.upcase == request.host.upcase
108
+ return repository
109
+ end
110
+ end
111
+
112
+ # If no match, use the first repository as the default
113
+ settings.repositories.first
114
+ end
101
115
  end
102
116
  end
@@ -57,8 +57,16 @@ module Smeagol
57
57
  # Attempt to find the git binary
58
58
  update_git_path(opts)
59
59
 
60
- # Set the path to the Gollum repository if not already set
61
- opts.gollum_path ||= args[0] || Dir.pwd
60
+ # Append repositories from the command line.
61
+ opts.repositories ||= []
62
+ if !args.first.nil?
63
+ opts.repositories.unshift({:path => args.first}.to_ostruct)
64
+ end
65
+
66
+ # Set repository to present working directory if no paths specified.
67
+ if opts.repositories.empty?
68
+ opts.repositories = [{:path => Dir.pwd}.to_ostruct]
69
+ end
62
70
 
63
71
  # Merge all options
64
72
  return opts
@@ -96,7 +104,6 @@ module Smeagol
96
104
  end
97
105
 
98
106
  config = YAML.load(IO.read(path))
99
- p config
100
107
  end
101
108
 
102
109
  return config
@@ -0,0 +1,5 @@
1
+ // html5shiv MIT @rem remysharp.com/html5-enabling-script
2
+ // iepp v1.5.1 MIT @jon_neal iecss.com/print-protector
3
+ /*@cc_on(function(p,e){var q=e.createElement("div");q.innerHTML="<z>i</z>";q.childNodes.length!==1&&function(){function r(a,b){if(g[a])g[a].styleSheet.cssText+=b;else{var c=s[l],d=e[j]("style");d.media=a;c.insertBefore(d,c[l]);g[a]=d;r(a,b)}}function t(a,b){for(var c=new RegExp("\\b("+m+")\\b(?!.*[;}])","gi"),d=function(k){return".iepp_"+k},h=-1;++h<a.length;){b=a[h].media||b;t(a[h].imports,b);r(b,a[h].cssText.replace(c,d))}}for(var s=e.documentElement,i=e.createDocumentFragment(),g={},m="abbr article aside audio canvas details figcaption figure footer header hgroup mark meter nav output progress section summary time video".replace(/ /g, '|'),
4
+ n=m.split("|"),f=[],o=-1,l="firstChild",j="createElement";++o<n.length;){e[j](n[o]);i[j](n[o])}i=i.appendChild(e[j]("div"));p.attachEvent("onbeforeprint",function(){for(var a,b=e.getElementsByTagName("*"),c,d,h=new RegExp("^"+m+"$","i"),k=-1;++k<b.length;)if((a=b[k])&&(d=a.nodeName.match(h))){c=new RegExp("^\\s*<"+d+"(.*)\\/"+d+">\\s*$","i");i.innerHTML=a.outerHTML.replace(/\r|\n/g," ").replace(c,a.currentStyle.display=="block"?"<div$1/div>":"<span$1/span>");c=i.childNodes[0];c.className+=" iepp_"+
5
+ d;c=f[f.length]=[a,c];a.parentNode.replaceChild(c[1],c[0])}t(e.styleSheets,"all")});p.attachEvent("onafterprint",function(){for(var a=-1,b;++a<f.length;)f[a][1].parentNode.replaceChild(f[a][0],f[a][1]);for(b in g)s[l].removeChild(g[b]);g={};f=[]})}()})(this,document);@*/
@@ -5,6 +5,10 @@
5
5
  <title>{{wiki_title}} - {{page_title}}</title>
6
6
  <link rel="stylesheet" href="/smeagol/main.css" type="text/css"/>
7
7
  <link rel="stylesheet" href="/smeagol/pygment.css" type="text/css"/>
8
+
9
+ <!--[if lt IE 9]>
10
+ <script src="/smeagol/html5.js"></script>
11
+ <![endif]-->
8
12
  </head>
9
13
 
10
14
  <body>
@@ -3,19 +3,22 @@ module Smeagol
3
3
  # Public: Updates the repository that the server is point at.
4
4
  #
5
5
  # git - The path to the git binary.
6
- # repo - The path to the git repository to update.
6
+ # path - The paths to the git repository to update.
7
7
  #
8
8
  # Returns true if successful. Otherwise returns false.
9
- def self.update(git, repo)
9
+ def self.update(git, path)
10
+ # TODO: Change this method to raise errors if something goes wrong instead
11
+ # of returning a status.
12
+
10
13
  # If the git executable is available, pull from master and check status.
11
- if !git.nil? && !repo.nil?
12
- output = `cd #{repo} && #{git} pull origin master 2>/dev/null`
13
-
14
+ if !git.nil? && !path.nil?
15
+ output = `cd #{path} && #{git} pull origin master 2>/dev/null`
16
+
14
17
  # Write update to log if something happened
15
18
  if output.index('Already up-to-date').nil?
16
- puts "==Repository updated at #{Time.new()}=="
19
+ $stderr.puts "==Repository updated at #{Time.new()} : #{path}=="
17
20
  end
18
-
21
+
19
22
  return $? == 0
20
23
  # Otherwise return false.
21
24
  else
@@ -1,3 +1,3 @@
1
1
  module Smeagol
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
data/test/helper.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- require 'bundler/setup'
3
2
  require 'minitest/autorun'
4
3
  require 'mocha'
5
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smeagol
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Johnson
@@ -15,27 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-30 00:00:00 -06:00
18
+ date: 2010-10-01 00:00:00 -06:00
19
19
  default_executable: smeagol
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 23
28
- segments:
29
- - 1
30
- - 0
31
- - 0
32
- version: 1.0.0
33
- requirement: *id001
34
- type: :runtime
35
- name: bundler
22
+ name: rack
36
23
  prerelease: false
37
- - !ruby/object:Gem::Dependency
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
39
25
  none: false
40
26
  requirements:
41
27
  - - "="
@@ -46,12 +32,12 @@ dependencies:
46
32
  - 2
47
33
  - 0
48
34
  version: 1.2.0
49
- requirement: *id002
50
35
  type: :runtime
51
- name: rack
52
- prerelease: false
36
+ version_requirements: *id001
53
37
  - !ruby/object:Gem::Dependency
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
38
+ name: gollum
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
55
41
  none: false
56
42
  requirements:
57
43
  - - ~>
@@ -62,12 +48,12 @@ dependencies:
62
48
  - 0
63
49
  - 1
64
50
  version: 1.0.1
65
- requirement: *id003
66
51
  type: :runtime
67
- name: gollum
68
- prerelease: false
52
+ version_requirements: *id002
69
53
  - !ruby/object:Gem::Dependency
70
- version_requirements: &id004 !ruby/object:Gem::Requirement
54
+ name: sinatra
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
71
57
  none: false
72
58
  requirements:
73
59
  - - ~>
@@ -77,12 +63,12 @@ dependencies:
77
63
  - 1
78
64
  - 0
79
65
  version: "1.0"
80
- requirement: *id004
81
66
  type: :runtime
82
- name: sinatra
83
- prerelease: false
67
+ version_requirements: *id003
84
68
  - !ruby/object:Gem::Dependency
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
69
+ name: mustache
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
86
72
  none: false
87
73
  requirements:
88
74
  - - ~>
@@ -93,12 +79,12 @@ dependencies:
93
79
  - 11
94
80
  - 2
95
81
  version: 0.11.2
96
- requirement: *id005
97
82
  type: :runtime
98
- name: mustache
99
- prerelease: false
83
+ version_requirements: *id004
100
84
  - !ruby/object:Gem::Dependency
101
- version_requirements: &id006 !ruby/object:Gem::Requirement
85
+ name: OptionParser
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
102
88
  none: false
103
89
  requirements:
104
90
  - - ~>
@@ -109,40 +95,28 @@ dependencies:
109
95
  - 5
110
96
  - 1
111
97
  version: 0.5.1
112
- requirement: *id006
113
98
  type: :runtime
114
- name: OptionParser
115
- prerelease: false
99
+ version_requirements: *id005
116
100
  - !ruby/object:Gem::Dependency
117
- version_requirements: &id007 !ruby/object:Gem::Requirement
118
- none: false
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- hash: 3
123
- segments:
124
- - 0
125
- version: "0"
126
- requirement: *id007
127
- type: :runtime
128
- name: rdiscount
101
+ name: daemons
129
102
  prerelease: false
130
- - !ruby/object:Gem::Dependency
131
- version_requirements: &id008 !ruby/object:Gem::Requirement
103
+ requirement: &id006 !ruby/object:Gem::Requirement
132
104
  none: false
133
105
  requirements:
134
- - - ">="
106
+ - - ~>
135
107
  - !ruby/object:Gem::Version
136
- hash: 3
108
+ hash: 19
137
109
  segments:
110
+ - 1
111
+ - 1
138
112
  - 0
139
- version: "0"
140
- requirement: *id008
113
+ version: 1.1.0
141
114
  type: :runtime
142
- name: RedCloth
143
- prerelease: false
115
+ version_requirements: *id006
144
116
  - !ruby/object:Gem::Dependency
145
- version_requirements: &id009 !ruby/object:Gem::Requirement
117
+ name: rake
118
+ prerelease: false
119
+ requirement: &id007 !ruby/object:Gem::Requirement
146
120
  none: false
147
121
  requirements:
148
122
  - - ~>
@@ -153,12 +127,12 @@ dependencies:
153
127
  - 8
154
128
  - 3
155
129
  version: 0.8.3
156
- requirement: *id009
157
130
  type: :development
158
- name: rake
159
- prerelease: false
131
+ version_requirements: *id007
160
132
  - !ruby/object:Gem::Dependency
161
- version_requirements: &id010 !ruby/object:Gem::Requirement
133
+ name: minitest
134
+ prerelease: false
135
+ requirement: &id008 !ruby/object:Gem::Requirement
162
136
  none: false
163
137
  requirements:
164
138
  - - ~>
@@ -169,12 +143,12 @@ dependencies:
169
143
  - 7
170
144
  - 0
171
145
  version: 1.7.0
172
- requirement: *id010
173
146
  type: :development
174
- name: minitest
175
- prerelease: false
147
+ version_requirements: *id008
176
148
  - !ruby/object:Gem::Dependency
177
- version_requirements: &id011 !ruby/object:Gem::Requirement
149
+ name: mocha
150
+ prerelease: false
151
+ requirement: &id009 !ruby/object:Gem::Requirement
178
152
  none: false
179
153
  requirements:
180
154
  - - ~>
@@ -185,12 +159,12 @@ dependencies:
185
159
  - 9
186
160
  - 8
187
161
  version: 0.9.8
188
- requirement: *id011
189
162
  type: :development
190
- name: mocha
191
- prerelease: false
163
+ version_requirements: *id009
192
164
  - !ruby/object:Gem::Dependency
193
- version_requirements: &id012 !ruby/object:Gem::Requirement
165
+ name: cucumber
166
+ prerelease: false
167
+ requirement: &id010 !ruby/object:Gem::Requirement
194
168
  none: false
195
169
  requirements:
196
170
  - - ~>
@@ -201,12 +175,12 @@ dependencies:
201
175
  - 8
202
176
  - 5
203
177
  version: 0.8.5
204
- requirement: *id012
205
178
  type: :development
206
- name: cucumber
207
- prerelease: false
179
+ version_requirements: *id010
208
180
  - !ruby/object:Gem::Dependency
209
- version_requirements: &id013 !ruby/object:Gem::Requirement
181
+ name: rspec
182
+ prerelease: false
183
+ requirement: &id011 !ruby/object:Gem::Requirement
210
184
  none: false
211
185
  requirements:
212
186
  - - ~>
@@ -217,12 +191,12 @@ dependencies:
217
191
  - 3
218
192
  - 0
219
193
  version: 1.3.0
220
- requirement: *id013
221
194
  type: :development
222
- name: rspec
223
- prerelease: false
195
+ version_requirements: *id011
224
196
  - !ruby/object:Gem::Dependency
225
- version_requirements: &id014 !ruby/object:Gem::Requirement
197
+ name: capybara
198
+ prerelease: false
199
+ requirement: &id012 !ruby/object:Gem::Requirement
226
200
  none: false
227
201
  requirements:
228
202
  - - ~>
@@ -233,15 +207,14 @@ dependencies:
233
207
  - 3
234
208
  - 9
235
209
  version: 0.3.9
236
- requirement: *id014
237
210
  type: :development
238
- name: capybara
239
- prerelease: false
211
+ version_requirements: *id012
240
212
  description:
241
213
  email:
242
214
  - benbjohnson@yahoo.com
243
215
  executables:
244
216
  - smeagol
217
+ - smeagold
245
218
  extensions: []
246
219
 
247
220
  extra_rdoc_files: []
@@ -252,6 +225,7 @@ files:
252
225
  - lib/smeagol/cache.rb
253
226
  - lib/smeagol/hash.rb
254
227
  - lib/smeagol/option_parser.rb
228
+ - lib/smeagol/public/smeagol/html5.js
255
229
  - lib/smeagol/public/smeagol/main.css
256
230
  - lib/smeagol/public/smeagol/pygment.css
257
231
  - lib/smeagol/templates/page.mustache
@@ -267,6 +241,7 @@ files:
267
241
  - test/test_hash.rb
268
242
  - test/test_wiki.rb
269
243
  - bin/smeagol
244
+ - bin/smeagold
270
245
  has_rdoc: true
271
246
  homepage: http://smeagolrb.info
272
247
  licenses: []