Erlang/OTP Forums

Author Message

<  Erlyweb mailing list  ~  Erlyweb without erlydb?

ketralnis
Posted: Thu Sep 20, 2007 6:26 pm Reply with quote
User Joined: 20 Jul 2007 Posts: 151 Location: San Francisco, CA
I'm trying to write a small project that doesn't have a need for
erlydb. What would it take to to be able to use erlyweb without
having to supply an erlydb driver?

--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
View user's profile Send private message AIM Address
Guest
Posted: Thu Sep 20, 2007 7:01 pm Reply with quote
Guest
Just don't put any model files in src/components (it should contain
only controllers and views) and you won't have to supply an
erlydb_driver option.

On 9/20/07, David King <dking@ketralnis.com> wrote:
>
> I'm trying to write a small project that doesn't have a need for
> erlydb. What would it take to to be able to use erlyweb without
> having to supply an erlydb driver?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Thu Sep 20, 2007 11:01 pm Reply with quote
Guest
Is there any way to call erlyweb:create_component() and have it NOT
create a model file? Somewhat relatedly, is it also possible to choose
whether to create a .et view file, or a .erl one?

-Ghalib

On Sep 20, 11:01 pm, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> Just don't put any model files in src/components (it should contain
> only controllers and views) and you won't have to supply an
> erlydb_driver option.
>
> On 9/20/07, David King <dk...@ketralnis.com> wrote:
>
>
>
> > I'm trying to write a small project that doesn't have a need for
> > erlydb. What would it take to to be able to use erlyweb without
> > having to supply an erlydb driver?


--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Fri Sep 21, 2007 3:35 am Reply with quote
Guest
Currently there is no way of doing it -- you have to create the files
manually. Adding this feature to ErlyWeb would be a good programming
exercise Wink

Yariv

On 9/20/07, Ghalib Suleiman <cowmoo@gmail.com> wrote:
>
> Is there any way to call erlyweb:create_component() and have it NOT
> create a model file? Somewhat relatedly, is it also possible to choose
> whether to create a .et view file, or a .erl one?
>
> -Ghalib
>
> On Sep 20, 11:01 pm, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> > Just don't put any model files in src/components (it should contain
> > only controllers and views) and you won't have to supply an
> > erlydb_driver option.
> >
> > On 9/20/07, David King <dk...@ketralnis.com> wrote:
> >
> >
> >
> > > I'm trying to write a small project that doesn't have a need for
> > > erlydb. What would it take to to be able to use erlyweb without
> > > having to supply an erlydb driver?
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Fri Sep 21, 2007 8:26 pm Reply with quote
Guest
I'll see what I can do Smile

-Ghalib

On Sep 21, 7:35 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> Currently there is no way of doing it -- you have to create the files
> manually. Adding this feature to ErlyWeb would be a good programming
> exercise Wink
>
> Yariv
>


--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Sat Sep 22, 2007 9:28 pm Reply with quote
Guest
Hi Yariv, I'm thinking of using a proplist-based approach. What do you
think? i.e. erlyweb:create_component() would take in a proplist, for
example [{magic, off}, {model, on}, {erltl, on}], the proplist would
be validated and the right files will be created accordingly. Is this
too drastic a change?

-Ghalib


> On Sep 21, 7:35 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
>
> > Currently there is no way of doing it -- you have to create the files
> > manually. Adding this feature to ErlyWeb would be a good programming
> > exercise Wink
>
> > Yariv


--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Sat Sep 22, 2007 9:40 pm Reply with quote
Guest
I think it looks good.

Yariv

On 9/22/07, Ghalib Suleiman <cowmoo@gmail.com> wrote:
>
> Hi Yariv, I'm thinking of using a proplist-based approach. What do you
> think? i.e. erlyweb:create_component() would take in a proplist, for
> example [{magic, off}, {model, on}, {erltl, on}], the proplist would
> be validated and the right files will be created accordingly. Is this
> too drastic a change?
>
> -Ghalib
>
>
> > On Sep 21, 7:35 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> >
> > > Currently there is no way of doing it -- you have to create the files
> > > manually. Adding this feature to ErlyWeb would be a good programming
> > > exercise Wink
> >
> > > Yariv
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Thu Sep 27, 2007 12:06 am Reply with quote
Guest
Hi Yariv, sorry this is dragging, got sidetracked with real life/other
projects.

Anyway, two questions:

1) Should having both {magic, on} and {model, off} be an error?
2) Erltl files don't have magic declarations implicitly right? In
other words, if using Erltl, one should specify <%~ erlyweb_magic(on)
%> if one wants magic?

-Ghalib

On Sep 23, 1:39 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> I think it looks good.
>
> Yariv
>
> On 9/22/07, Ghalib Suleiman <cow...@gmail.com> wrote:
>
>
>
> > Hi Yariv, I'm thinking of using a proplist-based approach. What do you
> > think? i.e. erlyweb:create_component() would take in a proplist, for
> > example [{magic, off}, {model, on}, {erltl, on}], the proplist would
> > be validated and the right files will be created accordingly. Is this
> > too drastic a change?
>
> > -Ghalib
>
> > > On Sep 21, 7:35 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
>
> > > > Currently there is no way of doing it -- you have to create the files
> > > > manually. Adding this feature to ErlyWeb would be a good programming
> > > > exercise Wink
>
> > > > Yariv


--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Thu Sep 27, 2007 1:20 am Reply with quote
Guest
On 9/26/07, Ghalib Suleiman <cowmoo@gmail.com> wrote:
>
> Hi Yariv, sorry this is dragging, got sidetracked with real life/other
> projects.
>
> Anyway, two questions:
>
> 1) Should having both {magic, on} and {model, off} be an error?

Yes, I think so. You can't have a CRUD app without a model, after all.

> 2) Erltl files don't have magic declarations implicitly right? In
> other words, if using Erltl, one should specify <%~ erlyweb_magic(on)
> %> if one wants magic?

That's right. I've never tried using erlyweb_magic in ErlTL, though.
I'm not sure if it would work.

Yariv

>
> -Ghalib
>
> On Sep 23, 1:39 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> > I think it looks good.
> >
> > Yariv
> >
> > On 9/22/07, Ghalib Suleiman <cow...@gmail.com> wrote:
> >
> >
> >
> > > Hi Yariv, I'm thinking of using a proplist-based approach. What do you
> > > think? i.e. erlyweb:create_component() would take in a proplist, for
> > > example [{magic, off}, {model, on}, {erltl, on}], the proplist would
> > > be validated and the right files will be created accordingly. Is this
> > > too drastic a change?
> >
> > > -Ghalib
> >
> > > > On Sep 21, 7:35 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> >
> > > > > Currently there is no way of doing it -- you have to create the files
> > > > > manually. Adding this feature to ErlyWeb would be a good programming
> > > > > exercise Wink
> >
> > > > > Yariv
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Thu Sep 27, 2007 8:33 pm Reply with quote
Guest
So, having <%~ -erlyweb_magic(erlyweb_view) %> in an ertl file and
then compiling, I get an error:

** exited: {error,{parse_error,{999999,
erl_parse,
["syntax error before: ",[]]}}} **

I don't really know how easy this would be fix - any ideas?

On Sep 27, 5:19 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> On 9/26/07, Ghalib Suleiman <cow...@gmail.com> wrote:
>
>
>
> > Hi Yariv, sorry this is dragging, got sidetracked with real life/other
> > projects.
>
> > Anyway, two questions:
>
> > 1) Should having both {magic, on} and {model, off} be an error?
>
> Yes, I think so. You can't have a CRUD app without a model, after all.
>
> > 2) Erltl files don't have magic declarations implicitly right? In
> > other words, if using Erltl, one should specify <%~ erlyweb_magic(on)
> > %> if one wants magic?
>
> That's right. I've never tried using erlyweb_magic in ErlTL, though.
> I'm not sure if it would work.
>
> Yariv
>
>
>
> > -Ghalib
>
> > On Sep 23, 1:39 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> > > I think it looks good.
>
> > > Yariv
>
> > > On 9/22/07, Ghalib Suleiman <cow...@gmail.com> wrote:
>
> > > > Hi Yariv, I'm thinking of using a proplist-based approach. What do you
> > > > think? i.e. erlyweb:create_component() would take in a proplist, for
> > > > example [{magic, off}, {model, on}, {erltl, on}], the proplist would
> > > > be validated and the right files will be created accordingly. Is this
> > > > too drastic a change?
>
> > > > -Ghalib
>
> > > > > On Sep 21, 7:35 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
>
> > > > > > Currently there is no way of doing it -- you have to create the files
> > > > > > manually. Adding this feature to ErlyWeb would be a good programming
> > > > > > exercise Wink
>
> > > > > > Yariv


--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Thu Sep 27, 2007 8:40 pm Reply with quote
Guest
Try adding a dot after the closing paren.

On 9/27/07, Ghalib Suleiman <cowmoo@gmail.com> wrote:
>
> So, having <%~ -erlyweb_magic(erlyweb_view) %> in an ertl file and
> then compiling, I get an error:
>
> ** exited: {error,{parse_error,{999999,
> erl_parse,
> ["syntax error before: ",[]]}}} **
>
> I don't really know how easy this would be fix - any ideas?
>
> On Sep 27, 5:19 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> > On 9/26/07, Ghalib Suleiman <cow...@gmail.com> wrote:
> >
> >
> >
> > > Hi Yariv, sorry this is dragging, got sidetracked with real life/other
> > > projects.
> >
> > > Anyway, two questions:
> >
> > > 1) Should having both {magic, on} and {model, off} be an error?
> >
> > Yes, I think so. You can't have a CRUD app without a model, after all.
> >
> > > 2) Erltl files don't have magic declarations implicitly right? In
> > > other words, if using Erltl, one should specify <%~ erlyweb_magic(on)
> > > %> if one wants magic?
> >
> > That's right. I've never tried using erlyweb_magic in ErlTL, though.
> > I'm not sure if it would work.
> >
> > Yariv
> >
> >
> >
> > > -Ghalib
> >
> > > On Sep 23, 1:39 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> > > > I think it looks good.
> >
> > > > Yariv
> >
> > > > On 9/22/07, Ghalib Suleiman <cow...@gmail.com> wrote:
> >
> > > > > Hi Yariv, I'm thinking of using a proplist-based approach. What do you
> > > > > think? i.e. erlyweb:create_component() would take in a proplist, for
> > > > > example [{magic, off}, {model, on}, {erltl, on}], the proplist would
> > > > > be validated and the right files will be created accordingly. Is this
> > > > > too drastic a change?
> >
> > > > > -Ghalib
> >
> > > > > > On Sep 21, 7:35 am, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> >
> > > > > > > Currently there is no way of doing it -- you have to create the files
> > > > > > > manually. Adding this feature to ErlyWeb would be a good programming
> > > > > > > exercise Wink
> >
> > > > > > > Yariv
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Fri Sep 28, 2007 12:43 pm Reply with quote
Guest
On Sep 27, 4:33 pm, Ghalib Suleiman <cow...@gmail.com> wrote:
> So, having <%~ -erlyweb_magic(erlyweb_view) %> in an ertl file and
> then compiling, I get an error:

You've probably figured this out already, but just in case: If that's
a direct copy and paste, the problem is that there is no '.' after the
erlyweb_magic clause. Change it to:

<%~ -erlyweb_magic(erlyweb_view). %>

I run into that one every time I type in an include, rather than copy/
pasting. Razz

-Bryan


--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Fri Sep 28, 2007 12:44 pm Reply with quote
Guest
On Sep 27, 4:39 pm, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> Try adding a dot after the closing paren.

Doh! Stupid new Google Groups view. If I scroll to the bottom, I
expect to be at the end of the thread. Razz

Offtopic: Does anyone else think that Google Groups is a complete
mess? Not that I have a better solution, but I felt like venting.

-Bryan


--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Sun Sep 30, 2007 10:38 pm Reply with quote
Guest
sigh, I always forget the dot in ErlTL files and yet never learn...

Anyway, here's a patch (this was diffed with trunk) that has
erlyweb:create_component also take a proplist that allows for one to
choose between having magic on or off, as well as having a model file
or not, and whether to use an Erlang source file as the view, or an
ErlTL file. I hope the edoc modifications I made are clear enough. I
apologise in advance if the code is "hackey"; I wrote it quickly so
that I could get back to my erlyweb app (I'd like to increase the
number of public erlyweb apps by 50% asap Smile. If you have a problem
with it, let me know and I'll spend more time on it. A few small
things I also changed:

- The Emakefile from trunk was pointing to the wrong Yaws include dir
for me. I changed it to the include dir of a default Yaws installation
on my OS X machine.
- erlydb_mnesia.erl had used httpd_util:to_upper(), which is
deprecated. Changed to string:to_upper().
- Small typo with the @spec for erlyweb:compile ("AooDir" is now
"AppDir").

-Ghalib

---------

diff -Naur --exclude=.DS_Store erlyweb/Emakefile erlyweb-new/Emakefile
--- erlyweb/Emakefile 2007-09-27 02:01:48.000000000 +0400
+++ erlyweb-new/Emakefile 2007-09-27 17:08:43.000000000 +0400
@@ -1,4 +1,4 @@
-{"src/erlyweb/*", [debug_info, {outdir, "ebin"}, {i,"/usr/local/src/
yaws/include"}]}.
+{"src/erlyweb/*", [debug_info, {outdir, "ebin"}, {i,"/usr/local/lib/
yaws/include"}]}.
{"src/erlydb/*", [debug_info, {outdir, "ebin"}]}.
{"src/erlsql/*", [debug_info, {outdir, "ebin"}]}.
{"src/erltl/*", [debug_info, {outdir, "ebin"}]}.
diff -Naur --exclude=.DS_Store erlyweb/src/erlydb/erlydb_mnesia.erl
erlyweb-new/src/erlydb/erlydb_mnesia.erl
--- erlyweb/src/erlydb/erlydb_mnesia.erl 2007-09-27 02:01:45.000000000
+0400
+++ erlyweb-new/src/erlydb/erlydb_mnesia.erl 2007-09-27
17:29:24.000000000 +0400
@@ -574,7 +574,7 @@

get_qlc_metadata([Table | Tables], QLCData) when is_tuple(Table) ==
false ->
% Create an alias for the table (table name in all caps)
- get_qlc_metadata({Table, 'as',
httpd_util:to_upper(atom_to_list(Table))}, Tables, QLCData);
+ get_qlc_metadata({Table, 'as',
string:to_upper(atom_to_list(Table))}, Tables, QLCData);
get_qlc_metadata([{_, 'as', _} = Table | Tables], QLCData) ->
get_qlc_metadata(Table, Tables, QLCData);
get_qlc_metadata([], QLCData) ->
diff -Naur --exclude=.DS_Store erlyweb/src/erlyweb/erlyweb.erl erlyweb-
new/src/erlyweb/erlyweb.erl
--- erlyweb/src/erlyweb/erlyweb.erl 2007-09-27 02:01:48.000000000
+0400
+++ erlyweb-new/src/erlyweb/erlyweb.erl 2007-10-01 02:20:21.000000000
+0400
@@ -48,31 +48,40 @@
Other -> Other
end.

-%% @equiv create_component(Component, AppDir, on)
+%% @equiv create_component(Component, AppDir, [{magic, on}, {model,
on},
+%% {erltl, off})
create_component(Component, AppDir) ->
- create_component(Component, AppDir, on).
+ create_component(Component, AppDir, [{magic, on}, {model, on},
+ {erltl, off}]).

-%% @doc Create all the files (model, view and controller) for a
component
-%% that implements basic CRUD features for a database table.
-%% 'Component' is the name of the component and 'AppDir' is the
application's
-%% root directory.
-%%
-%% The view and controller source files this function creates have
the line
-%% "-erlyweb_magic(on)."
-%% This tells ErlyWeb that the module in which the line appears
should extend
-%% the erlyweb_view or erlyweb_controller modules, which provide
basic CRUD
-%% capabilities.
-%%
-%% You can override the default base module setting by replace 'on'
with
-%% the name of the module you want to extend. You can also disable
the
-%% build-in CRUD features by removing the '-erlyweb_magic(on).' lines
from
-%% the view and/or controller source files.
+%% @doc Create all files (model, view, and controller) for a
component
+%% that implements basic CRUD features for a database table.
'Component'
+%% is the name of the component and 'AppDir' is the application's
root
+%% directory.
+%%
+%% This function also lets you define the following options:
+%%
+%% - `{magic, Val:Surprisedn | off | atom() | string()}'.
+%% If Val is 'on', the view and controller source files this
function
+%% creates will have the line "-erlyweb_magic(on)". This tells
Erlyweb that
+%% the module in which the line appears should extend the
erlyweb_view
+%% or erlyweb_controller modules, which provide basic CRUD
+%% capabilities. You can override the default base module by
replacing
+%% 'on' with the name of the module you want to extend. You can
also
+%% disable the built-in CRUD features by having 'Val' be 'off'.
+%%
+%% - `{model, Val:Surprisedn | off}'.
+%% This tells Erlyweb whether to create a model file or not.
+%%
+%% - `{erltl, Val:Surprisedn | off}.
+%% This tells Erlyweb whether the view file should be an ErlTL
file, or
+%% an Erlang source file.
%%
-%% @spec create_component(Component::atom(), AppDir::string(),
-%% Magic:Surprisedn | atom() | string()) ->
+%% @spec create_component(Component:atom(), AppDir:string(),
+%% Options::[option()]) ->
%% ok | {error, Err}
-create_component(Component, AppDir, Magic) ->
- case catch erlyweb_util:create_component(Component, AppDir,
Magic) of
+create_component(Component, AppDir, Options) ->
+ case catch erlyweb_util:create_component(Component, AppDir,
Options) of
{'EXIT', Err} ->
{error, Err};
Other -> Other
@@ -88,7 +97,7 @@
%% changed (ErlyWeb does this automatically when the auto-
compilation
%% is turned on).
%%
-%% @spec compile(AooDir::string()) -> ok | {error, Err}
+%% @spec compile(AppDir::string()) -> ok | {error, Err}
compile(AppDir) ->
compile(AppDir, []).

diff -Naur --exclude=.DS_Store erlyweb/src/erlyweb/erlyweb_util.erl
erlyweb-new/src/erlyweb/erlyweb_util.erl
--- erlyweb/src/erlyweb/erlyweb_util.erl 2007-09-27 02:01:48.000000000
+0400
+++ erlyweb-new/src/erlyweb/erlyweb_util.erl 2007-10-01
02:22:27.000000000 +0400
@@ -161,10 +161,46 @@
"H1 {font-size: 1.5em;}",
iolist_to_binary(Text).

+magic_declaration("", _) ->
+ "";
+magic_declaration(MagicStr, controller) ->
+ "-erlyweb_magic(" ++ MagicStr ++"_controller).";
+magic_declaration(MagicStr, {erltl, off}) ->
+ "-erlyweb_magic(" ++ MagicStr ++"_view).";
+magic_declaration(MagicStr, {erltl, on}) ->
+ "<%~ -erlyweb_magic(" ++ MagicStr ++ "_view). %>".
+
+view_declaration(ComponentName, {ertl, off}) ->
+ "-module(" ++ ComponentName ++ "_view).\n";
+view_declaration(_ComponentName, {ertl, on}) ->
+ "".
+
+view_filename(ComponentName, {ertl, off}) ->
+ ComponentName ++ "_view.erl";
+view_filename(ComponentName, {ertl, on}) ->
+ ComponentName ++ "_view.et".
+
+model_filename(_ComponentName, {model, off}) ->
+ "";
+model_filename(ComponentName, {model, on}) ->
+ ComponentName ++ ".erl".
+
%% @hidden
-create_component(ComponentName, AppDir, Magic) ->
+create_component(ComponentName, AppDir, Options) ->
+ {Magic, Model, Erltl} = {proplists:get_value(magic, Options, on),
+ proplists:get_value(model, Options, on),
+ proplists:get_value(erltl, Options, off)},
+
+ if (Magic == on) andalso (Model == off) ->
+ exit({bad_options, "Can't have magic without a model."});
+ true ->
+ void
+ end,
+
MagicStr = if Magic == on ->
"erlyweb";
+ Magic == off ->
+ "";
true ->
if is_atom(Magic) ->
atom_to_list(Magic);
@@ -172,15 +208,19 @@
Magic
end
end,
- Files =
- [{ComponentName ++ ".erl",
- "-module(" ++ ComponentName ++ ")."},
- {ComponentName ++ "_controller.erl",
- "-module(" ++ ComponentName ++ "_controller).\n"
- "-erlyweb_magic(" ++ MagicStr ++"_controller)."},
- {ComponentName ++ "_view.erl",
- "-module(" ++ ComponentName ++ "_view).\n"
- "-erlyweb_magic(" ++ MagicStr ++ "_view)."}],
+
+ %% Remove empty filenames from the list.
+ Files = lists:filter(fun({"", _Bin}) -> false;
+ (_) -> true end,
+ [{model_filename(ComponentName, {model, Model}),
+ "-module(" ++ ComponentName ++ ")."},
+ {ComponentName ++ "_controller.erl",
+ "-module(" ++ ComponentName ++ "_controller).\n" ++
+ magic_declaration(MagicStr, controller)},
+ {view_filename(ComponentName, {ertl, Erltl}),
+ view_declaration(ComponentName, {ertl, Erltl}) ++
+ magic_declaration(MagicStr, {erltl, Erltl})}]),
+
lists:foreach(
fun({FileName, Text}) ->
create_file(AppDir ++ "/src/components/" ++ FileName, Text)


--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist
Guest
Posted: Sun Sep 30, 2007 10:52 pm Reply with quote
Guest
Great, thanks a lot. Please go ahead and check the changes into trunk.
I added you as a committer in the ErlyWeb Google code project.

Cheers,
Yariv

On 9/30/07, Ghalib Suleiman <cowmoo@gmail.com> wrote:
>
> sigh, I always forget the dot in ErlTL files and yet never learn...
>
> Anyway, here's a patch (this was diffed with trunk) that has
> erlyweb:create_component also take a proplist that allows for one to
> choose between having magic on or off, as well as having a model file
> or not, and whether to use an Erlang source file as the view, or an
> ErlTL file. I hope the edoc modifications I made are clear enough. I
> apologise in advance if the code is "hackey"; I wrote it quickly so
> that I could get back to my erlyweb app (I'd like to increase the
> number of public erlyweb apps by 50% asap Smile. If you have a problem
> with it, let me know and I'll spend more time on it. A few small
> things I also changed:
>
> - The Emakefile from trunk was pointing to the wrong Yaws include dir
> for me. I changed it to the include dir of a default Yaws installation
> on my OS X machine.
> - erlydb_mnesia.erl had used httpd_util:to_upper(), which is
> deprecated. Changed to string:to_upper().
> - Small typo with the @spec for erlyweb:compile ("AooDir" is now
> "AppDir").
>
> -Ghalib
>
> ---------
>
> diff -Naur --exclude=.DS_Store erlyweb/Emakefile erlyweb-new/Emakefile
> --- erlyweb/Emakefile 2007-09-27 02:01:48.000000000 +0400
> +++ erlyweb-new/Emakefile 2007-09-27 17:08:43.000000000 +0400
> @@ -1,4 +1,4 @@
> -{"src/erlyweb/*", [debug_info, {outdir, "ebin"}, {i,"/usr/local/src/
> yaws/include"}]}.
> +{"src/erlyweb/*", [debug_info, {outdir, "ebin"}, {i,"/usr/local/lib/
> yaws/include"}]}.
> {"src/erlydb/*", [debug_info, {outdir, "ebin"}]}.
> {"src/erlsql/*", [debug_info, {outdir, "ebin"}]}.
> {"src/erltl/*", [debug_info, {outdir, "ebin"}]}.
> diff -Naur --exclude=.DS_Store erlyweb/src/erlydb/erlydb_mnesia.erl
> erlyweb-new/src/erlydb/erlydb_mnesia.erl
> --- erlyweb/src/erlydb/erlydb_mnesia.erl 2007-09-27 02:01:45.000000000
> +0400
> +++ erlyweb-new/src/erlydb/erlydb_mnesia.erl 2007-09-27
> 17:29:24.000000000 +0400
> @@ -574,7 +574,7 @@
>
> get_qlc_metadata([Table | Tables], QLCData) when is_tuple(Table) ==
> false ->
> % Create an alias for the table (table name in all caps)
> - get_qlc_metadata({Table, 'as',
> httpd_util:to_upper(atom_to_list(Table))}, Tables, QLCData);
> + get_qlc_metadata({Table, 'as',
> string:to_upper(atom_to_list(Table))}, Tables, QLCData);
> get_qlc_metadata([{_, 'as', _} = Table | Tables], QLCData) ->
> get_qlc_metadata(Table, Tables, QLCData);
> get_qlc_metadata([], QLCData) ->
> diff -Naur --exclude=.DS_Store erlyweb/src/erlyweb/erlyweb.erl erlyweb-
> new/src/erlyweb/erlyweb.erl
> --- erlyweb/src/erlyweb/erlyweb.erl 2007-09-27 02:01:48.000000000
> +0400
> +++ erlyweb-new/src/erlyweb/erlyweb.erl 2007-10-01 02:20:21.000000000
> +0400
> @@ -48,31 +48,40 @@
> Other -> Other
> end.
>
> -%% @equiv create_component(Component, AppDir, on)
> +%% @equiv create_component(Component, AppDir, [{magic, on}, {model,
> on},
> +%% {erltl, off})
> create_component(Component, AppDir) ->
> - create_component(Component, AppDir, on).
> + create_component(Component, AppDir, [{magic, on}, {model, on},
> + {erltl, off}]).
>
> -%% @doc Create all the files (model, view and controller) for a
> component
> -%% that implements basic CRUD features for a database table.
> -%% 'Component' is the name of the component and 'AppDir' is the
> application's
> -%% root directory.
> -%%
> -%% The view and controller source files this function creates have
> the line
> -%% "-erlyweb_magic(on)."
> -%% This tells ErlyWeb that the module in which the line appears
> should extend
> -%% the erlyweb_view or erlyweb_controller modules, which provide
> basic CRUD
> -%% capabilities.
> -%%
> -%% You can override the default base module setting by replace 'on'
> with
> -%% the name of the module you want to extend. You can also disable
> the
> -%% build-in CRUD features by removing the '-erlyweb_magic(on).' lines
> from
> -%% the view and/or controller source files.
> +%% @doc Create all files (model, view, and controller) for a
> component
> +%% that implements basic CRUD features for a database table.
> 'Component'
> +%% is the name of the component and 'AppDir' is the application's
> root
> +%% directory.
> +%%
> +%% This function also lets you define the following options:
> +%%
> +%% - `{magic, Val:Surprisedn | off | atom() | string()}'.
> +%% If Val is 'on', the view and controller source files this
> function
> +%% creates will have the line "-erlyweb_magic(on)". This tells
> Erlyweb that
> +%% the module in which the line appears should extend the
> erlyweb_view
> +%% or erlyweb_controller modules, which provide basic CRUD
> +%% capabilities. You can override the default base module by
> replacing
> +%% 'on' with the name of the module you want to extend. You can
> also
> +%% disable the built-in CRUD features by having 'Val' be 'off'.
> +%%
> +%% - `{model, Val:Surprisedn | off}'.
> +%% This tells Erlyweb whether to create a model file or not.
> +%%
> +%% - `{erltl, Val:Surprisedn | off}.
> +%% This tells Erlyweb whether the view file should be an ErlTL
> file, or
> +%% an Erlang source file.
> %%
> -%% @spec create_component(Component::atom(), AppDir::string(),
> -%% Magic:Surprisedn | atom() | string()) ->
> +%% @spec create_component(Component:atom(), AppDir:string(),
> +%% Options::[option()]) ->
> %% ok | {error, Err}
> -create_component(Component, AppDir, Magic) ->
> - case catch erlyweb_util:create_component(Component, AppDir,
> Magic) of
> +create_component(Component, AppDir, Options) ->
> + case catch erlyweb_util:create_component(Component, AppDir,
> Options) of
> {'EXIT', Err} ->
> {error, Err};
> Other -> Other
> @@ -88,7 +97,7 @@
> %% changed (ErlyWeb does this automatically when the auto-
> compilation
> %% is turned on).
> %%
> -%% @spec compile(AooDir::string()) -> ok | {error, Err}
> +%% @spec compile(AppDir::string()) -> ok | {error, Err}
> compile(AppDir) ->
> compile(AppDir, []).
>
> diff -Naur --exclude=.DS_Store erlyweb/src/erlyweb/erlyweb_util.erl
> erlyweb-new/src/erlyweb/erlyweb_util.erl
> --- erlyweb/src/erlyweb/erlyweb_util.erl 2007-09-27 02:01:48.000000000
> +0400
> +++ erlyweb-new/src/erlyweb/erlyweb_util.erl 2007-10-01
> 02:22:27.000000000 +0400
> @@ -161,10 +161,46 @@
> "H1 {font-size: 1.5em;}",
> iolist_to_binary(Text).
>
> +magic_declaration("", _) ->
> + "";
> +magic_declaration(MagicStr, controller) ->
> + "-erlyweb_magic(" ++ MagicStr ++"_controller).";
> +magic_declaration(MagicStr, {erltl, off}) ->
> + "-erlyweb_magic(" ++ MagicStr ++"_view).";
> +magic_declaration(MagicStr, {erltl, on}) ->
> + "<%~ -erlyweb_magic(" ++ MagicStr ++ "_view). %>".
> +
> +view_declaration(ComponentName, {ertl, off}) ->
> + "-module(" ++ ComponentName ++ "_view).\n";
> +view_declaration(_ComponentName, {ertl, on}) ->
> + "".
> +
> +view_filename(ComponentName, {ertl, off}) ->
> + ComponentName ++ "_view.erl";
> +view_filename(ComponentName, {ertl, on}) ->
> + ComponentName ++ "_view.et".
> +
> +model_filename(_ComponentName, {model, off}) ->
> + "";
> +model_filename(ComponentName, {model, on}) ->
> + ComponentName ++ ".erl".
> +
> %% @hidden
> -create_component(ComponentName, AppDir, Magic) ->
> +create_component(ComponentName, AppDir, Options) ->
> + {Magic, Model, Erltl} = {proplists:get_value(magic, Options, on),
> + proplists:get_value(model, Options, on),
> + proplists:get_value(erltl, Options, off)},
> +
> + if (Magic == on) andalso (Model == off) ->
> + exit({bad_options, "Can't have magic without a model."});
> + true ->
> + void
> + end,
> +
> MagicStr = if Magic == on ->
> "erlyweb";
> + Magic == off ->
> + "";
> true ->
> if is_atom(Magic) ->
> atom_to_list(Magic);
> @@ -172,15 +208,19 @@
> Magic
> end
> end,
> - Files =
> - [{ComponentName ++ ".erl",
> - "-module(" ++ ComponentName ++ ")."},
> - {ComponentName ++ "_controller.erl",
> - "-module(" ++ ComponentName ++ "_controller).\n"
> - "-erlyweb_magic(" ++ MagicStr ++"_controller)."},
> - {ComponentName ++ "_view.erl",
> - "-module(" ++ ComponentName ++ "_view).\n"
> - "-erlyweb_magic(" ++ MagicStr ++ "_view)."}],
> +
> + %% Remove empty filenames from the list.
> + Files = lists:filter(fun({"", _Bin}) -> false;
> + (_) -> true end,
> + [{model_filename(ComponentName, {model, Model}),
> + "-module(" ++ ComponentName ++ ")."},
> + {ComponentName ++ "_controller.erl",
> + "-module(" ++ ComponentName ++ "_controller).\n" ++
> + magic_declaration(MagicStr, controller)},
> + {view_filename(ComponentName, {ertl, Erltl}),
> + view_declaration(ComponentName, {ertl, Erltl}) ++
> + magic_declaration(MagicStr, {erltl, Erltl})}]),
> +
> lists:foreach(
> fun({FileName, Text}) ->
> create_file(AppDir ++ "/src/components/" ++ FileName, Text)
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 recived from mailinglist

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