Skip to content
Browse files

Adding some EDoc, and getting rid of a Make-time warning

git-svn-id: http://erlydtl.googlecode.com/svn/trunk@164 a5195066-8e3e-0410-a82a-05b01b1b9875
  • Loading branch information...
1 parent 8f3835d commit 20cf7fd43308b4af8e4f38bee8d2dfb36b621e45 emmiller committed Sep 29, 2009
Showing with 29 additions and 7 deletions.
  1. +1 −1 Makefile
  2. +2 −0 src/erlydtl/erlydtl.erl
  3. +26 −6 src/erlydtl/erlydtl_filters.erl
View
2 Makefile
@@ -8,7 +8,7 @@ all: $(PARSER).erl ebin/$(APP)
$(ERL) -make
ebin/$(APP): src/erlydtl/$(APP)
- -mkdir ebin
+ -mkdir -p ebin
cp $< $@
$(PARSER).erl: $(PARSER).yrl
View
2 src/erlydtl/erlydtl.erl
@@ -38,8 +38,10 @@
%% API
-export([compile/2, compile/3]).
+%% @spec compile( FileOrBinary, Module::atom() ) -> ok | {error, Reason}
compile(FileOrBinary, Module) ->
erlydtl_compiler:compile(FileOrBinary, Module).
+%% @spec compile( FileOrBinary, Module::atom(), Options ) -> ok | {error, Reason}
compile(FileOrBinary, Module, Options) ->
erlydtl_compiler:compile(FileOrBinary, Module, Options).
View
32 src/erlydtl/erlydtl_filters.erl
@@ -35,14 +35,18 @@
-author('rsaccon@gmail.com').
-author('emmiller@gmail.com').
--compile(export_all).
+-export([add/2, capfirst/1, center/2, date/2, escapejs/1, first/1]).
+-export([fix_ampersands/1, force_escape/1, format_integer/1, format_number/1]).
+-export([join/2, last/1, length/1, length_is/2, linebreaksbr/1, ljust/2]).
+-export([lower/1, rjust/2, upper/1, urlencode/1]).
-define(NO_ENCODE(C), ((C >= $a andalso C =< $z) orelse
- (C >= $A andalso C =< $Z) orelse
- (C >= $0 andalso C =< $9) orelse
- (C =:= $\. orelse C =:= $-
- orelse C =:= $~ orelse C =:= $_))).
+ (C >= $A andalso C =< $Z) orelse
+ (C >= $0 andalso C =< $9) orelse
+ (C =:= $\. orelse C =:= $-
+ orelse C =:= $~ orelse C =:= $_))).
+%% @doc Adds a number to the value.
add([Input], Number) when is_list(Input) or is_binary(Input) ->
add(Input, Number);
add(Input, Number) when is_binary(Input) ->
@@ -52,20 +56,23 @@ add(Input, Number) when is_list(Input) ->
add(Input, Number) when is_integer(Input) ->
Input + Number.
+%% @doc Capitalizes the first character of the value.
capfirst([Input]) when is_list(Input) or is_binary (Input) ->
capfirst(Input);
capfirst([H|T]) when H >= $a andalso H =< $z ->
[H + $A - $a | T];
capfirst(<<Byte:8/integer, Binary/binary>>) when Byte >= $a andalso Byte =< $z ->
[<<(Byte + $A - $a)>>, Binary].
+%% @doc Centers the value in a field of a given width.
center([Input], Number) when is_list(Input) or is_binary(Input) ->
center(Input, Number);
center(Input, Number) when is_binary(Input) ->
list_to_binary(center(binary_to_list(Input), Number));
center(Input, Number) when is_list(Input) ->
string:centre(Input, Number).
+%% @doc Formats a date according to the given format.
date([Input], FormatStr) when is_list(Input) or is_binary(Input) ->
date(Input, FormatStr);
date(Input, FormatStr) when is_binary(Input) ->
@@ -78,28 +85,31 @@ date(Input, _FormatStr) when is_list(Input) ->
io:format("Unexpected date parameter : ~p~n", [Input]),
"".
-
+%% @doc Escapes characters for use in JavaScript strings.
escapejs([Input]) when is_list(Input) or is_binary(Input) ->
escapejs(Input);
escapejs(Input) when is_binary(Input) ->
escapejs(Input, 0);
escapejs(Input) when is_list(Input) ->
escapejs(Input, []).
+%% @doc Returns the first item in a list.
first([Input]) when is_list(Input) or is_binary(Input) ->
first(Input);
first([First|_Rest]) ->
[First];
first(<<First, _/binary>>) ->
<<First>>.
+%% @doc Replaces ampersands with &amp; entities.
fix_ampersands([Input]) when is_list(Input) or is_binary(Input) ->
fix_ampersands(Input);
fix_ampersands(Input) when is_binary(Input) ->
fix_ampersands(Input, 0);
fix_ampersands(Input) when is_list(Input) ->
fix_ampersands(Input, []).
+%% @doc Applies HTML escaping to a string.
force_escape([Input]) when is_list(Input) or is_binary(Input) ->
force_escape(Input);
force_escape(Input) when is_list(Input) ->
@@ -121,9 +131,11 @@ format_number(Input) when is_function(Input, 0) ->
format_number(Input) ->
Input.
+%% @doc Joins a list with a given separator.
join([Input], Separator) when is_list(Input) ->
join_io(Input, Separator).
+%% @doc Returns the last item in a list.
last([Input]) when is_list(Input) or is_binary(Input) ->
last(Input);
last(Input) when is_binary(Input) ->
@@ -137,52 +149,60 @@ last(Input) when is_binary(Input) ->
last(Input) when is_list(Input) ->
[lists:last(Input)].
+%% @doc Returns the length of the value.
length([]) -> "0";
length([Input]) when is_list(Input) ->
integer_to_list(erlang:length(Input));
length([Input]) when is_binary(Input) ->
integer_to_list(size(Input)).
+%% @doc Returns True iff the value's length is the argument.
length_is(Input, Number) when is_list(Input), is_integer(Number) ->
length_is(Input, integer_to_list(Number));
length_is(Input, Number) when is_list(Input), is_list(Number) ->
?MODULE:length(Input) =:= Number.
+%% @doc Converts all newlines to HTML line breaks.
linebreaksbr([Input]) when is_list(Input) or is_binary(Input) ->
linebreaksbr(Input);
linebreaksbr(Input) when is_binary(Input) ->
linebreaksbr(Input, 0);
linebreaksbr(Input) ->
linebreaksbr(Input, []).
+%% @doc Left-aligns the value in a field of a given width.
ljust([Input], Number) when is_list(Input) or is_binary(Input) ->
ljust(Input, Number);
ljust(Input, Number) when is_binary(Input) ->
list_to_binary(ljust(binary_to_list(Input), Number));
ljust(Input, Number) when is_list(Input) ->
string:left(Input, Number).
+%% @doc Converts a string into all lowercase.
lower([Input]) when is_list(Input) or is_binary(Input) ->
lower(Input);
lower(Input) when is_binary(Input) ->
lower(Input, 0);
lower(Input) ->
string:to_lower(Input).
+%% @doc Right-aligns the value in a field of a given width.
rjust([Input], Number) when is_list(Input) or is_binary(Input) ->
rjust(Input, Number);
rjust(Input, Number) when is_binary(Input) ->
list_to_binary(rjust(binary_to_list(Input), Number));
rjust(Input, Number) ->
string:right(Input, Number).
+%% @doc Converts a string into all uppercase.
upper([Input]) when is_list(Input) or is_binary(Input) ->
upper(Input);
upper(Input) when is_binary(Input) ->
list_to_binary(upper(binary_to_list(Input)));
upper(Input) ->
string:to_upper(Input).
+%% @doc Escapes a value for use in a URL.
urlencode([Input]) when is_list(Input) or is_binary(Input) ->
urlencode(Input);
urlencode(Input) when is_binary(Input) ->

0 comments on commit 20cf7fd

Please sign in to comment.
Something went wrong with that request. Please try again.