1

[Re-asked clearly -- this is not a duplicate question] I commented out all of my included scss files and for some reason Rails kept including them and it was causing an error. Then I realized that the error was happening in precompile. Rails was going through all of my assets to precompile them but this included all partials and all vendor partials. I couldn't just rename them. How do I blacklist assets from being precompile preferably by Regex? In this way I can rule out partials and vendor related partials that will never be referenced directly and their parent files can be properly precompiled without error

Michael K Madison
  • 2,242
  • 3
  • 21
  • 35
  • 1
    You ve to load mixins in every module scss file. Its annoying but rails sometimes doesnt load everything as it is stated. or try loading importing mixin file in module.scss at the beginning – Harry Bomrah Jan 14 '16 at 10:31
  • You need to include your mixins first - no point calling a mixin if SCSS doesn't know where it is – Richard Peck Jan 14 '16 at 11:04
  • `@HarryBomrah` you don't need to include mixins in every file, only the modules.scss – Richard Peck Jan 14 '16 at 11:09
  • @cimmanon this is definitely not a duplication, it's a Rails related question and adding an underscore is definitely not the answer, take for example, vendor partials -- you can't just rename all of your vendors partials, for every file you rename you have to change every reference, and what about vendor upgrades. – Michael K Madison Jan 30 '16 at 08:23
  • @cimmanon please unmark this as a duplicate. – Michael K Madison Jan 30 '16 at 08:30
  • You have done nothing to prove that this is not a duplicate, all you've done is come up with your own janky solution. Adding the underscore to the filename does **not** require you to update references to it. I have a hard time believing any vendor is shipping files that have errors. – cimmanon Jan 30 '16 at 12:08
  • @cimmanon First off, this question pertains to the Rails asset pipeline and it's precompile paths. You connected it to a question that has nothing to do with Rails at all. Rails is a topic you don't list as your expertise. nv3d ships with intro.js and outro.js -- they are partials not mean to be individually compiled; yet Rails will try to unless you take them out. i'm not clear why it's necessary to have such an attitude. You connected two things that are actually different. The other question is completely unrelated to Rails for example. – Michael K Madison Feb 04 '16 at 03:32
  • @cimmanon First off, this question pertains to the Rails asset pipeline and it's precompile paths. You connected it to a question that has nothing to do with Rails at all. Rails is a topic you don't list as your expertise. Secondly, Rails will precompile everything in your path and there are plenty libraries out there that ship with partials that don't have undercores (for example, nv3d ships with intro.js and outro.js -- partials). They aren't errors -- partials referenced by a parent and named without an underscore. i'm not clear why it's necessary to have such an attitude. – Michael K Madison Feb 04 '16 at 03:38
  • also it's not even just about sass.. it's about the full asset pipeline. – Michael K Madison Feb 04 '16 at 03:41

2 Answers2

0

The problem isn't with SCSS/SASS, it's that you're not calling your mixins.

Simply, it means that you have to reference admin/mixins first, so that your imported files have a reference to use:

#app/assets/stylesheets/modules.scss
@import "admin/mixins";
@import "modules/*";

This will call the mixins in the modules.scss file, to which you're then able to reference them as you need.

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
-1

[EDITED per review comments] The problem was that I was precompiling all of my assets even in development mode and so Rails was going through all assets including vendor assets without regard to whether individual files were partials. I fixed this by adding the below code to exclude anything that was a partial either because it began with an underscore or was on a "blacklist" I also describe that solution here:

Rails.application.config.assets.precompile << Proc.new { |path|
        blacklist = [
                /nvd3\/src\/intro.js$/,
                /nvd3\/src\/outro.js$/,
                /^.*\.less$/,
                /admin\/modules/,
                /admin\/themes/,
                /admin\/responsive\..*css/
        ]
        full_path = Rails.application.assets.resolve(path)#.to_path
        puts "path: #{path}\nfull_path: #{full_path}" if BLACK_MAGIC[:assets][:debug]

        if (path =~ /(^[^_\/]|\/[^_])[^\/]*$/) and (path !~ Regexp.union(blacklist) )

                puts "including asset: " + full_path if BLACK_MAGIC[:assets][:debug]
                true
        else
                puts "excluding asset: " + full_path if BLACK_MAGIC[:assets][:debug]
                false
        end
}

You can add all of your regular expressions to the blacklist array for exclusion and then the two part if condition

if (path =~ /(^[^_\/]|\/[^_])[^\/]*$/) and (path !~ Regexp.union(blacklist) )

will first eliminate items beginning with underscore (this isn't quite a perfect Regex yet, play with rubular) and secondly will eliminate anything that matches the blacklisted expressions.

Lastly, note that keithgaputis partly answers this question here but didn't account for the need for a blacklist of Regex's. In Rails, oftentimes vendor assets as well as your own app assets will have partials and it's a real pain to sort through this file by file or even file type by file type; much nicer to blacklist with Regex's.

Community
  • 1
  • 1
Michael K Madison
  • 2,242
  • 3
  • 21
  • 35