class Wiki::PagesController < ApplicationController before_filter :authenticate_user! before_filter :load_page def index @roots = Page.roots end def create create_params = page_params if params[:markdown_body].present? create_params[:body] = redcarpet(params[:markdown_body]) end @page = Page.new create_params.merge( creator: current_user, parent_id: params[:parent_id] ) if @page.save @page.update_to_gollum(current_user) @page.create_activity key: "page.created", owner: current_user end end def show @space = @page.root @subtree = @page.subtree.group_by(&:parent_id) @last_updated = @page.last_updated end def history end def combined @subtree = @page.subtree.group_by(&:parent_id) @hide_extras = true render layout: "minimal" end def update update_params = params.require(params[:type]).permit( :title, :body, ) if params[:markdown_body].present? update_params[:body] = redcarpet(params[:markdown_body]) end if @page.last_updated.created_at != Time.parse(params[:timestamp]) @page.errors.add(:base, "This page was edited by someone. Please refresh.") end if @page.errors.none? && @page.update_attributes(update_params) @page.update_to_gollum(current_user) @last_updated = @page.create_activity key: "page.update_details", owner: current_user end end def new @page = Page.new creator: current_user end def reorder old_parent_id = @page.parent_id old_position = @page.position if @page.reorder!( parent_id: params[:parent_id], position: params[:position] ) @activity = @page.create_activity key: "page.reorder", owner: current_user, parameters: { from_parent_id: old_parent_id, old_position: old_position, parent_id: params[:parent_id], position: params[:position] } end render json: {} end def attach @attachment = Attachment.create_from_uploaded_file(params[:file], current_user, attachable: @page) if @attachment.errors.none? @activity = @page.create_activity key: "page.attachment", owner: current_user, recipient: @attachment end end def subpages_dropdown render partial: 'subpages_dropdown' end protected def load_page @page = Page.find(params[:id]) if params[:id] end private def page_params params.require(params[:type]).permit(:title, :body) end def redcarpet(text) markdown = Redcarpet::Markdown.new( Redcarpet::Render::HTML, no_intra_emphasis: true, tables: true, fenced_code_blocks: true, autolink: true, # disable_indented_code_blocks: true, strikethrough: true, lax_spacing: true, space_after_headers: true, superscript: true, # underline: true, highlight: true, quote: true, footnotes: true, ) markdown.render text end end