#45 差分 API 作成
This commit is contained in:
@@ -8,14 +8,41 @@ class WikiPage < ApplicationRecord
|
||||
|
||||
validates :title, presence: true, length: { maximum: 255 }, uniqueness: true
|
||||
|
||||
def sha= val
|
||||
if val.present?
|
||||
@sha = val
|
||||
@page = wiki.page("#{ id }.md", @sha)
|
||||
else
|
||||
@page = wiki.page("#{ id }.md")
|
||||
@sha = @page.versions.first.id
|
||||
end
|
||||
vers = @page.versions
|
||||
idx = vers.find_index { |ver| ver.id == @sha }
|
||||
@pred = vers[idx + 1]&.id
|
||||
@succ = idx.positive? ? vers[idx - 1].id : nil
|
||||
@sha
|
||||
end
|
||||
|
||||
def sha
|
||||
@sha
|
||||
end
|
||||
|
||||
def pred
|
||||
@pred
|
||||
end
|
||||
|
||||
def succ
|
||||
@succ
|
||||
end
|
||||
|
||||
def body
|
||||
page = wiki.page("#{ id }.md")
|
||||
page&.raw_data
|
||||
sha = nil unless @page
|
||||
@page&.raw_data&.force_encoding('UTF-8')
|
||||
end
|
||||
|
||||
def set_body content, user:
|
||||
commit_info = { name: user.id.to_s,
|
||||
email: 'dummy@example.com' }
|
||||
commit_info = { name: user.id.to_s,
|
||||
email: 'dummy@example.com' }
|
||||
page = wiki.page("#{ id }.md")
|
||||
if page
|
||||
commit_info[:message] = "Updated #{ id }"
|
||||
|
||||
Reference in New Issue
Block a user