| CODENOTIFIER | HelpYou are not signed inSign in |
Project: erlyweb
Revision: 215
Author: yarivvv
Date: 01 Dec 2007 22:24:03
Changes:added erlyweb:out/2, allowing the embedding of erlyweb renderings in erlyweb components
Files:| ... | ...@@ -366,8 +366,8 @@ | |
| 366 | 366 | {ok, ignore}; |
| 367 | 367 | compile_file(FileName, BaseName, Extension, Type, |
| 368 | 368 | LastCompileTimeInSeconds, Options, IncludePaths) -> |
| 369 | %%?Debug("Filename: ~p~nBaseName: ~p~nExtension: ~p~nType: ~p~n" ++ | |
| 370 | %% "LastCompileTimeInSeconds: ~p~nOptions: ~p~nIncludePaths: ~p~n", | |
| 369 | %% ?Debug("Filename: ~p~nBaseName: ~p~nExtension: ~p~nType: ~p~n" ++ | |
| 370 | %% "LastCompileTimeInSeconds: ~p~nOptions: ~p~nIncludePaths: ~p~n", | |
| 371 | 371 | %% [FileName, BaseName, Extension, Type, |
| 372 | 372 | %% LastCompileTimeInSeconds, Options, IncludePaths]), |
| 373 | 373 | case should_compile(FileName,BaseName,LastCompileTimeInSeconds) of |
| ... | ...@@ -19,6 +19,7 @@ | |
| 19 | 19 | compile/1, |
| 20 | 20 | compile/2, |
| 21 | 21 | out/1, |
| 22 | out/2, | |
| 22 | 23 | get_initial_ewc/1, |
| 23 | 24 | get_ewc/1, |
| 24 | 25 | get_app_name/1, |
| ... | ...@@ -33,6 +34,7 @@ | |
| 33 | 34 | -define(Debug(Msg, Params), log(?MODULE, ?LINE, debug, Msg, Params)). |
| 34 | 35 | -define(Info(Msg, Params), log(?MODULE, ?LINE, info, Msg, Params)). |
| 35 | 36 | -define(Error(Msg, Params), log(?MODULE, ?LINE, error, Msg, Params)). |
| 37 | -define(Warn(Msg, Params), log(?MODULE, ?LINE, warn, Msg, Params)). | |
| 36 | 38 | |
| 37 | 39 | -define(L(Msg), io:format("~b ~p~n", [?LINE, Msg])). |
| 38 | 40 | |
| ... | ...@@ -148,25 +150,43 @@ | |
| 148 | 150 | out(A) -> |
| 149 | 151 | AppName = get_app_name(A), |
| 150 | 152 | AppData = erlyweb_compile:get_app_data_module(AppName), |
| 151 | case catch AppData:get_controller() of | |
| 152 | {'EXIT', {undef, _}} -> | |
| 153 | exit({no_application_data, | |
| 154 | "Did you forget to call erlyweb:compile(AppDir) or " | |
| 155 | "add the app's previously compiled .beam files to the " | |
| 156 | "Erlang code path?"}); | |
| 157 | AppController -> | |
| 158 | case AppData:auto_compile() of | |
| 159 | false -> ok; | |
| 160 | {true, Options} -> | |
| 161 | auto_compile(A, AppData, Options) | |
| 162 | end, | |
| 163 | A1 = yaws_arg:opaque(A, | |
| 164 | [{app_data_module, AppData} | | |
| 165 | yaws_arg:opaque(A)]), | |
| 166 | handle_request(A1, | |
| 167 | AppController, AppController:hook(A1), | |
| 168 | AppData) | |
| 169 | end. | |
| 153 | AppController = | |
| 154 | case catch AppData:get_controller() of | |
| 155 | {'EXIT', {undef, _}} -> | |
| 156 | exit({no_application_data, | |
| 157 | "Did you forget to call erlyweb:compile(AppDir) " | |
| 158 | "or add the app's previously compiled .beam " | |
| 159 | "files to the Erlang code path?"}); | |
| 160 | Other1 -> | |
| 161 | Other1 | |
| 162 | end, | |
| 163 | case AppData:auto_compile() of | |
| 164 | false -> ok; | |
| 165 | {true, Options} -> | |
| 166 | auto_compile(A, AppData, Options) | |
| 167 | end, | |
| 168 | ||
| 169 | out(yaws_arg:add_to_opaque( | |
| 170 | A, {app_data_module, AppData}), AppController). | |
| 171 | ||
| 172 | %% @doc This function is useful for embedding the result of a 'phased' | |
| 173 | %% ErlyWeb rendering in an ErlyWeb component from the same application, | |
| 174 | %% but using a different app controller. | |
| 175 | %% | |
| 176 | %% This function was originally designed to simplify Facebook app development | |
| 177 | %% with ErlyWeb using Erlang2Facebook | |
| 178 | %% (http://code.google.com/p/erlang2facebook). | |
| 179 | %% In erlang2facebook, the fb_canvas component intercepts requests | |
| 180 | %% from Facebook and authenticates them. After authentication, it may be | |
| 181 | %% useful to start a new ErlyWeb "flow" using an alternative app controller | |
| 182 | %% and display the result in of this flow the output of fb_canvas. | |
| 183 | %% | |
| 184 | %% @spec out(A::arg(), AppController::atom()) -> term() | |
| 185 | out(A, AppController) -> | |
| 186 | AppData = proplists:get_value(app_data_module, yaws_arg:opaque(A)), | |
| 187 | handle_request(A, | |
| 188 | AppController, AppController:hook(A), | |
| 189 | AppData). | |
| 170 | 190 | |
| 171 | 191 | %% checks that at least 3 seconds have passed since the last compilation |
| 172 | 192 | %% and that the request doesn't match the optional auto_compile_exclude |
| ... | ...@@ -441,10 +461,10 @@ | |
| 441 | 461 | Rendered; |
| 442 | 462 | {response, Other} -> |
| 443 | 463 | exit({invalid_response, Other, |
| 444 | "Response values other than 'data' and " | |
| 445 | "'ewc' tuples must be enclosed a 'response' tuple. " | |
| 446 | "In addition, subcomponents may only return " | |
| 447 | "'data' and/or 'ewc' tuples."}) | |
| 464 | "Response values other than 'data' and " | |
| 465 | "'ewc' tuples must be enclosed a 'response' tuple. " | |
| 466 | "In addition, subcomponents may only return " | |
| 467 | "'data' and/or 'ewc' tuples."}) | |
| 448 | 468 | end. |
| 449 | 469 | |
| 450 | 470 | get_ewc(A) -> |