ぼざクリ タグ広場 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.
 
 
 
 
 
 

37 lines
949 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. commit_info = { name: user.id.to_s,
  13. email: 'dummy@example.com' }
  14. page = wiki.page("#{ id }.md")
  15. if page
  16. commit_info[:message] = "Updated #{ id }"
  17. wiki.update_page(page, id.to_s, :markdown, content, commit_info)
  18. else
  19. commit_info[:message] = "Created #{ id }"
  20. wiki.write_page(id.to_s, :markdown, content, commit_info)
  21. end
  22. end
  23. private
  24. WIKI_PATH = Rails.root.join('wiki').to_s
  25. def wiki
  26. @wiki ||= Gollum::Wiki.new(WIKI_PATH)
  27. end
  28. end