11# encoding: UTF-8
2+
23require 'rubygems'
34require 'bundler/setup'
45require 'rake'
@@ -8,7 +9,6 @@ require 'yaml'
89require 'puppet_docs/config'
910require 'rake/clean'
1011
11-
1212CLOBBER . include ( 'output' )
1313CLOBBER . include ( 'externalsources' )
1414CLOBBER . include ( 'references_output' )
@@ -25,7 +25,6 @@ VERSION_FILE = "#{OUTPUT_DIR}/VERSION.txt"
2525@config_data = PuppetDocs ::Config . new ( "#{ SOURCE_DIR } /_config.yml" )
2626
2727def jekyll ( command = 'build' , source = SOURCE_DIR , destination = OUTPUT_DIR , *args )
28-
2928 about_verbose_mode = <<-ABOUT_VERBOSE_MODE
3029
3130 -*-*-*-*-*-*-*-*-*-*-*-*-
5453
5554desc "Stash all directories but one in a temporary location. Run a preview server on localhost:4000."
5655task :preview , :filename do |t , args |
57-
5856 if [ "marionette-collective" , "puppetdb_master" , "puppetdb_1.1" , "puppetdb" , "mcollective" ] . include? ( args . filename )
5957 abort ( "\n \n *** External documentation sources aren't supported right now.\n \n " )
6058 end
@@ -63,34 +61,35 @@ task :preview, :filename do |t, args|
6361 FileUtils . mkdir ( STASH_DIR ) unless File . exist? ( STASH_DIR )
6462
6563 # Directories and files we have to have for a good live preview
66- required_dirs = [ "_config.yml" , "_includes" , "_plugins" , "files" , "favicon.ico" , "_layouts" , "images" ]
64+ required_dirs = [ "_config.yml" , "_includes" , "_plugins" , "files" , "favicon.ico" , "_layouts" , "images" ]
6765
6866 # Move the things we don't need into the _stash
6967 Dir . glob ( "#{ SOURCE_DIR } /*" ) do |directory |
70- FileUtils . mv directory , STASH_DIR unless directory . include? ( args . filename ) || required_dirs . include? ( File . basename ( directory ) )
68+ FileUtils . mv directory ,
69+ STASH_DIR unless directory . include? ( args . filename ) || required_dirs . include? ( File . basename ( directory ) )
7170 end
7271
7372 # 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)
7473 Dir . chdir ( "#{ SOURCE_DIR } /#{ args . filename } " )
7574 file_list = Dir . glob ( "**/*.markdown" )
7675 preview_index_files = [ ]
7776 file_list . each do |f |
78- html_name = f . gsub ( /\. markdown/ , '.html' )
77+ html_name = f . gsub ( /\. markdown/ , '.html' )
7978 preview_index_files << "* [#{ args . filename } /#{ html_name } ](#{ args . filename } /#{ html_name } )\n "
8079 end
8180
82- preview_index = << PREVIEW_INDEX
83- ---
84- layout: frontpage
85- title: Files Available for Live Preview
86- canonical: "/"
87- ---
88- #{ preview_index_files }
89- PREVIEW_INDEX
81+ preview_index = <<~ PREVIEW_INDEX
82+ ---
83+ layout: frontpage
84+ title: Files Available for Live Preview
85+ canonical: "/"
86+ ---
87+ #{ preview_index_files }
88+ PREVIEW_INDEX
9089
9190 Dir . chdir ( SOURCE_DIR )
9291 # put our file list index in place
93- File . open ( "index.markdown" , 'w' ) { |f | f . write ( preview_index ) }
92+ File . open ( "index.markdown" , 'w' ) { |f | f . write ( preview_index ) }
9493
9594 # Run our preview server, watching ... watching ...
9695 jekyll ( 'serve' , SOURCE_DIR , PREVIEW_DIR )
@@ -111,7 +110,6 @@ task :unpreview do
111110end
112111
113112namespace :externalsources do
114-
115113 unless File . exist? ( "externalsources" ) && File . directory? ( "externalsources" )
116114 Dir . mkdir ( "externalsources" )
117115 end
@@ -147,7 +145,7 @@ namespace :externalsources do
147145
148146 # "Fetch all external doc repos (from externalsources in source/_config.yml), cloning any that don't yet exist"
149147 task :clone do
150- repos = @config_data [ 'externalsources' ] . values . map { |info | info [ 'repo' ] } . uniq
148+ repos = @config_data [ 'externalsources' ] . values . map { |info | info [ 'repo' ] } . uniq
151149
152150 Dir . chdir ( "externalsources" ) do
153151 repos . each do |repo |
@@ -180,7 +178,7 @@ namespace :externalsources do
180178
181179 # "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.
182180 task :clean do
183- allsymlinks = FileList . new ( "#{ SOURCE_DIR } /**/*" ) . select { |f | File . symlink? ( f ) }
181+ allsymlinks = FileList . new ( "#{ SOURCE_DIR } /**/*" ) . select { |f | File . symlink? ( f ) }
184182 allsymlinks . each do |f |
185183 File . delete ( f )
186184 end
@@ -231,9 +229,9 @@ task :symlink_latest_versions do
231229 @config_data [ 'symlink_latest' ] . each do |project |
232230 project_dir = "#{ OUTPUT_DIR } /#{ project } "
233231
234- versions = Pathname . glob ( "#{ project_dir } /*" ) . select { |f |
232+ versions = Pathname . glob ( "#{ project_dir } /*" ) . select { |f |
235233 f . directory? && !f . symlink?
236- } . map { |d | d . basename . to_s }
234+ } . map { |d | d . basename . to_s }
237235
238236 latest = @config_data [ 'lock_latest' ] [ project ] || PuppetDocs ::Versions . latest ( versions )
239237
@@ -258,10 +256,9 @@ task :generate_redirects do
258256 nginx_config = "#{ OUTPUT_DIR } /nginx_rewrite.conf"
259257 redirects_yaml = "#{ SOURCE_DIR } /_redirects.yaml"
260258 generated_lines = PuppetDocs ::AutoRedirects . generate ( @config_data , redirects_yaml )
261- File . open ( nginx_config , 'a' ) { |f | f . write ( generated_lines ) }
259+ File . open ( nginx_config , 'a' ) { |f | f . write ( generated_lines ) }
262260end
263261
264-
265262desc "Serve generated output on port 9292"
266263task :serve do
267264 system ( "rackup" )
270267desc "Generate docs and serve locally"
271268task :run => [ :generate , :serve ]
272269
273-
274270task :write_version do
275271 if File . directory? ( '.git' )
276272 current_commit = `git rev-parse HEAD` . strip
294290
295291task :check_build_version do
296292 abort "No site build found! Run 'rake build' before releasing." unless File . directory? ( OUTPUT_DIR )
297- abort "Site build is empty! Run 'rake build' before releasing." if ( Dir . entries ( OUTPUT_DIR ) - %w{ . .. } ) . empty?
293+ abort "Site build is empty! Run 'rake build' before releasing." if ( Dir . entries ( OUTPUT_DIR ) - %w{ . .. } ) . empty?
298294 if File . directory? ( '.git' )
299295 if File . exists? ( VERSION_FILE )
300296 head = `git rev-parse HEAD` . strip
@@ -323,8 +319,6 @@ task :build_and_check_links do
323319 Rake ::Task [ 'build' ] . invoke
324320end
325321
326-
327-
328322desc "Instead of building real pages, build naked HTML fragments (with no nav, etc.)"
329323task :build_html_fragments do
330324 Rake ::Task [ 'check_git_dirty_status' ] . invoke
@@ -347,7 +341,7 @@ task :build_and_mangle_html_fragments do
347341 all_fragments = Dir . glob ( 'output/**/*.html' ) # This actually sweeps up YARD pages too, but... never mind.
348342 total_size = all_fragments . length
349343 all_fragments . each_with_index do |fragment , i |
350- print "(#{ i + 1 } /#{ total_size } ) "
344+ print "(#{ i + 1 } /#{ total_size } ) "
351345 PuppetDocs ::SentenceSegmenter . mangle_file ( fragment )
352346 end
353347end
@@ -372,7 +366,6 @@ task :body_and_nav_html_only do
372366 Rake ::Task [ 'externalsources:clean' ] . invoke # The opposite of externalsources:link. Delete all symlinks in the source.
373367 Rake ::Task [ 'externalsources:clean' ] . reenable
374368
375-
376369 if @config_data [ 'preview' ] . class == Array && @config_data [ 'preview' ] . length > 0
377370 puts "THIS IS A PREVIEW VERSION, AND IT'S MISSING IMPORTANT STUFF. Do not deploy the site in this state; this is for local viewing only. To build a real version of the site, delete the `preview:` key from _config.yml."
378371 end
@@ -411,6 +404,3 @@ namespace :references do
411404 abort "No VERSION given to build references for" unless ENV [ 'VERSION' ]
412405 end
413406end
414-
415-
416-
0 commit comments