Use a better combined datasource: optional header, no crufty yaml files everywhere.

This commit is contained in:
Chris Eppstein 2010-01-26 23:27:09 -08:00
parent a9440b12c9
commit 7d1d4d49e0
28 changed files with 71 additions and 66 deletions

View File

@ -1,19 +1 @@
require 'nanoc3/tasks'
desc "Make files into items."
task :itemize do
Dir.glob("content/**/*").each do |filename|
yaml_file = File.join(File.dirname(filename), File.basename(filename)[0..-(File.extname(filename).size)]) + "yaml"
if File.extname(filename) == ".yaml"
# skip
elsif File.exists?(yaml_file)
# skip
elsif File.directory?(filename)
else
puts "Itemizing #{filename}"
File.open(yaml_file,"w") do |f|
f.write("---\nextension: #{File.extname(filename)[1..-1]}")
end
end
end
end

View File

@ -2,7 +2,7 @@
data_sources:
- items_root: /
layouts_root: /
type: filesystem_compact
type: better_combined
- items_root: /assets
layouts_root: /assets
type: filesystem_assets

View File

@ -1 +1,9 @@
---
title: Blueprint Pull Example
description: Uses pull to change the display order of columns.
framework: blueprint
stylesheet: blueprint/_grid.sass
mixin: pull
example: true
---
= render "partials/example"

View File

@ -1,7 +0,0 @@
---
title: Blueprint Pull Example
description: Uses pull to change the display order of columns.
framework: blueprint
stylesheet: blueprint/_grid.sass
mixin: pull
example: true

View File

@ -1,3 +1,5 @@
---
---
!blueprint_grid_columns = 3
@import blueprint/grid.sass

View File

@ -1,2 +0,0 @@
---
title: A New Item

View File

@ -1,3 +1,6 @@
---
title: Home
---
%h1 Compass Documentation
%p

View File

@ -1,2 +0,0 @@
---
title: Home

View File

@ -1,3 +1,11 @@
---
title: Blueprint Module
crumb: Blueprint
framework: blueprint
stylesheet: _blueprint.sass
classnames:
- reference
---
%h1= item[:title]
= render "partials/breadcrumbs"

View File

@ -1,7 +0,0 @@
---
title: Blueprint Module
crumb: Blueprint
framework: blueprint
stylesheet: _blueprint.sass
classnames:
- reference

View File

@ -1,3 +1,11 @@
---
title: Blueprint Color Module
crumb: Colors
framework: blueprint
stylesheet: blueprint/_colors.sass
classnames:
- reference
---
%h1= item[:title]
= render "partials/breadcrumbs"

View File

@ -1,7 +0,0 @@
---
title: Blueprint Color Module
crumb: Colors
framework: blueprint
stylesheet: blueprint/_colors.sass
classnames:
- reference

View File

@ -1,3 +1,11 @@
---
title: Blueprint Grid Module
crumb: Grid
framework: blueprint
stylesheet: blueprint/_grid.sass
classnames:
- reference
---
%h1= item[:title]
= render "partials/breadcrumbs"

View File

@ -1,7 +0,0 @@
---
title: Blueprint Grid Module
crumb: Grid
framework: blueprint
stylesheet: blueprint/_grid.sass
classnames:
- reference

View File

@ -1 +0,0 @@
--- {}

View File

@ -1 +0,0 @@
--- {}

View File

@ -1,3 +1,8 @@
---
title: Blueprint Framework
classnames:
- tutorial
---
%h1= item[:title]
%h2#semantic-blueprint Semantic Blueprint Template

View File

@ -1,4 +0,0 @@
---
title: Blueprint Framework
classnames:
- tutorial

View File

@ -1,2 +0,0 @@
--- {}

View File

@ -1 +0,0 @@
--- {}

View File

@ -1 +0,0 @@
--- {}

View File

@ -1 +0,0 @@
--- {}

View File

@ -1 +0,0 @@
--- {}

View File

@ -1 +0,0 @@
--- {}

View File

@ -1 +0,0 @@
--- {}

View File

@ -1 +0,0 @@
--- {}

View File

@ -0,0 +1,28 @@
# This is basically the default filesystem_combined datasource
# But items without a metadata header don't get an error.
class BetterFilesystemCombined < Nanoc3::DataSources::FilesystemCombined
identifier :better_combined
def parse_file(filename, kind)
contents = File.read(filename)
if contents =~ /^(-{5}|-{3})/
# Split file
pieces = contents.split(/^(-{5}|-{3})/).compact
if pieces.size < 4
raise RuntimeError.new(
"The file '#{filename}' does not seem to be a nanoc #{kind}"
)
end
# Parse
meta = YAML.load(pieces[2]) || {}
content = pieces[4..-1].join.strip
[ meta, content ]
else
[{}, contents]
end
end
end