conflicts in the .gitignore preventing to add the unzip.rb file
did
committed Feb 08, 2013
commit de0bd17ad50cbbcf6526371e803710463dcf0bcf
Showing 3
changed files with
82 additions
and 5 deletions
.gitignore
+0
-4
| @@ | @@ -1,12 +1,8 @@ |
| .DS_Store | |
| - | <<<<<<< HEAD |
| - | site |
| tests | |
| .sass-cache | |
| .rbenv-gemsets | |
| - | ======= |
| /site | |
| - | >>>>>>> wip |
| *.gem | |
| *.rbc | |
| .bundle | |
locomotive/builder/generators/site/unzip.rb b/lib/locomotive/builder/generators/site/unzip.rb
+81
-0
| @@ | @@ -0,0 +1,81 @@ |
| + | require 'open-uri' |
| + | require 'zip/zipfilesystem' |
| + | |
| + | module Locomotive |
| + | module Builder |
| + | module Generators |
| + | module Site |
| + | |
| + | class Unzip < Base |
| + | |
| + | def prepare |
| + | remove_file join('tmp') |
| + | empty_directory join('tmp') |
| + | end |
| + | |
| + | def ask_for_location |
| + | @location = ask('What is the location (on the filesystem or url) of the zip file ?') |
| + | raise GeneratorException.new('Please enter a location') if @location.blank? |
| + | end |
| + | |
| + | def download_or_copy |
| + | @template_path = join('tmp', File.basename(@location)) |
| + | |
| + | if @location =~ /^https?:\/\// |
| + | say "downloading...#{@location}" |
| + | create_file @template_path, open(@location).read |
| + | else |
| + | say "copying...#{@location}" |
| + | create_file @template_path, open(@location, 'rb') { |io| io.read } |
| + | end |
| + | end |
| + | |
| + | def unzip |
| + | say "unzipping...#{@template_path}" |
| + | |
| + | begin |
| + | Zip::ZipFile.open(@template_path) do |zipfile| |
| + | zipfile.each do |file| |
| + | next if file.name =~ /^__MACOSX/ |
| + | zipfile.extract(file, join('tmp', file.name)) |
| + | |
| + | @path = $1 if file.name =~ /(.*)\/config\/site.yml$/ |
| + | end |
| + | end |
| + | rescue Exception => e |
| + | raise GeneratorException.new("Unable to unzip the archive") |
| + | end |
| + | |
| + | raise GeneratorException.new('Not a valid LocomotiveCMS site') if @path.blank? |
| + | end |
| + | |
| + | def copy_sources |
| + | self.class.source_root = File.expand_path(join('tmp', @path, '/')) |
| + | say "copying files from #{self.class.source_root} / #{self.destination}" |
| + | directory('.', self.destination, { recursive: true }) |
| + | end |
| + | |
| + | def self.source_root |
| + | # only way to change the source root from the instance |
| + | @@source_root |
| + | end |
| + | |
| + | def self.source_root=(value) |
| + | @@source_root = value |
| + | end |
| + | |
| + | protected |
| + | |
| + | def join(*args) |
| + | File.join(self.destination, *args) |
| + | end |
| + | |
| + | end |
| + | |
| + | Locomotive::Builder::Generators::Site.register(:unzip, Unzip, %{ |
| + | Unzip a local or remote (http, https, ftp) zipped LocomotiveCMS site. |
| + | }) |
| + | end |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
locomotive/builder/version.rb b/lib/locomotive/builder/version.rb
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| module Locomotive | |
| module Builder | |
| - | VERSION = '1.0.0.alpha7' |
| + | VERSION = '1.0.0.alpha8' |
| end | |
| end | |