Class: Amiba::Page::Publish

Inherits:
Thor::Group
  • Object
show all
Includes:
Generator, Repo
Defined in:
lib/amiba/page.rb

Overview

Thor task to mark a page published.

Instance Method Summary collapse

Methods included from Repo

#add_and_commit, #init, #last_commit_date, #last_commit_dates, #pull, #push, #repo

Methods included from Generator

included

Instance Method Details

#add_to_gitObject



92
93
94
# File 'lib/amiba/page.rb', line 92

def add_to_git
  add_and_commit @source.filename, "Published #{@source.filename}"
end

#init_sourceObject



65
66
67
# File 'lib/amiba/page.rb', line 65

def init_source
  @source = Amiba::Source::Page.new(name, format)
end

#save_pageObject



81
82
83
84
85
86
87
88
89
90
# File 'lib/amiba/page.rb', line 81

def save_page
  @source.state = "published"
  @source.save do |filename, file_data|
    remove_file filename, :verbose => false
    create_file(filename, :verbose => false) do
      file_data
    end
    say_status :published, filename, :green
  end
end

#should_existObject



69
70
71
72
73
# File 'lib/amiba/page.rb', line 69

def should_exist
  if @source.new?
    raise Thor::Error.new("Error: Can't publish a page that doesn't exist.")
  end
end

#should_not_be_publishedObject



75
76
77
78
79
# File 'lib/amiba/page.rb', line 75

def should_not_be_published
  if @source.state == "published"
    raise Thor::Error.new("Page already published")
  end
end