Skip to content

Commit

Permalink
Sass: explicitly set $bootstrap-sass-asset-helper
Browse files Browse the repository at this point in the history
Remove reliance on a hack as a polyfill for `function-exists`.
Remove clutter from the generated variables template.
  • Loading branch information
glebm committed Dec 17, 2014
1 parent 1965158 commit 7d30630
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
2 changes: 2 additions & 0 deletions assets/stylesheets/_bootstrap-compass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
@function twbs-image-path($path) {
@return image-url($path, true);
}

$bootstrap-sass-asset-helper: true;
2 changes: 2 additions & 0 deletions assets/stylesheets/_bootstrap-mincer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
@function twbs-image-path($file) {
@return "<%- asset_path('#{$file}') %>";
}

$bootstrap-sass-asset-helper: true;
2 changes: 2 additions & 0 deletions assets/stylesheets/_bootstrap-sprockets.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
@function twbs-image-path($path) {
@return image-path($path);
}

$bootstrap-sass-asset-helper: true;

This comment has been minimized.

Copy link
@halida

halida Jan 6, 2015

I've debugged two hours for this issue. I create a new rails project, using bootstrap-sass version 3.3.1, and compile the application.css file. In this file, unlike other assets, I found icon font files are not compiled with digest name. checking the source code, $bootstrap-sass-asset-helper is not set to true by default, then I check git repo, found it is fixed. May I ask when this version will be released? Currently I add this line to my application.css.scss file.

This comment has been minimized.

Copy link
@glebm

glebm Jan 8, 2015

Author Member

@halida It was set to true before. You need to import the asset pipeline integration before bootstrap.

9 changes: 3 additions & 6 deletions assets/stylesheets/bootstrap/_variables.scss
Original file line number Diff line number Diff line change
@@ -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
// --------------------------------------------------
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 4 additions & 8 deletions tasks/converter/less_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,10 @@ def process_stylesheet_assets
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'
Expand Down Expand Up @@ -146,7 +142,7 @@ def process_stylesheet_assets
# 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
Expand Down
8 changes: 2 additions & 6 deletions templates/project/_bootstrap-variables.sass
Original file line number Diff line number Diff line change
@@ -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
// --------------------------------------------------
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7d30630

Please sign in to comment.