From 94456bec3fe0c38584029efdfd955d3d248e2dc2 Mon Sep 17 00:00:00 2001 From: Adam Williams Date: Wed, 21 Dec 2011 12:38:38 -0500 Subject: [PATCH] Learned a lot, with create structured nicely. --- octopress/TODO.txt | 47 +++++++++++++++++++ octopress/bin/octopress | 8 +--- octopress/features/create.feature | 18 +++++-- .../step_definitions/octopress_steps.rb | 7 +++ octopress/lib/octopress.rb | 8 ++++ octopress/lib/octopress/commands.rb | 4 ++ octopress/lib/octopress/commands/create.rb | 19 ++++++++ .../lib/octopress/template/.rbenv-version | 1 + octopress/lib/octopress/template/.rvmrc | 1 + octopress/lib/octopress/template/Gemfile | 2 + .../version.rb} | 0 octopress/octopress.gemspec | 2 +- 12 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 octopress/features/step_definitions/octopress_steps.rb create mode 100644 octopress/lib/octopress.rb create mode 100644 octopress/lib/octopress/commands.rb create mode 100644 octopress/lib/octopress/commands/create.rb create mode 100644 octopress/lib/octopress/template/.rbenv-version create mode 100644 octopress/lib/octopress/template/.rvmrc create mode 100644 octopress/lib/octopress/template/Gemfile rename octopress/lib/{octopress_version.rb => octopress/version.rb} (100%) diff --git a/octopress/TODO.txt b/octopress/TODO.txt index a725a75..bae6729 100644 --- a/octopress/TODO.txt +++ b/octopress/TODO.txt @@ -1,3 +1,50 @@ +octopress create + + +------------------------------- +********************************************************************* +Congratulations! Your compass project has been created. + +You may now add and edit sass stylesheets in the sass subdirectory of your project. + +Sass files beginning with an underscore are called partials and won't be +compiled to CSS, but they can be imported into other sass stylesheets. + +You can configure your project by editing the config.rb configuration file. + +You must compile your sass stylesheets into CSS when they change. +This can be done in one of the following ways: + 1. To compile on demand: + compass compile [path/to/project] + 2. To monitor your project for changes and automatically recompile: + compass watch [path/to/project] + +More Resources: + * Website: http://compass-style.org/ + * Sass: http://sass-lang.com + * Community: http://groups.google.com/group/compass-users/ + + +To import your new stylesheets add the following lines of HTML (or equivalent) to your webpage: + + + + + + + + + + + + + + + + + octopress --global-option command -d myblog octopress --path /my/blog post --option new "Hello" diff --git a/octopress/bin/octopress b/octopress/bin/octopress index 971d838..3bc7309 100755 --- a/octopress/bin/octopress +++ b/octopress/bin/octopress @@ -3,7 +3,7 @@ $: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib') require 'rubygems' require 'gli' -require 'octopress_version' +require 'octopress' include GLI @@ -29,11 +29,7 @@ command :create do |c| c.default_value 'default' c.flag :f c.action do |global_options,options,args| - puts "Hello!" - # Your command logic here - - # If you have any errors, just raise them - # raise "that command made no sense" + Octopress::Commands::Create.new(args[0] || '.').execute end end diff --git a/octopress/features/create.feature b/octopress/features/create.feature index 7726a46..f2e5dc4 100644 --- a/octopress/features/create.feature +++ b/octopress/features/create.feature @@ -1,5 +1,17 @@ -Feature: Create a new Octopress Blog +Feature: create subcommand - Scenario: create with no flags, switches or arguments + In order to make blogs for hackers + As a hacker using the octopress executable + I want to generate a blog from a template + + Scenario: No flags, switches or arguments When I successfully run `octopress create` - Then the stdout should contain "Hello!" + Then the octopress blog files should exist + + Scenario: Path argument provided + When I successfully run `octopress create pathto/myblog` + Then a directory named "pathto/myblog" should exist + When I cd to "pathto/myblog" + Then the octopress blog files should exist + + Scenario: directory exists diff --git a/octopress/features/step_definitions/octopress_steps.rb b/octopress/features/step_definitions/octopress_steps.rb new file mode 100644 index 0000000..dcc9a56 --- /dev/null +++ b/octopress/features/step_definitions/octopress_steps.rb @@ -0,0 +1,7 @@ +Then /the octopress blog files should exist/ do + check_file_presence(%w( + .rvmrc + .rbenv-version + Gemfile + ), true) +end diff --git a/octopress/lib/octopress.rb b/octopress/lib/octopress.rb new file mode 100644 index 0000000..533f6ba --- /dev/null +++ b/octopress/lib/octopress.rb @@ -0,0 +1,8 @@ +module Octopress + def Octopress.template_root + File.join File.expand_path(File.dirname(__FILE__)), 'octopress', 'template' + end +end + +require 'octopress/version' +require 'octopress/commands' diff --git a/octopress/lib/octopress/commands.rb b/octopress/lib/octopress/commands.rb new file mode 100644 index 0000000..ca1aa50 --- /dev/null +++ b/octopress/lib/octopress/commands.rb @@ -0,0 +1,4 @@ +module Octopress::Commands +end + +require 'octopress/commands/create' diff --git a/octopress/lib/octopress/commands/create.rb b/octopress/lib/octopress/commands/create.rb new file mode 100644 index 0000000..d8a15da --- /dev/null +++ b/octopress/lib/octopress/commands/create.rb @@ -0,0 +1,19 @@ +class Octopress::Commands::Create + include FileUtils + + def initialize(project_path) + @project_root = File.expand_path project_path + @template_root = Octopress.template_root + puts @template_root + end + + def execute + mkdir_p @project_root + Dir.glob(File.join(@template_root, '*'), File::FNM_DOTMATCH).each do |template_path| + basename = File.basename template_path + next if %w(. ..).include?(basename) + puts "File: #{basename}" + cp template_path, @project_root + end + end +end diff --git a/octopress/lib/octopress/template/.rbenv-version b/octopress/lib/octopress/template/.rbenv-version new file mode 100644 index 0000000..0a95b9f --- /dev/null +++ b/octopress/lib/octopress/template/.rbenv-version @@ -0,0 +1 @@ +1.9.2-p290 diff --git a/octopress/lib/octopress/template/.rvmrc b/octopress/lib/octopress/template/.rvmrc new file mode 100644 index 0000000..35845a2 --- /dev/null +++ b/octopress/lib/octopress/template/.rvmrc @@ -0,0 +1 @@ +rvm use 1.9.2 diff --git a/octopress/lib/octopress/template/Gemfile b/octopress/lib/octopress/template/Gemfile new file mode 100644 index 0000000..a87b4df --- /dev/null +++ b/octopress/lib/octopress/template/Gemfile @@ -0,0 +1,2 @@ +source 'http://rubygems.org' +gem 'compass' diff --git a/octopress/lib/octopress_version.rb b/octopress/lib/octopress/version.rb similarity index 100% rename from octopress/lib/octopress_version.rb rename to octopress/lib/octopress/version.rb diff --git a/octopress/octopress.gemspec b/octopress/octopress.gemspec index d51e541..f4aa9a1 100644 --- a/octopress/octopress.gemspec +++ b/octopress/octopress.gemspec @@ -1,5 +1,5 @@ # Ensure we require the local version and not one we might have installed already -require File.join([File.dirname(__FILE__),'lib','octopress_version.rb']) +require File.join([File.dirname(__FILE__),'lib','octopress','version.rb']) spec = Gem::Specification.new do |s| s.name = 'octopress' s.version = Octopress::VERSION