Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

replace wf:short_if with ?WF_IF

  • Loading branch information...
commit 2e3bbc5651ee2a3dd41256cae5b2cd9d2d528b6a 1 parent eb1fc66
Jesse Gumm choptastic authored
12 doc/org-mode/api.org
View
@@ -129,18 +129,6 @@
Convert a String to a JS-safe string by adding backslashes to quotes and newlines.
-** wf:short\_if(Bool,IfTrue,IfFalse) -> Term
-
- If =Bool= is =true= return =IfTrue=, otherwise, return =IfFalse=. =IfTrue= and =IfFalse= can be functions arity 1, which will be evaluated instead of returned, and their return value is what gets returned.
-
-#+BEGIN_SRC erlang
- wf:short_if(Name /= "", Name, "Name Not Specified").
-#+END_SRC
-
-** wf:short\_if(Bool,IfTrue) -> Term
-
- If =Bool= is =true=, return =IfTrue=, otherwise return an empty list. Shorthand for =wf:short_if(Bool,IfTrue,"")=
-
** wf:join([Terms],Delimiter) -> [Terms]
Because Erlang doesn't provide a means to join a list in a non-string fashion, this will join the =Terms= on the delimiter, regardless of the type of =Delimiter=.
59 include/wf.hrl
View
@@ -1,3 +1,4 @@
+% vim: sw=4 ts=4 et ft=erlang
-ifndef(wf_inc).
-define(wf_inc, ok).
@@ -5,10 +6,10 @@
% Page Request Information.
-record(page_context, {
- series_id, % A unique ID assigned to the first request which stays constant on repeated requests.
- module, % The requested page module
- path_info, % Any extra info passed with the request
- async_mode= comet % {poll, Interval} or comet
+ series_id, % A unique ID assigned to the first request which stays constant on repeated requests.
+ module, % The requested page module
+ path_info, % Any extra info passed with the request
+ async_mode= comet % {poll, Interval} or comet
}).
% Event Information. A serialized version of this record
@@ -26,27 +27,27 @@
% to allow other frameworks to substitute their own behaviour.
% These are set in wf_context:make_context/1
-record(handler_context, {
- name, % The name of a handler. See wf_context for a list.
- module, % A module that provides the logic for a handler. This can be substituted by your app.
- config, % The config of the handler, set at the beginning of each request.
- state % The state of the handler, serialized and maintained between postbacks in a series.
+ name, % The name of a handler. See wf_context for a list.
+ module, % A module that provides the logic for a handler. This can be substituted by your app.
+ config, % The config of the handler, set at the beginning of each request.
+ state % The state of the handler, serialized and maintained between postbacks in a series.
}).
-record(context, {
- % Transient Information
- type, % Either first_request, postback_request, or static_file
- request_bridge, % Holds the simple_bridge request object
- response_bridge, % Holds the simple_bridge response object
- anchor=undefined, % Holds the unique ID of the current anchor element.
- data=[], % Holds whatever the page_module:main/1 method returns: HTML, Elements, Binary, etc..
- queued_actions=[], % List of actions queued in main/1, event/2, or when rendering elements.
- deferred_actions=[], % List of actions to be rendered after the primary actions
-
- % These are all serialized, sent to the browser
- % and de-serialized on each request.
- page_context,
- event_context,
- handler_list
+ % Transient Information
+ type, % Either first_request, postback_request, or static_file
+ request_bridge, % Holds the simple_bridge request object
+ response_bridge, % Holds the simple_bridge response object
+ anchor=undefined, % Holds the unique ID of the current anchor element.
+ data=[], % Holds whatever the page_module:main/1 method returns: HTML, Elements, Binary, etc..
+ queued_actions=[], % List of actions queued in main/1, event/2, or when rendering elements.
+ deferred_actions=[], % List of actions to be rendered after the primary actions
+
+ % These are all serialized, sent to the browser
+ % and de-serialized on each request.
+ page_context,
+ event_context,
+ handler_list
}).
%%% LOGGING %%%
@@ -58,7 +59,17 @@
-endif.
%%% GUARDS %%%
--define (IS_STRING(Term), (is_list(Term) andalso Term /= [] andalso is_integer(hd(Term)))).
+-define(IS_STRING(Term), (is_list(Term) andalso Term /= [] andalso is_integer(hd(Term)))).
+
+%%% TERNARY IF AND VARIATIONS %%%
+-define(WF_IF(Term,IfTrue,IfFalse),
+ case (Term) of
+ F when F==false;F==undefined;F==[] -> IfFalse;
+ _ -> IfTrue
+ end).
+
+-define(WF_IF(Term,IfTrue), ?WF_IF(Term,IfTrue,"")).
+
%%% FRAMEWORK %%%
@@ -146,7 +157,7 @@
-record(mobile_grid_block, {?ELEMENT_BASE(element_mobile_grid_block), data_fields=[], text="", body=[], new_row=default}).
-
+
%% HTML5 semantic elements
-record(section, {?ELEMENT_BASE(element_section), body=""}).
-record(nav, {?ELEMENT_BASE(element_nav), body=""}).
4 src/elements/forms/element_inplace_textarea.erl
View
@@ -44,7 +44,7 @@ render_element(Record) ->
#panel {
id=ViewPanelID,
class="view",
- style = wf:short_if(StartMode==edit,"diplay:none"),
+ style = ?WF_IF(StartMode==edit,"diplay:none"),
body=[
#span { id=LabelID, class="inplace_textarea", text=Text, html_encode=HTMLEncode, actions=[
#buttonize { target=ViewPanelID }
@@ -62,7 +62,7 @@ render_element(Record) ->
#panel {
id=EditPanelID,
class="edit",
- style = wf:short_if(StartMode==view,"display:none"),
+ style = ?WF_IF(StartMode==view,"display:none"),
body=[
#textarea { id=TextBoxID, text=Text },
#button { id=OKButtonID, text="OK", actions=OKEvent#event { type=click } },
18 src/lib/wf_convert.erl
View
@@ -16,8 +16,7 @@
hex_encode/1, hex_decode/1,
url_encode/1, url_decode/1,
js_escape/1,
- join/2,
- short_if/2,short_if/3
+ join/2
]).
@@ -181,21 +180,6 @@ js_escape(<<"script>", Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, "scr
js_escape(<<C, Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, C>>);
js_escape(<<>>, Acc) -> Acc.
-%%% SHORT IF %%%
-
-short_if(true,IfTrue,_IfFalse) when is_function(IfTrue) ->
- IfTrue();
-short_if(true,IfTrue,_IfFalse) ->
- IfTrue;
-short_if(_,_IfTrue,IfFalse) when is_function(IfFalse) ->
- IfFalse();
-short_if(_,_IfTrue,IfFalse) ->
- IfFalse.
-
-
-short_if(Cond,IfTrue) ->
- short_if(Cond,IfTrue,"").
-
%%% JOIN %%%
%% Erlang doesn't provide a short way to join lists of "things" with other things.
6 src/wf.erl
View
@@ -117,12 +117,6 @@ hex_decode(S) ->
js_escape(String) ->
_String = wf_convert:js_escape(String).
-short_if(Cond,IfTrue) ->
- _String = wf_convert:short_if(Cond,IfTrue).
-
-short_if(Cond,IfTrue,IfFalse) ->
- _String = wf_convert:short_if(Cond,IfTrue,IfFalse).
-
join(List,Delimiter) ->
_Result = wf_convert:join(List,Delimiter).
Please sign in to comment.
Something went wrong with that request. Please try again.