Skip to content

Commit

Permalink
Merge pull request #29 from soranoba/feature/partition_of_render_options
Browse files Browse the repository at this point in the history
Fix incompatible typespecs of some options
  • Loading branch information
soranoba authored Sep 27, 2018
2 parents 3aa9b89 + c9e96cf commit f03b295
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
APP=bbmustache
DIALYZER_OPTS=-Werror_handling -Wrace_conditions -Wunmatched_returns

LIBS=$(ERL_LIBS):_build/dev/lib

.PHONY: ct
all: compile eunit ct xref dialyze edoc

Expand Down
19 changes: 11 additions & 8 deletions src/bbmustache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
-define(RAISE_ON_PARTIAL_MISS_ENABLED(Options),
proplists:get_bool(raise_on_partial_miss, Options)).

-define(PARSE_OPTIONS, [raise_on_partial_miss]).

-type key() :: binary().
%% Key MUST be a non-whitespace character sequence NOT containing the current closing delimiter. <br />
%%
Expand Down Expand Up @@ -159,7 +161,8 @@ render(Bin, Data) ->
%% @equiv compile(parse_binary(Bin), Data, Options)
-spec render(binary(), data(), [render_option()]) -> binary().
render(Bin, Data, Options) ->
compile(parse_binary(Bin, Options), Data, Options).
{ParseOptions, CompileOptions} = lists:partition(fun(X) -> lists:member(X, ?PARSE_OPTIONS) end, Options),
compile(parse_binary(Bin, ParseOptions), Data, CompileOptions).

%% @equiv parse_binary(Bin, [])
-spec parse_binary(binary()) -> template().
Expand Down Expand Up @@ -423,7 +426,7 @@ parse_delimiter(State0, ParseDelimiterBin, NextBin, Result) ->
%% 3> split_tag(State, <<"...">>)
%% [<<"...">>]
%% '''
-spec split_tag(state(), binary()) -> [binary()].
-spec split_tag(state(), binary()) -> [binary(), ...].
split_tag(#state{start = StartDelimiter, stop = StopDelimiter}, Bin) ->
case binary:match(Bin, StartDelimiter) of
nomatch ->
Expand Down Expand Up @@ -482,7 +485,7 @@ standalone(State, Post0, Result0) ->
end.

%% @doc If the binary is repeatedly the character, return true. Otherwise, return false.
-spec repeatedly_binary(binary(), char()) -> boolean().
-spec repeatedly_binary(binary(), byte()) -> boolean().
repeatedly_binary(<<X, Rest/binary>>, X) ->
repeatedly_binary(Rest, X);
repeatedly_binary(<<>>, _) ->
Expand Down Expand Up @@ -565,19 +568,19 @@ to_iodata(X) ->
X.

%% @doc string or binary to binary
-spec to_binary(binary() | string()) -> binary().
-spec to_binary(binary() | [byte()]) -> binary().
to_binary(Bin) when is_binary(Bin) ->
Bin;
to_binary(Str) when is_list(Str) ->
list_to_binary(Str).
to_binary(Bytes) when is_list(Bytes) ->
list_to_binary(Bytes).

%% @doc HTML Escape
-spec escape(binary()) -> binary().
escape(Bin) ->
<< <<(escape_char(X))/binary>> || <<X:8>> <= Bin >>.

%% @doc escape a character if needed.
-spec escape_char(0..16#FFFF) -> binary().
-spec escape_char(byte()) -> <<_:8, _:_*8>>.
escape_char($<) -> <<"&lt;">>;
escape_char($>) -> <<"&gt;">>;
escape_char($&) -> <<"&amp;">>;
Expand Down Expand Up @@ -630,7 +633,7 @@ get_data_recursive_impl([Key | RestKey] = Keys, Data, #?MODULE{context_stack = S
end.

%% @doc find the value of the specified key from {@link data/0}
-spec find_data(data_key(), data()) -> {ok, Value ::term()} | error.
-spec find_data(data_key(), data() | term()) -> {ok, Value ::term()} | error.
-ifdef(namespaced_types).
find_data(Key, Map) when is_map(Map) ->
maps:find(Key, Map);
Expand Down

0 comments on commit f03b295

Please sign in to comment.