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

35 lines
876 B

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