Class: Mdpresent::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/mdpresent/github.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#githubObject

Returns the value of attribute github.



4
5
6
# File 'lib/mdpresent/github.rb', line 4

def github
  @github
end

Class Method Details

.create_gh_pages_branchObject



27
28
29
# File 'lib/mdpresent/github.rb', line 27

def create_gh_pages_branch
  Command.execute I18n.t("commands.github.create_gh_pages")
end

.deployObject



45
46
47
48
49
50
# File 'lib/mdpresent/github.rb', line 45

def deploy
  Command.execute I18n.t("commands.github.switch_to_gh_page")
  Command.execute I18n.t("commands.github.merge_master")
  Command.execute I18n.t("commands.github.switch_to_master")
  Command.execute I18n.t("commands.github.push_gh_pages_to_github")
end

.make_initial_commitObject



21
22
23
24
25
# File 'lib/mdpresent/github.rb', line 21

def make_initial_commit
  success = true
  success &&= Command.execute I18n.t("commands.git.initial_add")
  success &&= Command.execute I18n.t("commands.git.initial_commit", date_time: Time.now)
end

.openObject



52
53
54
55
56
# File 'lib/mdpresent/github.rb', line 52

def open
  url = `git config --get remote.origin.url`
  user_name, repo_name = url.strip.match(/http:\/\/github.com\/(.*)\/(.*)/).captures
  Launchy.open("http://#{user_name}.github.com/#{repo_name}")
end

.setupObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mdpresent/github.rb', line 7

def setup
  Git.setup_git
  # setup the repo if not already set
  setup_repo unless Git.origin_remote_present?

  success = make_initial_commit

  abort "Aborting..git add was unsucessful" unless success

  create_gh_pages_branch unless Git.gh_pages_branch_present?

  Command.execute I18n.t("commands.git.checkout_master")
end

.setup_repoObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mdpresent/github.rb', line 31

def setup_repo

  print "Enter your github username: "
  user_name = $stdin.gets
  print "Enter the repo name: "
  repo_name = $stdin.gets

  # add remote to git
  unless user_name.nil? || user_name.empty? || repo_name.nil? || repo_name.empty?
    success = Git.git_add_remote(user_name, repo_name)
    fail("unable to add git remote") unless success
  end
end