rosa-build/app/models/concerns/wiki.rb

32 lines
733 B
Ruby
Raw Normal View History

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) })
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' })
end
end
def destroy_wiki
FileUtils.rm_rf wiki_path
end
end