git-read

Generate /index.html dynamically

Generate the contents of the site’s /index.html page based on the contents of the project’s README.md.

To do so, this commit adds a dependency on the ruby-git gem, which introspects into the project to read the contents of the latest version of the file.

Since the contents of the README.md are are dynamic, and won’t be declared statically in the source/ directory, this commit transitions the routing for the /index.html page into a Middleman proxy declaration, rendering the source/README.html.md.erb template as the /index.html page.

Once again, the sequencing of the template file’s extensions are crucial, as they hint to the pre-processor to first render ERB, then yield those contents as static Markdown to be translated to HTML.

Set the page’s <title> element to the first line of the project’s README.md.

Testing this behavior

The order that the directory, repository, and application are declared and instantiated is also crucial.

Once the Capybara.app = Middleman.server line is invoked, a call to require the application’s config.rb file is made, and ruby-git‘s configuration is finalized.

To better control this, the test harness creates a temporary directory with Dir.mktmpdir from Ruby’s Standard Library, which it then passes to a Git.init call to prepare it as a Git directory.

Then, the new with_git_repository ensures that the Middleman.server call is made after the environment has been configured to point the application-side Git repository instance to the newly initialized temporary Git-ready directory.

To coordinate this sequence, this commit introduces a dependency on minitest-around gem for atomic test setup and teardown, and the climate_control gem for atomic ENV modifications and roll-back.