Rails 3.1 Asset Pipeline not precompiling files from a different directory
I currently have a Rails 3.1 app that hosts multiple sites for several different customers.
Each site is represented by a model that knows the domain name and path to where the assets are stored, along with some other info.

I've been using `app/sites/domain-name` as a location for storing assets, views and locales that are specific to a given site, and are running a custom middleware and controller actions for modifying the load path for Sprockets, setting up the view paths and so on.

middleware (loaded using `config.middleware.use "Configurator"` in `application.rb`):

    class Configurator
      def initialize(app)
        @app = app
      end

      def call(env)
        @env = env
        clear_existing_paths
        prepend_local_assets
        @app.call(env)
      end

      def current_site
        # find site using @env
      end

      def current_site_path
        Rails.root.join('app', 'sites', current_site.path)
      end

      def clear_existing_paths
        paths = Rails.application.assets.paths
        Rails.application.assets.clear_paths
        paths.each do |path|
          next if path.include?("app/sites/")
          Rails.application.assets.append_path path
        end
      end

      def prepend_local_assets
        path = current_site_path.join('assets')
        return unless Dir.exists?(path)

        ['images', 'javascripts', 'misc', 'stylesheets'].each do |subdir|
          asset_dir = path.join(subdir).to_s
          next unless Dir.exists?(asset_dir)
          next if     Rails.application.assets.paths.include? asset_dir

          Rails.application.assets.prepend_path asset_dir
        end
      end
    end

The problem is that while this setup works, it prevents me from precompiling the assets that is not shared with the entire app, making them be generated over and over again, from the looks of it.

Is there any way I could tell the precompiler to find the assets located here, and create a version of those as well? Each site has a `site.css.scss` and a `site.js.coffee` file that might require other assets inside the site-dir. Would be nice if I could get it precompiled to `public/assets/domain-name/site.(js|css)`, so I could easily set up a separate subdomain for assets down the line when I need to optimize further
Rails 3.1 Asset Pipeline not precompiling files from a different directory
===

I currently have a Rails 3.1 app that hosts multiple sites for several different customers.
Each site is represented by a model that knows the domain name and path to where the assets are stored, along with some other info.

I've been using `app/sites/domain-name` as a location for storing assets, views and locales that are specific to a given site, and are running a custom middleware and controller actions for modifying the load path for Sprockets, setting up the view paths and so on.

middleware (loaded using `config.middleware.use "Configurator"` in `application.rb`):

    class Configurator
      def initialize(app)
        @app = app
      end

      def call(env)
        @env = env
        clear_existing_paths
        prepend_local_assets
        @app.call(env)
      end

      def current_site
        # find site using @env
      end

      def current_site_path
        Rails.root.join('app', 'sites', current_site.path)
      end

      def clear_existing_paths
        paths = Rails.application.assets.paths
        Rails.application.assets.clear_paths
        paths.each do |path|
          next if path.include?("app/sites/")
          Rails.application.assets.append_path path
        end
      end

      def prepend_local_assets
        path = current_site_path.join('assets')
        return unless Dir.exists?(path)

        ['images', 'javascripts', 'misc', 'stylesheets'].each do |subdir|
          asset_dir = path.join(subdir).to_s
          next unless Dir.exists?(asset_dir)
          next if     Rails.application.assets.paths.include? asset_dir

          Rails.application.assets.prepend_path asset_dir
        end
      end
    end

The problem is that while this setup works, it prevents me from precompiling the assets that is not shared with the entire app, making them be generated over and over again, from the looks of it.

Is there any way I could tell the precompiler to find the assets located here, and create a version of those as well? Each site has a `site.css.scss` and a `site.js.coffee` file that might require other assets inside the site-dir. Would be nice if I could get it precompiled to `public/assets/domain-name/site.(js|css)`, so I could easily set up a separate subdomain for assets down the line when I need to optimize further