A generator for creating reference pages.

This commit is contained in:
Chris Eppstein 2010-01-27 23:44:46 -08:00
parent a97adbfaea
commit 389b8055f9
4 changed files with 72 additions and 7 deletions

View File

@ -87,9 +87,11 @@ After adding the example and adjusting the metadata, go to the reference page an
### How to Add New Reference Documentation ### How to Add New Reference Documentation
In the appropriate directory under content/reference add a haml file. You will probably find it convenient to copy another reference item and edit it. Generate a reference file for a stylesheet:
The item metadata (at the top of the file) must provide some details about what stylesheet is being documented. For instance, here is the metadata for the blueprint color module item: ./bin/thor generate:reference ../frameworks/compass/stylesheets/_compass.sass
The item metadata (at the top of the file) provides some details about what stylesheet is being documented. For instance, here is the metadata for the blueprint color module item:
--- ---
title: Blueprint Color Module title: Blueprint Color Module
@ -104,4 +106,4 @@ The `title` and `crumb` attributes are the H1 and the Breadcrumb label respectiv
There are some shared partials that do most of the sass file inspection and formatting. __Most of the docs are kept in the source code__, but if there are times when you need more control, you can drop down to more powerful tools. There are some shared partials that do most of the sass file inspection and formatting. __Most of the docs are kept in the source code__, but if there are times when you need more control, you can drop down to more powerful tools.
All source comments are formatted in Markdown. All source comments are formatted in Markdown.

View File

@ -79,4 +79,6 @@ ol#breadcrumbs
li:after li:after
content: " > " content: " > "
li.last:after li.last:after
content: "" content: ""
li.last
visibility: hidden

View File

@ -0,0 +1,9 @@
= render "partials/breadcrumbs"
%h1= item[:title]
= yield
= render "partials/reference/imports"
= render "partials/reference/mixins"

View File

@ -1,7 +1,10 @@
$: << File.join(File.dirname(__FILE__), '..', '..', 'lib')
require 'fileutils' require 'fileutils'
require 'compass'
class Generate < Thor class Generate < Thor
desc "example IDENTIFIER", "Generate a new example." desc "example IDENTIFIER", "Generate a new example."
method_options :title => :string, :framework => :string, :stylesheet => :string, :mixin => :string
def example(identifier) def example(identifier)
identifier = identifier.dup identifier = identifier.dup
identifier << "/" unless identifier[identifier.length - 1] == ?/ identifier << "/" unless identifier[identifier.length - 1] == ?/
@ -49,7 +52,56 @@ class Generate < Thor
end end
end end
desc "reference FRAMEWORK STYLESHEET", "Generate a reference page for the given stylesheet." desc "reference ../frameworks/fmwk/stylesheets/path/to/_module.sass", "Generate a reference page for the given stylesheet."
def reference(identifier) method_options :title => :string
def reference(stylesheet)
stylesheet = dereference(stylesheet)
identifier = "reference/#{stylesheet[:framework]}/#{stylesheet[:stylesheet]}"
identifier.gsub!(%r{/_},'/')
identifier.gsub!(/\.sass/,'')
identifier.gsub!(%r{/#{stylesheet[:framework]}/#{stylesheet[:framework]}/},"/#{stylesheet[:framework]}/")
module_name = File.basename(identifier).gsub(/\.[^.]+$/,'').capitalize
framework_name = stylesheet[:framework].capitalize
title = @options[:title] || "#{framework_name} #{module_name}"
crumb = @options[:title] || module_name
file_name = "content/#{identifier}.haml"
directory = File.dirname(file_name)
puts "DIRECTORY #{directory}"
FileUtils.mkdir_p directory
puts " CREATE #{file_name}"
open(file_name, "w") do |reference_file|
contents = <<-CONTENTS
| ---
| title: #{title}
| crumb: #{crumb}
| framework: #{stylesheet[:framework]}
| stylesheet: #{stylesheet[:stylesheet]}
| classnames:
| - reference
| ---
| - render 'reference' do
| %p
| Lorem ipsum dolor sit amet.
CONTENTS
reference_file.puts contents.gsub(/^ +\| /, '')
puts " ITEM /#{identifier}/"
end
end end
end
private
def dereference(stylesheet)
stylesheet = File.expand_path(stylesheet)
framework = Compass::Frameworks::ALL.find{|f| stylesheet.index(f.stylesheets_directory) == 0}
raise "No Framework found for #{stylesheet}" unless framework
{
:framework => framework.name,
:stylesheet => stylesheet[framework.stylesheets_directory.length+1..-1]
}
end
end