From 7d30630bc8d490239b15dce754dfba298a7d5bc2 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 17 Dec 2014 15:27:37 +0000 Subject: [PATCH] Sass: explicitly set $bootstrap-sass-asset-helper Remove reliance on a hack as a polyfill for `function-exists`. Remove clutter from the generated variables template. --- assets/stylesheets/_bootstrap-compass.scss | 2 ++ assets/stylesheets/_bootstrap-mincer.scss | 2 ++ assets/stylesheets/_bootstrap-sprockets.scss | 2 ++ assets/stylesheets/bootstrap/_variables.scss | 9 +++------ tasks/converter/less_conversion.rb | 12 ++++-------- templates/project/_bootstrap-variables.sass | 8 ++------ 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/assets/stylesheets/_bootstrap-compass.scss b/assets/stylesheets/_bootstrap-compass.scss index 82706c47..8fbc3cda 100644 --- a/assets/stylesheets/_bootstrap-compass.scss +++ b/assets/stylesheets/_bootstrap-compass.scss @@ -5,3 +5,5 @@ @function twbs-image-path($path) { @return image-url($path, true); } + +$bootstrap-sass-asset-helper: true; diff --git a/assets/stylesheets/_bootstrap-mincer.scss b/assets/stylesheets/_bootstrap-mincer.scss index 34132501..7ec46574 100644 --- a/assets/stylesheets/_bootstrap-mincer.scss +++ b/assets/stylesheets/_bootstrap-mincer.scss @@ -15,3 +15,5 @@ @function twbs-image-path($file) { @return "<%- asset_path('#{$file}') %>"; } + +$bootstrap-sass-asset-helper: true; diff --git a/assets/stylesheets/_bootstrap-sprockets.scss b/assets/stylesheets/_bootstrap-sprockets.scss index 7d306928..9fffc1eb 100644 --- a/assets/stylesheets/_bootstrap-sprockets.scss +++ b/assets/stylesheets/_bootstrap-sprockets.scss @@ -5,3 +5,5 @@ @function twbs-image-path($path) { @return image-path($path); } + +$bootstrap-sass-asset-helper: true; diff --git a/assets/stylesheets/bootstrap/_variables.scss b/assets/stylesheets/bootstrap/_variables.scss index 7d190f26..e23cba09 100644 --- a/assets/stylesheets/bootstrap/_variables.scss +++ b/assets/stylesheets/bootstrap/_variables.scss @@ -1,8 +1,4 @@ -// When true, asset path helpers are used, otherwise the regular CSS `url()` is used. -// When there no function is defined, `fn('')` is parsed as string that equals the right hand side -// NB: in Sass 3.3 there is a native function: function-exists(twbs-font-path) -$bootstrap-sass-asset-helper: (twbs-font-path("") != unquote('twbs-font-path("")')) !default; - +$bootstrap-sass-asset-helper: false !default; // // Variables // -------------------------------------------------- @@ -82,7 +78,8 @@ $headings-color: inherit !default; //** Load fonts from this directory. -// [converter] Asset helpers such as Sprockets and Node.js Mincer do not resolve relative paths +// [converter] If $bootstrap-sass-asset-helper if used, provide path relative to the assets load path. +// [converter] This is because some asset helpers, such as Sprockets, do not work with file-relative paths. $icon-font-path: if($bootstrap-sass-asset-helper, "bootstrap/", "../fonts/bootstrap/") !default; //** File name for all font files. diff --git a/tasks/converter/less_conversion.rb b/tasks/converter/less_conversion.rb index 4b4bf0c7..e6535758 100644 --- a/tasks/converter/less_conversion.rb +++ b/tasks/converter/less_conversion.rb @@ -95,14 +95,10 @@ class Converter file = apply_mixin_parent_selector file, '\.(?:visible|hidden)' when 'variables.less' file = insert_default_vars(file) - file = unindent <<-SCSS + "\n" + file, 14 - // When true, asset path helpers are used, otherwise the regular CSS `url()` is used. - // When there no function is defined, `fn('')` is parsed as string that equals the right hand side - // NB: in Sass 3.3 there is a native function: function-exists(twbs-font-path) - $bootstrap-sass-asset-helper: #{sass_fn_exists('twbs-font-path')} !default; - SCSS + file = ['$bootstrap-sass-asset-helper: false !default;', file].join("\n") file = replace_all file, %r{(\$icon-font-path): \s*"(.*)" (!default);}, "\n" + unindent(<<-SCSS, 14) - // [converter] Asset helpers such as Sprockets and Node.js Mincer do not resolve relative paths + // [converter] If $bootstrap-sass-asset-helper if used, provide path relative to the assets load path. + // [converter] This is because some asset helpers, such as Sprockets, do not work with file-relative paths. \\1: if($bootstrap-sass-asset-helper, "bootstrap/", "\\2bootstrap/") \\3; SCSS when 'close.less' @@ -146,7 +142,7 @@ class Converter # generate variables template save_file 'templates/project/_bootstrap-variables.sass', "// Override Bootstrap variables here (defaults from bootstrap-sass v#{Bootstrap::VERSION}):\n\n" + - File.read("#{save_to}/_variables.scss").gsub(/^(?=\$)/, '// ').gsub(/ !default;/, '') + File.read("#{save_to}/_variables.scss").lines[1..-1].join.gsub(/^(?=\$)/, '// ').gsub(/ !default;/, '') end def bootstrap_less_files diff --git a/templates/project/_bootstrap-variables.sass b/templates/project/_bootstrap-variables.sass index 968ceb62..080b1a38 100644 --- a/templates/project/_bootstrap-variables.sass +++ b/templates/project/_bootstrap-variables.sass @@ -1,10 +1,5 @@ // Override Bootstrap variables here (defaults from bootstrap-sass v3.3.1.0): -// When true, asset path helpers are used, otherwise the regular CSS `url()` is used. -// When there no function is defined, `fn('')` is parsed as string that equals the right hand side -// NB: in Sass 3.3 there is a native function: function-exists(twbs-font-path) -// $bootstrap-sass-asset-helper: (twbs-font-path("") != unquote('twbs-font-path("")')) - // // Variables // -------------------------------------------------- @@ -84,7 +79,8 @@ //** Load fonts from this directory. -// [converter] Asset helpers such as Sprockets and Node.js Mincer do not resolve relative paths +// [converter] If $bootstrap-sass-asset-helper if used, provide path relative to the assets load path. +// [converter] This is because some asset helpers, such as Sprockets, do not work with file-relative paths. // $icon-font-path: if($bootstrap-sass-asset-helper, "bootstrap/", "../fonts/bootstrap/") //** File name for all font files.