From maurizio.demagnis at gmail.com Tue Jul 21 15:45:42 2009 From: maurizio.demagnis at gmail.com (maurizio de magnis) Date: Tue, 21 Jul 2009 21:45:42 +0200 Subject: [Cells-talk] content_for renders nothing Message-ID: I've tried to use content_for inside a cell action's view and nothing get rendered. I'd like to use this because inside my main layout, inside I have a section for js code that I fill when needed by #content_for calls. Is it a common bug? Bye, Maurizio From michal.lomnicki at gmail.com Tue Jul 21 17:00:42 2009 From: michal.lomnicki at gmail.com (=?UTF-8?Q?Micha=C5=82_=C5=81omnicki?=) Date: Tue, 21 Jul 2009 23:00:42 +0200 Subject: [Cells-talk] content_for renders nothing In-Reply-To: References: Message-ID: <1248210042.24919.10.camel@wyjec> hi Maurizio > I'd like to use this because inside my main layout, inside I > have a section for js code that I fill when needed by #content_for > calls. > > Is it a common bug? I'm not sure if it's a bug. Cells support own layouts shared between then. When you call content_for it's understood as content for cell-level layout not application-level layout However it's possible to do what you want, but it's tricky and ugly, I warned you :) instead of plain content_for try <% @controller.instance_variable_get("@template").content_for :head do % > <%= "your js here" %> <% end %> but maybe someone could propose a better solution? Regards -- Micha? ?omnicki From maurizio.demagnis at gmail.com Tue Jul 21 17:17:44 2009 From: maurizio.demagnis at gmail.com (maurizio de magnis) Date: Tue, 21 Jul 2009 21:17:44 +0000 Subject: [Cells-talk] content_for renders nothing In-Reply-To: <1248210042.24919.10.camel@wyjec> References: <1248210042.24919.10.camel@wyjec> Message-ID: I understand the reason why plain content_for doesn't simply works and thanks for the workaround, but I think that a allowing such a mixed behavior could be useful to newcomers like me ;) Maurizio 2009/7/21 Micha? ?omnicki : > hi Maurizio > >> I'd like to use this because inside my main layout, inside I >> have a section for js code that I fill when needed by #content_for >> calls. >> >> Is it a common bug? > > I'm not sure if it's a bug. Cells support own layouts shared between > then. When you call content_for it's understood as content for > cell-level layout not application-level layout > > However it's possible to do what you want, but it's tricky and ugly, I > warned you :) > > instead of plain content_for try > <% @controller.instance_variable_get("@template").content_for :head do % >> > ? ? ? ?<%= "your js here" %> > <% end %> > > but maybe someone could propose a better solution? > > Regards > -- > Micha? ?omnicki > > From michal.lomnicki at gmail.com Tue Jul 21 17:28:44 2009 From: michal.lomnicki at gmail.com (=?UTF-8?Q?Micha=C5=82_=C5=81omnicki?=) Date: Tue, 21 Jul 2009 23:28:44 +0200 Subject: [Cells-talk] content_for renders nothing In-Reply-To: References: <1248210042.24919.10.camel@wyjec> Message-ID: <1248211724.24919.27.camel@wyjec> > I understand the reason why plain content_for doesn't simply works and > thanks for the workaround, but I think that a allowing such a mixed > behavior could be useful to newcomers like me ;) You may create an issue on github. http://github.com/apotonick/cells/issues I agree with you that setting a content for an app-level layout should be easier than now. Michal > 2009/7/21 Micha? ?omnicki : > > hi Maurizio > > > >> I'd like to use this because inside my main layout, inside I > >> have a section for js code that I fill when needed by #content_for > >> calls. > >> > >> Is it a common bug? > > > > I'm not sure if it's a bug. Cells support own layouts shared between > > then. When you call content_for it's understood as content for > > cell-level layout not application-level layout > > > > However it's possible to do what you want, but it's tricky and ugly, I > > warned you :) > > > > instead of plain content_for try > > <% @controller.instance_variable_get("@template").content_for :head do % > >> > > <%= "your js here" %> > > <% end %> > > > > but maybe someone could propose a better solution? > > > > Regards > > -- > > Micha? ?omnicki > > > > From apotonick at gmail.com Tue Jul 21 17:42:06 2009 From: apotonick at gmail.com (Nick Sutterer) Date: Tue, 21 Jul 2009 23:42:06 +0200 Subject: [Cells-talk] content_for renders nothing In-Reply-To: <1248211724.24919.27.camel@wyjec> References: <1248210042.24919.10.camel@wyjec> <1248211724.24919.27.camel@wyjec> Message-ID: thanks for your thoughts, guys. what about some #app_content_for in a cell? i don't like the fact that cells should be allowed to write to something global, but if you need it... cheers, gotta sleep, nick micha?: i'm gonna send you the docs tomorrow ;-) 2009/7/21 Micha? ?omnicki : > >> I understand the reason why plain content_for doesn't simply works and >> thanks for the workaround, but I think that a allowing such a mixed >> behavior could be useful to newcomers like me ;) > > You may create an issue on github. > http://github.com/apotonick/cells/issues > > I agree with you that setting a content for an app-level layout should > be easier than now. > > Michal > >> 2009/7/21 Micha? ?omnicki : >> > hi Maurizio >> > >> >> I'd like to use this because inside my main layout, inside I >> >> have a section for js code that I fill when needed by #content_for >> >> calls. >> >> >> >> Is it a common bug? >> > >> > I'm not sure if it's a bug. Cells support own layouts shared between >> > then. When you call content_for it's understood as content for >> > cell-level layout not application-level layout >> > >> > However it's possible to do what you want, but it's tricky and ugly, I >> > warned you :) >> > >> > instead of plain content_for try >> > <% @controller.instance_variable_get("@template").content_for :head do % >> >> >> > ? ? ? ?<%= "your js here" %> >> > <% end %> >> > >> > but maybe someone could propose a better solution? >> > >> > Regards >> > -- >> > Micha? ?omnicki >> > >> > > > > _______________________________________________ > Cells-talk mailing list > Cells-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/cells-talk > From maurizio.demagnis at gmail.com Wed Jul 22 01:26:47 2009 From: maurizio.demagnis at gmail.com (maurizio de magnis) Date: Wed, 22 Jul 2009 05:26:47 +0000 Subject: [Cells-talk] content_for renders nothing In-Reply-To: References: <1248210042.24919.10.camel@wyjec> <1248211724.24919.27.camel@wyjec> Message-ID: the idea of having a method with a name different from the rails one has both pros and cons, but enforcing the concept of "sandbox" in cell's context is better imho. so thumb up for this one. maurizio 2009/7/21 Nick Sutterer : > thanks for your thoughts, guys. what about some > > #app_content_for in a cell? i don't like the fact that cells should be > allowed to write to something global, but if you need it... > > > cheers, gotta sleep, > > nick > > > micha?: i'm gonna send you the docs tomorrow ;-) > > 2009/7/21 Micha? ?omnicki : >> >>> I understand the reason why plain content_for doesn't simply works and >>> thanks for the workaround, but I think that a allowing such a mixed >>> behavior could be useful to newcomers like me ;) >> >> You may create an issue on github. >> http://github.com/apotonick/cells/issues >> >> I agree with you that setting a content for an app-level layout should >> be easier than now. >> >> Michal >> >>> 2009/7/21 Micha? ?omnicki : >>> > hi Maurizio >>> > >>> >> I'd like to use this because inside my main layout, inside I >>> >> have a section for js code that I fill when needed by #content_for >>> >> calls. >>> >> >>> >> Is it a common bug? >>> > >>> > I'm not sure if it's a bug. Cells support own layouts shared between >>> > then. When you call content_for it's understood as content for >>> > cell-level layout not application-level layout >>> > >>> > However it's possible to do what you want, but it's tricky and ugly, I >>> > warned you :) >>> > >>> > instead of plain content_for try >>> > <% @controller.instance_variable_get("@template").content_for :head do % >>> >> >>> > ? ? ? ?<%= "your js here" %> >>> > <% end %> >>> > >>> > but maybe someone could propose a better solution? >>> > >>> > Regards >>> > -- >>> > Micha? ?omnicki >>> > >>> > >> >> >> _______________________________________________ >> Cells-talk mailing list >> Cells-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/cells-talk >> > _______________________________________________ > Cells-talk mailing list > Cells-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/cells-talk > From michal.lomnicki at gmail.com Wed Jul 22 03:29:30 2009 From: michal.lomnicki at gmail.com (=?UTF-8?Q?Micha=C5=82_=C5=81omnicki?=) Date: Wed, 22 Jul 2009 09:29:30 +0200 Subject: [Cells-talk] content_for renders nothing In-Reply-To: References: <1248210042.24919.10.camel@wyjec> <1248211724.24919.27.camel@wyjec> Message-ID: <1248247770.11331.5.camel@wyjec> > > #app_content_for in a cell? i don't like the fact that cells should be > allowed to write to something global, but if you need it... I guess it's not only content_for problem. I think other helpers should be analyzed also (#capture for example). What about a block defining global scope? <% with_global_scope do %> <% content_for :head do %> <%= "foobar" %> <% end %> <% end %> > 2009/7/21 Micha? ?omnicki : > > > >> I understand the reason why plain content_for doesn't simply works and > >> thanks for the workaround, but I think that a allowing such a mixed > >> behavior could be useful to newcomers like me ;) > > > > You may create an issue on github. > > http://github.com/apotonick/cells/issues > > > > I agree with you that setting a content for an app-level layout should > > be easier than now. > > > > Michal > > > >> 2009/7/21 Micha? ?omnicki : > >> > hi Maurizio > >> > > >> >> I'd like to use this because inside my main layout, inside I > >> >> have a section for js code that I fill when needed by #content_for > >> >> calls. > >> >> > >> >> Is it a common bug? > >> > > >> > I'm not sure if it's a bug. Cells support own layouts shared between > >> > then. When you call content_for it's understood as content for > >> > cell-level layout not application-level layout > >> > > >> > However it's possible to do what you want, but it's tricky and ugly, I > >> > warned you :) > >> > > >> > instead of plain content_for try > >> > <% @controller.instance_variable_get("@template").content_for :head do % > >> >> > >> > <%= "your js here" %> > >> > <% end %> > >> > > >> > but maybe someone could propose a better solution? > >> > > >> > Regards > >> > -- > >> > Micha? ?omnicki > >> > > >> > > > > > > > _______________________________________________ > > Cells-talk mailing list > > Cells-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/cells-talk > > > _______________________________________________ > Cells-talk mailing list > Cells-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/cells-talk -- Micha? ?omnicki From apotonick at gmail.com Wed Jul 22 11:43:57 2009 From: apotonick at gmail.com (Nick Sutterer) Date: Wed, 22 Jul 2009 17:43:57 +0200 Subject: [Cells-talk] content_for renders nothing In-Reply-To: <1248247770.11331.5.camel@wyjec> References: <1248210042.24919.10.camel@wyjec> <1248211724.24919.27.camel@wyjec> <1248247770.11331.5.camel@wyjec> Message-ID: > What about a block defining global scope? > > <% with_global_scope do %> > ? ? ? ?<% content_for :head do %> > ? ? ? ? ? ? ? ?<%= "foobar" %> > ? ? ? ?<% end %> > <% end %> > this looks like a very good solution, micha?. so this block would "capture" the output and put it in the right place? what kind of methods like #content_for are there? cheers, nick > >> 2009/7/21 Micha? ?omnicki : >> > >> >> I understand the reason why plain content_for doesn't simply works and >> >> thanks for the workaround, but I think that a allowing such a mixed >> >> behavior could be useful to newcomers like me ;) >> > >> > You may create an issue on github. >> > http://github.com/apotonick/cells/issues >> > >> > I agree with you that setting a content for an app-level layout should >> > be easier than now. >> > >> > Michal >> > >> >> 2009/7/21 Micha? ?omnicki : >> >> > hi Maurizio >> >> > >> >> >> I'd like to use this because inside my main layout, inside I >> >> >> have a section for js code that I fill when needed by #content_for >> >> >> calls. >> >> >> >> >> >> Is it a common bug? >> >> > >> >> > I'm not sure if it's a bug. Cells support own layouts shared between >> >> > then. When you call content_for it's understood as content for >> >> > cell-level layout not application-level layout >> >> > >> >> > However it's possible to do what you want, but it's tricky and ugly, I >> >> > warned you :) >> >> > >> >> > instead of plain content_for try >> >> > <% @controller.instance_variable_get("@template").content_for :head do % >> >> >> >> >> > ? ? ? ?<%= "your js here" %> >> >> > <% end %> >> >> > >> >> > but maybe someone could propose a better solution? >> >> > >> >> > Regards >> >> > -- >> >> > Micha? ?omnicki >> >> > >> >> > >> > >> > >> > _______________________________________________ >> > Cells-talk mailing list >> > Cells-talk at rubyforge.org >> > http://rubyforge.org/mailman/listinfo/cells-talk >> > >> _______________________________________________ >> Cells-talk mailing list >> Cells-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/cells-talk > -- > Micha? ?omnicki > > From maurizio.demagnis at gmail.com Wed Jul 22 12:44:21 2009 From: maurizio.demagnis at gmail.com (maurizio de magnis) Date: Wed, 22 Jul 2009 18:44:21 +0200 Subject: [Cells-talk] content_for renders nothing In-Reply-To: References: <1248210042.24919.10.camel@wyjec> <1248211724.24919.27.camel@wyjec> <1248247770.11331.5.camel@wyjec> Message-ID: thumb up for that solution! 2009/7/22 Nick Sutterer : >> What about a block defining global scope? >> >> <% with_global_scope do %> >> ? ? ? ?<% content_for :head do %> >> ? ? ? ? ? ? ? ?<%= "foobar" %> >> ? ? ? ?<% end %> >> <% end %> >> > > this looks like a very good solution, micha?. > > so this block would "capture" the output and put it in the right place? exactly > what kind of methods like #content_for are there? > > cheers, > nick > >> >>> 2009/7/21 Micha? ?omnicki : >>> > >>> >> I understand the reason why plain content_for doesn't simply works and >>> >> thanks for the workaround, but I think that a allowing such a mixed >>> >> behavior could be useful to newcomers like me ;) >>> > >>> > You may create an issue on github. >>> > http://github.com/apotonick/cells/issues >>> > >>> > I agree with you that setting a content for an app-level layout should >>> > be easier than now. >>> > >>> > Michal >>> > >>> >> 2009/7/21 Micha? ?omnicki : >>> >> > hi Maurizio >>> >> > >>> >> >> I'd like to use this because inside my main layout, inside I >>> >> >> have a section for js code that I fill when needed by #content_for >>> >> >> calls. >>> >> >> >>> >> >> Is it a common bug? >>> >> > >>> >> > I'm not sure if it's a bug. Cells support own layouts shared between >>> >> > then. When you call content_for it's understood as content for >>> >> > cell-level layout not application-level layout >>> >> > >>> >> > However it's possible to do what you want, but it's tricky and ugly, I >>> >> > warned you :) >>> >> > >>> >> > instead of plain content_for try >>> >> > <% @controller.instance_variable_get("@template").content_for :head do % >>> >> >> >>> >> > ? ? ? ?<%= "your js here" %> >>> >> > <% end %> >>> >> > >>> >> > but maybe someone could propose a better solution? >>> >> > >>> >> > Regards >>> >> > -- >>> >> > Micha? ?omnicki >>> >> > >>> >> > >>> > >>> > >>> > _______________________________________________ >>> > Cells-talk mailing list >>> > Cells-talk at rubyforge.org >>> > http://rubyforge.org/mailman/listinfo/cells-talk >>> > >>> _______________________________________________ >>> Cells-talk mailing list >>> Cells-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/cells-talk >> -- >> Micha? ?omnicki >> >> > _______________________________________________ > Cells-talk mailing list > Cells-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/cells-talk > From michal.lomnicki at gmail.com Wed Jul 22 13:00:45 2009 From: michal.lomnicki at gmail.com (=?UTF-8?Q?Micha=C5=82_=C5=81omnicki?=) Date: Wed, 22 Jul 2009 19:00:45 +0200 Subject: [Cells-talk] content_for renders nothing In-Reply-To: References: <1248210042.24919.10.camel@wyjec> <1248211724.24919.27.camel@wyjec> <1248247770.11331.5.camel@wyjec> Message-ID: <1248282045.11331.16.camel@wyjec> > > What about a block defining global scope? > > > > <% with_global_scope do %> > > <% content_for :head do %> > > <%= "foobar" %> > > <% end %> > > <% end %> > > > > this looks like a very good solution, micha?. > > so this block would "capture" the output and put it in the right place? sort of. It would be cool if with_global_scope content is executed in context of view where cell is rendered. I'm not sure how exactly it should be implemented but believe it's possible :) > what kind of methods like #content_for are there? #capture for example http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#M001762 I don't remember more, but won't be surprised if they exist ;-) regards, Micha? > > > >> 2009/7/21 Micha? ?omnicki : > >> > > >> >> I understand the reason why plain content_for doesn't simply works and > >> >> thanks for the workaround, but I think that a allowing such a mixed > >> >> behavior could be useful to newcomers like me ;) > >> > > >> > You may create an issue on github. > >> > http://github.com/apotonick/cells/issues > >> > > >> > I agree with you that setting a content for an app-level layout should > >> > be easier than now. > >> > > >> > Michal > >> > > >> >> 2009/7/21 Micha? ?omnicki : > >> >> > hi Maurizio > >> >> > > >> >> >> I'd like to use this because inside my main layout, inside I > >> >> >> have a section for js code that I fill when needed by #content_for > >> >> >> calls. > >> >> >> > >> >> >> Is it a common bug? > >> >> > > >> >> > I'm not sure if it's a bug. Cells support own layouts shared between > >> >> > then. When you call content_for it's understood as content for > >> >> > cell-level layout not application-level layout > >> >> > > >> >> > However it's possible to do what you want, but it's tricky and ugly, I > >> >> > warned you :) > >> >> > > >> >> > instead of plain content_for try > >> >> > <% @controller.instance_variable_get("@template").content_for :head do % > >> >> >> > >> >> > <%= "your js here" %> > >> >> > <% end %> > >> >> > > >> >> > but maybe someone could propose a better solution? > >> >> > > >> >> > Regards > >> >> > -- > >> >> > Micha? ?omnicki > >> >> > > >> >> > > >> > > >> > > >> > _______________________________________________ > >> > Cells-talk mailing list > >> > Cells-talk at rubyforge.org > >> > http://rubyforge.org/mailman/listinfo/cells-talk > >> > > >> _______________________________________________ > >> Cells-talk mailing list > >> Cells-talk at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/cells-talk > > -- > > Micha? ?omnicki > > > > > _______________________________________________ > Cells-talk mailing list > Cells-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/cells-talk -- Micha? ?omnicki From maurizio.demagnis at gmail.com Sun Jul 26 07:40:35 2009 From: maurizio.demagnis at gmail.com (maurizio de magnis) Date: Sun, 26 Jul 2009 13:40:35 +0200 Subject: [Cells-talk] what about components? Message-ID: Hello everybody, maybe there's something like this already built in in apotomo but, of course, my lack of knowledge about the state of the art of apotomo made me do the following. Previously I used to do this kind of things: (A) http://pastie.org/559314 That's a simple widget which purpose is to enable an ajaxly selection of cities by countries: the view has one initial drop down select showing the available countries, and when the user triggers the change event on that form element, an apotomo event gets triggered too, showing a new drop down select containing the cities of the selected country. Now I've tried to abstract the widget tree creation process, keeping in mind the "skinny controller" dogma the controller: (replace city/country with action/container) (B) http://pastie.org/559322 basically the idea I've tried to implement is that imho it's useful to hide apotomo's composition logic, the user should only implement widget's states, transition rules and the widget tree structure. Everything else should be managed by the library. for example, it should be better to remove these from the widget's cell definition: CompositionRules[:required_options].each do |required_option| attr_accessor required_option.to_sym end def root_container yield self CompositionRules[:required_options].each do |option| set_local_param option.to_sym, @opts[option.to_sym] end end because every Component would always use them (by class inheritance?). I'd also like to implement the use of another apotomo component as a children, maybe nick can show a simpler way to accomplish this ;) Maurizio if you don't like pastie, here are the sources of the previous links: ---------------------------------------------------------------------- (A) RAILS CONTROLLER class SelectionsController < ApplicationController include Apotomo::ControllerMethods def compose @current_city = City.find(params[:id]) use_widgets do |root| root << selection = cell(:location, :manage, 'selection') selection << cell(:location, :init_countries, 'countries') selection << cell(:location, :init_cities, 'cities') selection.watch(:selection, 'cities', :update_cities, nil) end @selection = render_widget 'selection' do |cell| cell.current_city = @current_city end end end APOTOMO CELL class LocationCell < Apotomo::StatefulWidget attr_accessor :current_city transition :from => :display_cities, :to => :update_cities def manage yield self set_local_param :selected_city, @opts[:current_city] end def init_cities @cities = [] jump_to_state :display_cities end def init_countries @countries = Country.all jump_to_state :display_countries end def display_cities render end def display_countries render end def update_cities @cities = City.find_all_by_country_id(param(:country)) end end (B) RAILS CONTROLLER class CellActionsController < ResourceController::Base include Apotomo::ControllerMethods include ApotomoComponents edit.before do @cell_selection = render_apotomo_component(:cell_selection, {:current_object => @object}) end end /lib/apotomo_components.rb module ApotomoComponents def render_apotomo_component(apotomo_component, options = {}) klass = (apotomo_component.to_s + "_cell").classify.constantize composition_rules = klass::CompositionRules for required_option in composition_rules[:required_options] do raise "not enough options" unless options.keys.include? required_option end root_container_id = composition_rules[:root_container_id] use_widgets do |root| root << cell_container = cell(apotomo_component, :root_container, root_container_id ) compose_widget_tree(apotomo_component, cell_container, composition_rules[:widget_tree]) for event_handler in composition_rules[:event_handlers] do cell_container.watch(event_handler[:event], event_handler[:target_cell_id], event_handler[:invoked_state], nil) end end rendered_output = render_widget(root_container_id) do |root_cell| options.each do |key, value| root_cell.send(key.to_s + "=", value) end end return rendered_output end def compose_widget_tree(apotomo_component, cell_container, children) for child in children do cell_container << cell(apotomo_component, child[:method], child[:id]) if child.has_key? :children compose_widget_tree(apotomo_component, cell_container, child[:children]) end end end end APOTOMO CELL class CellSelectionCell < Apotomo::StatefulWidget =begin - interaction layer * TODO learn how to do plugins -.-' * TODO/DISCUSS get from YAML where? /app/cells/my_cell_name.yml /app/cells/my_cell_name/composition_rules.yml * TODO add :component parameter inside the children and render a complete component as a child. * widget_tree structure allows infinte depth levels: :widget_tree => [{ :method => :method_0, :id => "id_for_method_0" :children => [{ :method => :method_0_0, :id => "id_for_method_0_0" }, { :method => :method_0_1, :id => "id_for_method_0_1" }]}, { :method => :method_1 :id => "id_for_method_1" }] that will map this tree structure: method_0 method_0_0 method_0_1 method_1 * every component will have a root_container that will make passed params accessible to its children. =end CompositionRules = { :required_options => [:current_object], :root_container_id => 'cell_selection', :widget_tree => [{ :method => :init_actions, :id => "cell_actions" }, { :method => :init_containers, :id => "cell_containers" }], :event_handlers => [{ :event => :selection, :target_cell_id => "cell_actions", :invoked_state => :update_actions }] } # code shared among apotomo components # TODO pack these into external functions CompositionRules[:required_options].each do |required_option| attr_accessor required_option.to_sym end def root_container yield self CompositionRules[:required_options].each do |option| set_local_param option.to_sym, @opts[option.to_sym] end end CUSTOM WIDGET DEFINITION transition :from => :display_actions, :to => :update_actions def init_actions # do something here jump_to_state :display_actions end def init_containers # do something here jump_to_state :display_containers end def display_actions render end def display_containers render end def update_actions # do something here jump_to_state :display_actions end end ----------------------------------------------------------------------