mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-10-31 23:35:00 -04:00
Downloading theme-classic for default behavior of create command.
This commit is contained in:
parent
dc85be2ff6
commit
c6f194fb1e
@ -2,16 +2,16 @@ Feature: create subcommand
|
|||||||
|
|
||||||
In order to make blogs for hackers
|
In order to make blogs for hackers
|
||||||
As a hacker using the octopress executable
|
As a hacker using the octopress executable
|
||||||
I want to create a blog from a template
|
I want to create a blog using a theme
|
||||||
|
|
||||||
Scenario: No flags, switches or arguments
|
Scenario: No flags, switches or arguments
|
||||||
When I successfully run `octopress create`
|
When I successfully run `octopress create`
|
||||||
Then an empty project structure should exist
|
Then a theme-classic project structure should exist
|
||||||
|
|
||||||
Scenario: Path argument provided
|
Scenario: Path argument provided
|
||||||
When I successfully run `octopress create pathto/myblog`
|
When I successfully run `octopress create pathto/myblog`
|
||||||
Then a directory named "pathto/myblog" should exist
|
Then a directory named "pathto/myblog" should exist
|
||||||
When I cd to "pathto/myblog"
|
When I cd to "pathto/myblog"
|
||||||
Then an empty project structure should exist
|
Then a theme-classic project structure should exist
|
||||||
|
|
||||||
Scenario: directory exists
|
Scenario: directory exists
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
Then /an empty project structure should exist/ do
|
Then /a theme-classic project structure should exist/ do
|
||||||
|
|
||||||
|
# Basic project structure
|
||||||
check_directory_presence(%w(
|
check_directory_presence(%w(
|
||||||
_plugins
|
_plugins
|
||||||
|
_posts
|
||||||
), true)
|
), true)
|
||||||
|
|
||||||
check_file_presence(%w(
|
check_file_presence(%w(
|
||||||
@ -8,6 +11,25 @@ Then /an empty project structure should exist/ do
|
|||||||
.rbenv-version
|
.rbenv-version
|
||||||
_config.yml
|
_config.yml
|
||||||
Gemfile
|
Gemfile
|
||||||
_plugins/octopress.rb
|
|
||||||
), true)
|
), true)
|
||||||
|
|
||||||
|
# Classic theme files
|
||||||
|
check_directory_presence(%w(
|
||||||
|
_includes
|
||||||
|
_layouts
|
||||||
|
_sass
|
||||||
|
assets
|
||||||
|
blog
|
||||||
|
images
|
||||||
|
javascripts
|
||||||
|
), true)
|
||||||
|
|
||||||
|
check_file_presence(%w(
|
||||||
|
blog/archives/index.html
|
||||||
|
atom.xml
|
||||||
|
favicon.png
|
||||||
|
index.html
|
||||||
|
_sass/screen.scss
|
||||||
|
), true)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1 +1,5 @@
|
|||||||
require 'aruba/cucumber'
|
require 'aruba/cucumber'
|
||||||
|
|
||||||
|
Before do
|
||||||
|
@aruba_timeout_seconds = 10
|
||||||
|
end
|
||||||
|
@ -1,13 +1,62 @@
|
|||||||
|
require 'fileutils'
|
||||||
|
|
||||||
class Octopress::Commands::Create
|
class Octopress::Commands::Create
|
||||||
include FileUtils
|
|
||||||
|
|
||||||
def initialize(project_path)
|
def initialize(project_path)
|
||||||
@project_root = File.expand_path project_path
|
@project_root = File.expand_path project_path
|
||||||
|
@project_tmp = File.join @project_root, 'tmp'
|
||||||
@template_root = Octopress.template_root
|
@template_root = Octopress.template_root
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
mkdir_p @project_root
|
FileUtils.mkdir_p @project_root
|
||||||
cp_r File.join(@template_root, '.'), @project_root
|
FileUtils.cp_r File.join(@template_root, '.'), @project_root
|
||||||
|
FileUtils.mkdir File.join(@project_root, '_posts')
|
||||||
|
zip_file_path = download 'https://github.com/octopress/theme-classic/zipball/master', 'theme-classic.zip'
|
||||||
|
unzip zip_file_path, @project_tmp
|
||||||
|
extracted_root = Dir[File.join(@project_tmp, 'octopress-theme-classic-*')].first
|
||||||
|
FileUtils.cp_r Dir.glob(File.join(extracted_root, '*')), @project_root
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read_url(url, &block)
|
||||||
|
require 'net/http'
|
||||||
|
success_response, limit, tries = false, 5, 0
|
||||||
|
uri = URI(url)
|
||||||
|
until success_response || tries == limit
|
||||||
|
tries += 1
|
||||||
|
Net::HTTP.start(uri.host, uri.port, use_ssl:(uri.scheme == 'https')) do |http|
|
||||||
|
http.request_get(uri.path) { |response|
|
||||||
|
case response
|
||||||
|
when Net::HTTPRedirection
|
||||||
|
success_response = false
|
||||||
|
uri = URI(response['location'])
|
||||||
|
when Net::HTTPSuccess
|
||||||
|
success_response = true
|
||||||
|
block.call response
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def download(url, filename)
|
||||||
|
FileUtils.mkdir_p @project_tmp
|
||||||
|
File.join(@project_tmp, filename).tap do |download_path|
|
||||||
|
File.open(download_path, 'w') do |f|
|
||||||
|
read_url(url) { |resp| resp.read_body { |segment| f.write(segment) } }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def unzip(file, destination)
|
||||||
|
require 'zip/zip'
|
||||||
|
Zip::ZipFile.open(file) do |zip_file|
|
||||||
|
zip_file.each do |f|
|
||||||
|
f_path = File.join(destination, f.name)
|
||||||
|
FileUtils.mkdir_p File.dirname(f_path)
|
||||||
|
zip_file.extract f, f_path unless File.exist?(f_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,9 @@ bin/octopress
|
|||||||
s.executables << 'octopress'
|
s.executables << 'octopress'
|
||||||
s.add_dependency('gli', '~> 1.4.0')
|
s.add_dependency('gli', '~> 1.4.0')
|
||||||
s.add_dependency('jekyll', '~> 0.11.0')
|
s.add_dependency('jekyll', '~> 0.11.0')
|
||||||
|
s.add_dependency('rubyzip', '~> 0.9.5')
|
||||||
s.add_development_dependency('rake')
|
s.add_development_dependency('rake')
|
||||||
s.add_development_dependency('rdoc')
|
s.add_development_dependency('rdoc')
|
||||||
s.add_development_dependency('aruba', '~> 0.4.9')
|
s.add_development_dependency('fakefs')
|
||||||
|
s.add_development_dependency('aruba', '0.4.10')
|
||||||
end
|
end
|
||||||
|
16
octopress/spec/octopress/commands/create_spec.rb
Normal file
16
octopress/spec/octopress/commands/create_spec.rb
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Octopress::Commands::Create do
|
||||||
|
include FakeFS::SpecHelpers
|
||||||
|
|
||||||
|
let(:project_path) { File.expand_path File.join('tmp', 'create') }
|
||||||
|
|
||||||
|
subject { described_class.new(project_path) }
|
||||||
|
|
||||||
|
it 'downloads to tmp location in project_path' do
|
||||||
|
download_path = subject.download 'https://github.com/octopress/theme-classic/zipball/master', 'theme-classic.zip'
|
||||||
|
download_path.should == File.join(project_path, 'tmp', 'theme-classic.zip')
|
||||||
|
File.exists?(download_path).should be_true
|
||||||
|
File.size(download_path).should > 0
|
||||||
|
end
|
||||||
|
end
|
2
octopress/spec/spec_helper.rb
Normal file
2
octopress/spec/spec_helper.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
require 'fakefs/spec_helpers'
|
||||||
|
require 'octopress'
|
Loading…
Reference in New Issue
Block a user