From 571704322dfddd332743ff59d3c5899ce2474012 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Mon, 26 May 2014 19:55:25 -0700 Subject: [PATCH] Load templates from Git --- middleman-cli/lib/middleman-cli.rb | 3 ++ middleman-cli/lib/middleman-cli/git.rb | 52 ++++++++++++++++++++++++++ middleman-cli/middleman-cli.gemspec | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 middleman-cli/lib/middleman-cli/git.rb diff --git a/middleman-cli/lib/middleman-cli.rb b/middleman-cli/lib/middleman-cli.rb index e49df2f9..fa8a4b0f 100644 --- a/middleman-cli/lib/middleman-cli.rb +++ b/middleman-cli/lib/middleman-cli.rb @@ -32,6 +32,8 @@ module Middleman say "Middleman #{Middleman::VERSION}" end + desc 'help', 'Show help' + # Override the Thor help method to find help for subtasks # @param [Symbol, String, nil] meth # @param [Boolean] subcommand @@ -92,3 +94,4 @@ require 'middleman-cli/extension' require 'middleman-cli/server' require 'middleman-cli/build' require 'middleman-cli/console' +require 'middleman-cli/git' diff --git a/middleman-cli/lib/middleman-cli/git.rb b/middleman-cli/lib/middleman-cli/git.rb new file mode 100644 index 00000000..b8d512e0 --- /dev/null +++ b/middleman-cli/lib/middleman-cli/git.rb @@ -0,0 +1,52 @@ +# CLI Module +module Middleman::Cli + # A thor task for creating new projects + class Git < Thor + include Thor::Actions + check_unknown_options! + + namespace :git + + desc 'git REPO TARGET [options]', 'Create new project from REPO at TARGET' + + # Do not run bundle install + method_option 'skip-bundle', + type: :boolean, + aliases: '-B', + default: false, + desc: "Don't run bundle install" + + # The git task + # @param [String] name + def git(repo, target='.') + require 'rugged' + require 'tmpdir' + + path = repository_path(repo) + + Dir.mktmpdir do |dir| + Rugged::Repository.clone_at(path, dir) + + source_paths << dir + + directory dir, target, exclude_pattern: /\.git\/|\.gitignore$/ + + inside(target) do + run('bundle install') + end unless ENV['TEST'] || options[:'skip-bundle'] + end + end + + protected + + def repository_path(repo) + "git://github.com/#{repo}.git" + end + end + + def self.exit_on_failure? + true + end + + Base.map('g' => 'git') +end diff --git a/middleman-cli/middleman-cli.gemspec b/middleman-cli/middleman-cli.gemspec index 8102ed15..5a2fde18 100644 --- a/middleman-cli/middleman-cli.gemspec +++ b/middleman-cli/middleman-cli.gemspec @@ -23,5 +23,5 @@ Gem::Specification.new do |s| s.add_dependency('thor', ['>= 0.17.0', '< 2.0']) # Templates - s.add_dependency('octokit', ['~> 3.1']) + s.add_dependency('rugged', []) end