From de6f5026ff4bb4412627a0259fd16af4de6d0610 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 1 Oct 2012 12:43:25 +0200 Subject: [PATCH] doh. add missing files --- lib/travis/web/app/assets.rb | 27 +++++++++++++++++++++++++++ lib/travis/web/app/filter/assets.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 lib/travis/web/app/assets.rb create mode 100644 lib/travis/web/app/filter/assets.rb diff --git a/lib/travis/web/app/assets.rb b/lib/travis/web/app/assets.rb new file mode 100644 index 00000000..05316d15 --- /dev/null +++ b/lib/travis/web/app/assets.rb @@ -0,0 +1,27 @@ +class Travis::Web::App + class Assets + include Helpers + + attr_reader :app, :config + + def initialize(app, config) + @app = app + @config = config + end + + def call(env) + path = env['PATH_INFO'] + if !asset?(path) + app.call(map_env(env, config.version)) + else + app.call(env) + end + end + + private + + def asset?(path) + path !~ Travis::Web::App::ASSET_DIRS + end + end +end diff --git a/lib/travis/web/app/filter/assets.rb b/lib/travis/web/app/filter/assets.rb new file mode 100644 index 00000000..06df9539 --- /dev/null +++ b/lib/travis/web/app/filter/assets.rb @@ -0,0 +1,29 @@ +class Travis::Web::App::Filter + class Assets + attr_reader :config + + def initialize(config) + @config = config + end + + def apply(string) + string = version(string) + string = minify(string) # if config.production? + string + end + + private + + def version(string) + string.gsub(Travis::Web::App::ASSET_DIRS) do + "/#{config.version}/#{$1}/" + end + end + + def minify(string) + string.gsub(%r((/javascripts/.*).js)) do + "#{$1}.min.js/" + end + end + end +end