Class: DocumentationEditor::PagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- DocumentationEditor::PagesController
- Defined in:
- app/controllers/documentation_editor/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #diff ⇒ Object
- #edit ⇒ Object
- #history ⇒ Object
- #index ⇒ Object
- #preview ⇒ Object
- #show ⇒ Object
- #source ⇒ Object
- #update ⇒ Object
- #upload_image ⇒ Object
- #versions ⇒ Object
Instance Method Details
#create ⇒ Object
35 36 37 38 39 40 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 35 def create p = Page.new p.slug = params[:page][:slug] p.save! redirect_to edit_page_path(p) end |
#destroy ⇒ Object
54 55 56 57 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 54 def destroy @page.destroy redirect_to :admin end |
#diff ⇒ Object
74 75 76 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 74 def diff render inline: Diffy::Diff.new(Revision.find(params[:prev]).content, Revision.find(params[:cur]).content, context: 5, include_plus_and_minus_in_html: true, include_diff_info: true).to_s(:html) end |
#edit ⇒ Object
23 24 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 23 def edit end |
#history ⇒ Object
67 68 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 67 def history end |
#index ⇒ Object
20 21 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 20 def index end |
#preview ⇒ Object
42 43 44 45 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 42 def preview @revision = @page.revisions.last @options = params end |
#show ⇒ Object
47 48 49 50 51 52 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 47 def show @page = Page.find_by(slug: params[:slug]) @revision = @page.published_revision @options = params render :preview end |
#source ⇒ Object
26 27 28 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 26 def source render json: { source: (@page.revisions.last.try(:content) || 'FIXME') } end |
#update ⇒ Object
30 31 32 33 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 30 def update @page.add_revision!(params[:data], !params[:preview], respond_to?(:current_user) ? current_user.id : nil) render nothing: true end |
#upload_image ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 59 def upload_image image = Image.new image.caption = params[:caption] image.image = params[:file] image.save! render json: { id: image.id, url: image.image.url } end |
#versions ⇒ Object
70 71 72 |
# File 'app/controllers/documentation_editor/pages_controller.rb', line 70 def versions render json: { revisions: @page.revisions.order('id DESC').all } end |