#19 トップバーと新規作成ちょっとだけ

This commit is contained in:
2025-06-10 01:23:24 +09:00
parent 39dce3a39f
commit 5b8a560024
10 changed files with 327 additions and 67 deletions
+14 -11
View File
@@ -2,33 +2,36 @@ require 'gollum-lib'
class WikiPage < ApplicationRecord
WIKI_PATH = Rails.root.join('wiki').to_s
belongs_to :tag, optional: true
belongs_to :created_user, class_name: 'User', foreign_key: 'created_user_id'
belongs_to :updated_user, class_name: 'User', foreign_key: 'updated_user_id'
validates :title, presence: true, length: { maximum: 255 }, uniqueness: true
def markdown
wiki = Gollum::Wiki.new(WIKI_PATH)
page = wiki.page(title)
def body
page = wiki.page("#{ id }.md")
page&.raw_data
end
def markdown= content
wiki = Gollum::Wiki.new(WIKI_PATH)
page = wiki.page(title)
def body= content, user:
page = wiki.page("#{ id }.md")
commit_info = { message: "Update #{ title }",
name: current_user.id,
name: user.id,
email: 'dummy@example.com' }
if page
page.update(content, commit: commit_info)
else
wiki.write_page(title, :markdown, content, commit_info)
wiki.write_page("#{ id }.md", :markdown, content, commit_info)
end
end
private
WIKI_PATH = Rails.root.join('wiki').to_s
def wiki
@wiki ||= Gollum::Wiki.new(WIKI_PATH)
end
end