From a11c07bd5fb8d7b2af1d779dd40370a3891538ba Mon Sep 17 00:00:00 2001 From: Adam Williams Date: Thu, 22 Dec 2011 23:23:36 -0500 Subject: [PATCH] A bit more thinking. We are going to need to understand themes a lot sooner than I thought. --- octopress/Gemfile.lock | 20 +++++++++++ octopress/features/create.feature | 6 ++-- .../step_definitions/octopress_steps.rb | 8 ++++- octopress/lib/octopress/commands/create.rb | 8 +---- octopress/lib/octopress/plugins/titlecase.rb | 36 +++++++++++++++++++ octopress/lib/octopress/template/Gemfile | 17 ++++++++- octopress/lib/octopress/template/_config.yml | 0 .../octopress/template/_plugins/octopress.rb | 9 +++++ octopress/octopress.gemspec | 1 + 9 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 octopress/lib/octopress/plugins/titlecase.rb create mode 100644 octopress/lib/octopress/template/_config.yml create mode 100644 octopress/lib/octopress/template/_plugins/octopress.rb diff --git a/octopress/Gemfile.lock b/octopress/Gemfile.lock index 3f5b1a0..fb58e71 100644 --- a/octopress/Gemfile.lock +++ b/octopress/Gemfile.lock @@ -3,10 +3,13 @@ PATH specs: octopress (0.0.1) gli (~> 1.4.0) + jekyll (~> 0.11.0) GEM remote: http://rubygems.org/ specs: + albino (1.3.3) + posix-spawn (>= 0.3.6) aruba (0.4.9) childprocess (>= 0.2.3) cucumber (>= 1.1.1) @@ -15,6 +18,8 @@ GEM builder (3.0.0) childprocess (0.2.3) ffi (~> 1.0.6) + classifier (1.3.3) + fast-stemmer (>= 1.0.0) cucumber (1.1.4) builder (>= 2.1.2) diff-lcs (>= 1.1.2) @@ -22,11 +27,25 @@ GEM json (>= 1.4.6) term-ansicolor (>= 1.0.6) diff-lcs (1.1.3) + directory_watcher (1.4.1) + fast-stemmer (1.0.0) ffi (1.0.11) gherkin (2.7.1) json (>= 1.4.6) gli (1.4.0) + jekyll (0.11.0) + albino (>= 1.3.2) + classifier (>= 1.3.1) + directory_watcher (>= 1.1.1) + kramdown (>= 0.13.2) + liquid (>= 1.9.0) + maruku (>= 0.5.9) json (1.6.3) + kramdown (0.13.4) + liquid (2.3.0) + maruku (0.6.0) + syntax (>= 1.0.0) + posix-spawn (0.3.6) rake (0.9.2.2) rdoc (3.11) json (~> 1.4) @@ -38,6 +57,7 @@ GEM rspec-expectations (2.7.0) diff-lcs (~> 1.1.2) rspec-mocks (2.7.0) + syntax (1.0.0) term-ansicolor (1.0.7) PLATFORMS diff --git a/octopress/features/create.feature b/octopress/features/create.feature index f2e5dc4..b6049fc 100644 --- a/octopress/features/create.feature +++ b/octopress/features/create.feature @@ -2,16 +2,16 @@ Feature: create subcommand In order to make blogs for hackers As a hacker using the octopress executable - I want to generate a blog from a template + I want to create a blog from a template Scenario: No flags, switches or arguments When I successfully run `octopress create` - Then the octopress blog files should exist + Then an empty project structure 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 + Then an empty project structure should exist Scenario: directory exists diff --git a/octopress/features/step_definitions/octopress_steps.rb b/octopress/features/step_definitions/octopress_steps.rb index dcc9a56..3d6e83b 100644 --- a/octopress/features/step_definitions/octopress_steps.rb +++ b/octopress/features/step_definitions/octopress_steps.rb @@ -1,7 +1,13 @@ -Then /the octopress blog files should exist/ do +Then /an empty project structure should exist/ do + check_directory_presence(%w( + _plugins + ), true) + check_file_presence(%w( .rvmrc .rbenv-version + _config.yml Gemfile + _plugins/octopress.rb ), true) end diff --git a/octopress/lib/octopress/commands/create.rb b/octopress/lib/octopress/commands/create.rb index d8a15da..4f0ccb3 100644 --- a/octopress/lib/octopress/commands/create.rb +++ b/octopress/lib/octopress/commands/create.rb @@ -4,16 +4,10 @@ class Octopress::Commands::Create 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 + cp_r File.join(@template_root, '.'), @project_root end end diff --git a/octopress/lib/octopress/plugins/titlecase.rb b/octopress/lib/octopress/plugins/titlecase.rb new file mode 100644 index 0000000..7648932 --- /dev/null +++ b/octopress/lib/octopress/plugins/titlecase.rb @@ -0,0 +1,36 @@ +class String + def titlecase + small_words = %w(a an and as at but by en for if in of on or the to v v. via vs vs.) + + x = split(" ").map do |word| + # note: word could contain non-word characters! + # downcase all small_words, capitalize the rest + small_words.include?(word.gsub(/\W/, "").downcase) ? word.downcase! : word.smart_capitalize! + word + end + # capitalize first and last words + x.first.to_s.smart_capitalize! + x.last.to_s.smart_capitalize! + # small words are capitalized after colon, period, exclamation mark, question mark + x.join(" ").gsub(/(:|\.|!|\?)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{$2.smart_capitalize} " } + end + + def titlecase! + replace(titlecase) + end + + def smart_capitalize + # ignore any leading crazy characters and capitalize the first real character + if self =~ /^['"\(\[']*([a-z])/ + i = index($1) + x = self[i,self.length] + # word with capitals and periods mid-word are left alone + self[i,1] = self[i,1].upcase unless x =~ /[A-Z]/ or x =~ /\.\w+/ + end + self + end + + def smart_capitalize! + replace(smart_capitalize) + end +end diff --git a/octopress/lib/octopress/template/Gemfile b/octopress/lib/octopress/template/Gemfile index a87b4df..b347c59 100644 --- a/octopress/lib/octopress/template/Gemfile +++ b/octopress/lib/octopress/template/Gemfile @@ -1,2 +1,17 @@ source 'http://rubygems.org' -gem 'compass' + +# The gems you'll need for generating your site on your development machine. +# The deployment strategy you use determines what you need in production, if +# anything. +# +group :development do + gem 'jekyll', '~> 0.11.0' + gem 'compass', '~> 0.11.0' +end + +# If your deployment target has you running Ruby, you might have some gems +# listed here. This will be the case if you deploy to Heroku. +# +group :production do + +end diff --git a/octopress/lib/octopress/template/_config.yml b/octopress/lib/octopress/template/_config.yml new file mode 100644 index 0000000..e69de29 diff --git a/octopress/lib/octopress/template/_plugins/octopress.rb b/octopress/lib/octopress/template/_plugins/octopress.rb new file mode 100644 index 0000000..fda6fcd --- /dev/null +++ b/octopress/lib/octopress/template/_plugins/octopress.rb @@ -0,0 +1,9 @@ +# Files in this directory are loaded by Jekyll. Learn more at +# https://github.com/mojombo/jekyll/wiki/Plugins. + +# The Title Case plugin adds some handy String methods: +# +# "my string".titlecase -> "My String" +# "my string".smart_capitalize -> "???" +# +# require 'octopress/plugins/titlecase' diff --git a/octopress/octopress.gemspec b/octopress/octopress.gemspec index f4aa9a1..df6b4b4 100644 --- a/octopress/octopress.gemspec +++ b/octopress/octopress.gemspec @@ -18,6 +18,7 @@ bin/octopress s.bindir = 'bin' s.executables << 'octopress' s.add_dependency('gli', '~> 1.4.0') + s.add_dependency('jekyll', '~> 0.11.0') s.add_development_dependency('rake') s.add_development_dependency('rdoc') s.add_development_dependency('aruba', '~> 0.4.9')