packer-cn/website/config.rb

94 lines
2.3 KiB
Ruby
Raw Normal View History

2013-06-24 19:25:42 -04:00
require "net/http"
raise "PACKER_VERSION must be set." if !ENV["PACKER_VERSION"]
#-------------------------------------------------------------------------
# Download the list of Packer downloads
#-------------------------------------------------------------------------
$packer_files = {}
$packer_os = []
if !ENV["PACKER_DISABLE_DOWNLOAD_FETCH"]
raise "BINTRAY_API_KEY must be set." if !ENV["BINTRAY_API_KEY"]
http = Net::HTTP.new("dl.bintray.com", 80)
2014-02-21 23:38:58 -05:00
req = Net::HTTP::Get.new("/mitchellh/packer/")
req.basic_auth "mitchellh", ENV["BINTRAY_API_KEY"]
response = http.request(req)
response.body.split("\n").each do |line|
next if line !~ /\/mitchellh\/packer\/(#{Regexp.quote(ENV["PACKER_VERSION"])}.+?)'/
2013-06-28 11:56:11 -04:00
filename = $1.to_s
os = filename.split("_")[1]
2013-06-28 11:56:11 -04:00
next if os == "SHA256SUMS"
$packer_files[os] ||= []
$packer_files[os] << filename
end
$packer_os = ["darwin", "linux", "windows"] & $packer_files.keys
$packer_os += $packer_files.keys
$packer_os.uniq!
$packer_files.each do |key, value|
value.sort!
end
2013-06-24 19:25:42 -04:00
end
#-------------------------------------------------------------------------
# Configure Middleman
#-------------------------------------------------------------------------
2013-06-08 01:41:02 -04:00
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
# Use the RedCarpet Markdown engine
set :markdown_engine, :redcarpet
set :markdown,
:fenced_code_blocks => true,
:with_toc_data => true
2013-06-08 01:41:02 -04:00
# Build-specific configuration
configure :build do
activate :asset_hash
activate :minify_css
activate :minify_html
activate :minify_javascript
end
2013-06-24 19:25:42 -04:00
#-------------------------------------------------------------------------
# Helpers
#-------------------------------------------------------------------------
helpers do
def download_arch(file)
2013-06-28 11:56:11 -04:00
parts = file.split("_")
return "" if parts.length != 3
parts[2].split(".")[0]
2013-06-24 19:25:42 -04:00
end
def download_os_human(os)
if os == "darwin"
return "Mac OS X"
elsif os == "freebsd"
return "FreeBSD"
elsif os == "openbsd"
return "OpenBSD"
elsif os == "Linux"
return "Linux"
elsif os == "windows"
return "Windows"
else
return os
end
end
def download_url(file)
"https://dl.bintray.com/mitchellh/packer/#{file}"
2013-06-24 19:25:42 -04:00
end
def latest_version
ENV["PACKER_VERSION"]
end
end