Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add exts and mimes functions to generated module

  • Loading branch information...
commit 915050ddcb6bf00927fe54133d46f9c34718fbaa 1 parent d692e37
Magnus Klaar authored
Showing with 28 additions and 2 deletions.
  1. +28 −2 src/mimetypes.erl
View
30 src/mimetypes.erl
@@ -234,7 +234,15 @@ map_to_abstract_(Module, Pairs) ->
%% mime_to_exts/1
erl_syntax:arity_qualifier(
erl_syntax:atom(mime_to_exts),
- erl_syntax:integer(1))])]),
+ erl_syntax:integer(1)),
+ %% exts/0
+ erl_syntax:arity_qualifier(
+ erl_syntax:atom(exts),
+ erl_syntax:integer(0)),
+ %% mimes/0
+ erl_syntax:arity_qualifier(
+ erl_syntax:atom(exts),
+ erl_syntax:integer(0))])]),
%% ext_to_mimes(Extension) -> [MimeType].
erl_syntax:function(
erl_syntax:atom(ext_to_mimes),
@@ -246,7 +254,11 @@ map_to_abstract_(Module, Pairs) ->
erl_syntax:atom(mime_to_exts),
mime_to_exts_clauses(Pairs) ++
[erl_syntax:clause(
- [erl_syntax:underscore()], none, [erl_syntax:abstract([])])])].
+ [erl_syntax:underscore()], none, [erl_syntax:abstract([])])]),
+ %% exts() -> [Extension].
+ erl_syntax:function(erl_syntax:atom(exts), [exts_clause(Pairs)]),
+ %% mimes() -> [MimeType].
+ erl_syntax:function(erl_syntax:atom(mimes), [mimes_clause(Pairs)])].
%% @private Generate a set of ext_to_mimes clauses.
-spec ext_to_mimes_clauses([{binary(), binary()}]) -> [erl_syntax:syntaxTree()].
@@ -266,6 +278,20 @@ mime_to_exts_clauses(Pairs) ->
|| {T, Es} <- Groups].
+%% @private Generate a clause returning the set of extensions.
+-spec exts_clause([{binary(), binary()}]) -> [erl_syntax:syntaxTree()].
+exts_clause(Pairs) ->
+ Exts = lists:usort([E || {E,_} <- Pairs]),
+ erl_syntax:clause([], none, [erl_syntax:abstract(Exts)]).
+
+
+%% @private Generate a clause returning the set of mimetypes.
+-spec mimes_clause([{binary(), binary()}]) -> [erl_syntax:syntaxTree()].
+mimes_clause(Pairs) ->
+ Types = lists:usort([T || {_,T} <- Pairs]),
+ erl_syntax:clause([], none, [erl_syntax:abstract(Types)]).
+
+
%% @private Compile and load a module.
%% Copied from the meck_mod module of the meck project.
-spec compile_and_load_forms(erlang_form(), compile_options()) -> ok.
Please sign in to comment.
Something went wrong with that request. Please try again.