Skip to content

Commit 3484b56

Browse files
committed
rubocop: fix layoyt (-x --safe)
1 parent b4b9e88 commit 3484b56

51 files changed

Lines changed: 569 additions & 612 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Rakefile

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: UTF-8
2+
23
require 'rubygems'
34
require 'bundler/setup'
45
require 'rake'
@@ -8,7 +9,6 @@ require 'yaml'
89
require 'puppet_docs/config'
910
require 'rake/clean'
1011

11-
1212
CLOBBER.include('output')
1313
CLOBBER.include('externalsources')
1414
CLOBBER.include('references_output')
@@ -25,7 +25,6 @@ VERSION_FILE = "#{OUTPUT_DIR}/VERSION.txt"
2525
@config_data = PuppetDocs::Config.new("#{SOURCE_DIR}/_config.yml")
2626

2727
def jekyll(command = 'build', source = SOURCE_DIR, destination = OUTPUT_DIR, *args)
28-
2928
about_verbose_mode = <<-ABOUT_VERBOSE_MODE
3029
3130
-*-*-*-*-*-*-*-*-*-*-*-*-
@@ -54,7 +53,6 @@ end
5453

5554
desc "Stash all directories but one in a temporary location. Run a preview server on localhost:4000."
5655
task :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
111110
end
112111

113112
namespace :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) }
262260
end
263261

264-
265262
desc "Serve generated output on port 9292"
266263
task :serve do
267264
system("rackup")
@@ -270,7 +267,6 @@ end
270267
desc "Generate docs and serve locally"
271268
task :run => [:generate, :serve]
272269

273-
274270
task :write_version do
275271
if File.directory?('.git')
276272
current_commit = `git rev-parse HEAD`.strip
@@ -294,7 +290,7 @@ end
294290

295291
task :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
324320
end
325321

326-
327-
328322
desc "Instead of building real pages, build naked HTML fragments (with no nav, etc.)"
329323
task :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
353347
end
@@ -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
413406
end
414-
415-
416-

config.ru

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'pathname'
22

3-
43
module Rack
54
class DirectoryWithIndexes < Rack::Directory
65
def initialize(*args)
@@ -12,6 +11,7 @@ module Rack
1211

1312
if stat.readable?
1413
return @app.call(env) if stat.file?
14+
1515
if stat.directory?
1616
index = Pathname.new(path) + 'index.html'
1717
if index.readable?
@@ -25,7 +25,6 @@ module Rack
2525
else
2626
raise Errno::ENOENT, 'No such file or directory'
2727
end
28-
2928
rescue Errno::ENOENT, Errno::ELOOP
3029
return entity_not_found(path_info)
3130
end
@@ -39,6 +38,7 @@ module Rack
3938

4039
if @stat.readable?
4140
return @app.call(@env) if @stat.file?
41+
4242
if @stat.directory?
4343
index = Pathname.new(@path) + 'index.html'
4444
if index.readable?
@@ -51,11 +51,9 @@ module Rack
5151
else
5252
raise Errno::ENOENT, 'No such file or directory'
5353
end
54-
5554
rescue Errno::ENOENT, Errno::ELOOP
5655
return entity_not_found(@path_info)
5756
end
58-
5957
end
6058
end
6159

config/deploy.rb

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,42 @@
33
set :user, "docsdeploy"
44

55
task :mirror0 do
6-
set :domain, "#{user}@staticweb1-prod.puppetlabs.com"
7-
set :deploy_to, "/var/www/#{application}"
6+
set :domain, "#{user}@staticweb1-prod.puppetlabs.com"
7+
set :deploy_to, "/var/www/#{application}"
88
end
99

1010
task :mirror1 do
11-
set :domain, "#{user}@staticweb2-prod.puppetlabs.com"
12-
set :deploy_to, "/var/www/#{application}"
11+
set :domain, "#{user}@staticweb2-prod.puppetlabs.com"
12+
set :deploy_to, "/var/www/#{application}"
1313
end
1414

1515
task :preview1 do
16-
set :domain, "#{user}@staticweb1-dev.puppetlabs.com"
17-
set :deploy_to, "/var/www/docspreview1.ops.puppetlabs.net"
16+
set :domain, "#{user}@staticweb1-dev.puppetlabs.com"
17+
set :deploy_to, "/var/www/docspreview1.ops.puppetlabs.net"
1818
end
1919

2020
task :preview2 do
21-
set :domain, "#{user}@staticweb1-dev.puppetlabs.com"
22-
set :deploy_to, "/var/www/docspreview2.ops.puppetlabs.net"
21+
set :domain, "#{user}@staticweb1-dev.puppetlabs.com"
22+
set :deploy_to, "/var/www/docspreview2.ops.puppetlabs.net"
2323
end
2424

2525
task :preview3 do
26-
set :domain, "#{user}@staticweb1-dev.puppetlabs.com"
27-
set :deploy_to, "/var/www/docspreview3.ops.puppetlabs.net"
26+
set :domain, "#{user}@staticweb1-dev.puppetlabs.com"
27+
set :deploy_to, "/var/www/docspreview3.ops.puppetlabs.net"
2828
end
2929

3030
namespace :vlad do
31+
desc "Release the documentation site"
32+
remote_task :release do
33+
Rake::Task['check_build_version'].invoke
34+
puts "DEPLOYING TO: #{domain}"
3135

32-
desc "Release the documentation site"
33-
remote_task :release do
34-
Rake::Task['check_build_version'].invoke
35-
puts "DEPLOYING TO: #{domain}"
36+
stage_dir = deploy_to + '/stage'
3637

37-
stage_dir = deploy_to + '/stage'
38-
39-
sh "rsync -crlpv --delete --force output/ #{domain}:#{stage_dir}/"
40-
41-
# Create tarball, move everything into place, and reload NGINX. Rake has
42-
# trouble mixing stdout and stderr, so we combine them on the remote host.
43-
run "sh #{stage_dir}/install.sh #{deploy_to} 2>&1"
44-
end
38+
sh "rsync -crlpv --delete --force output/ #{domain}:#{stage_dir}/"
4539

40+
# Create tarball, move everything into place, and reload NGINX. Rake has
41+
# trouble mixing stdout and stderr, so we combine them on the remote host.
42+
run "sh #{stage_dir}/install.sh #{deploy_to} 2>&1"
43+
end
4644
end

lib/puppet_docs.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ module PuppetDocs
77
require 'puppet_docs/config'
88
require 'puppet_docs/versions'
99
end
10-

lib/puppet_docs/auto_redirects.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.generate(config, redirects_yaml)
2929
redirects = YAML.load(File.read(redirects_yaml))
3030

3131
# Convert array of redirect data hashes into array of redirect lines
32-
redirect_lines = redirects.reduce( ["\n\n# Auto-generated rewrites from _redirects.yaml:"] ) {|memo, redirect|
32+
redirect_lines = redirects.reduce(["\n\n# Auto-generated rewrites from _redirects.yaml:"]) { |memo, redirect|
3333
doc = redirect['in_doc']
3434
at_version = redirect['at_version'].to_s
3535
was = normalize_paths(redirect['was'])
@@ -38,14 +38,14 @@ def self.generate(config, redirects_yaml)
3838
latest = "/#{doc}/latest"
3939

4040
# First, bail out unless the doc exists and this is a valid version.
41-
if config['document_version_index'][doc].class != Hash || !( config['document_version_index'][doc].has_key?(at_version) )
41+
if config['document_version_index'][doc].class != Hash || !(config['document_version_index'][doc].has_key?(at_version))
4242
puts "Skipping bad auto-redirect (make sure the syntax is right and the version exists!): #{redirect.to_s}"
4343
memo
4444
else
4545
at_baseurl = config['document_version_index'][doc][at_version]
4646
at_index = config['document_version_order'][doc].index(at_baseurl)
4747
new_versions = [latest] + config['document_version_order'][doc][0..at_index]
48-
old_versions = config['document_version_order'][doc][at_index+1..-1]
48+
old_versions = config['document_version_order'][doc][at_index + 1..-1]
4949

5050
if forward_only
5151
generated_rewrites = [
@@ -67,14 +67,13 @@ def self.generate(config, redirects_yaml)
6767

6868
# Normalize string-or-array into normal array, and strip leading ./ or /
6969
def self.normalize_paths(path_or_array)
70-
[path_or_array].flatten.map {|path| path.sub(/^\.?\/?/, '')}
70+
[path_or_array].flatten.map { |path| path.sub(/^\.?\/?/, '') }
7171
end
7272

7373
# Takes an array of affected path prefixes, an array of "from" filenames,
7474
# and an array of "to" filenames.
7575
def self.build_rewrite_for_versions(versions, from, to)
76-
"rewrite ^(#{ versions.join('|') })/(#{ from.join('|') }) $1/#{to.first} permanent;"
76+
"rewrite ^(#{versions.join('|')})/(#{from.join('|')}) $1/#{to.first} permanent;"
7777
end
78-
7978
end
80-
end
79+
end

0 commit comments

Comments
 (0)