Skip to content

Commit

Permalink
Meh.
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Jun 9, 2012
0 parents commit d34803c
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "http://rubygems.org"

gem "middleman", "3.0.0.rc.1"
105 changes: 105 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
GEM
remote: http://rubygems.org/
specs:
activesupport (3.2.5)
i18n (~> 0.6)
multi_json (~> 1.0)
chunky_png (1.2.5)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.3.3)
compass (0.12.1)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
execjs (1.3.2)
multi_json (~> 1.0)
ffi (1.0.11)
fssm (0.2.9)
haml (3.1.6)
hike (1.2.1)
http_router (0.10.2)
rack (>= 1.0.0)
url_mount (~> 0.2.1)
i18n (0.6.0)
listen (0.4.4)
rb-fchange (~> 0.0.5)
rb-fsevent (~> 0.9.1)
rb-inotify (~> 0.8.8)
maruku (0.6.0)
syntax (>= 1.0.0)
middleman (3.0.0.rc.1)
middleman-core (= 3.0.0.rc.1)
middleman-more (= 3.0.0.rc.1)
middleman-sprockets (= 3.0.0.rc.1)
middleman-core (3.0.0.rc.1)
activesupport (~> 3.2.4)
bundler (~> 1.1)
listen (~> 0.4.2)
rack (~> 1.4.0)
rack-test (~> 0.6.1)
thor (~> 0.14.3)
tilt (~> 1.3.1)
middleman-more (3.0.0.rc.1)
coffee-script (~> 2.2.0)
coffee-script-source (~> 1.3.3)
compass (>= 0.12.1)
execjs (~> 1.3.2)
haml (>= 3.1.0)
i18n (~> 0.6.0)
maruku (~> 0.6.0)
middleman-core (= 3.0.0.rc.1)
padrino-helpers (~> 0.10.6)
sass (>= 3.1.7)
uglifier (~> 1.2.0)
middleman-sprockets (3.0.0.rc.1)
middleman-more (= 3.0.0.rc.1)
sprockets (~> 2.1)
sprockets-sass (~> 0.8.0)
multi_json (1.1.0)
padrino-core (0.10.6)
activesupport (~> 3.2.0)
http_router (~> 0.10.2)
sinatra (~> 1.3.1)
thor (~> 0.14.3)
tilt (~> 1.3.0)
padrino-helpers (0.10.6)
i18n (~> 0.6)
padrino-core (= 0.10.6)
rack (1.4.1)
rack-protection (1.2.0)
rack
rack-test (0.6.1)
rack (>= 1.0)
rb-fchange (0.0.5)
ffi
rb-fsevent (0.9.1)
rb-inotify (0.8.8)
ffi (>= 0.5.0)
sass (3.1.19)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-sass (0.8.0)
sprockets (~> 2.0)
tilt (~> 1.1)
syntax (1.0.0)
thor (0.14.6)
tilt (1.3.3)
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
url_mount (0.2.1)
rack

PLATFORMS
ruby

DEPENDENCIES
middleman (= 3.0.0.rc.1)
184 changes: 184 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
activate :automatic_image_sizes
activate :relative_assets

helpers do
def here
Page.glob(request.path + '.*').first
end
def roots
Page.roots
end

# Relativize
def rel(url)
# Assume abs path
url = url[1..-1]
url = url.squeeze('/')

# Append ../'s
depth = request.path.count('/') - 1
path = '../' * depth + url

path.squeeze('/')
end
end

# Page model.
#
# # Lookup by filename
# Page['index.html.haml'] #=> Page instance or nil
# Page.glob 'index.html.*' #=> Array of Pages
#
#
# Metadata:
#
# page.title #=> "Getting started"
# page.basename #=> "getting_started"
# page.path #=> "/getting_started/index.html"
# page.data #=> Hash
# page.template_type #=> "haml"
# page.raw #=> String (raw template data)
# page.content #=> String
#
# Tree traversal:
#
# page.parent? #=> True/false
# page.parent #=> Page, or nil if it's a root
# page.root? #=> True if depth = 0
# page.depth #=> Number, minimum of 0
# page.breadcrumbs #=> Array of ancestors
# page.children #=> Array
# page.siblings #=> Array
#
class Page
attr_reader :path
attr_reader :basename
attr_reader :raw
attr_reader :title
attr_reader :data
attr_reader :template_type

def self.source_path
'source'
end

def self.glob(spec, except=nil)
fullspec = File.join(source_path, spec)
list = Dir[fullspec].map do |f|
Page[ f[(source_path.length + 1)..-1] ]
end.sort
list.delete except if except
list
end

def self.[](name)
@pages ||= Hash.new
@pages[name] ||= Page.new name
end

def self.roots
glob('*.html.*') + glob('*/index.html.*')
end

def sort_index
[ (data['order'] || 99999), @basename ]
end

def <=>(other)
sort_index <=> other.sort_index
end

def self.mm_server
::Middleman::Application.server.inst
end

def self.fm_manager
mm_server.frontmatter_manager
end

def initialize(path)
path = path.gsub(/^(\.?\/)+/, '')
@basepath = (path =~ /^(.*)\.html\.([A-Za-z0-9]*)$/) && $1 || path
@template_type = $2
@basename = File.basename(@basepath)
@dir = File.dirname(path)
@parent_dir = File.dirname(@dir)
@parent_dir = '' if @parent_dir == '.'
@full_path = File.join(self.class.source_path, path)
@path = "/#{@basepath}.html"
@data, @raw = self.class.fm_manager.data(path)
@title = data['title'] || @basename
end

def content
# TODO: Parse
@content ||= @raw
end

def to_s
title
end

def parent
if @basename == 'index'
Page.glob(File.join(@parent_dir, 'index.html.*'), self).first
else
Page.glob(File.join(@dir, 'index.html.*'), self).first ||
Page.glob(File.join(@parent_dir, "#{basename}.html.*"), self).first
end
end

def parent?
!! parent
end

def root?
! parent?
end

def depth
root ? 0 : parent.depth + 1
end

def breadcrumbs
if parent?
[ *parent.breadcrumbs, self ]
else
[ self ]
end
end

def children
@children ||= if @basename == 'index' && !root?
(Page.glob(File.join(@dir, '*.html.*'), self) +
Page.glob(File.join(@dir, '*', 'index.html.*'), self)).sort
else
(Page.glob(File.join(@dir, @basepath, '*.html.*'), self) +
Page.glob(File.join(@dir, @basepath, '*', 'index.html.*'), self)).sort
end
end

def all_siblings
@all_siblings ||= begin
list = if @basename == 'index' && !root?
(Page.glob(File.join(@parent_dir, '*.html.*')) +
Page.glob(File.join(@parent_dir, '*', 'index.html.*'))).sort
else
(Page.glob(File.join(@dir, '*.html.*')) +
Page.glob(File.join(@dir, '*', 'index.html.*'))).sort
end
list = list.reject { |p| p.basename == 'index' }
list
end
end

def siblings
@siblings ||= begin
list = all_siblings.dup
list.delete self
list
end
end
end

set :layout, :'_templates/layout'
31 changes: 31 additions & 0 deletions source/_templates/layout.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
!!! 5
%html
%head
%meta{charset: 'utf-8'}
%meta{content: 'IE=edge,chrome=1', 'http-equiv' => 'X-UA-Compatible'}
%title= data.page.title
= stylesheet_link_tag 'site.css'
= yield_content :head
%body{class: page_classes}
#sidebar
%h3 Parent:
- if here && here.parent?
%a{href: rel(here.parent.path)}= here.parent
%h3 Roots:
%ul
- roots.each do |page|
%li
%a{href: rel(page.path)}= page
- if here
%h3 Children:
%ul
- here.children.each do |page|
%li
%a{href: rel(page.path)}= page
%h3 Siblings:
%ul
- here.all_siblings.each do |page|
%li
%a{href: rel(page.path)}= page
#main
= yield
3 changes: 3 additions & 0 deletions source/getting_started.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%h1 Getting started

%p Hello there
Empty file added source/guide/index.html.haml
Empty file.
Empty file added source/guide/part_one.html.haml
Empty file.
Empty file added source/guide/part_two.html.haml
Empty file.
3 changes: 3 additions & 0 deletions source/hello.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%h1 Hello

%p Hello there
8 changes: 8 additions & 0 deletions source/hello.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Hello
---

Hello there

* Yes
* Yo
7 changes: 7 additions & 0 deletions source/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Lol
---
- content_for :head do
%title The Middleman!

%p The Middleman is watching.
32 changes: 32 additions & 0 deletions source/stylesheets/site.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@import "compass";

$link-color: #0388a6;
$link-hover-color: #009ce0;
$link-focus-color: false;
$link-active-color: false;
$link-visited-color: false;

$font-color: #2a2a2a;
$font-family: sans-serif;
$base-font-size: 12px;
$base-line-height: 18px;

$total-cols: 12;
$col-width: 4em;
$gutter-width: 1em;
$side-gutter-width: $gutter-width;

@include global-reset;

body {
font-family: $font-family;
color: $font-color;
}

a {
@include link-colors($link-color, $link-hover-color, $link-focus-color, $link-active-color, $link-visited-color);
}

#main {
padding: 50px;
}

0 comments on commit d34803c

Please sign in to comment.