rack-jekyll 0.3.7 → 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.markdown CHANGED
@@ -69,6 +69,16 @@ It now can read the `_config.yml` file for destination path. Read [Jekyll Config
69
69
 
70
70
  You can create a new file: `404.html` with YAML Front Matter. See my [Heroku Demo 404](http://bry4n.heroku.com/show/me/404/)
71
71
 
72
+ ## Contributors
73
+ * adaoraul (Adão Raul)
74
+ * Nerian (Gonzalo Rodríguez-Baltanás Díaz)
75
+ * scottwater (Scott Watermasysk)
76
+ * thedjinn (Emil Loer)
77
+ * bry4n (Bryan Goines)
78
+ * thibaudgg (Thibaud Guillaume-Gentil)
79
+ * bemurphy (Brendon Murphy)
80
+ * imajes (James Cox)
81
+ * mattr- (Matt Rogers)
72
82
 
73
83
  ## Contribution
74
84
 
data/lib/rack/jekyll.rb CHANGED
@@ -4,39 +4,66 @@ require "rack/request"
4
4
  require "rack/response"
5
5
  require File.join(File.dirname(__FILE__), 'jekyll', 'helpers')
6
6
  require File.join(File.dirname(__FILE__), 'jekyll', 'version')
7
+ require File.join(File.dirname(__FILE__), 'jekyll', 'ext')
7
8
 
8
9
  module Rack
9
10
  class Jekyll
10
11
  @compiling = false
11
-
12
+
12
13
  def initialize(opts = {})
13
14
  config_file = '_config.yml'
14
15
  if ::File.exist?(config_file)
15
16
  config = YAML.load_file(config_file)
16
- @path = (config[:destination].nil? && "_site") || config[:destination]
17
+ @path = (config['destination'].nil? && "_site") || config['destination']
17
18
 
18
19
  @files = ::Dir[@path + "/**/*"].inspect
19
20
  @files unless ENV['RACK_DEBUG']
20
21
  end
21
-
22
+
22
23
  @mimes = Rack::Mime::MIME_TYPES.map{|k,v| /#{k.gsub('.','\.')}$/i }
23
-
24
+ require "jekyll"
25
+ options = ::Jekyll.configuration(opts)
26
+ site = ::Jekyll::Site.new(options)
24
27
  if ::Dir[@path + "/**/*"].empty?
25
- require "jekyll"
26
- options = ::Jekyll.configuration(opts)
27
- site = ::Jekyll::Site.new(options)
28
28
  site.process
29
-
30
29
  @compiling = true
31
30
  else
32
31
  @compiling = false
33
32
  end
33
+ if options['auto']
34
+ require 'directory_watcher'
35
+ require 'pathname'
36
+ source, destination = options['source'], options['destination']
37
+ puts "Auto-regenerating enabled: #{source} -> #{destination}"
38
+
39
+ dw = DirectoryWatcher.new(source)
40
+ dw.interval = 1
41
+ dw.glob = globs(source)
42
+
43
+ dw.add_observer do |*args|
44
+ t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
45
+ puts "[#{t}] regeneration: #{args.size} files changed"
46
+ site.process
47
+ end
48
+
49
+ dw.start
50
+ end
51
+ end
52
+
53
+ def globs(source)
54
+ Dir.chdir(source) do
55
+ dirs = Dir['*'].select { |x| Pathname(x).directory? }
56
+ dirs -= ['_site']
57
+ dirs = dirs.map { |x| "#{x}/**/*" }
58
+ dirs += ['*']
59
+ end
34
60
  end
35
-
61
+
36
62
  def call(env)
37
63
  @request = Rack::Request.new(env)
38
64
  @response = Rack::Response.new
39
65
  path_info = @request.path_info
66
+ @files = ::Dir[@path + "/**/*"].inspect if @files == "[]"
40
67
  if @files.include?(path_info)
41
68
  if path_info =~ /(\/?)$/
42
69
  if @mimes.collect {|regex| path_info =~ regex }.compact.empty?
@@ -48,22 +75,26 @@ module Rack
48
75
  file = file_info(@path + path_info)
49
76
  body = file[:body]
50
77
  time = file[:time]
78
+ hdrs = { 'Last-Modified' => time }
51
79
 
52
80
  if time == @request.env['HTTP_IF_MODIFIED_SINCE']
53
- [@response.status, {'Last-Modified' => time}, []]
81
+ [304, hdrs, []]
54
82
  else
55
- [@response.status, {"Content-Type" => mime, "Content-length" => body.length.to_s, 'Last-Modified' => time}, [body]]
83
+ hdrs.update({ 'Content-length' => body.bytesize.to_s,
84
+ 'Content-Type' => mime, } )
85
+ [@response.status, hdrs, [body]]
56
86
  end
57
87
 
58
88
  else
59
89
  status, body, path_info = ::File.exist?(@path+"/404.html") ? [404,file_info(@path+"/404.html")[:body],"404.html"] : [404,"Not found","404.html"]
60
90
  mime = mime(path_info)
61
91
  if !@compiling
62
- [status, {"Content-Type" => mime, "Content-length" => body.length.to_s}, [body]]
92
+ [status, {"Content-Type" => mime, "Content-length" => body.bytesize.to_s}, [body]]
63
93
  else
64
- [200, {"Content-Type" => "text/plain"}, ["This site is currently generating pages. Please reload this page after 10 secs."]]
94
+ @compiling = ::Dir[@path + "/**/*"].empty?
95
+ [200, {"Content-Type" => "text/plain"}, ["This site is currently generating pages. Please reload this page after a couple of seconds."]]
65
96
  end
66
97
  end
67
- end
98
+ end
68
99
  end
69
- end
100
+ end
@@ -0,0 +1,7 @@
1
+ class String
2
+ if RUBY_VERSION < "1.9"
3
+ def bytesize
4
+ size
5
+ end
6
+ end
7
+ end
@@ -2,7 +2,7 @@ module Rack
2
2
  class Jekyll
3
3
  def mime(path_info)
4
4
  if path_info !~ /html$/i
5
- ext = $1 if path_info =~ /(\.\S+)$/
5
+ ext = $1 if path_info =~ /(\.[\S&&[^.]]+)$/
6
6
  Mime.mime_type((ext.nil? ? ".html" : ext))
7
7
  else
8
8
  Mime.mime_type(".html")
@@ -16,4 +16,4 @@ module Rack
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -1,12 +1,13 @@
1
1
  require "rack"
2
2
  require "rack/request"
3
3
  require "rack/response"
4
+ require File.join(File.dirname(__FILE__), 'ext')
4
5
 
5
6
  module Rack
6
7
  class Jekyll
7
8
  class Test
8
9
  def initialize
9
- @files = %w{_fake/ _fake/index.html _fake/3/2/1/helloworld/index.html _fake/css/test.css _fake/js/test.js}
10
+ @files = %w{_fake/ _fake/index.html _fake/3/2/1/helloworld/index.html _fake/css/test.css _fake/js/test.js _fake/js/test.min.js}
10
11
  @mimes = Rack::Mime::MIME_TYPES.reject{|k,v|k=~%r{html?}}.map{|k,v|%r{#{k.gsub('.','\.')}$}i}
11
12
  end
12
13
 
@@ -25,16 +26,16 @@ module Rack
25
26
  if time == request.env['HTTP_IF_MODIFIED_SINCE']
26
27
  [304, {'Last-Modified' => time}, []]
27
28
  else
28
- [200, {"Content-Type" => mime, "Content-length" => body.length.to_s, "Last-Modified" => "Thu, 01 Apr 2010 15:27:52 GMT"}, [body]]
29
+ [200, {"Content-Type" => mime, "Content-length" => body.bytesize.to_s, "Last-Modified" => "Thu, 01 Apr 2010 15:27:52 GMT"}, [body]]
29
30
  end
30
31
  else
31
32
  status, body, path_info = [404,"Not found","404.html"]
32
33
  mime = mime(path_info)
33
- [status, {"Content-Type" => mime, "Content-Type" => body.length.to_s}, [body]]
34
+ [status, {"Content-Type" => mime, "Content-Type" => body.bytesize.to_s}, [body]]
34
35
  end
35
36
  end
36
37
  def mime(path_info)
37
- ext = $1 if path_info =~ /(\.\S+)$/
38
+ ext = $1 if path_info =~ /(\.[\S&&[^.]]+)$/
38
39
  Mime.mime_type((ext.nil? ? ".html" : ext))
39
40
  end
40
41
  end
@@ -1,7 +1,7 @@
1
1
  module Rack
2
2
  class Jekyll
3
3
  def self.version
4
- '0.3.7'
4
+ '0.4.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,92 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-jekyll
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
4
5
  prerelease:
5
- version: 0.3.7
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Bryan Goines
9
- - "Ad\xC3\xA3o Raul"
9
+ - Adão Raul
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-07-15 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2013-04-02 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: jekyll
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
19
+ requirements:
22
20
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: 0.6.2
21
+ - !ruby/object:Gem::Version
22
+ version: 0.12.0
25
23
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rack
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 0.12.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: rack
33
+ requirement: !ruby/object:Gem::Requirement
31
34
  none: false
32
- requirements:
35
+ requirements:
33
36
  - - ~>
34
- - !ruby/object:Gem::Version
35
- version: 1.2.1
37
+ - !ruby/object:Gem::Version
38
+ version: 1.5.0
36
39
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: bacon
40
40
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
42
42
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.5.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: bacon
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  type: :development
48
- version_requirements: *id003
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
49
63
  description: Transform your jekyll based app into a Rack application
50
- email: bryan@ffiirree.com
64
+ email: adao.raul@gmail.com
51
65
  executables: []
52
-
53
66
  extensions: []
54
-
55
- extra_rdoc_files:
67
+ extra_rdoc_files:
56
68
  - README.markdown
57
- files:
69
+ files:
58
70
  - README.markdown
59
71
  - LICENSE
60
72
  - lib/rack/jekyll.rb
61
73
  - lib/rack/jekyll/test.rb
62
74
  - lib/rack/jekyll/helpers.rb
63
75
  - lib/rack/jekyll/version.rb
76
+ - lib/rack/jekyll/ext.rb
64
77
  homepage: http://github.com/adaoraul/rack-jekyll
65
78
  licenses: []
66
-
67
79
  post_install_message:
68
80
  rdoc_options: []
69
-
70
- require_paths:
81
+ require_paths:
71
82
  - lib
72
- required_ruby_version: !ruby/object:Gem::Requirement
83
+ required_ruby_version: !ruby/object:Gem::Requirement
73
84
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: "0"
78
- required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ segments:
90
+ - 0
91
+ hash: 849397492136401640
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
93
  none: false
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
83
97
  version: 1.3.6
84
98
  requirements: []
85
-
86
99
  rubyforge_project: rack-jekyll
87
- rubygems_version: 1.8.4
100
+ rubygems_version: 1.8.23
88
101
  signing_key:
89
102
  specification_version: 3
90
103
  summary: rack-jekyll
91
104
  test_files: []
92
-