improvements to the example generator

This commit is contained in:
Chris Eppstein 2010-01-30 12:39:56 -08:00
parent 932ae8820d
commit 6470c6093d

View File

@ -3,25 +3,27 @@ require 'fileutils'
require 'compass' require 'compass'
class Generate < Thor class Generate < Thor
desc "example IDENTIFIER", "Generate a new example." desc "example IDENTIFIER [../frameworks/fmwk/stylesheets/path/to/_module.sass]", "Generate a new example."
method_options :title => :string, :framework => :string, :stylesheet => :string, :mixin => :string method_options :title => :string, :framework => :string, :stylesheet => :string, :mixin => :string
def example(identifier) def example(identifier, stylesheet = nil)
identifier = identifier.dup identifier = identifier.dup
identifier << "/" unless identifier[identifier.length - 1] == ?/ identifier << "/" unless identifier[identifier.length - 1] == ?/
identifier = identifier[1..-1] if identifier[0] == ?/ identifier = identifier[1..-1] if identifier[0] == ?/
stylesheet = stylesheet && dereference(stylesheet) || {}
options = @options.merge(stylesheet)
puts "Generating /examples/#{identifier}" puts "Generating /examples/#{identifier}"
puts "DIRECTORY content/examples/#{identifier}" puts "DIRECTORY content/examples/#{identifier}"
FileUtils.mkdir_p("content/examples/#{identifier}") FileUtils.mkdir_p("content/examples/#{identifier}")
puts " CREATE content/examples/#{identifier[0..-2]}.haml" puts " CREATE content/examples/#{identifier[0..-2]}.haml"
open("content/examples/#{identifier[0..-2]}.haml", "w") do |example_file| open("content/examples/#{identifier[0..-2]}.haml", "w") do |example_file|
mixin = "mixin: #{options[:mixin]}\n" if options[:mixin]
example_contents = <<-EXAMPLE example_contents = <<-EXAMPLE
| --- | ---
| title: Blueprint Pull Example | title: #{options[:framework].capitalize} #{options[:mixin].capitalize if options[:mixin]} Example
| description: Uses pull to change the display order of columns. | description: How to do X with Y
| framework: blueprint | framework: #{options[:framework]}
| stylesheet: blueprint/_grid.sass | stylesheet: #{options[:stylesheet]}
| mixin: pull | #{mixin}example: true
| example: true
| --- | ---
| = render "partials/example" | = render "partials/example"
EXAMPLE EXAMPLE