nanoc-git 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ .rvmrc
3
+ *.gem
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
7
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,2 @@
1
+ module NanocGit
2
+ end
@@ -0,0 +1,102 @@
1
+ require 'git'
2
+
3
+ module NanocGit::Extra::Deployers
4
+
5
+ # A class for deploying a site using git.
6
+ class Git
7
+
8
+ # Creates a new deployer that uses git. The deployment configurations
9
+ # will be read from the configuration file of the site (which is assumed
10
+ # to exist).
11
+ #
12
+ # The deployment configurations are stored like this in the site's
13
+ # configuration file:
14
+ #
15
+ # deploy:
16
+ # NAME:
17
+ # dst_remote: origin
18
+ # dst_branch: master
19
+ # src_branch: source
20
+ #
21
+ # `NAME` is a unique name for the deployment configuration. By default,
22
+ # the deployer will use the deployment configuration named `"default"`.
23
+ #
24
+ # `DST_REMOTE` is the remote repository to which you are deploying your
25
+ # site.
26
+ #
27
+ # `DST_BRANCH` is the branch to which you are deploying your compiled site.
28
+ #
29
+ # `SRC_BRANCH` is the branch that contains the source files for your site.
30
+ #
31
+ def initialize
32
+ error 'No site configuration found' unless File.file?('config.yaml')
33
+ @site = Nanoc3::Site.new('.')
34
+ end
35
+
36
+ # Runs the task. Possible params:
37
+ #
38
+ # @option params [String] :config_name (:default) The name of the
39
+ # deployment configuration to use.
40
+ #
41
+ # @return [void]
42
+ def run(params={})
43
+ config_name = params.has_key?(:config_name) ? params[:config_name].to_sym : :default
44
+
45
+ # Validate config
46
+ error 'No deploy configuration found' if @site.config[:deploy].nil?
47
+ error "No deploy configuration found for #{config_name}" if @site.config[:deploy][config_name].nil?
48
+
49
+ src_branch = @site.config[:deploy][config_name][:src_branch]
50
+ dst_branch = @site.config[:deploy][config_name][:dst_branch]
51
+ dst_remote = @site.config[:deploy][config_name][:dst_remote]
52
+
53
+ error 'No source branch found in deployment configuration' if src_branch.nil?
54
+ error 'No destination branch found in deployment configuration' if dst_branch.nil?
55
+ error 'No destination remote found in deployment configuration' if dst_remote.nil?
56
+
57
+ git = ::Git::Base.open('.')
58
+
59
+ # Compile the site from scratch
60
+ Nanoc3::Tasks::Clean.new(@site).run
61
+
62
+ # Check out the source branch
63
+ puts "Checking out #{src_branch}."
64
+ git.checkout(src_branch)
65
+
66
+ # Compile the site from scratch
67
+ puts "Compiling site."
68
+ @site.load_data
69
+ @site.compiler.run
70
+
71
+ # Check out the destination branch
72
+ puts "Checking out destination branch."
73
+ git.checkout(dst_branch)
74
+
75
+ # Copy output files recursively into the current directory
76
+ puts "Copying files."
77
+ FileUtils.cp_r(@site.config[:output_dir].chomp('/') + '/.', '.')
78
+
79
+ # Automatically add and commit changes
80
+ puts "Committing changes."
81
+ git.add
82
+ git.commit("updated #{Time.now.to_s}", :add_all => true)
83
+
84
+ # Push changes to the destination repo/branch
85
+ puts "Pushing to #{dst_remote} #{dst_branch}."
86
+ git.push(dst_remote, dst_branch)
87
+
88
+ # Switch back to the source branch
89
+ puts "Checking out #{src_branch}."
90
+ git.checkout(src_branch)
91
+ end
92
+
93
+ private
94
+
95
+ # Prints the given message on stderr and exits.
96
+ def error(msg)
97
+ raise RuntimeError.new(msg)
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::Extra
4
+ module Deployers
5
+ autoload 'Git', 'nanoc-git/extra/deployers/git'
6
+ end
7
+ end
File without changes
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ namespace :deploy do
4
+ desc 'Upload the compiled site using git'
5
+ task :git do
6
+ config_name = ENV['config'] || :default
7
+
8
+ deployer = NanocGit::Extra::Deployers::Git.new
9
+ deployer.run(:config_name => config_name)
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ require 'nanoc-git'
4
+ require 'rake'
5
+
6
+ module NanocGit::Tasks
7
+ end
8
+
9
+ Dir[File.dirname(__FILE__) + '/tasks/**/*.rb'].each { |f| load f }
10
+ Dir[File.dirname(__FILE__) + '/tasks/**/*.rake'].each { |f| Rake.application.add_import(f) }
data/nanoc-git.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = 'nanoc-git'
4
+ s.version = '0.0.1'
5
+ s.authors = ["Cameron Spickert"]
6
+ s.email = ["cspicker@gmail.com"]
7
+ s.homepage = "https://github.com/cspicker/nanoc-git"
8
+ s.summary = "A Nanoc3 deployer for git"
9
+ s.description = "A Nanoc3 extension that adds a Git deployer and associated rake task."
10
+
11
+ s.rubyforge_project = "nanoc-git"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_runtime_dependency('nanoc', '>= 3.1.6')
19
+ s.add_runtime_dependency('git', '>= 1.2.5')
20
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Cameron Spickert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-01 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nanoc
17
+ requirement: &2152316460 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.1.6
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2152316460
26
+ - !ruby/object:Gem::Dependency
27
+ name: git
28
+ requirement: &2152315980 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2152315980
37
+ description: A Nanoc3 extension that adds a Git deployer and associated rake task.
38
+ email:
39
+ - cspicker@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - lib/nanoc-git/base.rb
47
+ - lib/nanoc-git/extra.rb
48
+ - lib/nanoc-git/extra/deployers.rb
49
+ - lib/nanoc-git/extra/deployers/git.rb
50
+ - lib/nanoc-git/tasks.rb
51
+ - lib/nanoc-git/tasks/deploy/git.rake
52
+ - nanoc-git.gemspec
53
+ has_rdoc: true
54
+ homepage: https://github.com/cspicker/nanoc-git
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project: nanoc-git
74
+ rubygems_version: 1.6.2
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: A Nanoc3 deployer for git
78
+ test_files: []