Class: GithubPagesRakeTasks::PublishTask

Inherits:
Rake::TaskLib
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/github_pages_rake_tasks/publish_task.rb

Overview

Instantiate this class to create a Rake task that pushes the contents from a local documentation directory to a GitHub repository branch.

See #initialize for more details.

Instance Method Summary collapse

Constructor Details

#initialize(*task_args, &initialization_block) {|state, task_args| ... } ⇒ PublishTask

Create the publish task

By default, the rake task github-pages:publish is created which pushes the doc directory within the local copy of your repository to the same repository's gh-pages branch. The contents of the branch are completely replaced by the contents of the documentation directory.

An initialization block can be passed to the initializer to set attributes to customize the behavior of the rake task created. State details all the attributes which can be set and what effect they have on the task.

Examples:

with default options

require 'github_pages_rake_tasks'
GitHubPagesRakeTasks.Tasks.new
task default: 'github-pages:publish'

with an initialization block

require 'github_pages_rake_tasks'
GitHubPagesRakeTasks.Tasks.new do |task|
  task.doc_dir = 'documentation'
  task.verbose = true
end
task default: 'github-pages:publish'

Parameters:

  • task_args (Array<Object>)

    arguments to pass to the task initialization block.

  • initialization_block

    If given, the task initialization will yield to this block with the task_args to perform user initialization of the publish task.

Yields:

  • yields to the passed initialization_block for user initialization of this task.

Yield Parameters:

  • state (GithubPagesRakeTasks::State)

    the configuration state of this task. See State for a description of the configuration attributes that can be set.

  • task_args (Array<Object>)

    any args passed to this initializer are passed to the yielded block.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/github_pages_rake_tasks/publish_task.rb', line 68

def initialize(*task_args, &initialization_block)
  super

  @state = State.new

  # Allow user to override defaults
  #
  yield(*[@state, task_args].slice(0, initialization_block.arity)) if initialization_block

  namespace rake_namespace do
    desc "Publish #{doc_dir} to #{repo_url}##{branch_name}"
    task :publish do
      publish_task
    end
  end
end