51 | 51 |
-define(RAISE_ON_PARTIAL_MISS_ENABLED(Options),
|
52 | 52 |
proplists:get_bool(raise_on_partial_miss, Options)).
|
53 | 53 |
|
|
54 |
-define(PARSE_OPTIONS, [raise_on_partial_miss]).
|
|
55 |
|
54 | 56 |
-type key() :: binary().
|
55 | 57 |
%% Key MUST be a non-whitespace character sequence NOT containing the current closing delimiter. <br />
|
56 | 58 |
%%
|
|
158 | 160 |
%% @equiv compile(parse_binary(Bin), Data, Options)
|
159 | 161 |
-spec render(binary(), data(), [render_option()]) -> binary().
|
160 | 162 |
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).
|
162 | 165 |
|
163 | 166 |
%% @equiv parse_binary(Bin, [])
|
164 | 167 |
-spec parse_binary(binary()) -> template().
|
|
422 | 425 |
%% 3> split_tag(State, <<"...">>)
|
423 | 426 |
%% [<<"...">>]
|
424 | 427 |
%% '''
|
425 | |
-spec split_tag(state(), binary()) -> [binary()].
|
|
428 |
-spec split_tag(state(), binary()) -> [binary(), ...].
|
426 | 429 |
split_tag(#state{start = StartDelimiter, stop = StopDelimiter}, Bin) ->
|
427 | 430 |
case binary:match(Bin, StartDelimiter) of
|
428 | 431 |
nomatch ->
|
|
481 | 484 |
end.
|
482 | 485 |
|
483 | 486 |
%% @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().
|
485 | 488 |
repeatedly_binary(<<X, Rest/binary>>, X) ->
|
486 | 489 |
repeatedly_binary(Rest, X);
|
487 | 490 |
repeatedly_binary(<<>>, _) ->
|
|
564 | 567 |
X.
|
565 | 568 |
|
566 | 569 |
%% @doc string or binary to binary
|
567 | |
-spec to_binary(binary() | string()) -> binary().
|
|
570 |
-spec to_binary(binary() | [byte()]) -> binary().
|
568 | 571 |
to_binary(Bin) when is_binary(Bin) ->
|
569 | 572 |
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).
|
572 | 575 |
|
573 | 576 |
%% @doc HTML Escape
|
574 | 577 |
-spec escape(binary()) -> binary().
|
|
576 | 579 |
<< <<(escape_char(X))/binary>> || <<X:8>> <= Bin >>.
|
577 | 580 |
|
578 | 581 |
%% @doc escape a character if needed.
|
579 | |
-spec escape_char(0..16#FFFF) -> binary().
|
|
582 |
-spec escape_char(byte()) -> <<_:8, _:_*8>>.
|
580 | 583 |
escape_char($<) -> <<"<">>;
|
581 | 584 |
escape_char($>) -> <<">">>;
|
582 | 585 |
escape_char($&) -> <<"&">>;
|
|
629 | 632 |
end.
|
630 | 633 |
|
631 | 634 |
%% @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.
|
633 | 636 |
-ifdef(namespaced_types).
|
634 | 637 |
find_data(Key, Map) when is_map(Map) ->
|
635 | 638 |
maps:find(Key, Map);
|