Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit a58e71c1e55d9ab2be8c9d462b5eaaf887e0dc6b @madx committed Jan 8, 2010
Showing with 461 additions and 0 deletions.
  1. +5 −0 config.ru
  2. +25 −0 lib/haze.rb
  3. +44 −0 lib/haze/app.rb
  4. +37 −0 lib/haze/post.rb
  5. +148 −0 public/style.css
  6. +158 −0 public/style.sass
  7. +10 −0 views/contents.haml
  8. +20 −0 views/entry.haml
  9. +14 −0 views/layout.haml
@@ -0,0 +1,5 @@
+require File.join(File.dirname(__FILE__), 'lib', 'haze')
+
+Haze.reload!
+
+run Haze::App
@@ -0,0 +1,25 @@
+require 'time'
+require 'pathname'
+require 'sinatra/base'
+require 'haml'
+require 'mime/types'
+
+module Haze
+ extend self
+
+ attr_reader :posts, :tags
+
+ @posts, @tags = [], {}
+
+ def reload!
+ @posts = Dir['entries/*'].map {|p| Post.open(p) }.sort_by {|p| p.date }
+ @posts.map {|p| p.tags }.flatten.tap do |ts|
+ @tags = ts.flatten.uniq.inject({}) {|h,t| h.merge({t => ts.count(t)}) }
+ end
+ end
+
+end
+
+%w(post app).each {|l|
+ require File.join(File.dirname(__FILE__), 'haze', l)
+}
@@ -0,0 +1,44 @@
+module Haze
+ class App < Sinatra::Base
+ configure do
+ set :haml, :attr_wrapper => '"'
+ end
+
+ get '/' do
+ @entry = Haze.posts.last
+ raise Sinatra::NotFound unless @entry
+
+ haml :entry
+ end
+ # Fix to allow mapping to an url with Rack
+ get('') { redirect env['SCRIPT_NAME']+'/' }
+
+ get '/contents' do
+ @entries = Haze.posts.reverse
+
+ if params[:tag]
+ @entries = @entries.select {|p| p.tags.include?(params[:tag]) }
+ end
+
+ haml :contents
+ end
+
+ get '/pub/*' do
+ path = File.join('public', params[:splat].first)
+ halt 403 if path.include?('..')
+
+ content_type MIME::Types.of(path).first.to_s
+ File.read path
+ end
+
+ get '/feed' do
+ end
+
+ get '/entry/:slug' do
+ @entry = Haze.posts.detect {|p| p.slug == params[:slug] }
+ raise Sinatra::NotFound unless @entry
+
+ haml :entry
+ end
+ end
+end
@@ -0,0 +1,37 @@
+module Haze
+ class Post
+ attr_accessor :date, :slug, :title, :body, :tags
+
+ def after
+ Haze.posts[Haze.posts.index(self)+1]
+ end
+
+ def before
+ (idx = Haze.posts.index(self) - 1) < 0 ? nil : Haze.posts[idx]
+ end
+
+ class << self
+ def open(path)
+ path = Pathname.new(path)
+ new.tap {|p|
+ get_attributes(path).map {|a,v| p.__send__(a, v) }
+ }
+ end
+
+ private
+ def get_attributes(path)
+ Hash.new.tap do |a|
+ header, body = path.read.split(/^---+$/, 2)
+ date, a[:slug=] = path.basename.to_s.split('_', 2)
+ base, increment = date.split('+')
+ a[:date=] = Time.parse(base) + (increment || 0).to_i
+ a[:title=] = header.gsub(/\{#.+\}/, '').gsub(/#(\w+)/, '\1').strip
+ a[:tags=] = header.scan(/#(\w+)/).flatten.map {|t| t.downcase }.uniq
+ a[:body=] = body.lstrip
+ end
+ end
+
+ private :new
+ end
+ end
+end
@@ -0,0 +1,148 @@
+body {
+ width: 60%;
+ min-width: 600px;
+ margin: 1em auto;
+ font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
+}
+
+a:link, a:visited {
+ text-decoration: none;
+ color: #204a87;
+ padding: 0 1px;
+}
+
+a:hover, a:focus, a:active {
+ color: #729fcf;
+}
+
+h1 {
+ padding: 0.25em 0.5em;
+ margin: 1em auto 0;
+ font-size: 3em;
+ font-family: "Warnock Pro", "Goudy Old Style", "Palatino", Georgia, serif;
+ font-style: italic;
+ text-align: center;
+ color: #3465a4;
+ -moz-border-radius: 12px 12px 0 0;
+}
+
+#content {
+ border-top: 1px solid #d3d7cf;
+ border-bottom: 1px solid #d3d7cf;
+ background-color: #eeeeec;
+ position: relative;
+}
+#content #menu {
+ position: absolute;
+ width: 8em;
+ top: 2em;
+ left: -8em;
+ margin: 0;
+ padding: 0;
+}
+#content #menu li {
+ display: block;
+ font-weight: bold;
+ text-align: right;
+ color: white;
+ padding: 0.5em 1em 0.5em 2em;
+ margin: 0 0 4px;
+ background-color: #cc0000;
+ border-right: 2px solid #a40000;
+}
+#content .entry {
+ position: relative;
+}
+#content .entry h2 {
+ margin: 0;
+ padding: 0.5em 2em;
+ font-family: "Warnock Pro", "Goudy Old Style", "Palatino", Georgia, serif;
+ font-style: italic;
+ font-size: 2em;
+}
+#content .entry p.date {
+ position: absolute;
+ top: 1em;
+ right: -2.5em;
+ font-weight: bold;
+ text-align: center;
+ color: white;
+ padding: 0.5em 1em;
+ margin: 0;
+ background-color: #4e9a06;
+ border: 1px solid #8ae234;
+ -moz-border-radius: 16px;
+ -webkit-border-radius: 16px;
+}
+#content .entry p.date .day {
+ font-size: 1.75em;
+ display: block;
+}
+#content .entry p.date .month {
+ font-size: 1.5em;
+ font-family: "Warnock Pro", "Goudy Old Style", "Palatino", Georgia, serif;
+ font-style: italic;
+ font-weight: bold;
+}
+#content .entry .tags {
+ margin: 0;
+ padding: 0;
+ position: absolute;
+ top: 8em;
+ right: -10em;
+ width: 10em;
+ text-align: left;
+}
+#content .entry .tags li {
+ display: block;
+ margin: 0 0 8px;
+}
+#content .entry .tags a:link, #content .entry .tags a:visited {
+ background-color: #204a87;
+ color: #ccf9ff;
+ border-left: 2px solid #0c3673;
+ padding: 2px 6px 2px 4px;
+ text-decoration: none;
+ -moz-border-radius: 0 5px 5px 0;
+ -webkit-border-radius: 0 5px 5px 0;
+}
+#content .entry .tags a:hover, #content .entry .tags a:focus, #content .entry .tags a:active {
+ background-color: #3465a4;
+ border-color: #205190;
+}
+#content .entry .body {
+ margin: 0 4em 1em 2em;
+ padding: 0.25em 1.25em;
+ background-color: #fdfdfb;
+ border-top: 1px solid #d3d7cf;
+ font-size: 1.15em;
+ line-height: 160%;
+ color: #555753;
+}
+#content .entry .body h3 {
+ margin: 1em 0 0;
+}
+#content .entry .body pre {
+ background-color: #000023;
+ color: #d3d7cf;
+ font-family: Monaco, "DejaVu Sans Mono", monospace;
+ font-size: 0.9em;
+ padding: 0.25em 0.5em;
+ border: 2px solid #204a87;
+ width: 90%;
+ margin: 1em auto;
+}
+#content .entry .body code {
+ background-color: #000023;
+ color: #d3d7cf;
+ font-family: Monaco, "DejaVu Sans Mono", monospace;
+ padding: 1px 4px;
+ font-size: 0.9em;
+}
+
+#nav {
+ text-align: center;
+ font-size: 1.2em;
+ font-weight: bold;
+ padding: 0.5em 1em;
+}
Oops, something went wrong.

0 comments on commit a58e71c

Please sign in to comment.