Sha256: 13abad6c16d67cb0070be532777e857ce104b68715676e0ee80d1e0644f34ae3

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

module Tonic
  module GhPages
    class << self

      def activate
        gh_pages
      end

      def push_pages
        if in_gh_pages_branch?
          exec 'git push -f origin gh-pages'
        else
          puts 'Forget about it bro'
        end
      end

      private

      def in_gh_pages_branch?
        branches = sh('git branch')
        branches.lines.any? { |it| it =~ /\* gh-pages/ }
      end

      def gh_pages
        if branch_exists?
          abort 'You shall no pass. First you should delete gh-pages branch'
        end

        puts 'Do you really want to create gh-pages branch with tonic? [y/n]'
        if gets.chomp =~ /y/i
          check_status
          create_branch
          remove_all_files
          Template.create
          commit_changes
        end
      end

      def branch_exists?
        branches = sh('git branch')
        branches.lines.any? { |it| it =~ /gh-pages/ }
      end

      def check_status
        unless sh('git status -s').to_s.empty?
          abort "You have uncommited changes. I don't want to you to loose it."
        end
      end

      # TODO: Later I will think about how to do it through github-gem properly
      def create_branch
        sh 'git branch gh-pages'
        sh 'git checkout gh-pages'
      end

      def remove_all_files
        sh 'rm -rf ./*'
      end

      def commit_changes
        sh "git add ."
        sh "git commit -am 'Init github pages'"
      end

      def sh(*command)
        Tonic::Shell.run(*command)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tonic-0.0.2 lib/tonic/gh_pages.rb