Permalink
Browse files

[enhance] favicon: merge the favicon registering with the register se…

…rver handler, and added explicit js and css registering also
  • Loading branch information...
1 parent a9f43c1 commit ec2c2f52c02ef3874907e14ea44ecd99d0631178 @Aqua-Ye Aqua-Ye committed Mar 5, 2012
Showing with 19 additions and 15 deletions.
  1. +1 −0 CHANGELOG
  2. +18 −15 stdlib/core/web/server/server.opa
View
@@ -8,6 +8,7 @@ API:
STDLIB:
* included Twitter's Bootstrap CSS inside the stdlib, and improved the import system (see doc)
+ * added a way to register favicons (like css and js)
PERFS:
@@ -111,10 +111,10 @@ type Server.handler =
/** An empty request handler but useful for external resources
registering. */
- / {register : list(string)}
-
- /** An empty request handler but useful for favicon registering. */
- / {favicon : list(Favicon.t)}
+ / {register : list(string)
+ / {favicon : list(Favicon.t)}
+ / {js : list(string)}
+ / {css : list(string)}}
/** Request handler which aggregates several request handlers. On
incomming request all handlers (in the order of list) are tested
@@ -230,17 +230,20 @@ Server = {{
)
| {nil} -> Rule.fail
| ~{register} ->
- do List.iter(file ->
- if String.has_suffix(".css", file) then
- Resource.register_external_css(file)
- else if String.has_suffix(".js", file) then
- Resource.register_external_js(file)
- else
- Log.error("Server", "Unknown type of file, the resource \"{file}\" will not registered")
- , register)
- Rule.fail
- | ~{favicon} ->
- do List.iter(f -> Resource.register_external_favicon(f), favicon)
+ do match register
+ | ~{favicon} -> List.iter(f -> Resource.register_external_favicon(f), favicon)
+ | ~{js} -> List.iter(f -> Resource.register_external_js(f), js)
+ | ~{css} -> List.iter(f -> Resource.register_external_css(f), css)
+ | ~{hd tl} ->
+ List.iter(file ->
+ if String.has_suffix(".css", file) then
+ Resource.register_external_css(file)
+ else if String.has_suffix(".js", file) then
+ Resource.register_external_js(file)
+ else
+ Log.error("Server", "Unknown type of file, the resource \"{file}\" will not registered")
+ , ~{hd tl})
+ | {nil} -> void
Rule.fail
| {custom=_} as e
| {title=_; page=_} as e

0 comments on commit ec2c2f5

Please sign in to comment.