From cf713fc1ade3574d713f3884414e3af2b6ea0cb3 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Mon, 12 Oct 2015 08:21:52 -0400 Subject: [PATCH] Blade handles all Sprockets environments now --- .blade.yml | 10 +++++ Gemfile | 3 +- Gemfile.lock | 33 +++++++------- Rakefile | 24 ----------- config.ru | 21 +++------ lib/trix/environment.rb | 96 ----------------------------------------- 6 files changed, 36 insertions(+), 151 deletions(-) delete mode 100644 lib/trix/environment.rb diff --git a/.blade.yml b/.blade.yml index 89b3e842c..269af13ce 100644 --- a/.blade.yml +++ b/.blade.yml @@ -7,6 +7,16 @@ load_paths: logical_paths: - trix.js - test.js + - trix.css + +build: + logical_paths: + - trix.js + - trix-core.js + - trix.css + path: dist + js_compressor: uglifier + css_compressor: sass plugins: sauce_labs: diff --git a/Gemfile b/Gemfile index fc75485df..46162f9a6 100644 --- a/Gemfile +++ b/Gemfile @@ -8,9 +8,8 @@ gem 'coffee-script' gem 'coffee-script-source', '~> 1.9.1' gem 'ejs' gem 'eco' -gem 'rack-rewrite' gem 'uglifier' gem 'sass' -gem 'blade', '~> 0.4.0' +gem 'blade', github: 'javan/blade' gem 'blade-sauce_labs_plugin', '~> 0.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index 1548b1a47..b5455473a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,20 @@ +GIT + remote: git://github.com/javan/blade.git + revision: 09b6a162f38e0f6402879c0c378c7bb0ae8f2ed6 + specs: + blade (0.4.0) + activesupport (>= 3.0.0) + blade-qunit_adapter (~> 0.4.0) + coffee-script (~> 2.4.0) + coffee-script-source (~> 1.9.0) + curses (~> 1.0.0) + eventmachine (~> 1.0.0) + faye (= 1.1.1) + sprockets (~> 3.2.0) + thin (~> 1.6.0) + thor (~> 0.19.1) + useragent (~> 0.13.0) + PATH remote: . specs: @@ -13,18 +30,6 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.3.8) - blade (0.4.0) - activesupport (>= 3.0.0) - blade-qunit_adapter (~> 0.4.0) - coffee-script (~> 2.4.0) - coffee-script-source (~> 1.9.0) - curses (~> 1.0.0) - eventmachine (~> 1.0.0) - faye (= 1.1.1) - sprockets (~> 3.2.0) - thin (~> 1.6.0) - thor (~> 0.19.1) - useragent (~> 0.13.0) blade-qunit_adapter (0.4.0) blade-sauce_labs_plugin (0.4.0) blade @@ -72,7 +77,6 @@ GEM multi_json (1.11.2) multipart-post (2.0.0) rack (1.6.4) - rack-rewrite (1.5.0) rake (10.0.4) sass (3.4.3) sprockets (3.2.0) @@ -97,13 +101,12 @@ PLATFORMS ruby DEPENDENCIES - blade (~> 0.4.0) + blade! blade-sauce_labs_plugin (~> 0.4.0) coffee-script coffee-script-source (~> 1.9.1) eco ejs - rack-rewrite rake sass sprockets diff --git a/Rakefile b/Rakefile index 7252766c7..4bb299e32 100644 --- a/Rakefile +++ b/Rakefile @@ -1,28 +1,4 @@ -require 'bundler/setup' -require 'uglifier' -require File.join(File.dirname(__FILE__) + '/lib/trix/environment') - namespace :trix do - environment = Trix::Environment.new(".") - environment.paths = %w( assets polyfills src ) - environment.assets = %w( trix.css trix.js trix-core.js ) - environment.sprockets_environment.js_compressor = Uglifier.new - - desc "Clean Trix distribution" - task :clean do - environment.clean - end - - desc "Build Trix distribution" - task :dist do - environment.dist - end - - desc "Open Trix demo in a browser" - task :browser => :dist do - system "open", environment.dist_path_for("index.html") - end - desc "Print code statistics" task :stats do lines = `find src -name '*.coffee' -type f | xargs sed -n '/^ *\\(#.*\\)*\$/!p'`.strip.split("\n") diff --git a/config.ru b/config.ru index 05249f210..46edc1811 100644 --- a/config.ru +++ b/config.ru @@ -1,22 +1,15 @@ require 'bundler/setup' -require 'rack/rewrite' -require 'pathname' -require 'json' require 'blade' +require 'json' -root = Pathname.new(File.dirname(__FILE__)) - -require root.join('lib/trix/environment') -environment = Trix::Environment.new(root) -environment.paths = %w( assets polyfills src ) - -use Blade::RackAdapter, mount: '/test' +Blade.initialize! map '/' do - run environment.sprockets_environment - use Rack::Rewrite do - rewrite '/', '/index.html' - end + run Blade::Assets.environment(:user) +end + +map '/test' do + run Blade::RackAdapter.new end map '/submit' do diff --git a/lib/trix/environment.rb b/lib/trix/environment.rb deleted file mode 100644 index caa6abf23..000000000 --- a/lib/trix/environment.rb +++ /dev/null @@ -1,96 +0,0 @@ -require 'trix' -require 'pathname' -require 'sprockets' -require 'coffee-script' - -module Trix - class Environment - attr_writer :paths - attr_writer :assets - - def initialize(root = ".") - @root = root - end - - def sprockets_environment - @sprockets_environment ||= Sprockets::Environment.new do |env| - env.cache = Sprockets::Cache::FileStore.new(project_root.join("tmp")) - paths.each do |path| - env.append_path(path) - end - end - end - - def manifest - @manifest ||= Sprockets::Manifest.new(sprockets_environment.index, build_path) - end - - def compile - manifest.compile(assets) - end - - def dist - clean - compile - - assets.each do |logical_path| - install_asset(logical_path) - end - end - - def install_asset(logical_path) - create_dist_path - fingerprint_path = manifest.assets[logical_path] - FileUtils.cp(build_path.join(fingerprint_path), dist_path.join(logical_path)) - end - - def clean - remove_build_path - remove_dist_path - end - - def remove_build_path - FileUtils.rm_rf(build_path) - end - - def create_dist_path - FileUtils.mkdir_p(dist_path) - end - - def remove_dist_path - FileUtils.rm_rf(dist_path) - end - - def project_root - Pathname.new(File.dirname(__FILE__) + "/../..") - end - - def build_path - project_root.join(".assets") - end - - def dist_path - root.join("dist") - end - - def root - project_root.join(@root || ".") - end - - def paths - (@paths || []).map { |path| root.join(path) } - end - - def assets - @assets || [] - end - - def path_for(file) - root.join(file).to_s - end - - def dist_path_for(file) - dist_path.join(file).realpath.to_s - end - end -end