Created
May 25, 2012 19:37
-
-
Save budu/2790068 to your computer and use it in GitHub Desktop.
Basic Stasis/Kramdown powered blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'kramdown' | |
require 'nokogiri' | |
ABBREVIATIONS = <<abbrev | |
*[DSL]: Domain-specific language | |
*[REPL]: Read-eval-print loop | |
*[DDL]: Data definition language | |
*[PORO]: Plain Old Ruby Object | |
abbrev | |
module Base | |
def self.github2kramdown content | |
content.gsub! /^```(.+)/, "{::comment}\nbrush: \\1\n{:/comment}\n~~~" | |
content.gsub! /^```$/, '~~~' | |
end | |
def self.parse content | |
github2kramdown content | |
content = Kramdown::Document.new(content).to_html | |
document = Nokogiri::HTML(content) | |
content = document.root() | |
content.css('h1').remove | |
[document, content] | |
end | |
def self.wrap document, content | |
wrapper = Nokogiri::XML::Node.new('div', document) | |
content.each { |c| c.parent = wrapper } | |
wrapper | |
end | |
def self.pre content | |
content.xpath('//comment()').each do |node| | |
pre = node.next.next | |
pre['class'] = node.content.strip | |
pre.children = pre.children.inner_html | |
node.remove | |
end | |
end | |
def self.md path | |
content = File.read File.expand_path(path, File.dirname(__FILE__)) | |
content += ABBREVIATIONS | |
document, content = parse content | |
pre content | |
content.css('body').children.to_html | |
end | |
end | |
before /.*\.md/ do |action| | |
instead Base.md(action.params[:path]) | |
end | |
ignore /Gemfile/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'http://rubygems.org/' | |
gem 'coffee-script' | |
gem 'compass' | |
gem 'guard' | |
gem 'guard-shell' | |
gem 'haml' | |
gem 'rb-inotify' | |
gem 'kramdown' | |
gem 'nokogiri' | |
gem 'sass' | |
gem 'slop' | |
gem 'stasis', git: 'git@github.com:budu/stasis.git' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment