Properly set config for Ember CLI app

This commit is contained in:
Piotr Sarnacki 2015-02-03 12:44:52 +01:00
parent 0dba0fdad5
commit bf28f66b44

View File

@ -3,6 +3,7 @@ require 'rack/ssl'
require 'rack/protection' require 'rack/protection'
require 'delegate' require 'delegate'
require 'time' require 'time'
require 'json'
class Travis::Web::App class Travis::Web::App
autoload :AltVersions, 'travis/web/app/alt_versions' autoload :AltVersions, 'travis/web/app/alt_versions'
@ -115,7 +116,7 @@ class Travis::Web::App
end end
def index?(file) def index?(file)
file.end_with?('index.html') file == File.join(root, 'index.html') || file == 'index.html'
end end
def fingerprinted?(file) def fingerprinted?(file)
@ -157,19 +158,27 @@ class Travis::Web::App
end end
def set_config(string, opts = {}) def set_config(string, opts = {})
string.gsub! %r(<meta (rel|name)="travis\.([^"]*)" (href|value)="([^"]*)"[^>]*>) do p options
%(<meta #{$1}="travis.#{$2}" #{$3}="#{options[$2.to_sym] || $4}">) config = {}
end config[:api_endpoint] = options[:api_endpoint] if options[:api_endpoint]
config[:pages_endpoint] = options[:pages_endpoint] if options[:pages_endpoint]
config[:billing_endpoint] = options[:billing_endpoint] if options[:billing_endpoint]
config[:source_endpoint] = options[:source_endpoint] if options[:source_endpoint]
pusher = {}
pusher[:key] = options[:pusher_key] if options[:pusher_key]
pusher[:host] = options[:pusher_host] if options[:pusher_host]
pusher[:path] = options[:pusher_path] if options[:pusher_path]
config[:pusher] = pusher
string.gsub! %r{(src|href)="(?:\/?)((styles|scripts)\/[^"]*)"} do config[:ga_code] = options[:ga_code] if options[:ga_code]
src = if options[:assets_host] config[:pro] = options[:pro] if options[:pro]
"#{options[:assets_host].chomp('/')}/#{$2}" config[:enterprise] = options[:enterprise] if options[:enterprise]
elsif opts[:alt]
"#{S3_URL}/#{opts[:alt]}/#{$2}" config[:code_climate] = options[:code_climate] if options[:code_climate]
else config[:code_climate_url] = options[:code_climate_url] if options[:code_climate_url]
"/#{$2}"
end json = config.to_json
%(#{$1}="#{src}")
end string.gsub! /window.TravisENV = {}/, "window.TravisENV = #{json}"
end end
end end