Compass support in Sprockets
This commit is contained in:
parent
7d6386fdc0
commit
5cc96210ce
|
@ -1,16 +1,16 @@
|
|||
Feature: Sprockets
|
||||
|
||||
Scenario: Sprockets require
|
||||
Scenario: Sprockets JS require
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/javascripts/sprockets_base.js"
|
||||
Then I should see "sprockets_sub_function"
|
||||
|
||||
Scenario: Sprockets require with custom :js_dir
|
||||
Scenario: Sprockets JS require with custom :js_dir
|
||||
Given the Server is running at "sprockets-app"
|
||||
When I go to "/library/javascripts/sprockets_base.js"
|
||||
Then I should see "sprockets_sub_function"
|
||||
|
||||
Scenario: Sprockets should have access to yaml data
|
||||
Scenario: Sprockets JS should have access to yaml data
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/javascripts/multiple_engines.js"
|
||||
Then I should see "Hello One"
|
||||
|
@ -18,4 +18,24 @@ Feature: Sprockets
|
|||
Scenario: Multiple engine files should build correctly
|
||||
Given a built app at "test-app"
|
||||
Then "javascripts/multiple_engines.js" should exist at "test-app" and include "Hello One"
|
||||
And cleanup built app at "test-app"
|
||||
And cleanup built app at "test-app"
|
||||
|
||||
Scenario: Sprockets CSS require //require
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/stylesheets/sprockets_base1.css"
|
||||
Then I should see "hello"
|
||||
|
||||
Scenario: Sprockets CSS require @import
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/stylesheets/sprockets_base2.css"
|
||||
Then I should see "hello"
|
||||
|
||||
Scenario: Sprockets CSS require with custom :css_dir //require
|
||||
Given the Server is running at "sprockets-app"
|
||||
When I go to "/library/stylesheets/sprockets_base1.css"
|
||||
Then I should see "hello"
|
||||
|
||||
Scenario: Sprockets CSS require with custom :css_dir @import
|
||||
Given the Server is running at "sprockets-app"
|
||||
When I go to "/library/stylesheets/sprockets_base2.css"
|
||||
Then I should see "hello"
|
|
@ -1,7 +1,5 @@
|
|||
@wip
|
||||
Feature: Sprockets Gems
|
||||
|
||||
Scenario: Sprockets can pull jQuery from gem
|
||||
Given the Server is running at "sprockets-app"
|
||||
When I go to "/javascripts/jquery_include.js"
|
||||
When I go to "/library/javascripts/jquery_include.js"
|
||||
Then I should see "var jQuery ="
|
|
@ -1 +1,2 @@
|
|||
set :js_dir, "library/javascripts"
|
||||
set :js_dir, "library/javascripts"
|
||||
set :css_dir, "library/stylesheets"
|
|
@ -0,0 +1 @@
|
|||
//= require "sprockets_sub"
|
|
@ -0,0 +1 @@
|
|||
@import "sprockets_sub";
|
|
@ -0,0 +1 @@
|
|||
hello { world: "hi"; }
|
|
@ -0,0 +1 @@
|
|||
//= require "sprockets_sub"
|
|
@ -0,0 +1 @@
|
|||
@import "sprockets_sub";
|
|
@ -0,0 +1 @@
|
|||
hello { world: "hi"; }
|
|
@ -68,7 +68,7 @@ module Middleman::CoreExtensions::Compass
|
|||
config.asset_cache_buster :none
|
||||
config.output_style = :nested
|
||||
|
||||
config.add_import_path(config.sass_dir)
|
||||
# config.add_import_path(config.sass_dir)
|
||||
end
|
||||
|
||||
# Required for relative paths
|
||||
|
@ -84,8 +84,9 @@ module Middleman::CoreExtensions::Compass
|
|||
end
|
||||
|
||||
app.execute_after_compass_init!
|
||||
app.execute_after_compass_config!
|
||||
|
||||
app.set :sass, ::Compass.configuration.to_sass_engine_options
|
||||
# app.set :sass, ::Compass.configuration.to_sass_engine_options
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
|
@ -102,5 +103,15 @@ module Middleman::CoreExtensions::Compass
|
|||
@run_after_compass ||= []
|
||||
@run_after_compass.each { |block| block.call(::Compass.configuration) }
|
||||
end
|
||||
|
||||
def after_compass_config(&block)
|
||||
@run_after_compass_config ||= []
|
||||
@run_after_compass_config << block
|
||||
end
|
||||
|
||||
def execute_after_compass_config!
|
||||
@run_after_compass_config ||= []
|
||||
@run_after_compass_config.each { |block| block.call() }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -33,10 +33,20 @@ module Middleman::CoreExtensions::Sprockets
|
|||
app.map "/#{app.js_dir}" do
|
||||
run js_env
|
||||
end
|
||||
end
|
||||
|
||||
# app.map "/#{app.css_dir}" do
|
||||
# run Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(app)
|
||||
# end
|
||||
app.after_compass_config do
|
||||
css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(app)
|
||||
css_dir = File.join("vendor", "assets", "stylesheets")
|
||||
gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||
::Middleman.spec_has_file?(spec, css_dir)
|
||||
end.each do |spec|
|
||||
css_env.append_path File.join(spec.full_gem_path, css_dir)
|
||||
end
|
||||
|
||||
app.map "/#{app.css_dir}" do
|
||||
run css_env
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
|
@ -82,21 +92,20 @@ module Middleman::CoreExtensions::Sprockets
|
|||
end
|
||||
end
|
||||
|
||||
# class StylesheetEnvironment < MiddlemanEnvironment
|
||||
# def initialize(app)
|
||||
# super
|
||||
#
|
||||
# # Disable js
|
||||
# unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor
|
||||
#
|
||||
# # configure search paths
|
||||
# stylesheets_path = File.join(File.expand_path(app.views), app.css_dir)
|
||||
# append_path stylesheets_path
|
||||
# end
|
||||
#
|
||||
# def css_exception_response(exception)
|
||||
# expire_index!
|
||||
# super(exception)
|
||||
# end
|
||||
# end
|
||||
class StylesheetEnvironment < MiddlemanEnvironment
|
||||
def initialize(app)
|
||||
super
|
||||
|
||||
# Disable js
|
||||
unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor
|
||||
|
||||
# configure search paths
|
||||
append_path app.css_dir
|
||||
end
|
||||
|
||||
def css_exception_response(exception)
|
||||
expire_index!
|
||||
super(exception)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
require "sprockets"
|
||||
require "sprockets-sass"
|
||||
require "sass"
|
||||
require "sass/plugin"
|
||||
|
||||
module Middleman::Renderers::Sass
|
||||
class << self
|
||||
|
@ -9,41 +10,50 @@ module Middleman::Renderers::Sass
|
|||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
class SassPlusCSSFilenameTemplate < ::Tilt::SassTemplate
|
||||
def sass_options_with_scope(scope)
|
||||
return sass_options if basename.nil?
|
||||
|
||||
location_of_sass_file = if scope.build?
|
||||
File.join(scope.root, scope.build_dir)
|
||||
else
|
||||
scope.views
|
||||
end
|
||||
|
||||
parts = basename.split('.')
|
||||
parts.pop
|
||||
css_filename = File.join(location_of_sass_file, scope.css_dir, parts.join("."))
|
||||
sass_options.merge(scope.settings.sass).merge(:css_filename => css_filename)
|
||||
end
|
||||
|
||||
def evaluate(scope, locals, &block)
|
||||
@engine = ::Sass::Engine.new(data, sass_options_with_scope(scope.class))
|
||||
|
||||
class SassPlusCSSFilenameTemplate < ::Sprockets::Sass::SassTemplate
|
||||
self.default_mime_type = "text/css"
|
||||
|
||||
# Add exception messaging
|
||||
def evaluate(context, locals, &block)
|
||||
begin
|
||||
super
|
||||
rescue Sass::SyntaxError => e
|
||||
Sass::SyntaxError.exception_to_css(e, :full_exception => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
::Tilt.register 'sass', SassPlusCSSFilenameTemplate
|
||||
::Tilt.prefer(SassPlusCSSFilenameTemplate)
|
||||
|
||||
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
||||
def sass_options_with_scope(scope)
|
||||
super.merge(:syntax => :scss)
|
||||
|
||||
protected
|
||||
def sass_options
|
||||
location_of_sass_file = if @context.build?
|
||||
File.expand_path(@context.build_dir, @context.root)
|
||||
else
|
||||
File.expand_path(@context.views, @context.root)
|
||||
end
|
||||
|
||||
parts = basename.split('.')
|
||||
parts.pop
|
||||
css_filename = File.join(location_of_sass_file, @context.css_dir, parts.join("."))
|
||||
|
||||
super.merge(
|
||||
:css_filename => css_filename
|
||||
)
|
||||
end
|
||||
end
|
||||
::Sprockets.register_engine ".sass", SassPlusCSSFilenameTemplate
|
||||
::Tilt.register 'sass', SassPlusCSSFilenameTemplate
|
||||
::Tilt.prefer(SassPlusCSSFilenameTemplate)
|
||||
|
||||
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
||||
self.default_mime_type = "text/css"
|
||||
|
||||
# Define the expected syntax for the template
|
||||
def syntax
|
||||
:scss
|
||||
end
|
||||
end
|
||||
|
||||
::Sprockets.register_engine ".scss", ScssPlusCSSFilenameTemplate
|
||||
::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
|
||||
::Tilt.prefer(ScssPlusCSSFilenameTemplate)
|
||||
end
|
||||
|
|
|
@ -51,6 +51,7 @@ eos
|
|||
s.add_dependency("compass", ["~> 0.11.3"])
|
||||
s.add_dependency("coffee-script", ["~> 2.2.0"])
|
||||
s.add_dependency("sprockets", ["~> 2.0.3"])
|
||||
s.add_dependency("sprockets-sass", ["~> 0.3.0"])
|
||||
s.add_dependency("padrino-core", ["~> 0.10.5"])
|
||||
s.add_dependency("padrino-helpers", ["~> 0.10.5"])
|
||||
|
||||
|
@ -68,5 +69,6 @@ eos
|
|||
s.add_development_dependency("cucumber", ["~> 1.0.2"])
|
||||
s.add_development_dependency("rake", ["~> 0.9.2"])
|
||||
s.add_development_dependency("rspec", ["~> 2.6.0"])
|
||||
s.add_development_dependency("jquery-rails")
|
||||
end
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ eos
|
|||
s.add_dependency("coffee-script", ["~> 2.2.0"])
|
||||
s.add_dependency("execjs", ["~> 1.2.7"])
|
||||
s.add_dependency("sprockets", ["~> 2.0.3"])
|
||||
s.add_dependency("sprockets-sass", ["~> 0.3.0"])
|
||||
s.add_dependency("padrino-core", ["~> 0.10.5"])
|
||||
s.add_dependency("padrino-helpers", ["~> 0.10.5"])
|
||||
|
||||
|
@ -65,5 +66,6 @@ eos
|
|||
s.add_development_dependency("cucumber", ["~> 1.0.2"])
|
||||
s.add_development_dependency("rake", ["~> 0.9.2"])
|
||||
s.add_development_dependency("rspec", ["~> 2.6.0"])
|
||||
s.add_development_dependency("jquery-rails")
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue