Skip to content
This repository

middleware src & dest optionally as functions #930

Merged
merged 1 commit into from 9 months ago

3 participants

Anders D. Johnson jascha ehrenreich Roman Komarov
Anders D. Johnson

See #210. This is a flexible solution that doesn't break the current API for string paths. It allows one to provide functions that return file paths given the request path. Usual case for these will involve some string replaces on the request path.

P.S. - How are you generating the markdown docs? Seems to come from the JSDoc-style annotations, but I didn't see any scripts.

jascha ehrenreich
jaeh commented March 01, 2013

the markdown docs are generated using mocha and lib-cov afaik.

mocha

Roman Komarov kizu merged commit 9345896 into from August 01, 2013
Roman Komarov kizu closed this August 01, 2013
Roman Komarov
Collaborator
kizu commented August 01, 2013

Thanks, merged! I'll update docs on site later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 29, 2012
Anders D. Johnson middleware src & dest optionally as functions 9345896
This page is out of date. Refresh to see the latest.
6  docs/middleware.md
Source Rendered
@@ -10,8 +10,10 @@
10 10
 #### Options
11 11
 
12 12
       `force`     When __true__ styles will always re-compile
13  
-      `src`       Source directory used to find .styl files
14  
-      `dest`      Destination directory used to output .css files
  13
+      `src`       Source directory used to find .styl files,
  14
+                  a string or function accepting `(path)` of request.
  15
+      `dest`      Destination directory used to output .css files,
  16
+                  a string or function accepting `(path)` of request,
15 17
                   when undefined defaults to `src`.
16 18
       `compress`  Whether the output .css files should be compressed
17 19
       `compile`   Custom compile function, accepting the arguments
15  lib/middleware.js
@@ -29,8 +29,10 @@ var imports = {};
29 29
  * Options:
30 30
  *
31 31
  *    `force`     Always re-compile
32  
- *    `src`       Source directory used to find .styl files
33  
- *    `dest`      Destination directory used to output .css files
  32
+ *    `src`       Source directory used to find .styl files,
  33
+ *                a string or function accepting `(path)` of request.
  34
+ *    `dest`      Destination directory used to output .css files,
  35
+ *                a string or function accepting `(path)` of request,
34 36
  *                when undefined defaults to `src`.
35 37
  *    `compile`   Custom compile function, accepting the arguments
36 38
  *                `(str, path)`.
@@ -109,8 +111,13 @@ module.exports = function(options){
109 111
     if ('GET' != req.method && 'HEAD' != req.method) return next();
110 112
     var path = url.parse(req.url).pathname;
111 113
     if (/\.css$/.test(path)) {
112  
-      var cssPath = join(dest, path)
113  
-        , stylusPath = join(src, path.replace('.css', '.styl'));
  114
+      var cssPath, stylusPath;
  115
+      cssPath = (typeof dest == 'function')
  116
+        ? dest(path)
  117
+        : join(dest, path);
  118
+      stylusPath = (typeof src == 'function')
  119
+        ? src(path)
  120
+        : join(src, path.replace('.css', '.styl'));
114 121
 
115 122
       // Ignore ENOENT to fall through as 404
116 123
       function error(err) {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.