Hi Anthony,

I have to say, your proposal is logically correct. Good hint!
Furthermore, I find a more appropriate place to add those code. That
place is generic.load.

However, my complicated action "index" contains multi components, some
are even duplicated. Then after I deploy the new generic.load, the
"index" page's appearance or behavior is not 100% correct. I guess
that is caused by duplicated and/or improper location of those
component css&js files.

Experiment abort. :-(

Regards,
Iceberg

On May 8, 2:24 am, Anthony <abasta...@gmail.com> wrote:
> I see. One option might be to include code in your "component.load" view
> that makes use of the component's response.files, just like the code in
> web2py_ajax.html. For example, in "component.load" include:
>
> {{
> for _k,_file in enumerate(response.files or []):
>   if _file in response.files[:_k]:
>      continue
>   _file0=_file.lower().split('?')[0]
>   if _file0.endswith('.css'):}}
>      <link href="{{=_file}}" rel="stylesheet" type="text/css" />{{
>   elif _file0.endswith('.js'):}}
>      <script src="{{=_file}}" type="text/javascript"></script>{{
>   pass
> pass
>
> }}
>
> The above will link your component's css and js files in the component HTML,
> which will be inserted in your 'index' page (give that you have ajax=False).
> If you don't want to repeat that code in all your .load views, you can
> probably create a function in a model file or module and just call the
> function from your views.
>
> Anthony
>
>
>
>
>
>
>
> On Saturday, May 7, 2011 12:01:44 PM UTC-4, Iceberg wrote:
> > Thank you Anthony for your comments and here comes my clarification.
>
> > You are right that, adding response.files within a component, has no
> > effect at all when called by "component.load". But I still keep a copy
> > of those response.files inside the component, because they are needed
> > when visiting "component.html" (during developing or debugging phase).
>
> > On the other hand, when we have to copy those response.files in action
> > "skeleton" or action "index", that does not feel elegant, because
> > action "index" has to explicitly include some helper resources which
> > not needed by itself. Imagine that, after I change implementation of
> > "component" later, I have to modify "index" also. Grrr.
>
> > Pbreit's suggestion is what I can do right now (thank you Pbreit too),
> > it is DRY, but still not solving the unnecessary coupling mentioned
> > above.
>
> > Regards,
> > Iceberg
>
> > On May 7, 11:04 pm, Anthony <abas...@gmail.com> wrote:
> > > Does adding to response.files within a component controller work at all?
> > > With ajax=False, it looks like LOAD creates a new environment (and
> > response)
> > > to run the component controller, so I'm not sure appending to
> > response.files
> > > within a component controller will affect the response.files of the
> > parent
> > > controller.
>
> > > response.files is only used by web2py_ajax.html, which is typically
> > included
> > > in layout.html. Your index view probably extends layout.html, so
> > > response.files added within the index controller will get included by
> > > web2py_ajax.html. However, your component .load views probably do not
> > extend
> > > layout.html, so I would guess response.files added within component
> > > controllers would be ignored.
>
> > > Haven't tried it, though, so I may be missing something.
>
> > > Anthony
>
> > > On Saturday, May 7, 2011 9:52:27 AM UTC-4, Iceberg wrote:
> > > > Hi Massimo,
>
> > > > Can web2py support chaining response.files inside a component?
>
> > > > Scenario.
>
> > > > def component():
> > > >     response.files.extend([
> > > >         URL(..., 'fancy_helper1.js'),
> > > >         URL(..., 'fancy_helper2.js'),
> > > >         ......,
> > > >         URL(..., 'fancy_helper10.js'),
> > > >         ])
> > > >     return {'': 'Some fancy stuff'}
>
> > > > def skeleton():
> > > >     response.files.extend([
> > > >         URL(..., 'fancy_helper1.js'),
> > > >         URL(..., 'fancy_helper2.js'),
> > > >         ......,
> > > >         URL(..., 'fancy_helper10.js'),
> > > >         ]) # SAME AS THOSE IN component(). Can I omit this?
> > > >     return {'': LOAD('default', 'component.load', ajax=False)}
>
> > > > def index():
> > > >     response.files.extend([
> > > >         URL(..., 'fancy_helper1.js'),
> > > >         URL(..., 'fancy_helper2.js'),
> > > >         ......,
> > > >         URL(..., 'fancy_helper10.js'),
> > > >         ]) # SAME AS THOSE IN component(). Can I omit this?
> > > >     return {'': LOAD('default', 'skeleton.load', ajax=False)}
>
> > > > Currently, if I add one more helper_extra.js into my fancy
> > > > component(), I needed to duplicate them into skeleton() and index().
> > > > It is not DRY. Can it be improved?
>
> > > > Regards,
> > > > Ray Luo (Iceberg)

Reply via email to