Anyone can tell me how I can integrate some of the features from Sinatra into Middleman? I only need to use Sinatra for dynamic routes. I thought this would be easy to do since Middleman is built on top of Sinatra.
Middleman versions prior to 3.x used Sinatra, but the modern releases no longer do. However, it’s still very easy to use Sinatra. In your config.rb
:
require "sinatra"
class MySinatra < Sinatra::Base
get "/" do
"Hello World (Sinatra)"
end
get "/derp.html" do
"De doo"
end
end
map "/sinatra" do
run MySinatra
end
If you want to output some of the Sinatra content as static files during build, use the endpoint
command:
configure :build do
endpoint "my-sinatra-file.html", :path => "/sinatra/some_route"
end
Sweet, that worked. Out of curiosity, what is the “/derp.html” route for? I have seen that line of code before but is it just a smoke test? I’m still new to both sinatra and middleman so please forgive my ignorance.
Yeah, it’s just a fake example route.
I tried this example.
I’ve got two problems:
- When I run middleman build Webrick starts up and sits there until interrupted
- Can’t find any docs for this or endpoint method
Further info on 1. I found this behaviour occured by simply adding sinatra (and nothing else) to an empty middleman init X Gemfile. So I think something odd is going on there.
Any help onthis greatly appreciated.