Class: Detroit::GitHub

Inherits:
Tool
  • Object
show all
Includes:
Standard
Defined in:
lib/detroit-github.rb

Overview

Note:

This tool is useless unless your project is hosted on GitHub!

GitHub tool provides services for working with your project’s github repository.

Currently it only supports gh-pages publishing.

The following stations of the standard toolchain are targeted:

  • prepare

  • publish

  • clean

Constant Summary collapse

MANPAGE =

Location of manpage for tool.

File.dirname(__FILE__)+'/../man/detroit-github.5'
PAGES_BRANCH =
"gh-pages"
DEFAULT_FOLDER =

The project directory to store the gh-pages git repo.

"web"
DEFAULT_REMOTE =

Default remote name.

"origin"
DEFAULT_MESSAGE =

Default commit message.

"Update pages via Detroit."

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#branchObject (readonly)

The repository branch (ALWAYS “gh-pages”).



96
97
98
# File 'lib/detroit-github.rb', line 96

def branch
  @branch
end

#folderObject

Pages folder to use (defaults to ‘pages’).



59
60
61
# File 'lib/detroit-github.rb', line 59

def folder
  @folder
end

#messageObject

Commit message.



56
57
58
# File 'lib/detroit-github.rb', line 56

def message
  @message
end

#remoteObject

The remote to use (defaults to ‘origin’).



53
54
55
# File 'lib/detroit-github.rb', line 53

def remote
  @remote
end

Instance Method Details

#assemble?(station, options = {}) ⇒ Boolean

This tool ties into the ‘prepare`, `publish` and `clean` stations of the standard assembly.

Returns:

  • (Boolean)


161
162
163
164
165
166
# File 'lib/detroit-github.rb', line 161

def assemble?(station, options={})
  return true if station == :prepare
  return true if station == :publish
  return true if station == :purge
  return false
end

#clean(: station_clean(opts = {})) ⇒ Object



144
145
146
# File 'lib/detroit-github.rb', line 144

def clean
  rm_r File.join(Dir.tmpdir, 'detroit', 'github')
end

#keep=(entries) ⇒ Object

Set keep list.



86
87
88
89
90
91
92
93
# File 'lib/detroit-github.rb', line 86

def keep=(entries)
  case entries
  when String
    @keep = [entries.to_str]
  else
    @keep = entries
  end
end

#prepare(: station_publish(opts = {})) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/detroit-github.rb', line 149

def prepare
  return if child

  if File.exist?(pgdir)
    abort "Can't setup gh-pages at #{folder}. Directory already exists."
  end

  # does the master repo have a gh-pages branch?
  new = !master.branches.find{ |b| b.name == branch }

  if new
    create_branch
  else
    clone_branch
  end

  update_gitignore
end

#prepare?Boolean

We do not need to prepare if gh_pages directory is already created.

Returns:

  • (Boolean)


119
120
121
# File 'lib/detroit-github.rb', line 119

def prepare?
  !child
end

#prerequisiteObject



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

def prerequisite
  @branch  = PAGES_BRANCH
  @folder  = DEFAULT_FOLDER
  @remote  = DEFAULT_REMOTE
  @message = DEFAULT_MESSAGE
end

#publish(: station_publish(opts = {})) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/detroit-github.rb', line 128

def publish
  if !File.directory?(pgdir)
    report "No pages folder found (#{folder})."
    return
  end

  #copy_files  # post_generate assembly ?

  chdir(pgdir) do
    #sh %[git add -A]
    sh %[git commit -q -a -m "#{message}"]
    sh %[git push #{remote} #{branch}]
  end
end

#sitemap=(entries) ⇒ Object

Set sitemap.



76
77
78
79
80
81
82
83
# File 'lib/detroit-github.rb', line 76

def sitemap=(entries)
  case entries
  when String
    @sitemap = [entries.to_str]
  else
    @sitemap = entries
  end
end