Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality inline-svg-code #2069

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.gem
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rvm:
- ree
- 2.0.0
- 2.1.0
- 2.2.0

sudo: false

Expand Down
25 changes: 25 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ task :test do
end
end

desc "build gems"
task :build_gems => [:test] do
GEMS.each do |gem|
chdir gem do
if gem == 'cli'
sh "gem build compass.gemspec"
else
sh "gem build compass-#{gem}.gemspec"
end
end
end
end

desc "publish gems"
task :publish_gems => [:build_gems] do
GEMS.each do |gem|
chdir gem do
if gem == 'cli'
sh "gem push compass.gemspec"
else
sh "gem push compass-#{gem}.gemspec"
end
end
end
end

desc "Clean up all test files"
task :test_cleanup do
Expand Down
1 change: 1 addition & 0 deletions cli/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ unless ENV['PKG']
gem 'rake'
gem 'json', '~> 1.7.7', :platforms => :ruby_18
gem 'true', "~> 0.2.3"
gem 'test-unit', '~> 3.0.9'

# Warning be carful adding OS dependant gems above this line it will break the CI server please
# place them below so they are excluded
Expand Down
2 changes: 1 addition & 1 deletion cli/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.3
2 changes: 1 addition & 1 deletion cli/compass.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |gemspec|
Compass is charityware. If you love it, please donate on our behalf at http://umdf.org/compass Thanks!
MESSAGE

gemspec.files = %w(LICENSE.markdown VERSION Rakefile)
gemspec.files = %w(LICENSE.markdown VERSION VERSION_NAME Rakefile)
gemspec.files += Dir.glob("bin/*")
gemspec.files += Dir.glob("data/**/*")
gemspec.files += Dir.glob("frameworks/**/*")
Expand Down
7 changes: 4 additions & 3 deletions cli/lib/compass/sass_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ def when_deleting_sourcemap(filename)
def when_compilation_error(error, sass_file, css_file, sourcemap_file)
@error_count += 1
if error.respond_to?(:sass_filename)
if relativize(error.sass_filename) == relativize(sass_file)
logger.record :error, "#{relativize(error.sass_filename)} (Line #{error.sass_line}: #{error.message})"
error_filename = error.sass_filename || sass_file
if relativize(error_filename) == relativize(sass_file)
logger.record :error, "#{relativize(sass_file)} (Line #{error.sass_line}: #{error.message})"
else
logger.record :error, "#{relativize(sass_file)} (Line #{error.sass_line} of #{relativize(error.sass_filename)}: #{error.message})"
logger.record :error, "#{relativize(sass_file)} (Line #{error.sass_line} of #{relativize(error_filename)}: #{error.message})"
end
else
logger.record :error, "#{relativize(sass_file)} (#{error.backtrace.first}: #{error.message})"
Expand Down
1 change: 1 addition & 0 deletions core/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ gem 'pry'
gem 'diff-lcs', '~> 1.1.2'
gem 'true', "~> 0.2.3"
gem 'timecop', "~> 0.5.9.2"
gem 'test-unit', '~> 3.0.9'
2 changes: 1 addition & 1 deletion core/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.2
2 changes: 1 addition & 1 deletion core/lib/compass/core/caniuse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def all_prefixes(browser)
end

# returns the prefixes needed by the list of browsers given
def prefixes(browsers = browsers)
def prefixes(browsers = browsers())
result = browsers.map{|b| all_prefixes(b) }
result.flatten!
result.uniq!
Expand Down
38 changes: 38 additions & 0 deletions core/lib/compass/core/sass_extensions/functions/inline_image.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Uncomment lines to enable `inline-svg-code-to-png` functionality
# require 'RMagick'
# include Magick

module Compass::Core::SassExtensions::Functions::InlineImage

def inline_image(path, mime_type = nil)
Expand All @@ -17,13 +21,33 @@ def inline_font_files(*args)
list(files, :comma)
end

def inline_svg_code(str)
code = str.value

# Add the XML header (because it's a real drag adding it each time)
code = '<?xml version="1.0" ?>' + code

# Inline the SVG code
inline_svg_string(format_svg_code(code))
end

# def inline_svg_code_to_png(str)
# code = str.value
# inline_image_string(convert_svg_code_to_png(code), 'png')
# end

protected
def inline_image_string(data, mime_type)
data = [data].flatten.pack('m').gsub("\n","")
url = "url('data:#{mime_type};base64,#{data}')"
unquoted_string(url)
end

def inline_svg_string(data)
url = "url('data:image/svg+xml,#{data}')"
unquoted_string(url)
end

private
def compute_mime_type(path, mime_type = nil)
return mime_type.value if mime_type
Expand Down Expand Up @@ -60,4 +84,18 @@ def data(real_path)
raise Compass::Error, "File not found or cannot be read: #{real_path}"
end
end

def format_svg_code(code)
ERB::Util.url_encode(code)
end

# def convert_svg_code_to_png(str)
# img, data = Magick::Image.from_blob(str) {
# self.format = 'SVG'
# self.background_color = 'transparent'
# }
# img.to_blob {
# self.format = 'PNG'
# }
# end
end
4 changes: 2 additions & 2 deletions core/stylesheets/compass/_support.scss
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ $css-sel2-support-threshold: $critical-usage-threshold !default;
$old-range: map-get($ranges, $browser);
@if $old-range {
$old-min: nth($old-range, 1);
$old-max: nth($old-range, 2);
$old-max: if(length($old-range) == 1, $old-min, nth($old-range, 2));
$new-min: nth($new-range, 1);
$new-max: nth($new-range, 2);
$new-max: if(length($new-range) == 1, $new-min, nth($new-range, 2));
$maximin: if(compare-browser-versions($browser, $old-min, $new-min) > 0,
$old-min, $new-min);
$minimax: if(compare-browser-versions($browser, $old-max, $new-max) < 0,
Expand Down
10 changes: 10 additions & 0 deletions core/test/integrations/projects/compass/css/issue-1853.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.use-case {
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmMDAwMCIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzAwMDBmZiIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background-size: 100%;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ff0000), color-stop(100%, #0000ff));
background-image: -moz-linear-gradient(#ff0000, #0000ff);
background-image: -webkit-linear-gradient(#ff0000, #0000ff);
background-image: linear-gradient(#ff0000, #0000ff); }

.simple {
content: (ie: "9" "9"); }
16 changes: 16 additions & 0 deletions core/test/integrations/projects/compass/sass/issue-1853.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import "compass/support";
@import "compass/css3/images";

// An actual use-case that demonstrates the problem
.use-case {
@include with-browser-ranges(css-mediaqueries) {
@include background-image(linear-gradient(red, blue));
}
}

// A simplification of the issue
$ranges: (ie: "9" "11");
$new-ranges: (ie: "9");
.simple {
content: inspect(intersect-browser-ranges($ranges, $new-ranges));
}
2 changes: 2 additions & 0 deletions import-once/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source 'https://rubygems.org'

gem 'test-unit', '~> 3.0.9'

gemspec