soxer 0.9.12 → 0.9.13
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -4
- data/bin/soxer +141 -8
- data/lib/soxer/main.rb +1 -1
- data/soxer.gemspec +3 -3
- metadata +4 -4
data/README.markdown
CHANGED
@@ -13,6 +13,7 @@ It's strong points include:
|
|
13
13
|
- There is no relational database back end.
|
14
14
|
- It uses and follows standards. The document format is [YAML](http://www.yaml.org)
|
15
15
|
- Document model is loose (adaptable "on the fly") and only determined by your views or partials.
|
16
|
+
- Final deployment can be dynamic or static.
|
16
17
|
- It's a Sinatra modular application, so you can easily incorporate it into existing project.
|
17
18
|
|
18
19
|
What Soxer is not (yet)...
|
@@ -36,11 +37,14 @@ To create a "hello world" type 'empty' application named 'webpage', you can run:
|
|
36
37
|
`$ soxer create empty webpage`
|
37
38
|
|
38
39
|
The directory webpage, which you just created has everything you need to run your first soxer application. Just enter it and run soxer in developement mode:
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
`$ cd webpage; soxer test`
|
41
|
+
|
42
|
+
You can even create a static site:
|
43
|
+
`$ soxer generate htmls static`
|
44
|
+
This will generate a set of htmls (ending with .html) a directory called 'static' inside your project directory.
|
42
45
|
|
43
46
|
It's that simple.
|
44
47
|
|
45
|
-
You can read more about soxer on <http://soxer.mutsu.org>, which hosts a growing list of tutorials.
|
48
|
+
You can read more about soxer on <http://soxer.mutsu.org>, which hosts a growing list of tutorials.
|
49
|
+
You can also contact the author at **toni at formalibre dot si**.
|
46
50
|
|
data/bin/soxer
CHANGED
@@ -5,7 +5,7 @@ def colorize(text, color_code); "\033#{color_code}#{text}\033[0m"; end
|
|
5
5
|
def b(text); colorize(text, "[1m"); end
|
6
6
|
|
7
7
|
def h
|
8
|
-
'-'*79+"\n#{b 'Soxer'}, the web publishing tool. | Copyright 2010, Toni Anzlovar.\n"+'-'*79
|
8
|
+
'-'*79+"\n#{b 'Soxer'}, the web publishing tool. | Copyright 2010-11, Toni Anzlovar.\n"+'-'*79
|
9
9
|
end
|
10
10
|
|
11
11
|
def err message
|
@@ -37,35 +37,58 @@ def help
|
|
37
37
|
|
38
38
|
Actions:
|
39
39
|
|
40
|
-
#{b 'create'}
|
40
|
+
#{b 'create'} (No defaults)
|
41
41
|
Creates a new soxer project directory with default sinatra/soxer layout.
|
42
42
|
All aspects can be later customized to suite project's needs.
|
43
43
|
|
44
44
|
First parameter:
|
45
|
-
#{b 'empty'} - Creates an empty project
|
46
|
-
#{b 'blog'} - Creates a simple blog project
|
45
|
+
#{b 'empty'} - Creates an empty project.
|
46
|
+
#{b 'blog'} - Creates a simple blog project.
|
47
47
|
More project templates are in the making
|
48
48
|
|
49
49
|
Other parameters:
|
50
|
-
#{b '[name]'} - The name of the project directory
|
50
|
+
#{b '[name]'} - The name of the project directory.
|
51
|
+
|
52
|
+
|
53
|
+
#{b 'generate'} (Default: generate paths static)
|
54
|
+
Generates a static soxer site based on your content.
|
55
|
+
|
56
|
+
First parameter:
|
57
|
+
#{b 'htmls'} - Generates a static sate with .html extensions.
|
58
|
+
#{b 'paths'} - Generates a static sate with directories / indexes.
|
59
|
+
More static site options in the making
|
51
60
|
|
52
|
-
|
61
|
+
Other parameters:
|
62
|
+
#{b '[name]'} - The name of the static site directory.
|
63
|
+
|
64
|
+
|
65
|
+
#{b 'test'} (Default: soxer test 9394)
|
53
66
|
Runs the developement server (in the foreground) on your computer.
|
54
67
|
Point your browser to #{b 'http://localhost:9394'} to view the result.
|
55
68
|
You can exit with standard [ctrl]+c.
|
56
69
|
|
57
70
|
Parameters:
|
58
71
|
#{b '[int]'} - Port number you wish to run developement on
|
59
|
-
|
72
|
+
|
73
|
+
|
60
74
|
#{b 'help'}
|
61
75
|
Displays this help.
|
62
76
|
|
77
|
+
|
63
78
|
Examples:
|
64
79
|
|
65
80
|
#{b '$ soxer create empty app'}
|
66
81
|
This command would create a new project directory 'app' with a mockup empty
|
67
82
|
soxer/sinatra application in it. You can tweak the design and parameters to
|
68
83
|
acheve the desired experience.
|
84
|
+
|
85
|
+
#{b '$ soxer generate htmls static'}
|
86
|
+
This command would generate a static set of html files (with .html ending)
|
87
|
+
in directory static in current directory.
|
88
|
+
Option 'htmls' makes the site directory cleaner and easier to understand, but
|
89
|
+
introduces nasty '.html' in page urls.
|
90
|
+
Oprion 'paths' makes every url into a directory with index file. This makes a
|
91
|
+
bunch of directories, but makes urls absent of '.html'
|
69
92
|
|
70
93
|
#{b '$ soxer test 8907'}
|
71
94
|
This command (when executed within the soxer project directory root) will
|
@@ -95,6 +118,116 @@ def create template, dir
|
|
95
118
|
end
|
96
119
|
end
|
97
120
|
|
121
|
+
def generate argv
|
122
|
+
require 'net/http'
|
123
|
+
require 'open3'
|
124
|
+
|
125
|
+
type ||= 'paths'; type = argv[0] if argv[0]
|
126
|
+
dir ||= 'static'; dir = argv[1] if argv[1]
|
127
|
+
|
128
|
+
return err 'The static site type does not exist.' unless %w[htmls paths].include? type
|
129
|
+
|
130
|
+
# Fix URLs in html file according to type of static site generated
|
131
|
+
def fixurls path, data, type
|
132
|
+
if type == 'paths'
|
133
|
+
data.gsub!(/(href|src)="\/([^"]*)/) do |s|
|
134
|
+
case true
|
135
|
+
when ( path == '/index' and path.split('/').count == 2 )
|
136
|
+
s = $1 + '="./' + $2
|
137
|
+
when ( path != '/index' )
|
138
|
+
prepath = '../' * (path.split('/').count - 1)
|
139
|
+
s = $1 + '="' + prepath + $2
|
140
|
+
else
|
141
|
+
s = $&
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
if type == 'htmls' then
|
147
|
+
data.gsub!(/(\<[^>]+)(href="|src=")(\/[^"]*)([^>]+\>)/) do |s|
|
148
|
+
if $2 == 'href="' and !( $&.include? 'rel="stylesheet"' )
|
149
|
+
ending = '.html'
|
150
|
+
else ending = '';
|
151
|
+
end
|
152
|
+
case true
|
153
|
+
when path.split('/').count == 2
|
154
|
+
s = $1+$2+'.'+$3+ending+$4
|
155
|
+
when path.split('/').count > 2
|
156
|
+
prepath = '../' * (path.split('/').count - 2)
|
157
|
+
s = $1+$2+prepath[0..-2]+$3+ending+$4
|
158
|
+
else
|
159
|
+
s = $&
|
160
|
+
end
|
161
|
+
end
|
162
|
+
data.gsub!(/(href="[^"]*\/)(\.html)/, '\1index\2')
|
163
|
+
end
|
164
|
+
return data
|
165
|
+
end
|
166
|
+
|
167
|
+
def writefile what, where
|
168
|
+
File.open( where, 'w') do |f|
|
169
|
+
f.puts what
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Can we sniff out a free port in a better way?
|
174
|
+
s = TCPServer.new('127.0.0.1', 0); port = s.addr[1]; s.close
|
175
|
+
|
176
|
+
server = 'webrick'
|
177
|
+
ENV['PATH'].split(':').each {|folder| server = 'thin' if File.exists?(folder+'/thin')}
|
178
|
+
|
179
|
+
i,o,e,w = Open3.popen3 "rackup -s #{server} -p #{port}"
|
180
|
+
sleep 3
|
181
|
+
sitemap = Net::HTTP.get URI.parse("http://localhost:#{port}/sitemap.xml")
|
182
|
+
stylesheets = []
|
183
|
+
out = []
|
184
|
+
|
185
|
+
# Get all documents listed in sitemap
|
186
|
+
sitemap.scan(/http\:\/\/localhost[^<]+/).each do |url|
|
187
|
+
path = url.sub /http:\/\/localhost:\d+/, ''
|
188
|
+
html = path+'.html'
|
189
|
+
htm = path+'.htm'
|
190
|
+
data = Net::HTTP.get URI.parse "http://localhost:#{port}#{path}"
|
191
|
+
|
192
|
+
# Get header and scan for dynamically generated stuff (css mainly)
|
193
|
+
if header = data.scan(/\<head\>.+?\<\/head\>/m)[0] then
|
194
|
+
header.scan(/[^'"=]+\.css/).each {|ss| stylesheets << ss }
|
195
|
+
end
|
196
|
+
|
197
|
+
# Fix local URLs to relative
|
198
|
+
reldata = fixurls path, data, type
|
199
|
+
|
200
|
+
# Generate paths & files
|
201
|
+
case type
|
202
|
+
when 'paths'
|
203
|
+
d = File.join(dir, path)
|
204
|
+
FileUtils.mkpath d
|
205
|
+
writefile reldata, d + '/index.html'
|
206
|
+
FileUtils.cp dir + '/index/index.html', dir + '/index.html' if File.exist? dir + '/index/index.html'
|
207
|
+
when 'htmls'
|
208
|
+
f = path.split('/').last
|
209
|
+
d = File.join(dir, path.split('/')[0..-2].join('/'))
|
210
|
+
FileUtils.mkpath d
|
211
|
+
writefile reldata, d + '/' + f + '.html'
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# Get stylesheets out of HTML headers
|
216
|
+
stylesheets.uniq.compact.each do |s|
|
217
|
+
d = s.split('/'); d.pop; d.join('/')
|
218
|
+
FileUtils.mkdir_p File.join(dir, d)
|
219
|
+
data = Net::HTTP.get URI.parse "http://localhost:#{port}#{s}"
|
220
|
+
writefile data, File.join(dir, s)
|
221
|
+
end
|
222
|
+
|
223
|
+
# Copy static files and clean up
|
224
|
+
FileUtils.copy_entry( 'public', dir)
|
225
|
+
e = w.pid
|
226
|
+
Process.kill 9, w.pid
|
227
|
+
|
228
|
+
return notice "Successfully generated static #{type}."
|
229
|
+
end
|
230
|
+
|
98
231
|
def test port
|
99
232
|
port = 9394 unless port!=nil
|
100
233
|
server = 'webrick'
|
@@ -106,7 +239,7 @@ end
|
|
106
239
|
case $*[0]
|
107
240
|
when 'create' then printf create $*[1], $*[2]
|
108
241
|
when 'test' then printf test $*[1]
|
109
|
-
when '
|
242
|
+
when 'generate' then printf generate $*[1..-1]
|
110
243
|
when 'help' then printf help
|
111
244
|
else printf err 'You did not specify an action!'
|
112
245
|
end
|
data/lib/soxer/main.rb
CHANGED
@@ -49,7 +49,7 @@ module Sinatra
|
|
49
49
|
out = YAML.load_file( @f )
|
50
50
|
add_date unless out['date']
|
51
51
|
add_id unless out['uuid']
|
52
|
-
out['url'] = @f.gsub(/#{@s.origin}
|
52
|
+
out['url'] = @f.gsub(/#{@s.origin}(.+)\.yaml$/, "\\1" ).gsub(/(.+)\/index$/, "\\1" )
|
53
53
|
out['mtime'] = File.mtime( @f )
|
54
54
|
Hashie::Mash.new out
|
55
55
|
end
|
data/soxer.gemspec
CHANGED
@@ -4,12 +4,12 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.rubygems_version = '1.3.7'
|
5
5
|
|
6
6
|
s.name = 'soxer'
|
7
|
-
s.version = '0.9.
|
8
|
-
s.date = '2011-
|
7
|
+
s.version = '0.9.13'
|
8
|
+
s.date = '2011-05-23'
|
9
9
|
s.rubyforge_project = 'soxer'
|
10
10
|
|
11
11
|
s.summary = "Dynamic web site generator engine"
|
12
|
-
s.description = "Soxer is a file based dynamic web site creation tool for Sinatra."
|
12
|
+
s.description = "Soxer is a file based static/dynamic web site creation tool for Sinatra."
|
13
13
|
|
14
14
|
s.authors = ["Toni Anzlovar"]
|
15
15
|
s.email = 'toni@formalibre.si'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 13
|
9
|
+
version: 0.9.13
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Toni Anzlovar
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-05-23 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -85,7 +85,7 @@ dependencies:
|
|
85
85
|
version: "0.5"
|
86
86
|
type: :runtime
|
87
87
|
version_requirements: *id005
|
88
|
-
description: Soxer is a file based dynamic web site creation tool for Sinatra.
|
88
|
+
description: Soxer is a file based static/dynamic web site creation tool for Sinatra.
|
89
89
|
email: toni@formalibre.si
|
90
90
|
executables:
|
91
91
|
- soxer
|