From sharma.ruby1forge at zoemail.net Sun Jun 22 11:47:53 2008 From: sharma.ruby1forge at zoemail.net (Anil Sharma) Date: Sun, 22 Jun 2008 11:47:53 -0400 Subject: [Yui4rails-discuss] yui4rails - day one for me Message-ID: <1214149673.485e7429465e8@www.zoemail.net> Hi, I just started with yui4rails. The tutorial link ( http://martyhaught.com/articles/2008/05/23/yui4rails-component-tutorial ) was helpful. Quick takes: 1. Marty, Great Job! 2. Category: Your blog is archived by month. A tagged list by category will make your page even better. An example of a very similar blog : http://sonjayatandon.com/category/ruby/ . 3. Comment: I could not find any way to leave a comment for you on any of your pages! Did I miss something? 4. initialize_yui: On windows, the rake initialize_yui did not work. After reading the rakefile, I figured that the only thing it does at this time is copy the \vendor\plugins\yui4rails\public\yui directory to \public\yui directory. 5. SVN command: It didn't download anything for me. The .zip file download and unzipping in the \vendor\plugins directory did the trick. Will keep posted. Anil Sharma ___________________________________________________________________ Privacy Notice: This message has been sent via www.zoemail.net using patented e-mail protection technology developed by AT&T Labs. Reply to the "keyed address" above to ensure delivery. From mghaught at gmail.com Sun Jun 22 23:26:22 2008 From: mghaught at gmail.com (Marty Haught) Date: Sun, 22 Jun 2008 21:26:22 -0600 Subject: [Yui4rails-discuss] yui4rails - day one for me In-Reply-To: <1214149673.485e7429465e8@www.zoemail.net> References: <1214149673.485e7429465e8@www.zoemail.net> Message-ID: <57f29e620806222026o7996e2abn5c1862b0cb8a430f@mail.gmail.com> > I just started with yui4rails. The tutorial link ( > http://martyhaught.com/articles/2008/05/23/yui4rails-component-tutorial ) was > helpful. Quick takes: > > 1. Marty, Great Job! Welcome Anil and thanks. Though I will say that the quality of what's there is no where close to what I'd like it to be. As this plugin was extracted from two projects of mine that used YUI, it's not as polished as it could be. We're slowly making improvements and I hope it to be a solid plugin that others can use and extend before the summer's over. It's slow going though as both of those projects have me working in other areas at the moment. > 2. Category: Your blog is archived by month. A tagged list by category will make > your page even better. An example of a very similar blog : > http://sonjayatandon.com/category/ruby/ . Thank you and you're right. My blog is a base Radiant CMS install that I did back in 2006. I have done virtually no customization on it and while Radiant is very cool, it's not written to be a world-class blogging engine. They are slowly adding more standard blogging features to it so it might actually be a very good blog engine before the year is out. It has been on my list to add tagging as well as other basic features to make it more user-friendly. > 3. Comment: I could not find any way to leave a comment for you on any of your > pages! Did I miss something? No, you didn't. I felt bad that I didn't have any comment solution for the blog. However, I've seen more people moving away from comments due to the high maintenance of comment spam. I may still add them in but I'll want to be sure the comments are meaningful. At the least I should add to the footer something about sending me an email if you want to pass along any feedback. > 4. initialize_yui: On windows, the rake initialize_yui did not work. After > reading the rakefile, I figured that the only thing it does at this time is > copy the \vendor\plugins\yui4rails\public\yui directory to > \public\yui directory. Sorry, I didn't keep the README up-to-date. I improved that rask task and moved into a more fitting namespace. Assuming you're running on the newer codebase, you should be able to run rake yui4rails:update to move the files over. Right now the project is in a funky state as I've added some new features and changed how things work in the github repo. I also need to incorporate the latest 2.5.2 release from YUI. Once that's done I'll do another official release and there shouldn't have any more significant API changes. > 5. SVN command: It didn't download anything for me. The .zip file download and > unzipping in the \vendor\plugins directory did the trick. My co-worker, Andy, added some tags to the svn repo recently. Here's the new path to the last official patch. Note, that this will not be compatible with what I wrote about in my component tutorial post. svn://rubyforge.org/var/svn/yui4rails/tags/yui4rails-0.1.1/ For the tutorial stuff, please use the github master branch. There are two popular ways of pulling down the code. First, if you have git installed run this command: git clone git://github.com/mghaught/yui4rails vendor/plugins/yui4rails Second, assuming you don't have git, use the download button on this page: http://github.com/mghaught/yui4rails/tree/master It will give you a tarball of the master branch (think svn trunk). I'm still debating dropping svn support and going 100% with git. Working in Git and trying to sync changes back into svn is an extra layer of hassle, I may opt for simplicity on my part. Beyond the learning curve for those new to Git, it's superior for handling contributions in my experience. There will always be official releases in zip/tarball formats. Anyway, hopefully that will get you going with the plugin. Please post back to the list how things are going. Cheers, Marty From sharma.ruby1forge at zoemail.net Mon Jun 23 01:10:31 2008 From: sharma.ruby1forge at zoemail.net (Anil Sharma) Date: Mon, 23 Jun 2008 01:10:31 -0400 Subject: [Yui4rails-discuss] Using yui4rails Message-ID: <1214197831.485f3047030cf@www.zoemail.net> Hi Marty, Thanks for the prompt response. I made a little more progress. I used the old README file, and documented my steps. My application is a pilot's logbook. The individual entries are in the logrows table. I want to display all entries when called with the index action. The layout file is app/views/layout/standard.html.erb. 1. In app/views/layout/standard.html.erb, after includes for all .js and .css, add the yui resources: <%= include_yui :datatable, :charts %> 2. In app/controller/logrows_controller.rb, change as follows: def index @logrows = Logrow.find(:all) @table_id = "pilottable" #this will be the div id of the generated table @column_definitions = [ {:key => 'flt_dt', :label => "Flight Date", :resizeable => true, :sortable => true}, {:key => 'make_model', :label => "Make/ Model", :resizeable => true, :sortable => true} ] @data_rows = [] for logrow in @logrows # this block is just to format the @data_rows var. row = {} logrow.attribute_names.each do |f| row[f] = logrow.send(f) end @data_rows << row end @datatable = Yui4Rails::Widgets::DataTable.new(@table_id, @column_definitions, @data_rows, footer_row = "") end Note: The @data_rows parameter looks like this: @data_rows = [{:flt_dt => '05/01', :make_model => "C172"}, {:flt_dt => '05/02', :make_model => "B747"}] I would have liked to say @data_rows = @logrows. But that doesn't work. It would be nice to specify a table name, and an instance variable loaded with the find results, and be able to tabulate. The plugin could help keep DRY. Also, resizeable and sortable are not part of the plugin but are passed thru to yui. They worked in first guess and try. Nice touch Marty. 3. In app/views/logrows/index.html.erb, I deleted everything and included one statement. <%= @datatable.render %> That's it. Next stop: Pagination. ___________________________________________________________________ Privacy Notice: This message has been sent via www.zoemail.net using patented e-mail protection technology developed by AT&T Labs. Reply to the "keyed address" above to ensure delivery. From mghaught at gmail.com Mon Jun 23 23:29:43 2008 From: mghaught at gmail.com (Marty Haught) Date: Mon, 23 Jun 2008 21:29:43 -0600 Subject: [Yui4rails-discuss] Using yui4rails In-Reply-To: <1214197831.485f3047030cf@www.zoemail.net> References: <1214197831.485f3047030cf@www.zoemail.net> Message-ID: <57f29e620806232029r42056baex56d4460523ae438c@mail.gmail.com> Hi Anil, Glad to hear of your progress. Which release did you end up with? Things will change slightly with the current trunk/github code. One of the things that I wish to do with datatable is remove the need to call include_yui separately. With the latest AssetManager code it is no longer necessary. I'll see if I can modernize the datatable code in the coming weeks. Also, I did get some time to upgrade my current projects to 2.5.2 and that went well. The github account has my latest commits. I encourage any of you that are git-savvy to pull down the changes and see how they work with your projects. I'll give push it to the svn trunk in the next few days for others to try out. On your approach with datatable, that's on the right track. Unfortunately the datatable structure isn't easy and I'm not sure how you can generically handle it without shutting down a lot of options. What I would do is extract all that controller code into helpers and models. For example, I'd put that hefty controller on a diet with this: def index @logrows = Logrow.find(:all) end Of course, you will probably need to add in more options such as sorting and pagination controls. Not sure. I would then look to make most of the datatable specific code into a helper such as: module LogrowsHelper def lowrow_datatable(logrows, options = {}) table_id = options[:table_id] || "pilottable" column_definitions = [ {:key => 'flt_dt', :label => "Flight Date", :resizeable => true, :sortable => true}, {:key => 'make_model', :label => "Make/ Model", :resizeable => true, :sortable => true} ] data_rows = logrows.map(&:datarow) @datatable = Yui4Rails::Widgets::DataTable.new(table_id, column_definitions, data_rows) end end Now I'd probably look hard at moving the column definitions code to the model or at least have it be driven by your model. You will probably want to interact with the @datatable object for sorting/pagination and then render it when you're ready. That leaves the model code, where I would move the datarow creation. class Logrow .... def datarow row = {} self.attribute_names.each do |f| row[f] = self.send(f) end end --OR-- def data_keys ["flt_dt", "make_model"] end def datarow row = {} data_keys.each do |key| row[key] = self.send(key) end end end The datarow method essentially converts the individual Logrow record into a datatable-compatible hash. I put two examples in there. One which is identical to what you had except I moved it to the model and invoked with the symbol.to_proc map combo. The attribute_names approach is pretty efficient unless you get more attributes that you don't want in your table. Additionally, it would be nice to drive the keys from the same source. Furthermore if you could have the column labels driven from the model that would be great. I know it's primarily a view concern but the model should know more about its attributes so I'd put it there. If you see other ways to improve the developer interaction with the datatable model, please send them to the list. Cheers, Marty On Sun, Jun 22, 2008 at 11:10 PM, Anil Sharma wrote: > Hi Marty, > > Thanks for the prompt response. I made a little more progress. I used the old > README file, and documented my steps. > > My application is a pilot's logbook. The individual entries are in the logrows > table. I want to display all entries when called with the index action. The > layout file is app/views/layout/standard.html.erb. > > 1. In app/views/layout/standard.html.erb, after includes for all .js and .css, > add the yui resources: > > <%= include_yui :datatable, :charts %> > > 2. In app/controller/logrows_controller.rb, change as follows: > > def index > @logrows = Logrow.find(:all) > > @table_id = "pilottable" #this will be the div id of the generated table > > @column_definitions = [ > {:key => 'flt_dt', :label => "Flight Date", :resizeable => true, > :sortable => > true}, > {:key => 'make_model', :label => "Make/ Model", :resizeable => true, > :sortable > => true} > ] > > @data_rows = [] > for logrow in @logrows # this block is just to format the @data_rows var. > row = {} > logrow.attribute_names.each do |f| > row[f] = logrow.send(f) > end > @data_rows << row > end > > @datatable = Yui4Rails::Widgets::DataTable.new(@table_id, > @column_definitions, @data_rows, footer_row = "") > end > > Note: The @data_rows parameter looks like this: > > @data_rows = [{:flt_dt => '05/01', :make_model => "C172"}, > {:flt_dt => '05/02', :make_model => "B747"}] > > I would have liked to say @data_rows = @logrows. But that doesn't work. It > would be nice to specify a table name, and an instance variable loaded with the > find results, and be able to tabulate. The plugin could help keep DRY. > > Also, resizeable and sortable are not part of the plugin but are passed thru to > yui. They worked in first guess and try. Nice touch Marty. > > 3. In app/views/logrows/index.html.erb, I deleted everything and included one > statement. > > <%= @datatable.render %> > > That's it. > > Next stop: Pagination. > > > ___________________________________________________________________ > > Privacy Notice: This message has been sent via www.zoemail.net using > patented e-mail protection technology developed by AT&T Labs. Reply to > the "keyed address" above to ensure delivery. > > _______________________________________________ > Yui4rails-discuss mailing list > Yui4rails-discuss at rubyforge.org > http://rubyforge.org/mailman/listinfo/yui4rails-discuss >