Permalink
Browse files

Live previews with `rake preview[directory]`. Look to http://localhos…

…t:4000
  • Loading branch information...
1 parent 4e1a7e6 commit f7208d1fc16787976e3dc8e812852820bfc87a20 @pdxmph pdxmph committed Feb 7, 2013
Showing with 72 additions and 9 deletions.
  1. +4 −4 Gemfile.lock
  2. +68 −5 Rakefile
View
8 Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/puppetlabs/jekyll.git
- revision: 0ee3de7eb06e9c67892fbcb86ed8ce2166a0b759
+ revision: fe15ab6a097fad071c6003c642b8e226607d9d52
branch: puppetdocs
specs:
jekyll (0.11.2)
@@ -35,7 +35,7 @@ GEM
fast-stemmer (>= 1.0.0)
directory_watcher (1.4.1)
facter (1.6.17)
- fast-stemmer (1.0.1)
+ fast-stemmer (1.0.2)
i18n (0.6.1)
json (1.7.6)
kramdown (0.14.2)
@@ -50,7 +50,7 @@ GEM
rake-remote_task (2.1.0)
open4 (~> 1.0)
rake (>= 0.8, < 11.0)
- rdoc (3.12)
+ rdoc (3.12.1)
json (~> 1.4)
syntax (1.0.0)
tzinfo (0.3.35)
@@ -61,7 +61,7 @@ GEM
rake-remote_task (~> 2.1)
vlad-git (2.2.0)
vlad (>= 2.1.0)
- yard (0.8.3)
+ yard (0.8.4.1)
PLATFORMS
ruby
View
73 Rakefile
@@ -21,6 +21,69 @@ $LOAD_PATH.unshift File.expand_path('lib')
references = %w(configuration function indirection metaparameter report type developer)
top_dir = Dir.pwd
+source_dir = "#{top_dir}/source"
+stash_dir = "#{top_dir}/_stash"
+preview_dir = "#{top_dir}/_preview"
+
+
+desc "Stash all directories but one in a temporary location. Run a preview server on localhost:4000."
+task :preview, :filename do |t, args|
+
+ if ["marionette-collective", "puppetdb_master", "puppetdb_1.1", "puppetdb", "mcollective"].include?(args.filename)
+ abort("\n\n*** External documentation sources aren't supported right now.\n\n")
+ end
+
+ # Make sure we have a stash_directory
+ FileUtils.mkdir(stash_dir) unless File.exist?(stash_dir)
+
+ # Directories and files we have to have for a good live preview
+ required_dirs = ["_config.yml", "_includes", "_plugins", "files", "favicon.ico", "_layouts","images"]
+
+ # Move the things we don't need into the _stash
+ Dir.glob("#{source_dir}/*") do |directory|
+ FileUtils.mv directory, stash_dir unless directory.include?(args.filename) || required_dirs.include?(File.basename(directory))
+ end
+
+ # Get all the files we'd like to see in a temporary preview index (so we don't have to hunt for files by name)
+ Dir.chdir("#{source_dir}/#{args.filename}")
+ file_list = Dir.glob("**/*.markdown")
+ preview_index_files = []
+ file_list.each do |f|
+ html_name = f.gsub(/\.markdown/,'.html')
+ preview_index_files << "* [#{args.filename}/#{html_name}](#{args.filename}/#{html_name})\n"
+ end
+
+preview_index=<<PREVIEW_INDEX
+---
+layout: frontpage
+title: Files Available for Live Preview
+canonical: "/"
+---
+#{preview_index_files}
+PREVIEW_INDEX
+
+ Dir.chdir(source_dir)
+ # put our file list index in place
+ File.open("index.markdown", 'w') {|f| f.write(preview_index) }
+
+ # Run our preview server, watching ... watching ...
+ system("bundle exec jekyll #{preview_dir} --auto --serve")
+
+ # When we kill it with a ctl-c ...
+ puts "\n\n*** Shut down the server."
+
+ # Clean up after ourselves (in a separate task in case something goes wrong and we need to do it manually)
+ Rake::Task['unpreview'].invoke
+end
+
+desc "Move all stashed directories back into the source directory, ready for site generation. "
+task :unpreview do
+ puts "\n*** Putting back the stashed files, removing the preview directory."
+ FileUtils.mv Dir.glob("#{stash_dir}/*"), "#{source_dir}"
+ FileUtils.rm_rf(preview_dir)
+ puts "\n*** Done.\n\n"
+end
+
namespace :externalsources do
unless File.exists?("externalsources") && File.directory?("externalsources")
@@ -37,7 +100,7 @@ namespace :externalsources do
def repo_name(repo_url)
repo_url.split('/')[-1].sub(/\.git$/, '')
end
-
+
# "Update all working copies defined in source/_config.yml"
task :update do
Rake::Task['externalsources:clone'].invoke
@@ -80,8 +143,8 @@ namespace :externalsources do
FileUtils.ln_sf "#{top_dir}/externalsources/#{name}/#{info['subdirectory']}", "source#{info['url']}"
end
end
-
- # "Clean up any external source symlinks from the source directory" # In the current implementation, all external sources are symlinks and there are no other symlinks in the source. This means we can naively kill all symlinks in ./source.
+
+ # "Clean up any external source symlinks from the source directory" # In the current implementation, all external sources are symlinks and there are no other symlinks in the source. This means we can naively kill all symlinks in ./source.
task :clean do
system("find ./source -type l -print0 | xargs -0 rm")
end
@@ -90,8 +153,8 @@ end
desc "Generate the documentation"
task :generate do
Rake::Task['externalsources:update'].invoke # Create external sources if necessary, and check out the required working directories
- Rake::Task['externalsources:link'].invoke # Link docs folders from external sources into the source at the appropriate places.
-
+ Rake::Task['externalsources:link'].invoke # Link docs folders from external sources into the source at the appropriate places.
+
system("mkdir -p output")
system("rm -rf output/*")
system("mkdir output/references")

0 comments on commit f7208d1

Please sign in to comment.