Generating pages from layout. Question about code location for this

I am not sure of where to put the code referenced @ https://middlemanapp.com/advanced/dynamic_pages/ in order to dynamically create static pages instead of having to manually create each one of these files. Also, is there some sort of extensively documented API notes beside on middleman docs? I am new to Ruby, but am using Middleman with Ruby code. Should I spend time learning Ruby more extensively before taking on Middleman with Ruby, or what? Any advice would be greatly appreciated.

So to answer your first question:

You place the code in your config.rb file. This will create the files when you use either the server or build command. You also need to have a template for the layout created.

In regards to Doc, the middleman site is the best, but if you do some creative google-ing you will find creative solutions to your problem but middleman is the best place to start.