ぼざクリ タグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
883 B

  1. require 'gollum-lib'
  2. class WikiPage < ApplicationRecord
  3. belongs_to :tag, optional: true
  4. belongs_to :created_user, class_name: 'User', foreign_key: 'created_user_id'
  5. belongs_to :updated_user, class_name: 'User', foreign_key: 'updated_user_id'
  6. validates :title, presence: true, length: { maximum: 255 }, uniqueness: true
  7. def body
  8. page = wiki.page("#{ id }.md")
  9. page&.raw_data
  10. end
  11. def set_body content, user:
  12. page = wiki.page("#{ id }.md")
  13. commit_info = { message: "Update #{ title }",
  14. name: user.id.to_s,
  15. email: 'dummy@example.com' }
  16. if page
  17. page.update(content, commit: commit_info)
  18. else
  19. wiki.write_page(id.to_s, :markdown, content, commit_info)
  20. end
  21. end
  22. private
  23. WIKI_PATH = Rails.root.join('wiki').to_s
  24. def wiki
  25. @wiki ||= Gollum::Wiki.new(WIKI_PATH)
  26. end
  27. end