Blogue is a rails model for static blog posts, wrapped in an engine. It means that you can have blog posts as static files (kind of like views) inside your rails app, and hook up posts like any other resource. The only reason this is an engine and not just a class in a gem is because it also adds an asset path and a handler for .md views.
Check out my blogue article for some fun stuff it can do: http://hakunin.com/blogue
What you get
- Handler for ".md" views (kramdown by default)
- Syntax highlighting for code blocks (rouge by default)
What you don't get
- Mountable endpoint
- Default controllers
- Default views
- Comments, tags or pretty much any functionality
There are thousands of gems that you can pick from to do that stuff.
- Generate a rails app (or use existing)
Add all needed gems to Gemfile and bundle
gem 'kramdown' gem 'rouge', '~> 1.11.1' # 2.x and newer is not supported yet gem 'blogue'
Create a model
app/models/post.rb(the name 'Post' is chosen at random)
class Post < Blogue::Post # Here you can override inherited methods any way you like. # See app/models/blogue/post.rb to see what you have end
Create a controller
class PostsController < ApplicationController def index @posts = Post.all end def show @post = Post.find(params[:id]) || raise(ActionController::RoutingError.new('Not Found')) end end
Add a route to your
root to: 'posts#index' # if you want an index page get '/:id', to: 'posts#show'
app/views/posts/index.html.erbfor your index page
<% @posts.each do |post| %> <p> <%= link_to post.title, post.id %> <% if post.tldr %> <blockquote> <%= post.tldr %> </blockquote> <% end %> </p> <% end %>
app/views/posts/show.html.erbfor your post page
<%= link_to 'index', root_path %> <%=raw render file: @post.path %> <% if @post.date %> <p>Published on <%= @post.date.to_s(:long) %></p> <% end %>
Create a directory
app/posts(that's default location of posts)
- Create a directory
app/posts/assets(it's added to assets paths by default)
Add a post like
# Yay my first post This is some text. ![picture](/assets/picture.jpg) ~~~ruby foo = 'foo' # a codeblock ~~~ <!--meta date: 2013-10-21 tldr: Awesome -->
Start server and go to http://localhost:3000/my-first-post