Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[enhance] favicon: removed the command line options for favicon, and …

…added a way to register favicons, just like css or js
  • Loading branch information...
commit a9f43c1b643e85912134cffe056350db7bba0604 1 parent 0a95c4c
@Aqua-Ye Aqua-Ye authored
View
10 libnet/httpServer.ml
@@ -1,5 +1,5 @@
(*
- Copyright © 2011 MLstate
+ Copyright © 2011, 2012 MLstate
This file is part of OPA.
@@ -741,14 +741,6 @@ let spec_args name =
ServerArg.func ServerArg.int (fun o i -> { o with maximum_number_of_headers = i }),
"<int>", (sprintf "Maximum number of request headers (default: %d)" default_options.maximum_number_of_headers);
- p"favicon-ico",
- ServerArg.func ServerArg.string (fun o s -> { o with favicon_ico = body_value_from_file ~log:true s }),
- "<string>", (sprintf "Favicon.ico file (default: %s)" (bv_file default_options.favicon_ico));
-
- p"favicon-gif",
- ServerArg.func ServerArg.string (fun o s -> { o with favicon_gif = body_value_from_file ~log:true s }),
- "<string>", (sprintf "Favicon.gif file (default: %s)" (bv_file default_options.favicon_gif));
-
p"no-print-log-info",
ServerArg.func ServerArg.unit (fun o () -> { o with print_log_info = false }),
"", (sprintf "Disable access and error logs" (*default_options.print_log_info*));
View
63 stdlib/core/web/resource/favicon.opa
@@ -0,0 +1,63 @@
+/*
+ Copyright © 2012 MLstate
+
+ This file is part of OPA.
+
+ OPA is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License, version 3, as published by
+ the Free Software Foundation.
+
+ OPA is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
+ more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with OPA. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * Format of a favicon, mixes type and
+ */
+type Favicon.format =
+ { ico }
+/ { png }
+/ { gif }
+/ { `apple-touch-icon` }
+/ { `apple-touch-icon-precomposed` }
+
+/**
+ * Type of a favicon meant to be registered in a web page
+ */
+type Favicon.t = {
+ format : Favicon.format
+ path : string
+}
+
+/**
+ * Module allowing to create and generate favicon links.
+ * Meant to be used as a Server.handler,
+ * or to be registered with Resource.register_favicon.
+ */
+Favicon = {{
+
+ /**
+ * Creates a favicon
+ */
+ make(format, path) = {
+ ~format
+ ~path
+ }
+
+ /**
+ * Converts a favicon into an html link
+ */
+ to_html(f) =
+ match f.format
+ { ico } -> <link rel="icon" type="image/x-icon" href="{f.path}"/>
+ { png } -> <link rel="icon" type="image/png" href="{f.path}"/>
+ { gif } -> <link rel="icon" type="image/gif" href="{f.path}"/>
+ { `apple-touch-icon` } -> <link rel="apple-touch-icon" href="{f.path}"/>
+ { `apple-touch-icon-precomposed` } -> <link rel="apple-touch-icon-precomposed" href="{f.path}"/>
+
+}}
View
9 stdlib/core/web/resource/resource.opa
@@ -710,6 +710,15 @@ export_data({~rc_content rc_status=_ rc_headers=_}: resource)=
register_external_css(url : string) : void = Resource_private.register_external_css(url)
/**
+ * Adds an favicon link to the default_customizers of ALL resources.
+ * Will be appended in the headers of the page.
+ * @param favicon A favicon item
+ * @usage This should be used in modules of the standard library not loaded by default (so not stdlib.*)
+ * (Its interest is very limited in user code, since it's easier to customize resources directly)
+ */
+ register_external_favicon(favicon : Favicon.t) : void = Resource_private.register_external_favicon(favicon)
+
+ /**
* Removes an external javascript file (identified by its url) to the default_customizers of ALL resources if it exists.
* @param url An url (as a string) to a javascript file
*/
View
7 stdlib/core/web/resource/resource_private.opa
@@ -634,15 +634,20 @@ required_customizer_for_opa_ad =
@private autoloaded_js = Mutable.make([] : list(string))
@private autoloaded_css = Mutable.make([] : list(string))
+@private autoloaded_favicon = Mutable.make([] : list(Favicon.t))
@package register_external_js(url : string) = autoloaded_js.set([url | autoloaded_js.get()])
@package unregister_external_js(url : string) = autoloaded_js.set(List.remove(url, autoloaded_js.get()))
@package register_external_css(url : string) = autoloaded_css.set([url | autoloaded_css.get()])
@package unregister_external_css(url : string) = autoloaded_css.set(List.remove(url, autoloaded_css.get()))
+@package register_external_favicon(f:Favicon.t) = autoloaded_favicon.set([f | autoloaded_favicon.get()])
customizer_autoloaded : platform_customization =
_ -> some(
{ custom_body = none
- custom_headers = none
+ custom_headers =
+ favicons = autoloaded_favicon.get()
+ if List.is_empty(favicons) then none
+ else some(Xhtml.createFragment(List.map(f->Favicon.to_html(f), favicons)))
custom_js = List.rev(autoloaded_js.get())
custom_css = List.rev(autoloaded_css.get())
})
View
BIN  stdlib/core/web/server/resources/favicon.gif
Deleted file not rendered
View
BIN  stdlib/core/web/server/resources/favicon.ico
Binary file not shown
View
BIN  stdlib/core/web/server/resources/opa-logo-iOS.png
Deleted file not rendered
View
6 stdlib/core/web/server/server.opa
@@ -113,6 +113,9 @@ type Server.handler =
registering. */
/ {register : list(string)}
+ /** An empty request handler but useful for favicon registering. */
+ / {favicon : list(Favicon.t)}
+
/** Request handler which aggregates several request handlers. On
incomming request all handlers (in the order of list) are tested
until one succeed and returns a resource. */
@@ -236,6 +239,9 @@ Server = {{
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)
+ Rule.fail
| {custom=_} as e
| {title=_; page=_} as e
| {dispatch=_} as e
View
12 stdlib/core/web/server/server_private.opa
@@ -1,5 +1,5 @@
/*
- Copyright © 2011 MLstate
+ Copyright © 2011, 2012 MLstate
This file is part of OPA.
@@ -89,17 +89,7 @@ Server_private = {{
launch_date: Date.date = Date.now()
some_launch_date = {some = launch_date} //Provided for functions that would otherwise need to box [launch_date] all the time
- /**
- * Resources defined by the standard library but which can be overridden by the user
- */
- @private provide_default_favicon_ico = @static_resource("stdlib/core/web/server/resources/favicon.ico") //Default favicon
- @private provide_default_favicon_gif = @static_resource("stdlib/core/web/server/resources/favicon.gif") //Default favicon
- @private provide_default_touchicon = @static_resource("stdlib/core/web/server/resources/opa-logo-iOS.png")
-
overridable_handlers = parser
- | "/favicon.ico" -> provide_default_favicon_ico
- | "/favicon." .* -> provide_default_favicon_gif
- | "/apple-touch-icon.png" -> provide_default_touchicon
| "/about/opa" -> page_version
Please sign in to comment.
Something went wrong with that request. Please try again.