cdepillabout/servant-static-th

Files that has to be ignored and not served

Opened this issue · 1 comments

Hello,
I have static files (.sass) that do not need to be served but ignored by the extensionToMimeTypeInfoEx function
Right now, it fails with "unknown extension type"
Do you have a plan for such issue already ?
Thanks for your reply.
Alexandre

@delanoe Currently I don't have any plans to add a feature like this. However, I agree it would be nice to be able to give a file glob and have functions like createApiAndServerDecs ignore it.


If you (or anyone else) is interested in sending a PR adding this, you'll probably need to do the following things:

  1. Change the createApiType function to add a parameter that takes a list of file globs to ignore:

    createApiType
    :: FilePath -- ^ directory name to read files from
    -> Q Type
    createApiType templateDir = do
    fileTree <- runIO $ getFileTreeIgnoreEmpty templateDir
    combineWithServantOrT $ fmap fileTreeToApiType fileTree

    Do the same for createServerExp:

    createServerExp
    :: FilePath
    -> Q Exp
    createServerExp templateDir = do
    fileTree <- runIO $ getFileTreeIgnoreEmpty templateDir
    combineWithServantOr $ fmap fileTreeToServer fileTree

    Actually change the underlying getFileTreeIgnoreEmpty function to ignore files that match a glob in a list of globs.

  2. Add a new top-level function in https://github.com/cdepillabout/servant-static-th/blob/3baf38ab5021d2dd22c662010f857dbf9ec02173/src/Servant/Static/TH.hs that exposes the required functionality. Probably a function like createApiAndServerDecs, but it takes one more argument (the list of globs to ignore).

I'm imagining an example of the list of globs could look something like the following:

globsToIgnore =
  [ "*.sass" -- This is the example from delanoe.  It would ignore all files with a .sass file extension
  , ".git"  -- Ignore a .git directory.
  . ".git*" -- Ignore all files that start with .git
  ]

I'm not sure what a good library is for matching on globs, but you might want to check out http://hackage.haskell.org/package/Glob.

It would be nice if the list of globs matched against hierarchies of directories, so you could match against the same sort of globs you put in a .gitignore file. This would mean you could match against something like some/path/file.hs. That would ignore the file.hs file, but only if it is in the some/path/ directory.

However, I'd be happy with just globs matching against single filenames (not full paths), if this feature is too much work.