You're on the right line of thinking with templates + engines.
Templates are great for one-time use. They allow you to generate an application that conforms to a specific, um, template, which provides an excellent base for you to build on top of. You can find more information about templates in this wonderful guide.
Engines, I think, are the better of the two. They allow you to provide that same base that templates would, but then also allow you to expand on that base for later. Within an engine you can have all the things you want. You can generate one of these fabulous creations by running this command:
rails plugin new pixelearth_base --mountable
This will generate the base of an engine, which then you can have all the things you wanted.
Let me show you the ways.
CSS files / images
CSS files go into app/assets
, just like in a Rails 3.1 application, and are then processed the same way. You can read more about them in the Asset Pipeline guide. You can reference them exactly the same way you would reference them if they were inside your application. Of course, any asset inside your application named identically to one inside your engine will take precedence.
Initializers
These go in config/initializers
, just like an application (hint: this is a running theme with engines). They work the same way and are explained in this section of the Configuring Guide, although I reckon you know that much already.
Shared views
These go into app/views/shared
in your engine. Any file in your application named identically will take precedence over the file in the engine. The application will be able to seamlessly access any file in this directory, since engines have their view paths added to the application's.
Partials
Ditto.
Admin
Have you tried the wonderful rails_admin engine for this? Perhaps that would suit you. If not, you can build this functionality into your engine just as you would in an application.
Helpers
Work in much the same way as everything else. Add them to your engine and you'll be good to go. Although I am not confident in that last point, you may have to do helper SomeHelper
at the top of the controller to get them included.
Haml
Specify this as a dependency of the engine in the engine's pixelearth_base.gemspec
file using a line like this:
s.add_dependency 'haml', '3.1.3'
Your engine (and by extension, your application) would be able to use haml in views.
Templates
I am not sure what you mean by this, so I am going to gloss over it.
Gems
Shared gem dependencies should be specified in the pixelearth_base.gemspec
just like the haml example.
Including the engine
Now, you're going to need to include this engine into your application but you don't want to go through the pain of updating a gem all the time. I reckon the best way to do this is to push the gem to GitHub and then specify a line like this inside your application's Gemfile
:
gem 'pixelearth_base', :git => "git://github.com/pixelearth/pixelearth_base"
Whenever you update this gem and push new changes to GitHub, you will need to run bundle update pixelearth_base
to update your application with the latest version. Each time you run bundle update
it will be locked to that specific version. Any further changes to the engine won't be acknowledged until you run bundle update ...
again.
Mounting the engine
One final thing which you asked about in IRC is mounting. If you happen to go the route of having shared functionality in your engine (i.e. controllers and so on) then you'll need to mount your engine within your application. This is very easy and can be done by putting this line in your config/routes.rb
:
mount PixelEarth::Engine, :at => "pixelearth"
The PixelEarth::Engine
class is defined in your engine at lib/pixel_earth/engine.rb
and provides all the functionality it needs by inheriting from Rails::Engine
. Any functionality from your application will now be available at /pixelearth
in your application.