smeagol 0.3.0 → 0.4.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.
data/README.md CHANGED
@@ -44,7 +44,7 @@ There are two ways to update the repository through Smeagol:
44
44
  1. Manual Update
45
45
 
46
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
47
+ simply pass the `--auto-update` option in the command line and Smeagol will
48
48
  automatically perform a `git pull origin master` on your repository once per
49
49
  day.
50
50
 
data/bin/smeagol CHANGED
@@ -26,7 +26,8 @@ if options.git && options.auto_update
26
26
  while true do
27
27
  sleep 86400
28
28
  options.repositories.each do |repository|
29
- Smeagol::Updater.update(options.git, repository.path)
29
+ wiki = Smeagol::Wiki.new(repository.path)
30
+ wiki.update(options.git)
30
31
  end
31
32
  end
32
33
  end
data/lib/smeagol/app.rb CHANGED
@@ -23,11 +23,21 @@ module Smeagol
23
23
  ##############################################################################
24
24
 
25
25
  # Update the gollum repository
26
- get '/update' do
27
- if Updater.update(settings.git, repository)
28
- 'ok'
26
+ get '/update/?*' do
27
+ key = params[:splat].first
28
+
29
+ # If a secret key is specified for the repository, only update if the
30
+ # secret is appended to the URL.
31
+ if repository.secret.nil? || key == repository.secret
32
+ wiki = Smeagol::Wiki.new(repository.path)
33
+ if wiki.update(settings.git)
34
+ 'ok'
35
+ else
36
+ 'error'
37
+ end
29
38
  else
30
- 'error'
39
+ # Show a forbidden response if the secret was not correct
40
+ 'forbidden'
31
41
  end
32
42
  end
33
43
 
@@ -7,6 +7,7 @@ module Smeagol
7
7
  # Returns an OpenStruct of the options.
8
8
  def self.parse(args)
9
9
  # Set parse options
10
+ secret = nil
10
11
  options = {}
11
12
  parser = ::OptionParser.new do |parser|
12
13
  parser.banner = 'usage: smeagol [OPTIONS] [PATH]\n\n'
@@ -25,7 +26,7 @@ module Smeagol
25
26
  options['config_path'] = path
26
27
  end
27
28
 
28
- parser.on('--autoupdate', 'Updates the repository on a daily basis.') do |flag|
29
+ parser.on('--auto-update', 'Updates the repository on a daily basis.') do |flag|
29
30
  options['auto_update'] = flag
30
31
  end
31
32
 
@@ -33,6 +34,10 @@ module Smeagol
33
34
  options['cache_enabled'] = flag
34
35
  end
35
36
 
37
+ parser.on('--secret [KEY]', 'Specifies the secret key used to update.') do |str|
38
+ secret = str
39
+ end
40
+
36
41
  parser.on('-v', '--version', 'Display current version.') do
37
42
  puts "Smeagol #{Smeagol::VERSION}"
38
43
  exit 0
@@ -68,6 +73,9 @@ module Smeagol
68
73
  opts.repositories = [{:path => Dir.pwd}.to_ostruct]
69
74
  end
70
75
 
76
+ # Set secret on default repository if passed in.
77
+ opts.repositories.first.secret = secret unless secret.nil?
78
+
71
79
  # Merge all options
72
80
  return opts
73
81
  end
@@ -93,13 +93,14 @@ article h1 {
93
93
 
94
94
  #content h3 {
95
95
  font-size: 110%;
96
- margin-top: 1em;
96
+ margin-top:1em;
97
+ margin-bottom:0.5em;
97
98
  font-size: 1.17em;
98
99
  }
99
100
 
100
101
  #content p {
101
102
  line-height: 1.5em;
102
- margin: 1em 0px;
103
+ margin: 0.5em 0em 1em 0em;
103
104
  }
104
105
 
105
106
  #content ol {
@@ -122,16 +123,20 @@ article h1 {
122
123
  }
123
124
 
124
125
  pre {
125
- background-color: ghostWhite;
126
- border: 1px solid #ddd;
127
- color: #444;
128
- font-size: 12px;
129
126
  line-height: 1.5em;
130
127
  margin: 1em 0px;
131
128
  overflow: auto;
132
129
  padding: 0.5em;
133
130
  }
134
131
 
132
+ code {
133
+ padding: 0px 0.2em;
134
+ }
135
+
135
136
  pre, code {
137
+ background-color: ghostWhite;
138
+ border: 1px solid #ddd;
139
+ color: #444;
140
+ font-size: 12px;
136
141
  font: normal normal normal 12px/normal Monaco, 'Courier New', monospace;
137
142
  }
@@ -12,6 +12,8 @@
12
12
  </head>
13
13
 
14
14
  <body>
15
+ {{{ribbon_html}}}
16
+
15
17
  <div id="container">
16
18
  <header>
17
19
  <h1>{{wiki_title}}</h1>
@@ -22,19 +24,17 @@
22
24
  </nav>
23
25
 
24
26
  <article>
25
- {{#is_not_home?}}
27
+ {{#not_home?}}
26
28
  <h1>{{page_title}}</h1>
27
- {{/is_not_home?}}
29
+ {{/not_home?}}
28
30
  <div id="content">
29
31
  {{{content}}}
30
32
  </div>
31
33
  </article>
32
34
 
33
- {{#is_not_home?}}
34
35
  <footer>
35
36
  <small>Last edited by <b>{{author}}</b> on {{date}}.</small>
36
37
  </footer>
37
- {{/is_not_home?}}
38
38
  </div>
39
39
  </body>
40
40
  </html>
@@ -1,3 +1,3 @@
1
1
  module Smeagol
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -40,8 +40,14 @@ module Smeagol
40
40
  page.version.authored_date.strftime("%B %d, %Y")
41
41
  end
42
42
 
43
+ # Public: The URL of the project source code. This is set in the settings
44
+ # file.
45
+ def source_url
46
+ page.wiki.settings.source_url
47
+ end
48
+
43
49
  # Public: A flag stating that this is not the home page.
44
- def is_not_home?
50
+ def not_home?
45
51
  page.title != "Home"
46
52
  end
47
53
 
@@ -57,6 +63,19 @@ module Smeagol
57
63
  end
58
64
  end
59
65
 
66
+ # Public: The HTML for the GitHub ribbon, if enabled. This can be set in
67
+ # the settings file as `ribbon`.
68
+ def ribbon_html
69
+ if !source_url.nil? && !page.wiki.settings.ribbon.nil?
70
+ name, pos = *page.wiki.settings.ribbon.split(' ')
71
+ pos ||= 'right'
72
+
73
+ html = "<a href=\"#{source_url}\">"
74
+ html << "<img style=\"position:absolute; top:0; #{pos}:0; border:0;\" src=\"#{ribbon_url(name, pos)}\" alt=\"Fork me on GitHub\"/>"
75
+ html << "</a>"
76
+ end
77
+ end
78
+
60
79
 
61
80
  ##########################################################################
62
81
  #
@@ -68,6 +87,16 @@ module Smeagol
68
87
 
69
88
  # The Gollum::Page that this view represents.
70
89
  attr_reader :page
90
+
91
+ # Generates the correct ribbon url
92
+ def ribbon_url(name, pos)
93
+ hexcolors = {'red' => 'aa0000', 'green' => '007200', 'darkblue' => '121621', 'orange' => 'ff7600', 'gray' => '6d6d6d', 'white' => 'ffffff'}
94
+ if hexcolor = hexcolors[name]
95
+ "http://s3.amazonaws.com/github/ribbons/forkme_#{pos}_#{name}_#{hexcolor}.png"
96
+ else
97
+ name
98
+ end
99
+ end
71
100
  end
72
101
  end
73
102
  end
data/lib/smeagol/wiki.rb CHANGED
@@ -4,6 +4,31 @@ require 'yaml'
4
4
 
5
5
  module Smeagol
6
6
  class Wiki < Gollum::Wiki
7
+ # Public: Updates the wiki repository.
8
+ #
9
+ # git - The path to the git binary.
10
+ #
11
+ # Returns true if successful. Otherwise returns false.
12
+ def update(git)
13
+ # TODO: Change this method to raise errors if something goes wrong instead
14
+ # of returning a status.
15
+
16
+ # If the git executable is available, pull from master and check status.
17
+ if !git.nil?
18
+ output = `cd #{path} && #{git} pull origin master 2>/dev/null`
19
+
20
+ # Write update to log if something happened
21
+ if output.index('Already up-to-date').nil?
22
+ $stderr.puts "==Repository updated at #{Time.new()} : #{path}=="
23
+ end
24
+
25
+ return $? == 0
26
+ # Otherwise return false.
27
+ else
28
+ return false
29
+ end
30
+ end
31
+
7
32
  ##############################################################################
8
33
  #
9
34
  # Settings
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: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Johnson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-01 00:00:00 -06:00
18
+ date: 2010-10-04 00:00:00 -06:00
19
19
  default_executable: smeagol
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -229,7 +229,6 @@ files:
229
229
  - lib/smeagol/public/smeagol/main.css
230
230
  - lib/smeagol/public/smeagol/pygment.css
231
231
  - lib/smeagol/templates/page.mustache
232
- - lib/smeagol/updater.rb
233
232
  - lib/smeagol/version.rb
234
233
  - lib/smeagol/views/page.rb
235
234
  - lib/smeagol/wiki.rb
@@ -1,29 +0,0 @@
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
- # path - The paths to the git repository to update.
7
- #
8
- # Returns true if successful. Otherwise returns false.
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
-
13
- # If the git executable is available, pull from master and check status.
14
- if !git.nil? && !path.nil?
15
- output = `cd #{path} && #{git} pull origin master 2>/dev/null`
16
-
17
- # Write update to log if something happened
18
- if output.index('Already up-to-date').nil?
19
- $stderr.puts "==Repository updated at #{Time.new()} : #{path}=="
20
- end
21
-
22
- return $? == 0
23
- # Otherwise return false.
24
- else
25
- return false
26
- end
27
- end
28
- end
29
- end