Module z_utils

Misc utility functions for zotonic.

Copyright 2009-2012 Marc Worrell Parts are from wf_utils.erl which is Copyright (c) 2008-2009 Rusty Klophaus

Authors: Marc Worrell.

Description

Misc utility functions for zotonic

Function Index

are_equal/2Check if two arguments are equal, optionally converting them.
assert/2Check if an assertion is ok or failed.
checksum/2
checksum_assert/3
coalesce/1
combine/2
combine_defined/2
decode_value/2
decode_value_expire/2
depickle/2
encode_value/2
encode_value_expire/3
ensure_existing_module/1Ensure that the given string matches an existing module.
erase_process_dict/0Safe erase of process dict, keeps some 'magical' proc_lib vars.
f/1
f/2
flush_message/1Flush all incoming messages, used when receiving timer ticks to prevent multiple ticks.
generate_username/2Generate a unique user name from a proplist.
get_nth/2
get_seconds/0Return the current universal time in seconds.
group_by/3Group by a property or m_rsc property, keeps the input list in the same order.
group_proplists/2Given a list of proplists, make it a nested list with respect to a property, combining elements with the same property.
hex_decode/1
hex_encode/1
index_proplist/2Make a property list based on the value of a property For example: [ [{a,b}], [{a,c}] ] gives [{a, [{a,b}]}, {c, [[{a,c}]]}].
is_empty/1Check if a value is 'empty'.
is_iolist/1
is_process_alive/1Multinode is_process_alive check.
is_proplist/1
is_true/1Check if the parameter could represent the logical value of "true".
js_array/1
js_escape/1
js_escape/2Javascript escape, see also: http://code.google.com/p/doctype/wiki/ArticleXSSInJavaScript.
js_object/1Create a javascript object from a proplist.
js_object/2
js_object/3
json_escape/1Deprecated: moved to z_json.
lib_dir/0Return an abspath to a directory relative to the application root.
lib_dir/1
list_dir_recursive/1Return a list of all files in a directory, recursive depth first search for files not starting with a '.'.
name_for_host/2Return the name used in the context of a hostname.
nested_proplist/1Scan the props of a proplist, when the prop is a list with a $.
nested_proplist/2
now/0Return the current tick count.
now_msec/0
only_digits/1
only_letters/1
os_escape/1Simple escape function for command line arguments.
os_filename/1Simple escape function for filenames as commandline arguments.
percent_encode/1
pickle/2
prefix/2
prop_delete/2
prop_replace/3Replace a property in a proplist.
props_merge/2
randomize/1Simple randomize of a list.
randomize/2
replace1/3
set_nth/3
split/2
split_in/2
url_decode/1
url_encode/1
url_path_encode/1
url_reserved_char/1
url_unreserved_char/1
url_valid_char/1
vsplit_in/2

Function Details

are_equal/2

are_equal(Arg1, Arg2) -> any()

Check if two arguments are equal, optionally converting them

assert/2

assert(X1::bool(), Error::error) -> none()

Check if an assertion is ok or failed

checksum/2

checksum(Data, Context) -> any()

checksum_assert/3

checksum_assert(Data, Checksum, Context) -> any()

coalesce/1

coalesce(T) -> any()

combine/2

combine(Sep, T) -> any()

combine_defined/2

combine_defined(Sep, List) -> any()

decode_value/2

decode_value(Data, Context) -> any()

decode_value_expire/2

decode_value_expire(Data, Context) -> any()

depickle/2

depickle(Data, Context) -> any()

encode_value/2

encode_value(Value, Context) -> any()

encode_value_expire/3

encode_value_expire(Value, Date, Context) -> any()

ensure_existing_module/1

ensure_existing_module(ModuleName) -> any()

Ensure that the given string matches an existing module. Used to prevent a denial of service attack where we exhaust the atom space.

erase_process_dict/0

erase_process_dict() -> any()

Safe erase of process dict, keeps some 'magical' proc_lib vars

f/1

f(S) -> any()

f/2

f(S, Args) -> any()

flush_message/1

flush_message(Msg) -> any()

Flush all incoming messages, used when receiving timer ticks to prevent multiple ticks.

generate_username/2

generate_username(Props, Context) -> any()

Generate a unique user name from a proplist.

get_nth/2

get_nth(N, L) -> any()

get_seconds/0

get_seconds() -> any()

Return the current universal time in seconds

group_by/3

group_by(L, Prop, Context) -> any()

Group by a property or m_rsc property, keeps the input list in the same order.

group_proplists/2

group_proplists(Prop::Property, Rest::[PropList]) -> PropList

Given a list of proplists, make it a nested list with respect to a property, combining elements with the same property. Assumes the list is sorted on the property you are splitting on For example: [[{a,b}{x}], [{a,b}{z}], [{a,c}{y}]] gives: [ {b, [[{a,b}{x}], [{a,b}{z}]]}, {c, [[{a,c}{y}]]} ]

hex_decode/1

hex_decode(Value) -> any()

hex_encode/1

hex_encode(Value) -> any()

index_proplist/2

index_proplist(Prop::Property, List::[PropList]) -> PropList

Make a property list based on the value of a property For example: [ [{a,b}], [{a,c}] ] gives [{a, [{a,b}]}, {c, [[{a,c}]]}]

is_empty/1

is_empty(X1) -> any()

Check if a value is 'empty'

is_iolist/1

is_iolist(C) -> any()

is_process_alive/1

is_process_alive(Pid) -> any()

Multinode is_process_alive check

is_proplist/1

is_proplist(R) -> any()

is_true/1

is_true(T) -> any()

Check if the parameter could represent the logical value of "true"

js_array/1

js_array(L) -> any()

js_escape/1

js_escape(V) -> any()

js_escape/2

js_escape(Tr, Context) -> any()

Javascript escape, see also: http://code.google.com/p/doctype/wiki/ArticleXSSInJavaScript

js_object/1

js_object(L) -> any()

Create a javascript object from a proplist

js_object/2

js_object(L, OptContext) -> any()

js_object/3

js_object(L, T, Context) -> any()

json_escape/1

json_escape(A) -> any()

Deprecated: moved to z_json.

lib_dir/0

lib_dir() -> any()

Return an abspath to a directory relative to the application root.

lib_dir/1

lib_dir(Dir) -> any()

list_dir_recursive/1

list_dir_recursive(Dir) -> any()

Return a list of all files in a directory, recursive depth first search for files not starting with a '.'

name_for_host/2

name_for_host(Name::atom(), Context::atom() | #context{}) -> atom()

Return the name used in the context of a hostname

nested_proplist/1

nested_proplist(Props) -> any()

Scan the props of a proplist, when the prop is a list with a $. characters in it then split the prop.

nested_proplist/2

nested_proplist(T, Acc) -> any()

now/0

now() -> any()

Return the current tick count

now_msec/0

now_msec() -> any()

only_digits/1

only_digits(L) -> any()

only_letters/1

only_letters(T) -> any()

os_escape/1

os_escape(A::String) -> String

Simple escape function for command line arguments

os_filename/1

os_filename(A::String) -> String

Simple escape function for filenames as commandline arguments. foo/"bar.jpg -> "foo/\"bar.jpg"; on windows "foo\\\"bar.jpg" (both including quotes!)

percent_encode/1

percent_encode(S) -> any()

pickle/2

pickle(Data, Context) -> any()

prefix/2

prefix(Sep, List) -> any()

prop_delete/2

prop_delete(Prop, List) -> any()

prop_replace/3

prop_replace(Prop, Value, List) -> any()

Replace a property in a proplist

props_merge/2

props_merge(Ps, Xs) -> any()

randomize/1

randomize(List) -> any()

Simple randomize of a list. Not good quality, but good enough for us

randomize/2

randomize(N, List) -> any()

replace1/3

replace1(F, T, L) -> any()

set_nth/3

set_nth(N, V, L) -> any()

split/2

split(N, L) -> any()

split_in/2

split_in(L, N) -> any()

url_decode/1

url_decode(S) -> any()

url_encode/1

url_encode(S) -> any()

url_path_encode/1

url_path_encode(L) -> any()

url_reserved_char/1

url_reserved_char(C) -> any()

url_unreserved_char/1

url_unreserved_char(C) -> any()

url_valid_char/1

url_valid_char(C) -> any()

vsplit_in/2

vsplit_in(L, N) -> any()


Generated by EDoc, Jul 10 2014, 12:31:49.