gitdoc 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.2.0
1
+ 4.3.0
data/gitdoc.rb CHANGED
@@ -27,7 +27,7 @@ def GitDoc!
27
27
  set :dir, dir
28
28
  if settings.compiler
29
29
  require 'gitdoc/response_cache'
30
- use GitDoc::ResponseCache, 'build'
30
+ use GitDoc::ResponseCache, File.join(dir,'build')
31
31
  end
32
32
  run GitDoc
33
33
  end
@@ -170,7 +170,7 @@ stylus.render str, {paths: ['#{File.dirname file}']}, (err,css) -> sys.puts css
170
170
  end
171
171
 
172
172
  def title
173
- settings.title || 'Documents'
173
+ @title || settings.title || 'Documents'
174
174
  end
175
175
 
176
176
  end
@@ -179,12 +179,20 @@ end
179
179
  # exists then it is compiled and rendered
180
180
  get '*' do |name|
181
181
  name += 'index' if name =~ /\/$/
182
- @file = File.join(settings.dir + '/' + name + '.md')
183
- pass unless File.exist? @file
184
- @doc = gd File.read(@file)
182
+ file = settings.dir + name + '.md'
183
+ pass unless File.exist? file
184
+ @doc = gd File.read(file)
185
185
  haml :doc
186
186
  end
187
187
 
188
+ # If the path doesn't have a file extension or the extension is .html and a
189
+ # matching html file exists then process it with the extended html compiler
190
+ get %r{(.*?)(\.html)?$} do |name,extension|
191
+ file = settings.dir + name + (extension || '.html')
192
+ pass unless File.exist? file
193
+ html file
194
+ end
195
+
188
196
  # GitDoc document styles
189
197
  get '/gitdoc.css' do
190
198
  content_type :css
@@ -204,13 +212,6 @@ get '*.coffee.js' do |name|
204
212
  coffee File.read(file)
205
213
  end
206
214
 
207
- # Extends html to support sass
208
- get '*.html' do |name|
209
- file = settings.dir + '/' + name + '.html'
210
- pass unless File.exist? file
211
- html file
212
- end
213
-
214
215
  get '*.txt' do |name|
215
216
  file = settings.dir + '/' + name
216
217
  pass unless File.exist? file
@@ -232,8 +233,9 @@ end
232
233
 
233
234
  not_found do
234
235
  version = File.read(File.dirname(__FILE__)+'/VERSION')
236
+ @title = "Not Found"
235
237
  @doc = gd(
236
- "# Not Found"+
238
+ "# #{@title}"+
237
239
  "\n\n"+
238
240
  "GitDoc version #{version}"
239
241
  )
@@ -1,62 +1,36 @@
1
- # Shamelessly stolen from:
2
- # https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/response_cache.rb
3
1
  require 'fileutils'
4
- require 'rack'
5
2
 
6
- # Rack::ResponseCache is a Rack middleware that caches responses for successful
7
- # GET requests with no query string to disk or any ruby object that has an
8
- # []= method (so it works with memcached). When caching to disk, it works similar to
9
- # Rails' page caching, allowing you to cache dynamic pages to static files that can
10
- # be served directly by a front end webserver.
11
3
  class GitDoc::ResponseCache
12
4
 
13
- # The default proc used if a block is not provided to .new
14
- # It unescapes the PATH_INFO of the environment, and makes sure that it doesn't
15
- # include '..'. If the Content-Type of the response is text/(html|css|xml),
16
- # return a path with the appropriate extension (.html, .css, or .xml).
17
- # If the path ends with a / and the Content-Type is text/html, change the basename
18
- # of the path to index.html.
19
- DEFAULT_PATH_PROC = proc do |env, res|
20
- path = Rack::Utils.unescape(env['PATH_INFO'])
21
- if !path.include?('..') and match = /text\/((?:x|ht)ml|css)/o.match(res[1]['Content-Type'])
22
- type = match[1]
23
- path = "#{path}.#{type}" unless /\.#{type}\z/.match(path)
24
- path = File.join(File.dirname(path), 'index.html') if type == 'html' and File.basename(path) == '.html'
25
- path
26
- end
27
- end
28
-
29
- # Initialize a new ReponseCache object with the given arguments. Arguments:
30
- # * app : The next middleware in the chain. This is always called.
31
- # * cache : The place to cache responses. If a string is provided, a disk
32
- # cache is used, and all cached files will use this directory as the root directory.
33
- # If anything other than a string is provided, it should respond to []=, which will
34
- # be called with a path string and a body value (the 3rd element of the response).
35
- # * &block : If provided, it is called with the environment and the response from the next middleware.
36
- # It should return nil or false if the path should not be cached, and should return
37
- # the pathname to use as a string if the result should be cached.
38
- # If not provided, the DEFAULT_PATH_PROC is used.
39
- def initialize(app, cache, &block)
5
+ def initialize(app, cache)
40
6
  @app = app
41
- @cache = cache
42
- @path_proc = block || DEFAULT_PATH_PROC
7
+ @dir = cache
43
8
  end
44
9
 
45
- # Call the next middleware with the environment. If the request was successful (response status 200),
46
- # was a GET request, and had an empty query string, call the block set up in initialize to get the path.
47
- # If the cache is a string, create any necessary middle directories, and cache the file in the appropriate
48
- # subdirectory of cache. Otherwise, cache the body of the reponse as the value with the path as the key.
49
10
  def call(env)
50
- res = @app.call(env)
51
- if env['REQUEST_METHOD'] == 'GET' and env['QUERY_STRING'] == '' and res[0] == 200 and path = @path_proc.call(env, res)
52
- if @cache.is_a?(String)
53
- path = File.join(@cache, path) if @cache
54
- FileUtils.mkdir_p(File.dirname(path))
11
+ @app.call(env).tap do |res|
12
+ if cache? env, res
13
+ path = File.join @dir, file_path(env,res)
14
+ FileUtils.mkdir_p File.dirname(path)
55
15
  File.open(path, 'wb'){|f| res[2].each{|c| f.write(c)}}
56
- else
57
- @cache[path] = res[2]
58
16
  end
59
17
  end
60
- res
61
18
  end
19
+
20
+ def cache? env, response
21
+ env['REQUEST_METHOD'] == 'GET' and
22
+ env['QUERY_STRING'] == '' and
23
+ response[0] == 200 and
24
+ not env['PATH_INFO'].include?('__sinatra__') and
25
+ not env['PATH_INFO'].include?('..')
26
+ end
27
+
28
+ def file_path env, response
29
+ env['PATH_INFO'].tap do |path|
30
+ if response[1]['Content-Type'] =~ /text\/html/ and path !~ /\.html$/
31
+ path << (path[-1] == ?/ ? 'index.html' : '.html')
32
+ end
33
+ end
34
+ end
35
+
62
36
  end
Binary file
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitdoc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 4
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 4.2.0
10
+ version: 4.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Myles Byrne
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-30 00:00:00 Z
18
+ date: 2011-05-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rdiscount
@@ -115,6 +115,8 @@ files:
115
115
  - gitdoc.rb
116
116
  - highlight.css
117
117
  - pkg/gitdoc-4.1.0.gem
118
+ - pkg/gitdoc-4.2.0.gem
119
+ - pkg/gitdoc-4.3.0.gem
118
120
  - Rakefile
119
121
  - README.md
120
122
  - reset.sass