Public Search - danmee10/rhyme-ninja GitHub Wiki

Overview

There really isn’t a whole lot to say about this feature. Basically, all I wanted was to have every public rhyme accessible through the search bar on the top nav. Clicking the search button without input results in all public rhymes being returned. The search box itself uses a simple JS RegExp.test() function to return matches. Down the road I imagine I’ll implement a fuzzy search (perhaps with an external library), and a safe search (black listing certain profane words that may or may not find their way into my user’s work). There is also a good amount to be done about how these rhymes are displayed. Right now all I have is an ugly list of the titles…the goal is (once I implement RhymeArt…) to have them all displayed with their images using Masonry; I’ll use the same technique on individual user’s my-rhymes page.

Directive?

I chose to extract the search form into a directive. I was a little hesitant to do this since I don’t have any concrete plans to reuse it anywhere, which is the point of directives. I eventually made the call based on the fact that I liked how it bundled the HTML and JS neatly into my <public-search></public-search> element. I realize that I could have easily just left the template in the base_nav and used a content_for tag to house all the controller logic at the bottom of the page like I do for the FAQ’s on the create_account page. First off, I don’t really like mixing JS into HTML. I broke this rule on the create_account page because it was simple enough that it felt silly to make a separate file for it. That page also doesn’t have any angular on it. Creating a directive allowed me to keep all the angular code in the javascripts/angular_ninja directory. In the back of my mind I’m also thinking I can adapt this directive to work on an individual user’s my-rhymes page…but probably not for a bit.