packer-cn/website/config.rb

89 lines
2.2 KiB
Ruby
Raw Normal View History

2013-06-24 19:25:42 -04:00
require "net/http"
raise "BINTRAY_API_KEY must be set." if !ENV["BINTRAY_API_KEY"]
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"]
http = Net::HTTP.new("dl.bintray.com", 80)
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\/(#{ENV["PACKER_VERSION"]}.+?)\?/
filename = $1.to_s
os = filename.split("_")[1]
$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
# 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)
file.split("_")[2].split(".")[0]
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)
"http://dl.bintray.com/mitchellh/packer/#{file}?direct"
end
def latest_version
ENV["PACKER_VERSION"]
end
end