smeagol 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ smeagol -- A Read-Only Gollum Server
2
+ =============================================
3
+
4
+ ## DESCRIPTION
5
+
6
+ Smeagol is a server that can run a read-only version of a
7
+ [Gollum](http://github.com/github/gollum) wiki. This can be useful when you want
8
+ to maintain a standalone copy of a Github wiki but you want to update it through
9
+ the Github interface.
10
+
11
+ Gollum follows the rules of [Semantic Versioning](http://semver.org/) and uses
12
+ [TomDoc](http://tomdoc.org/) for inline documentation.
13
+
14
+
15
+ ## INSTALLATION
16
+
17
+ You can install Smeagol with RubyGems:
18
+
19
+ $ [sudo] gem install smeagol
20
+
21
+ And then, if you want code highlighting, follow the
22
+ [Installation Guide](http://pygments.org/docs/installation) for Pygments.
23
+
24
+ Ta da. You're ready to go.
25
+
26
+
27
+ ## RUNNING
28
+
29
+ To run smeagol, simply change directories to your Gollum repository and run the
30
+ `smeagol` executable from the command line:
31
+
32
+ $ cd /path/to/repo
33
+ $ smeagol
34
+
35
+ This will run a web server at `http://localhost:4567`. You can change the port
36
+ by setting the `--port` or `-p` option on the command line.
37
+
38
+
39
+ ## UPDATING
40
+
41
+ There are two ways to update the repository through Smeagol:
42
+
43
+ 1. Auto Update
44
+ 1. Manual Update
45
+
46
+ To setup Smeagol to automatically update your repository in fixed intervals,
47
+ simply pass the `--autoupdate` option in the command line and Smeagol will
48
+ automatically perform a `git pull origin master` on your repository once per
49
+ day.
50
+
51
+ To perform a manual update, simply go to the URL,
52
+ `http://localhost:4567/update`, and Smeagol will perform a git pull. Change the
53
+ URL to your appropriate hostname and port.
54
+
55
+
56
+ ## CONTRIBUTE
57
+
58
+ Have a great idea for Smeagol? Awesome. Fork the repository and add a feature
59
+ or fix a bug. There are a couple things I ask:
60
+
61
+ 1. You must have tests for all code you check in.
62
+ 1. Create an appropriately named topic branch that contains your change.
data/bin/smeagol ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'optparse'
5
+ require 'ostruct'
6
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/smeagol')
7
+
8
+ # Parse options
9
+ options = OpenStruct.new
10
+ options.port = 4567
11
+ options.auto_update = false
12
+ opts = OptionParser.new do |opts|
13
+ opts.banner = 'usage: smeagol [OPTIONS] [PATH]\n\n'
14
+
15
+ opts.on('--port [PORT]', 'Bind port (default 4567).') do |port|
16
+ options.port = port.to_i
17
+ end
18
+
19
+ opts.on('--git [GIT]', 'Path to Git binary.') do |path|
20
+ options.git = path
21
+ end
22
+
23
+ opts.on('--autoupdate', 'Updates the repository on a daily basis.') do |flag|
24
+ options.auto_update = flag
25
+ end
26
+
27
+ opts.on('-v', '--version', 'Display current version.') do
28
+ puts "Smeagol #{Smeagol::VERSION}"
29
+ exit 0
30
+ end
31
+ end
32
+
33
+ # Read command line options into `options` hash
34
+ begin
35
+ opts.parse!
36
+ rescue OptionParser::InvalidOption
37
+ puts "smeagol: #{$!.message}"
38
+ puts "smeagol: try 'smeagol --help' for more information"
39
+ exit
40
+ end
41
+
42
+ # Attempt to find the git binary
43
+ if options.git.nil?
44
+ ['/usr/bin', '/usr/sbin', '/usr/local/bin', '/opt/local/bin'].each do |path|
45
+ file = "#{path}/git"
46
+ options.git = file if File.executable?(file)
47
+ break if options.git
48
+ end
49
+ end
50
+
51
+ # Alert user that updates are unavailable if git is not found
52
+ if options.git.nil? || !File.executable?(options.git)
53
+ puts "warning: git executable could not be found."
54
+ else
55
+ puts "git found: #{options.git}"
56
+ end
57
+
58
+ # Set the path to the Gollum repository
59
+ gollum_path = ARGV[0] || Dir.pwd
60
+
61
+ # Run the auto update process
62
+ if options.git && options.auto_update
63
+ Thread.new do
64
+ while true do
65
+ Smeagol::Updater.update(options.git, gollum_path)
66
+ sleep 5
67
+ end
68
+ end
69
+ end
70
+
71
+ # Run the web server
72
+ Smeagol::App.set(:gollum_path, gollum_path)
73
+ Smeagol::App.set(:git, options.git)
74
+ Smeagol::App.run!(:port => options.port)
75
+
data/lib/smeagol.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'smeagol/app'
3
+ require 'smeagol/updater'
4
+ require 'smeagol/version'
5
+ require 'rdiscount'
6
+ require 'RedCloth'
@@ -0,0 +1,70 @@
1
+ require 'gollum'
2
+ require 'sinatra'
3
+ require 'mustache'
4
+
5
+ module Smeagol
6
+ class App < Sinatra::Base
7
+ ##############################################################################
8
+ #
9
+ # Settings
10
+ #
11
+ ##############################################################################
12
+
13
+ set :public, File.dirname(__FILE__) + '/public'
14
+
15
+
16
+ ##############################################################################
17
+ #
18
+ # Routes
19
+ #
20
+ ##############################################################################
21
+
22
+ # Update the gollum repository
23
+ get '/update' do
24
+ if Updater.update(settings.git, settings.gollum_path)
25
+ 'ok'
26
+ else
27
+ 'error'
28
+ end
29
+ end
30
+
31
+ # All other resources go through Gollum.
32
+ get '/*' do
33
+ name = params[:splat].first
34
+ name = "Home" if name == ""
35
+
36
+ wiki = Gollum::Wiki.new(settings.gollum_path)
37
+ if page = wiki.page(name)
38
+ Mustache.render(page_template,
39
+ :page => page,
40
+ :title => page.title,
41
+ :content => page.formatted_data
42
+ )
43
+ elsif file = wiki.file(name)
44
+ content_type file.mime_type
45
+ file.raw_data
46
+ end
47
+ end
48
+
49
+
50
+ ##############################################################################
51
+ #
52
+ # Private methods
53
+ #
54
+ ##############################################################################
55
+
56
+ private
57
+ # The Mustache template to use for page rendering.
58
+ #
59
+ # Returns the content of the page.mustache file in the root of the Gollum
60
+ # repository if it exists. Otherwise, it uses the default page.mustache file
61
+ # packaged with the Smeagol library.
62
+ def page_template
63
+ if File.exists?("#{settings.gollum_path}/page.mustache")
64
+ IO.read("#{settings.gollum_path}/page.mustache")
65
+ else
66
+ IO.read(File.join(File.dirname(__FILE__), 'templates/page.mustache'))
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,10 @@
1
+ h1 {
2
+ padding-bottom: 3px;
3
+ border-bottom: 3px solid #ccc;
4
+ }
5
+
6
+ #container {
7
+ margin-left: auto;
8
+ margin-right: auto;
9
+ width: 650px;
10
+ }
@@ -0,0 +1,60 @@
1
+ .highlight{background:#fff;}
2
+ .highlight .c{color:#998;font-style:italic;}
3
+ .highlight .err{color:#a61717;background-color:#e3d2d2;}
4
+ .highlight .k{font-weight:bold;}
5
+ .highlight .o{font-weight:bold;}
6
+ .highlight .cm{color:#998;font-style:italic;}
7
+ .highlight .cp{color:#999;font-weight:bold;}
8
+ .highlight .c1{color:#998;font-style:italic;}
9
+ .highlight .cs{color:#999;font-weight:bold;font-style:italic;}
10
+ .highlight .gd{color:#000;background-color:#fdd;}
11
+ .highlight .gd .x{color:#000;background-color:#faa;}
12
+ .highlight .ge{font-style:italic;}
13
+ .highlight .gr{color:#a00;}
14
+ .highlight .gh{color:#999;}
15
+ .highlight .gi{color:#000;background-color:#dfd;}
16
+ .highlight .gi .x{color:#000;background-color:#afa;}
17
+ .highlight .go{color:#888;}
18
+ .highlight .gp{color:#555;}
19
+ .highlight .gs{font-weight:bold;}
20
+ .highlight .gu{color:#800080;font-weight:bold;}
21
+ .highlight .gt{color:#a00;}
22
+ .highlight .kc{font-weight:bold;}
23
+ .highlight .kd{font-weight:bold;}
24
+ .highlight .kp{font-weight:bold;}
25
+ .highlight .kr{font-weight:bold;}
26
+ .highlight .kt{color:#458;font-weight:bold;}
27
+ .highlight .m{color:#099;}
28
+ .highlight .s{color:#d14;}
29
+ .highlight .na{color:#008080;}
30
+ .highlight .nb{color:#0086B3;}
31
+ .highlight .nc{color:#458;font-weight:bold;}
32
+ .highlight .no{color:#008080;}
33
+ .highlight .ni{color:#800080;}
34
+ .highlight .ne{color:#900;font-weight:bold;}
35
+ .highlight .nf{color:#900;font-weight:bold;}
36
+ .highlight .nn{color:#555;}
37
+ .highlight .nt{color:#000080;}
38
+ .highlight .nv{color:#008080;}
39
+ .highlight .ow{font-weight:bold;}
40
+ .highlight .w{color:#bbb;}
41
+ .highlight .mf{color:#099;}
42
+ .highlight .mh{color:#099;}
43
+ .highlight .mi{color:#099;}
44
+ .highlight .mo{color:#099;}
45
+ .highlight .sb{color:#d14;}
46
+ .highlight .sc{color:#d14;}
47
+ .highlight .sd{color:#d14;}
48
+ .highlight .s2{color:#d14;}
49
+ .highlight .se{color:#d14;}
50
+ .highlight .sh{color:#d14;}
51
+ .highlight .si{color:#d14;}
52
+ .highlight .sx{color:#d14;}
53
+ .highlight .sr{color:#009926;}
54
+ .highlight .s1{color:#d14;}
55
+ .highlight .ss{color:#990073;}
56
+ .highlight .bp{color:#999;}
57
+ .highlight .vc{color:#008080;}
58
+ .highlight .vg{color:#008080;}
59
+ .highlight .vi{color:#008080;}
60
+ .highlight .il{color:#099;}
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
+ <title>{{title}}</title>
6
+ <link rel="stylesheet" href="/smeagol/main.css" type="text/css"/>
7
+ <link rel="stylesheet" href="/smeagol/pygment.css" type="text/css"/>
8
+ </head>
9
+
10
+ <body>
11
+ <div id="container">
12
+ <h1>{{title}}</h1>
13
+ <div>
14
+ {{{content}}}
15
+ </div>
16
+ </div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,26 @@
1
+ module Smeagol
2
+ class Updater
3
+ # Public: Updates the repository that the server is point at.
4
+ #
5
+ # git - The path to the git binary.
6
+ # repo - The path to the git repository to update.
7
+ #
8
+ # Returns true if successful. Otherwise returns false.
9
+ def self.update(git, repo)
10
+ # 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
+ # Write update to log if something happened
15
+ if output.index('Already up-to-date').nil?
16
+ puts "==Repository updated at #{Time.new()}=="
17
+ end
18
+
19
+ return $? == 0
20
+ # Otherwise return false.
21
+ else
22
+ return false
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Smeagol
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,246 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smeagol
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Ben Johnson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-20 00:00:00 -06:00
19
+ default_executable: smeagol
20
+ dependencies:
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: 31
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 0
32
+ version: 1.2.0
33
+ requirement: *id001
34
+ type: :runtime
35
+ name: rack
36
+ prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 21
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 1
48
+ version: 1.0.1
49
+ requirement: *id002
50
+ type: :runtime
51
+ name: gollum
52
+ prerelease: false
53
+ - !ruby/object:Gem::Dependency
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 15
60
+ segments:
61
+ - 1
62
+ - 0
63
+ version: "1.0"
64
+ requirement: *id003
65
+ type: :runtime
66
+ name: sinatra
67
+ prerelease: false
68
+ - !ruby/object:Gem::Dependency
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 55
75
+ segments:
76
+ - 0
77
+ - 11
78
+ - 2
79
+ version: 0.11.2
80
+ requirement: *id004
81
+ type: :runtime
82
+ name: mustache
83
+ prerelease: false
84
+ - !ruby/object:Gem::Dependency
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 9
91
+ segments:
92
+ - 0
93
+ - 5
94
+ - 1
95
+ version: 0.5.1
96
+ requirement: *id005
97
+ type: :runtime
98
+ name: OptionParser
99
+ prerelease: false
100
+ - !ruby/object:Gem::Dependency
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirement: *id006
111
+ type: :runtime
112
+ name: rdiscount
113
+ prerelease: false
114
+ - !ruby/object:Gem::Dependency
115
+ version_requirements: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirement: *id007
125
+ type: :runtime
126
+ name: RedCloth
127
+ prerelease: false
128
+ - !ruby/object:Gem::Dependency
129
+ version_requirements: &id008 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ~>
133
+ - !ruby/object:Gem::Version
134
+ hash: 57
135
+ segments:
136
+ - 0
137
+ - 8
138
+ - 3
139
+ version: 0.8.3
140
+ requirement: *id008
141
+ type: :development
142
+ name: rake
143
+ prerelease: false
144
+ - !ruby/object:Gem::Dependency
145
+ version_requirements: &id009 !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ~>
149
+ - !ruby/object:Gem::Version
150
+ hash: 53
151
+ segments:
152
+ - 0
153
+ - 8
154
+ - 5
155
+ version: 0.8.5
156
+ requirement: *id009
157
+ type: :development
158
+ name: cucumber
159
+ prerelease: false
160
+ - !ruby/object:Gem::Dependency
161
+ version_requirements: &id010 !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ hash: 27
167
+ segments:
168
+ - 1
169
+ - 3
170
+ - 0
171
+ version: 1.3.0
172
+ requirement: *id010
173
+ type: :development
174
+ name: rspec
175
+ prerelease: false
176
+ - !ruby/object:Gem::Dependency
177
+ version_requirements: &id011 !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ~>
181
+ - !ruby/object:Gem::Version
182
+ hash: 1
183
+ segments:
184
+ - 0
185
+ - 3
186
+ - 9
187
+ version: 0.3.9
188
+ requirement: *id011
189
+ type: :development
190
+ name: capybara
191
+ prerelease: false
192
+ description:
193
+ email:
194
+ - benbjohnson@yahoo.com
195
+ executables:
196
+ - smeagol
197
+ extensions: []
198
+
199
+ extra_rdoc_files: []
200
+
201
+ files:
202
+ - lib/smeagol/app.rb
203
+ - lib/smeagol/public/smeagol/main.css
204
+ - lib/smeagol/public/smeagol/pygment.css
205
+ - lib/smeagol/templates/page.mustache
206
+ - lib/smeagol/updater.rb
207
+ - lib/smeagol/version.rb
208
+ - lib/smeagol.rb
209
+ - README.md
210
+ - bin/smeagol
211
+ has_rdoc: true
212
+ homepage: http://smeagolrb.info
213
+ licenses: []
214
+
215
+ post_install_message:
216
+ rdoc_options: []
217
+
218
+ require_paths:
219
+ - lib
220
+ required_ruby_version: !ruby/object:Gem::Requirement
221
+ none: false
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ hash: 3
226
+ segments:
227
+ - 0
228
+ version: "0"
229
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
+ none: false
231
+ requirements:
232
+ - - ">="
233
+ - !ruby/object:Gem::Version
234
+ hash: 3
235
+ segments:
236
+ - 0
237
+ version: "0"
238
+ requirements: []
239
+
240
+ rubyforge_project:
241
+ rubygems_version: 1.3.7
242
+ signing_key:
243
+ specification_version: 3
244
+ summary: A read-only server for Gollum wikis
245
+ test_files: []
246
+