Erlang/OTP Forums

Author Message

<  Erlyweb mailing list  ~  patch: erlyweb_util:create_component extra {private, on/off}

Guest
Posted: Fri Jul 25, 2008 7:45 pm Reply with quote
Guest
Aloha,

I added a {private, on/off}-tuple to the Options of
erlyweb_util:create_component function, because I got tired of typing:
...
private () -> true. %% in <component>-controller.erl
...
for n components which must be hidden from url access.

The private/0 doesn't have to be exported to be effective. I
double-triple-quadruple-umpteenth-fold checked this.

Together with my last erlyweb:create_components patch, it's possible to
generate multiple (private) components using this syntax:

<code>
...
Components = [entry, category, tag, usr],
Options = [{private,on},{magic,on},{erltl,on},{model,on}],
erlyweb:create_components(Components, "/projectX", Options).
...
%% Or using the traditional method
...
Component = "blag",
Options = [{private,off},{model,off}],
%% {private,off} is the default value
erlyweb:create_component(Component, "/projectX", Options).
...
</code>

Once again, I declare that this code is welcome to anyone who might find
it useful. Yariv, you're welcome to incorporate it to the next
(sub-)version. I do hope someone finds it useful except me Razz.

I am eternally grateful for your efforts to proselytize the benefits of
erlang with relation to fault-resistent, scalable, concurrent
web-development (i.e. erlyweb). Oh, and of course, coding erlyweb Razz.

==patch starts here==
--- erlyweb_util.erl.bak 2008-07-25 20:24:14.000000000 +0200
+++ erlyweb_util.erl 2008-07-25 21:08:38.000000000 +0200
@@ -164,12 +164,15 @@
magic_declaration("", _) ->
"";
magic_declaration(MagicStr, controller) ->
- "-erlyweb_magic(" ++ MagicStr ++"_controller).";
+ "-erlyweb_magic(" ++ MagicStr ++"_controller).\n";
magic_declaration(MagicStr, {erltl, off}) ->
"-erlyweb_magic(" ++ MagicStr ++"_view).";
magic_declaration(MagicStr, {erltl, on}) ->
"<%~ -erlyweb_magic(" ++ MagicStr ++ "_view). %>".

+private_declaration(on) -> "\nprivate() -> true.";
+private_declaration(off) -> "".
+
view_declaration(ComponentName, {ertl, off}) ->
"-module(" ++ ComponentName ++ "_view).\n";
view_declaration(_ComponentName, {ertl, on}) ->
@@ -187,9 +190,10 @@

%% @hidden
create_component(ComponentName, AppDir, Options) ->
- {Magic, Model, Erltl} = {proplists:get_value(magic, Options, on),
+ {Magic, Model, Erltl, Private} = {proplists:get_value(magic,
Options, on),
proplists:get_value(model, Options, on),
- proplists:get_value(erltl, Options, off)},
+ proplists:get_value(erltl, Options, off),
+ proplists:get_value(private, Options, off)},

if (Magic == on) andalso (Model == off) ->
exit({bad_options, "Can't have magic without a model."});
@@ -216,7 +220,8 @@
"-module(" ++ ComponentName ++ ")."},
{ComponentName ++ "_controller.erl",
"-module(" ++ ComponentName ++
"_controller).\n" ++
- magic_declaration(MagicStr, controller)},
+ magic_declaration(MagicStr, controller) ++
+ private_declaration(Private)},
{view_filename(ComponentName, {ertl, Erltl}),
view_declaration(ComponentName, {ertl,
Erltl}) ++
magic_declaration(MagicStr, {erltl, Erltl})}]),
==patch ends here

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---



Post received from mailinglist
Guest
Posted: Mon Jul 28, 2008 5:40 pm Reply with quote
Guest
This is cool, thanks. I'll integrate it to the next version. I think
it would be more consistent with Erlang conventions to require that
private/0 be exported, though. Do you really hate having to export it?

On Fri, Jul 25, 2008 at 12:45 PM, Buggaboo <buggasnoo@gmail.com> wrote:
> Aloha,
>
> I added a {private, on/off}-tuple to the Options of
> erlyweb_util:create_component function, because I got tired of typing:
> ...
> private () -> true. %% in <component>-controller.erl
> ...
> for n components which must be hidden from url access.
>
> The private/0 doesn't have to be exported to be effective. I
> double-triple-quadruple-umpteenth-fold checked this.
>
> Together with my last erlyweb:create_components patch, it's possible to
> generate multiple (private) components using this syntax:
>
> <code>
> ...
> Components = [entry, category, tag, usr],
> Options = [{private,on},{magic,on},{erltl,on},{model,on}],
> erlyweb:create_components(Components, "/projectX", Options).
> ...
> %% Or using the traditional method
> ...
> Component = "blag",
> Options = [{private,off},{model,off}],
> %% {private,off} is the default value
> erlyweb:create_component(Component, "/projectX", Options).
> ...
> </code>
>
> Once again, I declare that this code is welcome to anyone who might find
> it useful. Yariv, you're welcome to incorporate it to the next
> (sub-)version. I do hope someone finds it useful except me Razz.
>
> I am eternally grateful for your efforts to proselytize the benefits of
> erlang with relation to fault-resistent, scalable, concurrent
> web-development (i.e. erlyweb). Oh, and of course, coding erlyweb Razz.
>
> ==patch starts here==
> --- erlyweb_util.erl.bak 2008-07-25 20:24:14.000000000 +0200
> +++ erlyweb_util.erl 2008-07-25 21:08:38.000000000 +0200
> @@ -164,12 +164,15 @@
> magic_declaration("", _) ->
> "";
> magic_declaration(MagicStr, controller) ->
> - "-erlyweb_magic(" ++ MagicStr ++"_controller).";
> + "-erlyweb_magic(" ++ MagicStr ++"_controller).\n";
> magic_declaration(MagicStr, {erltl, off}) ->
> "-erlyweb_magic(" ++ MagicStr ++"_view).";
> magic_declaration(MagicStr, {erltl, on}) ->
> "<%~ -erlyweb_magic(" ++ MagicStr ++ "_view). %>".
>
> +private_declaration(on) -> "\nprivate() -> true.";
> +private_declaration(off) -> "".
> +
> view_declaration(ComponentName, {ertl, off}) ->
> "-module(" ++ ComponentName ++ "_view).\n";
> view_declaration(_ComponentName, {ertl, on}) ->
> @@ -187,9 +190,10 @@
>
> %% @hidden
> create_component(ComponentName, AppDir, Options) ->
> - {Magic, Model, Erltl} = {proplists:get_value(magic, Options, on),
> + {Magic, Model, Erltl, Private} = {proplists:get_value(magic,
> Options, on),
> proplists:get_value(model, Options, on),
> - proplists:get_value(erltl, Options, off)},
> + proplists:get_value(erltl, Options, off),
> + proplists:get_value(private, Options, off)},
>
> if (Magic == on) andalso (Model == off) ->
> exit({bad_options, "Can't have magic without a model."});
> @@ -216,7 +220,8 @@
> "-module(" ++ ComponentName ++ ")."},
> {ComponentName ++ "_controller.erl",
> "-module(" ++ ComponentName ++
> "_controller).\n" ++
> - magic_declaration(MagicStr, controller)},
> + magic_declaration(MagicStr, controller) ++
> + private_declaration(Private)},
> {view_filename(ComponentName, {ertl, Erltl}),
> view_declaration(ComponentName, {ertl,
> Erltl}) ++
> magic_declaration(MagicStr, {erltl, Erltl})}]),
> ==patch ends here
>
> >
>
> --- erlyweb.erl.bak 2008-07-25 15:51:01.000000000 +0200
> +++ erlyweb.erl 2008-07-25 17:26:51.000000000 +0200
> @@ -16,6 +16,8 @@
> create_app/2,
> create_component/2,
> create_component/3,
> + create_components/3,
> + create_components/2,
> compile/1,
> compile/2,
> out/1,
> @@ -88,6 +90,29 @@
> Other -> Other
> end.
>
> +%% @doc Create all files like the singular create_component/3 function
> +%% but make multiple.
> +%% @spec create_components
> +%% ( Components::[ atom() | string() ]
> +%% , AppDir::string()
> +%% , Options::[option()])
> +%% ->
> +%% [ ok | {error, Err}]
> +create_components (Components, AppDir, Options) ->
> + F = fun (C) ->
> + if
> + is_atom(C) -> atom_to_list(C);
> + true -> C
> + end
> + end,
> + [ create_component(F(Component), AppDir, Options) || Component <- Components ].
> +
> +%% @doc Create all files like the singular create_component/2 function
> +%% @equiv create_components (Components, AppDir, [{magic, on}, {model, on}, {erltl, off}])
> +create_components (Components, AppDir) ->
> + Options = [{magic, on}, {model, on}, {erltl, off}],
> + create_components (Components, AppDir, Options).
> +
> %% @doc Compile all the files for an application. Files with the '.et'
> %% extension are compiled with ErlTL.
> %%
>
> --- erlyweb_util.erl.bak 2008-07-25 20:24:14.000000000 +0200
> +++ erlyweb_util.erl 2008-07-25 21:08:38.000000000 +0200
> @@ -164,12 +164,15 @@
> magic_declaration("", _) ->
> "";
> magic_declaration(MagicStr, controller) ->
> - "-erlyweb_magic(" ++ MagicStr ++"_controller).";
> + "-erlyweb_magic(" ++ MagicStr ++"_controller).\n";
> magic_declaration(MagicStr, {erltl, off}) ->
> "-erlyweb_magic(" ++ MagicStr ++"_view).";
> magic_declaration(MagicStr, {erltl, on}) ->
> "<%~ -erlyweb_magic(" ++ MagicStr ++ "_view). %>".
>
> +private_declaration(on) -> "\nprivate() -> true.";
> +private_declaration(off) -> "".
> +
> view_declaration(ComponentName, {ertl, off}) ->
> "-module(" ++ ComponentName ++ "_view).\n";
> view_declaration(_ComponentName, {ertl, on}) ->
> @@ -187,9 +190,10 @@
>
> %% @hidden
> create_component(ComponentName, AppDir, Options) ->
> - {Magic, Model, Erltl} = {proplists:get_value(magic, Options, on),
> + {Magic, Model, Erltl, Private} = {proplists:get_value(magic, Options, on),
> proplists:get_value(model, Options, on),
> - proplists:get_value(erltl, Options, off)},
> + proplists:get_value(erltl, Options, off),
> + proplists:get_value(private, Options, off)},
>
> if (Magic == on) andalso (Model == off) ->
> exit({bad_options, "Can't have magic without a model."});
> @@ -216,7 +220,8 @@
> "-module(" ++ ComponentName ++ ")."},
> {ComponentName ++ "_controller.erl",
> "-module(" ++ ComponentName ++ "_controller).\n" ++
> - magic_declaration(MagicStr, controller)},
> + magic_declaration(MagicStr, controller) ++
> + private_declaration(Private)},
> {view_filename(ComponentName, {ertl, Erltl}),
> view_declaration(ComponentName, {ertl, Erltl}) ++
> magic_declaration(MagicStr, {erltl, Erltl})}]),
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
Guest
Posted: Tue Jul 29, 2008 8:01 am Reply with quote
Guest
I don't hate exporting stuff. At that time while hacking that feature,
the feature worked without exporting the function private/0. I also
thought that an erlang programmer only exports stuff that other
modules will use, I thought that private/0 was called privately (I
guessed, I haven't actually looked into the code) within the module
(hence no need to export). So I thought it wasn't necessary to code
the extra -export([private/0]) bit.

I did not know whether the magic property adds any functions
dynamically to the component_controller. I know that the model
receives a bunch of handy crud functions. That's the 2nd reason why I
was hesitant to add an export expression.
I just looked at the code, and I doubt it does, unless I overlooked
something.

line 14 of my previous private.patch, should be replaced with the
following:

+private_declaration(on) -> "-export([private/0]).\n\nprivate() ->
true.";

Thanks for your reply.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
timrila
Posted: Tue Jun 12, 2012 9:32 am Reply with quote
User Joined: 28 Mar 2012 Posts: 32
Excellent post.thanks for the sharing, that greatly helped me.Good articles should share to every person ,hope you can write more and more good articles.
Custom Soccer Jerseys
England Soccer Jersey
France Soccer Jersey
Real Madrid Jersey
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum