Codebase list erlang-bbmustache / f03b295
Merge pull request #29 from soranoba/feature/partition_of_render_options Fix incompatible typespecs of some options Hinagiku Soranoba authored 5 years ago GitHub committed 5 years ago
2 changed file(s) with 11 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
0 APP=bbmustache
1 DIALYZER_OPTS=-Werror_handling -Wrace_conditions -Wunmatched_returns
2
3 LIBS=$(ERL_LIBS):_build/dev/lib
4
50 .PHONY: ct
61 all: compile eunit ct xref dialyze edoc
72
5151 -define(RAISE_ON_PARTIAL_MISS_ENABLED(Options),
5252 proplists:get_bool(raise_on_partial_miss, Options)).
5353
54 -define(PARSE_OPTIONS, [raise_on_partial_miss]).
55
5456 -type key() :: binary().
5557 %% Key MUST be a non-whitespace character sequence NOT containing the current closing delimiter. <br />
5658 %%
158160 %% @equiv compile(parse_binary(Bin), Data, Options)
159161 -spec render(binary(), data(), [render_option()]) -> binary().
160162 render(Bin, Data, Options) ->
161 compile(parse_binary(Bin, Options), Data, Options).
163 {ParseOptions, CompileOptions} = lists:partition(fun(X) -> lists:member(X, ?PARSE_OPTIONS) end, Options),
164 compile(parse_binary(Bin, ParseOptions), Data, CompileOptions).
162165
163166 %% @equiv parse_binary(Bin, [])
164167 -spec parse_binary(binary()) -> template().
422425 %% 3> split_tag(State, <<"...">>)
423426 %% [<<"...">>]
424427 %% '''
425 -spec split_tag(state(), binary()) -> [binary()].
428 -spec split_tag(state(), binary()) -> [binary(), ...].
426429 split_tag(#state{start = StartDelimiter, stop = StopDelimiter}, Bin) ->
427430 case binary:match(Bin, StartDelimiter) of
428431 nomatch ->
481484 end.
482485
483486 %% @doc If the binary is repeatedly the character, return true. Otherwise, return false.
484 -spec repeatedly_binary(binary(), char()) -> boolean().
487 -spec repeatedly_binary(binary(), byte()) -> boolean().
485488 repeatedly_binary(<<X, Rest/binary>>, X) ->
486489 repeatedly_binary(Rest, X);
487490 repeatedly_binary(<<>>, _) ->
564567 X.
565568
566569 %% @doc string or binary to binary
567 -spec to_binary(binary() | string()) -> binary().
570 -spec to_binary(binary() | [byte()]) -> binary().
568571 to_binary(Bin) when is_binary(Bin) ->
569572 Bin;
570 to_binary(Str) when is_list(Str) ->
571 list_to_binary(Str).
573 to_binary(Bytes) when is_list(Bytes) ->
574 list_to_binary(Bytes).
572575
573576 %% @doc HTML Escape
574577 -spec escape(binary()) -> binary().
576579 << <<(escape_char(X))/binary>> || <<X:8>> <= Bin >>.
577580
578581 %% @doc escape a character if needed.
579 -spec escape_char(0..16#FFFF) -> binary().
582 -spec escape_char(byte()) -> <<_:8, _:_*8>>.
580583 escape_char($<) -> <<"&lt;">>;
581584 escape_char($>) -> <<"&gt;">>;
582585 escape_char($&) -> <<"&amp;">>;
629632 end.
630633
631634 %% @doc find the value of the specified key from {@link data/0}
632 -spec find_data(data_key(), data()) -> {ok, Value ::term()} | error.
635 -spec find_data(data_key(), data() | term()) -> {ok, Value ::term()} | error.
633636 -ifdef(namespaced_types).
634637 find_data(Key, Map) when is_map(Map) ->
635638 maps:find(Key, Map);