Shinmun is designed for customization. Modify templates, add helpers, or define new routes.
ERB templates in templates/ control rendering. Key files:
layout.rhtml - Main HTML wrapperpost.rhtml - Single post viewindex.rhtml - Homepage listingcategory.rhtml - Category pagesExample post.rhtml:
<article>
<h1><%= @post.title %></h1>
<time><%= human_date(@post.date) %></time>
<%= @post.body_html %>
</article>Add helpers in lib/shinmun/helpers.rb:
module Shinmun::Helpers
def reading_time(post)
words = post.body.split.size
"#{(words / 200.0).ceil} min read"
end
endUse in templates: <%= reading_time(@post) %>
Routes are defined in lib/shinmun/routes.rb using regex patterns:
Shinmun::Blog.map do
# Custom page route
page '/projects' do
render 'projects.rhtml'
end # Route with parameter capture
archive '/archive/(.*)' do |year|
render 'archive.rhtml', :year => year.to_i
end
end
config.ru sets blog properties:
blog.config = {
title: "My Blog",
author: "Name",
categories: ["Ruby", "Web"],
base_path: "/blog"
}Access in templates via @blog.title, @blog.author, etc.
Create custom export behavior by modifying the Exporter class:
module Shinmun
class Exporter
alias_method :original_export, :export def export
original_export
generate_sitemap
end
def generate_sitemap
# Add custom sitemap.xml generation
sitemap = blog.posts.map { |p| post_url(p) }
write_file('sitemap.xml', sitemap.join("\n"))
end
end
end
Posted in category Ruby. Tagged with ruby, customization, templates.