jekyll 0.12.1 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of jekyll might be problematic. Click here for more details.

Files changed (124) hide show
  1. data/CONTRIBUTING.md +67 -0
  2. data/Gemfile +1 -1
  3. data/History.txt +50 -6
  4. data/README.textile +10 -6
  5. data/Rakefile +74 -36
  6. data/bin/jekyll +78 -276
  7. data/cucumber.yml +3 -1
  8. data/features/create_sites.feature +1 -1
  9. data/features/drafts.feature +25 -0
  10. data/features/site_configuration.feature +1 -1
  11. data/features/step_definitions/jekyll_steps.rb +13 -3
  12. data/features/support/env.rb +3 -1
  13. data/jekyll.gemspec +73 -17
  14. data/lib/jekyll.rb +31 -21
  15. data/lib/jekyll/command.rb +12 -0
  16. data/lib/jekyll/commands/build.rb +81 -0
  17. data/lib/jekyll/commands/serve.rb +28 -0
  18. data/lib/jekyll/converter.rb +1 -3
  19. data/lib/jekyll/converters/identity.rb +13 -14
  20. data/lib/jekyll/converters/markdown.rb +128 -128
  21. data/lib/jekyll/converters/textile.rb +37 -37
  22. data/lib/jekyll/convertible.rb +6 -4
  23. data/lib/jekyll/core_ext.rb +9 -1
  24. data/lib/jekyll/draft.rb +35 -0
  25. data/lib/jekyll/errors.rb +1 -3
  26. data/lib/jekyll/filters.rb +13 -4
  27. data/lib/jekyll/generator.rb +1 -4
  28. data/lib/jekyll/generators/pagination.rb +46 -46
  29. data/lib/jekyll/layout.rb +0 -2
  30. data/lib/jekyll/mime.types +1588 -0
  31. data/lib/jekyll/page.rb +24 -8
  32. data/lib/jekyll/plugin.rb +0 -2
  33. data/lib/jekyll/post.rb +66 -40
  34. data/lib/jekyll/site.rb +96 -20
  35. data/lib/jekyll/static_file.rb +0 -2
  36. data/lib/jekyll/tags/gist.rb +19 -0
  37. data/lib/jekyll/tags/highlight.rb +63 -62
  38. data/lib/jekyll/tags/include.rb +25 -25
  39. data/lib/jekyll/tags/post_url.rb +30 -25
  40. data/script/bootstrap +2 -0
  41. data/site/.gitignore +4 -0
  42. data/site/CNAME +1 -0
  43. data/site/README +1 -0
  44. data/site/_config.yml +5 -0
  45. data/site/_includes/analytics.html +32 -0
  46. data/site/_includes/docs_contents.html +82 -0
  47. data/site/_includes/footer.html +15 -0
  48. data/site/_includes/header.html +26 -0
  49. data/site/_includes/section_nav.html +22 -0
  50. data/site/_includes/top.html +14 -0
  51. data/site/_layouts/default.html +12 -0
  52. data/site/_layouts/docs.html +21 -0
  53. data/site/_posts/2012-07-01-configuration.md +277 -0
  54. data/site/_posts/2012-07-01-contributing.md +66 -0
  55. data/site/_posts/2012-07-01-deployment-methods.md +108 -0
  56. data/site/_posts/2012-07-01-extras.md +103 -0
  57. data/site/_posts/2012-07-01-frontmatter.md +120 -0
  58. data/site/_posts/2012-07-01-github-pages.md +34 -0
  59. data/site/_posts/2012-07-01-heroku.md +8 -0
  60. data/site/_posts/2012-07-01-home.md +47 -0
  61. data/site/_posts/2012-07-01-installation.md +43 -0
  62. data/site/_posts/2012-07-01-migrations.md +180 -0
  63. data/site/_posts/2012-07-01-pages.md +62 -0
  64. data/site/_posts/2012-07-01-pagination.md +116 -0
  65. data/site/_posts/2012-07-01-permalinks.md +163 -0
  66. data/site/_posts/2012-07-01-plugins.md +384 -0
  67. data/site/_posts/2012-07-01-posts.md +106 -0
  68. data/site/_posts/2012-07-01-resources.md +49 -0
  69. data/site/_posts/2012-07-01-sites.md +28 -0
  70. data/site/_posts/2012-07-01-structure.md +95 -0
  71. data/site/_posts/2012-07-01-templates.md +217 -0
  72. data/site/_posts/2012-07-01-troubleshooting.md +108 -0
  73. data/site/_posts/2012-07-01-usage.md +38 -0
  74. data/site/_posts/2012-07-01-variables.md +166 -0
  75. data/site/css/grid.css +62 -0
  76. data/site/css/normalize.css +504 -0
  77. data/site/css/pygments.css +70 -0
  78. data/site/css/style.css +697 -0
  79. data/site/docs/index.html +11 -0
  80. data/site/favicon.png +0 -0
  81. data/site/img/article-footer.png +0 -0
  82. data/site/img/footer-arrow.png +0 -0
  83. data/site/img/footer-logo.png +0 -0
  84. data/site/img/logo-2x.png +0 -0
  85. data/site/img/octojekyll.png +0 -0
  86. data/site/img/tube.png +0 -0
  87. data/site/img/tube1x.png +0 -0
  88. data/site/index.html +77 -0
  89. data/site/js/modernizr-2.5.3.min.js +4 -0
  90. data/test/fixtures/broken_front_matter2.erb +4 -0
  91. data/test/fixtures/broken_front_matter3.erb +7 -0
  92. data/test/fixtures/exploit_front_matter.erb +4 -0
  93. data/test/helper.rb +16 -0
  94. data/test/source/_posts/2013-01-12-nil-layout.textile +6 -0
  95. data/test/source/_posts/2013-01-12-no-layout.textile +5 -0
  96. data/test/source/contacts/bar.html +5 -0
  97. data/test/source/contacts/index.html +5 -0
  98. data/test/test_configuration.rb +7 -8
  99. data/test/test_convertible.rb +29 -0
  100. data/test/test_core_ext.rb +22 -0
  101. data/test/test_generated_site.rb +1 -1
  102. data/test/test_kramdown.rb +3 -3
  103. data/test/test_page.rb +88 -2
  104. data/test/test_post.rb +42 -6
  105. data/test/test_rdiscount.rb +1 -1
  106. data/test/test_redcarpet.rb +1 -1
  107. data/test/test_redcloth.rb +6 -6
  108. data/test/test_site.rb +73 -8
  109. data/test/test_tags.rb +36 -13
  110. metadata +150 -19
  111. data/lib/jekyll/migrators/csv.rb +0 -26
  112. data/lib/jekyll/migrators/drupal.rb +0 -103
  113. data/lib/jekyll/migrators/enki.rb +0 -49
  114. data/lib/jekyll/migrators/joomla.rb +0 -53
  115. data/lib/jekyll/migrators/marley.rb +0 -52
  116. data/lib/jekyll/migrators/mephisto.rb +0 -84
  117. data/lib/jekyll/migrators/mt.rb +0 -86
  118. data/lib/jekyll/migrators/posterous.rb +0 -67
  119. data/lib/jekyll/migrators/rss.rb +0 -47
  120. data/lib/jekyll/migrators/textpattern.rb +0 -58
  121. data/lib/jekyll/migrators/tumblr.rb +0 -195
  122. data/lib/jekyll/migrators/typo.rb +0 -51
  123. data/lib/jekyll/migrators/wordpress.rb +0 -294
  124. data/lib/jekyll/migrators/wordpressdotcom.rb +0 -70
@@ -1 +1,3 @@
1
- default: --format progress
1
+ default: --format pretty
2
+ travis: --format progress
3
+ html_report: --format progress --format html --out=features_report.html
@@ -89,7 +89,7 @@ Feature: Create sites
89
89
  And I have an "_includes/about.textile" file that contains "Generated by {% include jekyll.textile %}"
90
90
  And I have an "_includes/jekyll.textile" file that contains "Jekyll"
91
91
  And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}"
92
- When I debug jekyll
92
+ When I run jekyll
93
93
  Then the _site directory should exist
94
94
  And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html"
95
95
 
@@ -0,0 +1,25 @@
1
+ Feature: Draft Posts
2
+ As a hacker who likes to blog
3
+ I want to be able to preview drafts locally
4
+ In order to see if they look alright before publishing
5
+
6
+ Scenario: Preview a draft
7
+ Given I have a configuration file with "permalink" set to "none"
8
+ And I have a _drafts directory
9
+ And I have the following draft:
10
+ | title | date | layout | content |
11
+ | Recipe | 3/27/2009 | default | Not baked yet. |
12
+ When I run jekyll with drafts
13
+ Then the _site directory should exist
14
+ And I should see "Not baked yet." in "_site/recipe.html"
15
+
16
+ Scenario: Don't preview a draft
17
+ Given I have a configuration file with "permalink" set to "none"
18
+ And I have an "index.html" page that contains "Totally index"
19
+ And I have a _drafts directory
20
+ And I have the following draft:
21
+ | title | date | layout | content |
22
+ | Recipe | 3/27/2009 | default | Not baked yet. |
23
+ When I run jekyll
24
+ Then the _site directory should exist
25
+ And the "_site/recipe.html" file should not exist
@@ -22,7 +22,7 @@ Feature: Site configuration
22
22
  Given I have an "Rakefile" file that contains "I want to be excluded"
23
23
  And I have an "README" file that contains "I want to be excluded"
24
24
  And I have an "index.html" file that contains "I want to be included"
25
- And I have a configuration file with "exclude" set to "Rakefile", "README"
25
+ And I have a configuration file with "exclude" set to "['Rakefile', 'README']"
26
26
  When I run jekyll
27
27
  Then I should see "I want to be included" in "_site/index.html"
28
28
  And the "_site/Rakefile" file should not exist
@@ -50,9 +50,8 @@ Given /^I have an? (.*) directory$/ do |dir|
50
50
  FileUtils.mkdir_p(dir)
51
51
  end
52
52
 
53
- Given /^I have the following posts?(?: (.*) "(.*)")?:$/ do |direction, folder, table|
53
+ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, direction, folder, table|
54
54
  table.hashes.each do |post|
55
- date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d')
56
55
  title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
57
56
 
58
57
  if direction && direction == "in"
@@ -61,7 +60,14 @@ Given /^I have the following posts?(?: (.*) "(.*)")?:$/ do |direction, folder, t
61
60
  after = folder || '.'
62
61
  end
63
62
 
64
- path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{post['type'] || 'textile'}")
63
+ ext = post['type'] || 'textile'
64
+
65
+ if "draft" == status
66
+ path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}")
67
+ else
68
+ date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d')
69
+ path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}")
70
+ end
65
71
 
66
72
  matter_hash = {}
67
73
  %w(title layout tag tags category categories published author).each do |key|
@@ -117,6 +123,10 @@ When /^I run jekyll$/ do
117
123
  run_jekyll
118
124
  end
119
125
 
126
+ When /^I run jekyll with drafts$/ do
127
+ run_jekyll(:drafts => true)
128
+ end
129
+
120
130
  When /^I debug jekyll$/ do
121
131
  run_jekyll(:debug => true)
122
132
  end
@@ -10,7 +10,9 @@ TEST_DIR = File.join('/', 'tmp', 'jekyll')
10
10
  JEKYLL_PATH = File.join(ENV['PWD'], 'bin', 'jekyll')
11
11
 
12
12
  def run_jekyll(opts = {})
13
- command = JEKYLL_PATH
13
+ command = JEKYLL_PATH.clone
14
+ command << " build"
15
+ command << " --drafts" if opts[:drafts]
14
16
  command << " >> /dev/null 2>&1" if opts[:debug].nil?
15
17
  system command
16
18
  end
@@ -4,9 +4,9 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'jekyll'
7
- s.version = '0.12.1'
7
+ s.version = '1.0.0.beta1'
8
8
  s.license = 'MIT'
9
- s.date = '2013-02-19'
9
+ s.date = '2013-03-14'
10
10
  s.rubyforge_project = 'jekyll'
11
11
 
12
12
  s.summary = "A simple, blog aware, static site generator."
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
29
29
  s.add_runtime_dependency('maruku', "~> 0.5")
30
30
  s.add_runtime_dependency('kramdown', "~> 0.14")
31
31
  s.add_runtime_dependency('pygments.rb', "~> 0.3.2")
32
+ s.add_runtime_dependency('commander', "~> 4.1.3")
33
+ s.add_runtime_dependency('safe_yaml', "~> 0.7.0")
32
34
 
33
35
  s.add_development_dependency('rake', "~> 10.0.3")
34
36
  s.add_development_dependency('rdoc', "~> 3.11")
@@ -39,9 +41,13 @@ Gem::Specification.new do |s|
39
41
  s.add_development_dependency('RedCloth', "~> 4.2")
40
42
  s.add_development_dependency('rdiscount', "~> 1.6")
41
43
  s.add_development_dependency('redcarpet', "~> 2.2.2")
42
-
44
+ s.add_development_dependency('launchy', "~> 2.1.2")
45
+ s.add_development_dependency('simplecov', "~> 0.7")
46
+ s.add_development_dependency('simplecov-gem-adapter', "~> 1.0.1")
47
+
43
48
  # = MANIFEST =
44
49
  s.files = %w[
50
+ CONTRIBUTING.md
45
51
  Gemfile
46
52
  History.txt
47
53
  LICENSE
@@ -50,6 +56,7 @@ Gem::Specification.new do |s|
50
56
  bin/jekyll
51
57
  cucumber.yml
52
58
  features/create_sites.feature
59
+ features/drafts.feature
53
60
  features/embed_filters.feature
54
61
  features/markdown.feature
55
62
  features/pagination.feature
@@ -61,40 +68,85 @@ Gem::Specification.new do |s|
61
68
  features/support/env.rb
62
69
  jekyll.gemspec
63
70
  lib/jekyll.rb
71
+ lib/jekyll/command.rb
72
+ lib/jekyll/commands/build.rb
73
+ lib/jekyll/commands/serve.rb
64
74
  lib/jekyll/converter.rb
65
75
  lib/jekyll/converters/identity.rb
66
76
  lib/jekyll/converters/markdown.rb
67
77
  lib/jekyll/converters/textile.rb
68
78
  lib/jekyll/convertible.rb
69
79
  lib/jekyll/core_ext.rb
80
+ lib/jekyll/draft.rb
70
81
  lib/jekyll/errors.rb
71
82
  lib/jekyll/filters.rb
72
83
  lib/jekyll/generator.rb
73
84
  lib/jekyll/generators/pagination.rb
74
85
  lib/jekyll/layout.rb
75
- lib/jekyll/migrators/csv.rb
76
- lib/jekyll/migrators/drupal.rb
77
- lib/jekyll/migrators/enki.rb
78
- lib/jekyll/migrators/joomla.rb
79
- lib/jekyll/migrators/marley.rb
80
- lib/jekyll/migrators/mephisto.rb
81
- lib/jekyll/migrators/mt.rb
82
- lib/jekyll/migrators/posterous.rb
83
- lib/jekyll/migrators/rss.rb
84
- lib/jekyll/migrators/textpattern.rb
85
- lib/jekyll/migrators/tumblr.rb
86
- lib/jekyll/migrators/typo.rb
87
- lib/jekyll/migrators/wordpress.rb
88
- lib/jekyll/migrators/wordpressdotcom.rb
86
+ lib/jekyll/mime.types
89
87
  lib/jekyll/page.rb
90
88
  lib/jekyll/plugin.rb
91
89
  lib/jekyll/post.rb
92
90
  lib/jekyll/site.rb
93
91
  lib/jekyll/static_file.rb
92
+ lib/jekyll/tags/gist.rb
94
93
  lib/jekyll/tags/highlight.rb
95
94
  lib/jekyll/tags/include.rb
96
95
  lib/jekyll/tags/post_url.rb
96
+ script/bootstrap
97
+ site/.gitignore
98
+ site/CNAME
99
+ site/README
100
+ site/_config.yml
101
+ site/_includes/analytics.html
102
+ site/_includes/docs_contents.html
103
+ site/_includes/footer.html
104
+ site/_includes/header.html
105
+ site/_includes/section_nav.html
106
+ site/_includes/top.html
107
+ site/_layouts/default.html
108
+ site/_layouts/docs.html
109
+ site/_posts/2012-07-01-configuration.md
110
+ site/_posts/2012-07-01-contributing.md
111
+ site/_posts/2012-07-01-deployment-methods.md
112
+ site/_posts/2012-07-01-extras.md
113
+ site/_posts/2012-07-01-frontmatter.md
114
+ site/_posts/2012-07-01-github-pages.md
115
+ site/_posts/2012-07-01-heroku.md
116
+ site/_posts/2012-07-01-home.md
117
+ site/_posts/2012-07-01-installation.md
118
+ site/_posts/2012-07-01-migrations.md
119
+ site/_posts/2012-07-01-pages.md
120
+ site/_posts/2012-07-01-pagination.md
121
+ site/_posts/2012-07-01-permalinks.md
122
+ site/_posts/2012-07-01-plugins.md
123
+ site/_posts/2012-07-01-posts.md
124
+ site/_posts/2012-07-01-resources.md
125
+ site/_posts/2012-07-01-sites.md
126
+ site/_posts/2012-07-01-structure.md
127
+ site/_posts/2012-07-01-templates.md
128
+ site/_posts/2012-07-01-troubleshooting.md
129
+ site/_posts/2012-07-01-usage.md
130
+ site/_posts/2012-07-01-variables.md
131
+ site/css/grid.css
132
+ site/css/normalize.css
133
+ site/css/pygments.css
134
+ site/css/style.css
135
+ site/docs/index.html
136
+ site/favicon.png
137
+ site/img/article-footer.png
138
+ site/img/footer-arrow.png
139
+ site/img/footer-logo.png
140
+ site/img/logo-2x.png
141
+ site/img/octojekyll.png
142
+ site/img/tube.png
143
+ site/img/tube1x.png
144
+ site/index.html
145
+ site/js/modernizr-2.5.3.min.js
97
146
  test/fixtures/broken_front_matter1.erb
147
+ test/fixtures/broken_front_matter2.erb
148
+ test/fixtures/broken_front_matter3.erb
149
+ test/fixtures/exploit_front_matter.erb
98
150
  test/fixtures/front_matter.erb
99
151
  test/helper.rb
100
152
  test/source/.htaccess
@@ -126,9 +178,13 @@ Gem::Specification.new do |s|
126
178
  test/source/_posts/2010-01-16-override-data.textile
127
179
  test/source/_posts/2011-04-12-md-extension.md
128
180
  test/source/_posts/2011-04-12-text-extension.text
181
+ test/source/_posts/2013-01-12-nil-layout.textile
182
+ test/source/_posts/2013-01-12-no-layout.textile
129
183
  test/source/about.html
130
184
  test/source/category/_posts/2008-9-23-categories.textile
131
185
  test/source/contacts.html
186
+ test/source/contacts/bar.html
187
+ test/source/contacts/index.html
132
188
  test/source/css/screen.css
133
189
  test/source/deal.with.dots.html
134
190
  test/source/foo/_posts/bar/2008-12-12-topical-post.textile
@@ -18,7 +18,7 @@ require 'rubygems'
18
18
  # stdlib
19
19
  require 'fileutils'
20
20
  require 'time'
21
- require 'yaml'
21
+ require 'safe_yaml'
22
22
  require 'English'
23
23
 
24
24
  # 3rd party
@@ -33,6 +33,7 @@ require 'jekyll/convertible'
33
33
  require 'jekyll/layout'
34
34
  require 'jekyll/page'
35
35
  require 'jekyll/post'
36
+ require 'jekyll/draft'
36
37
  require 'jekyll/filters'
37
38
  require 'jekyll/static_file'
38
39
  require 'jekyll/errors'
@@ -41,33 +42,34 @@ require 'jekyll/errors'
41
42
  require 'jekyll/plugin'
42
43
  require 'jekyll/converter'
43
44
  require 'jekyll/generator'
45
+ require 'jekyll/command'
46
+
47
+ require_all 'jekyll/commands'
44
48
  require_all 'jekyll/converters'
45
49
  require_all 'jekyll/generators'
46
50
  require_all 'jekyll/tags'
47
51
 
52
+ SafeYAML::OPTIONS[:suppress_warnings] = true
53
+
48
54
  module Jekyll
49
- VERSION = '0.12.1'
55
+ VERSION = '1.0.0.beta1'
50
56
 
51
- # Default options. Overriden by values in _config.yml or command-line opts.
57
+ # Default options. Overriden by values in _config.yml.
52
58
  # Strings rather than symbols are used for compatability with YAML.
53
59
  DEFAULTS = {
54
- 'safe' => false,
55
- 'auto' => false,
56
- 'server' => false,
57
- 'server_port' => 4000,
58
-
59
60
  'source' => Dir.pwd,
60
61
  'destination' => File.join(Dir.pwd, '_site'),
61
- 'plugins' => File.join(Dir.pwd, '_plugins'),
62
+ 'plugins' => '_plugins',
62
63
  'layouts' => '_layouts',
64
+ 'keep_files' => ['.git','.svn'],
63
65
 
64
- 'future' => true,
65
- 'lsi' => false,
66
- 'pygments' => false,
67
- 'markdown' => 'maruku',
68
- 'permalink' => 'date',
69
- 'include' => ['.htaccess'],
70
- 'paginate_path' => 'page:num',
66
+ 'future' => true, # remove and make true just default
67
+ 'pygments' => false, # remove and make true just default
68
+
69
+ 'markdown' => 'maruku', # no longer a command option
70
+ 'permalink' => 'date', # no longer a command option
71
+ 'include' => ['.htaccess'], # no longer a command option
72
+ 'paginate_path' => 'page:num', # no longer a command option
71
73
 
72
74
  'markdown_ext' => 'markdown,mkd,mkdn,md',
73
75
  'textile_ext' => 'textile',
@@ -120,6 +122,9 @@ module Jekyll
120
122
  #
121
123
  # Returns the final configuration Hash.
122
124
  def self.configuration(override)
125
+ # Convert any symbol keys to strings and remove the old key/values
126
+ override = override.reduce({}) { |hsh,(k,v)| hsh.merge(k.to_s => v) }
127
+
123
128
  # _config.yml may override default source location, but until
124
129
  # then, we need to know where to look for _config.yml
125
130
  source = override['source'] || Jekyll::DEFAULTS['source']
@@ -127,13 +132,18 @@ module Jekyll
127
132
  # Get configuration from <source>/_config.yml
128
133
  config_file = File.join(source, '_config.yml')
129
134
  begin
130
- config = YAML.load_file(config_file)
131
- raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
132
- $stdout.puts "Configuration from #{config_file}"
135
+ config = YAML.safe_load_file(config_file)
136
+ raise "Configuration file: (INVALID) #{config_file}" if !config.is_a?(Hash)
137
+ $stdout.puts "Configuration file: #{config_file}"
138
+ rescue SystemCallError
139
+ # Errno:ENOENT = file not found
140
+ $stderr.puts "Configuration file: none"
141
+ config = {}
133
142
  rescue => err
134
- $stderr.puts "WARNING: Could not read configuration. " +
143
+ $stderr.puts " " +
144
+ "WARNING: Error reading configuration. " +
135
145
  "Using defaults (and options)."
136
- $stderr.puts "\t" + err.to_s
146
+ $stderr.puts "#{err}"
137
147
  config = {}
138
148
  end
139
149
 
@@ -0,0 +1,12 @@
1
+ module Jekyll
2
+ class Command
3
+ def self.globs(source, destination)
4
+ Dir.chdir(source) do
5
+ dirs = Dir['*'].select { |x| File.directory?(x) }
6
+ dirs -= [destination]
7
+ dirs = dirs.map { |x| "#{x}/**/*" }
8
+ dirs += ['*']
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,81 @@
1
+ module Jekyll
2
+ module Commands
3
+ class Build < Command
4
+ def self.process(options)
5
+ site = Jekyll::Site.new(options)
6
+
7
+ source = options['source']
8
+ destination = options['destination']
9
+
10
+ if options['watch']
11
+ self.watch(site, options)
12
+ else
13
+ self.build(site, options)
14
+ end
15
+ end
16
+
17
+ # Private: Build the site from source into destination.
18
+ #
19
+ # site - A Jekyll::Site instance
20
+ # options - A Hash of options passed to the command
21
+ #
22
+ # Returns nothing.
23
+ def self.build(site, options)
24
+ source = options['source']
25
+ destination = options['destination']
26
+ puts " Source: #{source}"
27
+ puts " Destination: #{destination}"
28
+ print " Generating... "
29
+ begin
30
+ site.process
31
+ rescue Jekyll::FatalException => e
32
+ puts
33
+ puts "ERROR: YOUR SITE COULD NOT BE BUILT:"
34
+ puts "------------------------------------"
35
+ puts e.message
36
+ exit(1)
37
+ end
38
+ puts "done."
39
+ end
40
+
41
+ # Private: Watch for file changes and rebuild the site.
42
+ #
43
+ # site - A Jekyll::Site instance
44
+ # options - A Hash of options passed to the command
45
+ #
46
+ # Returns nothing.
47
+ def self.watch(site, options)
48
+ require 'directory_watcher'
49
+
50
+ source = options['source']
51
+ destination = options['destination']
52
+
53
+ puts " Source: #{source}"
54
+ puts " Destination: #{destination}"
55
+ puts " Auto-regeneration: enabled"
56
+
57
+ dw = DirectoryWatcher.new(source)
58
+ dw.interval = 1
59
+ dw.glob = self.globs(source, destination)
60
+
61
+ dw.add_observer do |*args|
62
+ t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
63
+ print " Regenerating: #{args.size} files at #{t} "
64
+ site.process
65
+ puts "...done."
66
+ end
67
+
68
+ dw.start
69
+
70
+ unless options['serving']
71
+ trap("INT") do
72
+ puts " Halting auto-regeneration."
73
+ exit 0
74
+ end
75
+
76
+ loop { sleep 1000 }
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end