Nested Views in Backbone.Marionette A couple of weeks ago we published an article about Functional Programming that used a bagel as an example. It was very well-received, so why not try again? This week @samccone is back with the delicious carbohydrate to talk about Nesting Views in Marionette.js. Nesting views can be a difficult task at first glance. Suppose that we are tasked with creating an interface that covered the process of making a bagel sandwich. Making a sandwich is pretty darn complex though. Let's assume that the output we need to generate looks looks like this. It might look like this (click through to see code example): Programmatically rendering this bagel according to our data seems like it will be a pain. The three pieces we will use are Let start out with a foil Region that will hold our bagel. Now we will create our CollectionView class that will hold the contents of the bagel, and a View class to output each Ingredient. Alright, so far, so good. Take a look at the finished product here. Like to write code?
Using Marionette to Display Modal Views For a while, I’ve been thinking about how best to handle showing modal dialog boxes for my applications while utilizing Backbone views. A lot of interesting ideas passed through my head, but none of them seemed exactly right. Then I saw a post by Derick Bailey where he described how he uses Marionette’s Regions to handle the work. His post is a bit on the old side and Regions have changed a bit since, so I decided to look into how to do it myself. The Issues There are several issues surrounding creating modal dialogs just with a view. Along with that, we lose reusability. The Solution Now that we know we need to pull the modal functionality out of the views, it’s just a matter or figuring out where to put it. All we need to do is augment a Region to call the plugin’s method for showing the modal when the view is shown, make sure to hide the modal when the view is closed, and close the view when the modal is hidden. There are a few things worth noting here: Now it’s simple to use: Conclusion
Beyond grep: ack 2.14, a source code search tool for programmers Graphical vi-vim Cheat Sheet and Tutorial Learning vi or vim is not easy. But it doesn't have to be that difficult, either. It is, in any case, faster, more powerful, and more productive than editing with any other editor, so you would do very well in investing the time and effort to learn it. Being a vi lover myself, I came up with the idea of providing a graphical cheat sheet for those learning vi or vim, and I also found out it was a very good way to structure a tutorial. Here are the results for your learning enjoyment (or your colleagues'). By the way, I recently published the definitive article explaining why vi/vim editing is so much better than regular editing. Graphical cheat sheet This is a single page describing the full vi/vim input model, the function of all keys, and all major features. Graphical cheat sheet based tutorial The tutorial above is structured in 7 lessons that cover the major commands in vi/vim. Notes With the single exception of the external filter feature ("!") Relevant links Why, oh why, do those #?
Introducing Backbone.Radio | Marionette.js Blog Marionette comes bundled with a library called Backbone.Wreqr, and in the coming months we will replace it with a new library by the name of Backbone.Radio. Radio is heavily inspired by Wreqr, but it was rewritten from the ground up. I wouldn’t be surprised if you’re unacquainted with Wreqr. In fact, I would wager it’s one of the lesser-used pieces of Marionette. I blame this on the fact that it lives in a separate repository and is only mentioned in the Marionette documentation in passing (shameless plug: brand new Marionette docs are on the way!). This post will outline our decision to rewrite and replace Wreqr. What is Backbone.Wreqr? Backbone.Wreqr is a collection of three messaging patterns. There’s much interesting discussion about the pros and cons of event-driven architecture, but it’s beyond the scope of this post to get into those things. Why rewrite Wreqr? We think that the risk of fragmentation with this rewrite is low. The benefits of Radio Ordering the Command later:
mileszs/ack.vim RequireJS and Backbone View/Template loading | jsdude I’ve been playing with RequireJS and Backbone while making some home projects for quite long time now, and here’s what I think about it: IT’S TOTALLY AWESOME! In this article I’m going to describe some ideas about how to build backbone-specific modules with RequireJS I don’t like a lot of things about millions of backbone tutorials out there. Especially when it comes to Views and templating – I really hate the idea of putting html templates inside script tags and then accessing this strings via jQuery.text() method. RequireJS has some cool plugins available, one of them is require.text. Ok, here is how I did it. first of all, let’s define some simple folder structure (I use Python Flask Framework, so all my static files are in default static folder): /static —-/js ——–/templates ————/userListTemplate.tpl ————/someOtherTemplate.tpl ——–/views ————-/userListView.js ——–/collections ————-/usersCollection.js ——–/require.js ——–/text.js ——–/main.js then RequireJS will load just what we need.
rking/ag.vim Backbone.js object inheritance - @rjzaworski If you’ve ever wondered if the basic classes in Backbone.js could be inherited by other, related objects, the answer is a resounding “Yes!” The very same extend method used to create models, views, and collections is just as useful for passing methods from any of those objects on to its children. That’s good news, because it makes it ridiculously easy to share code between similar pieces of a Backbone application. An example’s worth at least a thousand words, so here’s a simple one: if animal is the base object and cat is the child, extend (predictably) will give the cat a voice. Instead of grunting incoherently, the new cat simply meows through the talk() method defined for all animals. The super function Children begin by loving their parents; as they grow older they judge them; sometimes, they forgive them(Oscar Wilde) Even the most judgmental of children may occasionally need to parent methods. Backbone.Model.prototype. By using . (new jabberwock). Oh, and you can play with an example here
Ack and Vim integration - ant0ine's blog I'm a fan of Andy Lester's App::Ack module. This a is a perl program that you can use as a replacement of grep. Today I wrote a little Vim plugin that integrate ack with Vim. This is a quick hack, it works for me with vim7/ubuntu and vim6.3/fedora. Just copy/paste the following lines in ~/.vim/plugin/ack.vim " usage: " (the same as ack, except that the path is required) " examples: " :Ack TODO . " :Ack sub Util.pm function! ack-1.60 is out, and the documentation mentions another way to integrate ack and vim by using the :grep function of vim: set grepprg=ack I think this is a better solution, and to make it nicely integrated withvim, I wrote this new little function: function! Just replace the old code by the new one in ~/.vim/plugin/ack.vim This time it works even if you don't specify the path, and you can still use the :grep function as before, grepprg is saved and restored. And as Yann says, "then :cnext is your friend"