Rails 3 - Precompiling all css, sass and scss files in a folder

前端 未结 2 1170
梦毁少年i
梦毁少年i 2020-12-11 07:35

So I have a project with page-specific styles and css. I\'ve put those files into their own directory assets/#{type}/page-specific/ and I\'m attempting to write

2条回答
  •  庸人自扰
    2020-12-11 07:56

    This answer is specifically for the regex. You're looking for "absence of character sequence css" in place of [^(css)].


    This regex takes a similar approach to yours:

    /(page-specific\/(?:(?!\.css).)++\.css)/
    

    Explanation:

    • page-specific\/ matches the character sequence "page-specific/" literally.
    • (?: opens a non-capturing group.
      • (?!\.css) asserts that the current index is not of character sequence ".css".

    If this assertion fails at the first time this group is matched, the current section will fail to be matched (page-specific/.css is no good), else this terminates group quantification as we've already matched .css, and returns to \.css)/ to finish.

      • . matches anything except for newline.
    • )++ closes the group and quantifies to unlimited times possessively (Without giving back).
      Note: Ruby supports possessive quantifiers starting with Ruby 1.9.
    • \.css matches the character sequence ".css" literally.

    Read more:

    • Possessive Quantifiers
    • Lookahead and Lookbehind Zero-Length Assertions

    However if nothing, this regex does it with a nongreedy modifier:

    /(page-specific\/.+?\.css)/
    

    As .+? matches as few times as possible, the resulting capture is guaranteed to end at the first .css.

    Read more:

    • Greedy and Lazy Regex

    PS: You may have forgotten to escape a dot near the end of your regex in .css/.


    Specified by:
    http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm

提交回复
热议问题