Skip to content

Instantly share code, notes, and snippets.

@diogofriggo
Created January 17, 2013 03:25

Revisions

  1. diogofriggo created this gist Jan 17, 2013.
    33 changes: 33 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    //Whenever I start a new story there comes the excessive boilerplating that tags along, a series of mini steps
    //to get you going, one such step is registering your ExtJs controller on App.js, it looks like this:

    Ext.application
    name: 'Fidget'
    autoCreateViewport: true
    controllers: [
    'YourController',
    'HundredsOfOtherControllers'
    ]

    //now given my lazyness has caught up with me today, I decided it was time to automate that step
    //using Embedded Ruby (erb)

    //File: App.js.coffee.erb
    Ext.application
    name: 'Fidget'
    autoCreateViewport: true
    controllers: [
    <%
    path = 'app/assets/javascripts/controller'
    root = "Fidget.controller."
    controllers = Dir.glob("#{path}/**/*")
    .select { |file| File.file? file and file.end_with? '.js' }
    .map { |file| File.read(file) }
    .map { |file| file.match(/#{root}(?<name>[\w\.]+)/)[:name] }
    .map { |file| "'#{file}'" }
    .join(",")
    %>
    <%= controllers %>
    ]

    //Now, that controllers array will get filled with all the 129 controllers the app has as of today