2014-03-11 08:58:36 +00:00
|
|
|
module Wiki
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
after_save :create_wiki
|
|
|
|
after_destroy :destroy_wiki
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_path
|
|
|
|
build_path(wiki_repo_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_repo_name
|
|
|
|
File.join owner.uname, "#{name}.wiki"
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def create_wiki
|
|
|
|
if has_wiki && !FileTest.exist?(wiki_path)
|
|
|
|
Grit::Repo.init_bare(wiki_path)
|
2014-03-21 10:41:35 +00:00
|
|
|
wiki = Gollum::Wiki.new(wiki_path, { base_path: Rails.application.routes.url_helpers.project_wiki_index_path(self) })
|
2014-03-11 08:58:36 +00:00
|
|
|
wiki.write_page('Home', :markdown, I18n.t("wiki.seed.welcome_content"),
|
2014-03-21 10:41:35 +00:00
|
|
|
{ name: owner.name, email: owner.email, message: 'Initial commit' })
|
2014-03-11 08:58:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_wiki
|
|
|
|
FileUtils.rm_rf wiki_path
|
|
|
|
end
|
|
|
|
end
|