Help!!! an important content on every web application, to add a help content in rails application simple approach will be to cram all pages inside public folder link all pages, done !!! wait… isn’t it an unstructured mess to add all pages inside the public folder, can there be a different approach?
Yes, Middleman- a static site generator a better option to add static content.
- middleman provides multiple template engines other than sticking to html one can create content using haml, md
1. Setup middleman
Install middleman gem in rails application
add middleman gem in gemfile gem “middleman” install bundle install command
After successful installation of middleman gem, create new middleman application, let’s consider our application name as helpsite.
$ middleman init helpsite
middleman init creates a file structure inside a helpsite folder
2. Running middleman application
Middleman allows running as a standalone application, by starting the middleman server.
$ cd helpsite $ middleman server
Which will start a middleman server and you would be able to access the middleman pages by hitting localhost:4567
But in this case, we will be using middleman as a part of our rails application so no need to start middleman server.
We need to build the middleman site which will create a static page for all contents from the source directory
$ middleman build
middleman build command creates a set of files under build folder.
Here index.html acts as a landing page for our helpsite.
Create a folder help inside public and move contents of build to help folder
helpsite/build -> public/help
now to access the helpsite just hit the URL like localhost:3000/help
3. Adding new pages to helpsite
let’s add terms and conditions page in helpsite, create a new page inside the content directory.
4. Navigating to static pages in middleman
To add navigation to newly created terms and conditions folder add a link on the index page as follows.
6. Multiple template engines
Middleman allows us to use multiple template engines like .md, haml etc. here is an example of how you can use markdown (.md) content in our middleman page, need to make changes in config files, middleman build will generate an HTML page for .md file.
Demo application: Github link.