1

I have a CSS framework submodule in my Git repo that includes a bunch of README, component.json and other files. I don’t want to modify or delete the files because I’d imagine it’d cause problems when updates are pushed to the submodule. Yet Middleman wants to process them.

I currently have this in my config.rb file:

# Ignore everything that's not a CSS file inside inuit.css
ignore 'css/inuit.css/*.html'
ignore 'css/inuit.css/*.json'
ignore 'css/inuit.css/LICENSE'

How could I express this with a file pattern or a regex?

6
  • 1
    It would help if you didn't have folders with .css in their names. _css would be better. Then it's a matter of using a regex that matches .css at the end of the file name. Otherwise you need to check whether things like inuit.css are folders or files. Commented Aug 22, 2013 at 20:44
  • 4
    Those aren't regular expressions. Those are file matching patterns, or fileglobs. Commented Aug 22, 2013 at 20:46
  • @AndyLester According to Middleman’s documentation, “you can give ignore exact source paths, filename globs, or regexes.” Commented Aug 22, 2013 at 20:49
  • It may allow you to ignore using regexes, but css/inuit.css/*.html is a filename glob, not a regex. Commented Aug 22, 2013 at 20:51
  • @AndyLester Oh, I know that. I was just indicating that regexes could be used in this question. And the answer probably will use regexes, since they are more powerful than file globs. Commented Aug 22, 2013 at 20:54

2 Answers 2

1

I’m not familiar with Middleman, but doesn’t this work?

ignore /^css\/inuit\.css\/.*(?<![.]css)$/
Sign up to request clarification or add additional context in comments.

1 Comment

That also needs an i flag to that so it can handle “.CSS” files, but if you add i then yes, that should work – it passes my test cases. Good use of negative lookbehind (?<!).
1

Since ignore can take a regex, pass ignore a Ruby regex // instead of a string "" with a filename glob. In the regex, use negative lookahead (?!) and the end-of-string anchor $ to check that the filename doesn’t end in “.css”.

ignore /^ css\/inuit\.css\/ (?:  [^.]+  |  .+ \. (?!css) \w+   ) $/ix

This regex correctly handles all of these test cases:

  • Should match:
    • css/inuit.css/abc.html
    • css/inuit.css/thecssthing.json
    • css/inuit.css/sub/in_a_folder.html
    • css/inuit.css/sub/crazily.named.css.json
    • css/inuit.css/sub/crazily.css.named.json
    • css/inuit.css/LICENSE
  • Shouldn’t match:
    • css/inuit.css/realcss.css
    • css/inuit.css/main.css
    • css/inuit.css/sub/in_a_folder.css
    • css/inuit.css/sub/crazily.css.named.css
    • css/inuit.css/sub/crazily.named.css.css

The first alternation of the (?:) non-capturing group handles the case of files with no extension (no “.”). Otherwise, the second case checks that the last “.” in the path is not followed by “css”, which would indicate a “.css” extension.

I use the x flag to ignore whitespace in the regex, so that I can add spaces in the regex to make it clearer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.