Skip to content

Instantly share code, notes, and snippets.

@scottharvey
Created August 3, 2014 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottharvey/94a5d3399eaebdfc11f1 to your computer and use it in GitHub Desktop.
Save scottharvey/94a5d3399eaebdfc11f1 to your computer and use it in GitHub Desktop.
Dir["#{Rails.root}/app/*/**"].each do |dir|
case File.basename(dir)
when 'assets'
Dir["#{dir}/*"].each do |assets_dir|
Rails.application.config.assets.paths << assets_dir
Dir["#{assets_dir}/*"].each do |asset|
parts = File.basename(asset).split('.')
name = "#{parts.first}.#{parts.second}"
Rails.application.config.assets.precompile += [name]
end
end
when 'views'
ActionController::Base.append_view_path dir.to_s
when 'helpers'
Rails.application.config.helpers_paths << dir.to_s
ActiveSupport::Dependencies.autoload_paths << dir.to_s
else
ActiveSupport::Dependencies.autoload_paths << dir.to_s
end
end
@scottharvey
Copy link
Author

I have been playing around with this idea in a small side project application I've been working on. By adding this file into config/initializers it allows you to structure your application grouped by feature or any way you want, eg:

app
├── blogs
│   └── models
│       └── blog.rb
├── maps
│   ├── assets
│   │   ├── javascripts
│   │   │   ├── map_editor.js.coffee
│   │   │   └── map_viewer.js.coffee
│   │   └── stylesheets
│   │       ├── map_editor.css.scss
│   │       └── map_viewer.css.scss
│   ├── controllers
│   │   ├── map_journeys_controller.rb
│   │   └── maps_controller.rb
│   ├── models
│   │   ├── map.rb
│   │   └── map_viewer.rb
│   └── views
│       └── maps
│           └── _edit.html.slim
└── shared
    ├── assets
    │   ├── javascripts
    │   │   ├── admin.js.coffee
    │   │   └── application.js.coffee
    │   └── stylesheets
    │       ├── admin.css.scss
    │       └── navbar.css.scss
    ├── controllers
    │   └── application_controller.rb
    └── views
        ├── application
        │   └── index.html.slim
        └── layouts
            ├── _navbar.html.slim
            ├── admin.html.slim
            └── application.html.slim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment