smeagol 0.5.8 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/smeagol-static +115 -0
  2. data/lib/smeagol/version.rb +1 -1
  3. metadata +6 -4
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'mustache'
5
+ require 'optparse'
6
+ require 'smeagol'
7
+
8
+ class Static
9
+ def initialize(wiki)
10
+ @wiki = wiki
11
+ @directory = []
12
+ end
13
+
14
+ def template
15
+ if File.exists?("#{@wiki.path}/page.mustache")
16
+ IO.read("#{@wiki.path}/page.mustache")
17
+ else
18
+ IO.read(File.join(File.dirname(__FILE__), "../lib/smeagol/templates/page.mustache"))
19
+ end
20
+ end
21
+
22
+ def current_directory
23
+ @directory.last
24
+ end
25
+
26
+ def directory_pop
27
+ @directory.pop()
28
+ end
29
+
30
+ def directory_push(dir)
31
+ if @directory.empty?
32
+ @directory << dir
33
+ else
34
+ @directory << "#{current_directory}/#{dir}"
35
+ end
36
+
37
+ if not File.directory?(current_directory)
38
+ Dir::mkdir(current_directory)
39
+ end
40
+ end
41
+
42
+ def build_tree(tree)
43
+ tree.contents.each do |item|
44
+ if item.class == Grit::Tree
45
+ directory_push(item.name)
46
+ build_tree(item)
47
+ directory_pop()
48
+ else
49
+ build_blob(item)
50
+ end
51
+ end
52
+ end
53
+
54
+ def build_blob(blob)
55
+ if name = @wiki.page_class.valid_page_name?(blob.name)
56
+ page = @wiki.page(name)
57
+
58
+ if name != 'Home'
59
+ directory_push(name)
60
+ end
61
+
62
+ File.open("#{current_directory}/index.html", 'w') do |f|
63
+ f.write(Mustache.render(template, Smeagol::Views::Page.new(page)))
64
+ end
65
+
66
+ if name != 'Home'
67
+ directory_pop
68
+ end
69
+ else
70
+ File.open("#{current_directory}/#{blob.name}", 'w') do |f|
71
+ f.write(blob.data)
72
+ end
73
+ end
74
+ end
75
+
76
+ def build(directory)
77
+ directory_push(directory)
78
+ build_tree(@wiki.repo.tree)
79
+ directory_pop
80
+ end
81
+ end
82
+
83
+ options = {}
84
+ optparse = OptionParser.new do |opts|
85
+ opts.banner = "usage: smeagol-static [options] [path]"
86
+
87
+ opts.on('-h', '--help', 'Displays this usage screen') do
88
+ puts optparse
89
+ exit
90
+ end
91
+
92
+ opts.on('-b', '--build DIRECTORY') do |dir|
93
+ options[:build_dir] = dir
94
+ end
95
+ end
96
+
97
+ begin
98
+ optparse.parse!
99
+ rescue OptionParser::InvalidOption
100
+ puts optparse
101
+ exit 1
102
+ end
103
+
104
+ if ARGV.first
105
+ options[:repo] = ARGV.first
106
+ else
107
+ options[:repo] = Dir.pwd
108
+ end
109
+
110
+ if not options.key?(:build_dir)
111
+ options[:build_dir] = options[:repo] + "/build"
112
+ end
113
+
114
+ static = Static.new(Smeagol::Wiki.new(options[:repo]))
115
+ static.build(options[:build_dir])
@@ -1,3 +1,3 @@
1
1
  module Smeagol
2
- VERSION = "0.5.8"
2
+ VERSION = "0.5.9"
3
3
  end
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 8
10
- version: 0.5.8
9
+ - 9
10
+ version: 0.5.9
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: 2011-09-23 00:00:00 -06:00
18
+ date: 2011-09-26 00:00:00 -06:00
19
19
  default_executable: smeagol
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -199,6 +199,7 @@ email:
199
199
  executables:
200
200
  - smeagol
201
201
  - smeagold
202
+ - smeagol-static
202
203
  extensions: []
203
204
 
204
205
  extra_rdoc_files: []
@@ -228,6 +229,7 @@ files:
228
229
  - test/test_wiki.rb
229
230
  - bin/smeagol
230
231
  - bin/smeagold
232
+ - bin/smeagol-static
231
233
  has_rdoc: true
232
234
  homepage: http://smeagolrb.info
233
235
  licenses: []