Commit 31215fc

mo <mo@mokhan.ca>
2018-09-25 22:31:35
use jekyll api directly.
1 parent 24c7950
Changed files (2)
lib/tasks/doc.rake
@@ -1,19 +1,29 @@
 # frozen_string_literal: true
 
 namespace :doc do
-  desc "Build static pages"
-  task build: [:clean] do
-    sh "jekyll b --config config/jekyll.yml"
-  end
+  Bundler.require(:doc)
 
-  desc "Watch and rebuild static pages"
-  task :watch do
-    sh "jekyll b --config config/jekyll.yml --watch"
+  def default_options
+    {
+      config: Rails.root.join("config", "jekyll.yml").to_s,
+      source: Rails.root.join('doc').to_s,
+      destination: Rails.root.join('public/doc').to_s
+    }
   end
 
-  desc "Clean up after Jekyll"
+  desc 'Clean the API documentation'
   task :clean do
-    sh "rm -fr public/doc"
-    sh "mkdir public/doc && touch public/doc/.keep"
+    rm_rf Rails.root.join('public/doc')
+  end
+
+  desc "Build static pages"
+  task build: [:clean, :environment] do
+    Jekyll::Site.new(Jekyll.configuration(default_options)).process
+  end
+
+  desc "Watch and rebuild static pages"
+  task watch: [:environment] do
+    custom_options = default_options.merge(watch: true)
+    Jekyll::Commands::Build.process(custom_options)
   end
 end
Gemfile
@@ -26,12 +26,14 @@ gem 'turbolinks', '~> 5'
 gem 'uglifier', '>= 1.3.0'
 gem 'webpacker', '~> 3.5'
 # gem 'redis', '~> 4.0'
+group :doc do
+  gem 'jekyll', '~> 3.8'
+  gem "minima", "~> 2.0" # This is the default theme for new Jekyll sites.
+end
 group :development do
   gem 'brakeman', '~> 4.3'
   gem 'bundler-audit', '~> 0.6'
-  gem 'jekyll', '~> 3.8'
   gem 'listen', '>= 3.0.5', '< 3.2'
-  gem "minima", "~> 2.0" # This is the default theme for new Jekyll sites.
   gem 'rubocop', '~> 0.58'
   gem 'web-console', '>= 3.3.0'
 end