Layout shared between sites

I’m trying to publish prose documentation for several of Basho’s open-source releases, each with a gh-pages and page-builder branch on their repos (c.f. https://github.com/basho/riak-ruby-client/tree/gh-pages-builder and http://basho.github.io/riak-ruby-client/ ), but with common styles and configurations so my coworkers (working with Python, Java, and PHP) don’t have to learn much Ruby, just the Markdown they already write.

I think I’ve got a handle on the CSS and JavaScript resources using Sprockets.

I’ve tried having the separate gem override the layout_dir (which causes Middleman to have issues because the layout isn’t in the site tree), but I haven’t tried having the extension symlink the layout in (I know this would work, it just seems… inelegant).

Is there a simple and supported way to move the layout for a site into a separate gem/extension that can be updated relatively easily? If not, does anyone know how much of a mission it would be to build and contribute this to the community?

1 Like

I spiked out the symlink version:

# config.rb
set :layout_target_dir, File.join(File.dirname(__FILE__), 'source', 'layouts')
activate :basho_client
add_basho_resources sprockets

# basho_client_middleman.gem / extension.rb
module BashoClientMiddleman
  class Extension < Middleman::Extension
    def initialize(app…)
      target = app.config[:layout_target_dir]
      FileUtils.ln_s(d('layouts/layout.haml'), target, force: true)
      app.include InstanceMethods
    end

    module InstanceMethods
      def add_basho_resources(sprockets)
        sprockets.append_path d('stylesheets')
        sprockets.append_path d('javascripts')
      end
      private

      def d(ext)
        File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'source', ext))
      end
    end
  end
end

It works, but I’m not really satisfied with it. Going to ship it anyways.