Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Examples] Refactor the module and file loading for Sass Extensions a…
…nd application integration. Fixed broken unit tests.
- Loading branch information
1 parent
f1832d0
commit 2b3b781
Showing
17 changed files
with
139 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
# If we're running inside Merb | ||
require File.join(File.dirname(__FILE__), 'app_integration', 'merb') if defined?(Merb::Plugins) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Compass::SassExtensions | ||
end | ||
|
||
require File.join(File.dirname(__FILE__), 'sass_extensions', 'functions') | ||
require File.join(File.dirname(__FILE__), 'sass_extensions', 'monkey_patches') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Compass::SassExtensions::Functions | ||
end | ||
|
||
['nest', 'enumerate', 'image_url'].each do |func| | ||
require File.join(File.dirname(__FILE__), 'functions', func) | ||
end | ||
|
||
module Sass::Script::Functions | ||
include Compass::SassExtensions::Functions::Nest | ||
include Compass::SassExtensions::Functions::Enumerate | ||
include Compass::SassExtensions::Functions::ImageUrl | ||
end | ||
|
||
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug? | ||
class Sass::Script::Functions::EvaluationContext | ||
include Sass::Script::Functions | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Compass::SassExtensions::Functions::Enumerate | ||
def enumerate(prefix, from, through) | ||
selectors = (from.value..through.value).map{|i| "#{prefix.value}-#{i}"}.join(", ") | ||
Sass::Script::String.new(selectors) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Compass::SassExtensions::Functions::ImageUrl | ||
def image_url(path) | ||
path = path.value # get to the string value of the literal. | ||
if absolute_path?(path) | ||
return Sass::Script::String.new("url(#{path})") | ||
end | ||
http_images_path = if Compass.configuration.http_images_path == :relative | ||
compute_relative_path | ||
else | ||
Compass.configuration.http_images_path | ||
end | ||
|
||
real_path = if Compass.configuration.images_dir | ||
File.join(Compass.configuration.project_path, Compass.configuration.images_dir, path) | ||
end | ||
|
||
if http_images_path | ||
http_images_path = "#{http_images_path}/" unless http_images_path[-1..-1] == "/" | ||
path = "#{http_images_path}#{path}" | ||
end | ||
|
||
if real_path && File.exists?(real_path) | ||
path += "?#{File.mtime(real_path).strftime("%s")}" | ||
elsif real_path | ||
$stderr.puts "WARNING: '#{File.basename(path)}' was not found in #{File.dirname(real_path)}" | ||
end | ||
|
||
Sass::Script::String.new("url(#{path})") | ||
end | ||
|
||
private | ||
|
||
def absolute_path?(path) | ||
path[0..0] == "/" || path[0..3] == "http" | ||
end | ||
|
||
def compute_relative_path | ||
if (target_css_file = options[:css_filename]) | ||
images_path = File.join(Compass.configuration.project_path, Compass.configuration.images_dir) | ||
Pathname.new(images_path).relative_path_from(Pathname.new(File.dirname(target_css_file))).to_s | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Compass::SassExtensions::Functions::Nest | ||
COMMA_SEPARATOR = /\s*,\s*/ | ||
|
||
def nest(*arguments) | ||
nested = arguments.map{|a| a.value}.inject do |memo,arg| | ||
ancestors = memo.split(COMMA_SEPARATOR) | ||
descendants = arg.split(COMMA_SEPARATOR) | ||
ancestors.map{|a| descendants.map{|d| "#{a} #{d}"}.join(", ")}.join(", ") | ||
end | ||
Sass::Script::String.new(nested) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
['stylesheet_updating'].each do |patch| | ||
require File.join(File.dirname(__FILE__), 'monkey_patches', patch) | ||
end |
23 changes: 23 additions & 0 deletions
23
lib/compass/sass_extensions/monkey_patches/stylesheet_updating.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'sass/plugin' | ||
|
||
# XXX: We can remove this monkeypatch once Sass 2.2 is released. | ||
module Sass::Plugin | ||
class << self | ||
unless method_defined?(:exact_stylesheet_needs_update?) | ||
def stylesheet_needs_update?(name, template_path, css_path) | ||
css_file = css_filename(name, css_path) | ||
template_file = template_filename(name, template_path) | ||
exact_stylesheet_needs_update?(css_file, template_file) | ||
end | ||
def exact_stylesheet_needs_update?(css_file, template_file) | ||
if !File.exists?(css_file) | ||
return true | ||
else | ||
css_mtime = File.mtime(css_file) | ||
File.mtime(template_file) > css_mtime || | ||
dependencies(template_file).any?(&dependency_updated?(css_mtime)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Compass | ||
module TestCaseHelper | ||
def absolutize(path) | ||
if path.blank? | ||
File.dirname(__FILE__) | ||
elsif path[0] == ?/ | ||
"#{File.dirname(__FILE__)}#{path}" | ||
else | ||
"#{File.dirname(__FILE__)}/#{path}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters