Class: DocumentationEditor::PagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/documentation_editor/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#commitObject



41
42
43
44
# File 'app/controllers/documentation_editor/pages_controller.rb', line 41

def commit
  @page.add_revision!(params[:data], params[:preview].to_s == 'false', respond_to?(:current_user) ? current_user.id : nil)
  render nothing: true
end

#createObject



46
47
48
49
50
51
52
53
# File 'app/controllers/documentation_editor/pages_controller.rb', line 46

def create
  p = Page.new
  p.author_id = respond_to?(:current_user) ? current_user.id : nil
  p.title = params[:page][:title]
  p.slug = params[:page][:slug]
  p.save!
  redirect_to edit_page_path(p)
end

#destroyObject



74
75
76
77
# File 'app/controllers/documentation_editor/pages_controller.rb', line 74

def destroy
  @page.destroy
  redirect_to :admin
end

#diffObject



94
95
96
# File 'app/controllers/documentation_editor/pages_controller.rb', line 94

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

#editObject



27
28
# File 'app/controllers/documentation_editor/pages_controller.rb', line 27

def edit
end

#historyObject



87
88
# File 'app/controllers/documentation_editor/pages_controller.rb', line 87

def history
end

#indexObject



24
25
# File 'app/controllers/documentation_editor/pages_controller.rb', line 24

def index
end

#previewObject



55
56
57
58
# File 'app/controllers/documentation_editor/pages_controller.rb', line 55

def preview
  @revision = @page.revisions.last
  @options = params
end

#showObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/documentation_editor/pages_controller.rb', line 60

def show
  @page = Page.find_by!(slug: params[:slug])
  @revision = @page.published_revision
  @options = params
  @base_path = if params[:section]
    s = request.path.split('/')
    s.pop
    s.join('/')
  else
    request.path
  end
  render :preview
end

#sourceObject



30
31
32
# File 'app/controllers/documentation_editor/pages_controller.rb', line 30

def source
  render json: { source: (@page.revisions.last.try(:content) || 'FIXME') }
end

#updateObject



34
35
36
37
38
39
# File 'app/controllers/documentation_editor/pages_controller.rb', line 34

def update
  @page.title = params[:page][:title] unless params[:page][:title].nil?
  @page.slug = params[:page][:slug] unless params[:page][:slug].nil?
  @page.save!
  render nothing: true
end

#upload_imageObject



79
80
81
82
83
84
85
# File 'app/controllers/documentation_editor/pages_controller.rb', line 79

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

#versionsObject



90
91
92
# File 'app/controllers/documentation_editor/pages_controller.rb', line 90

def versions
  render json: { revisions: @page.revisions.order('id DESC').all }
end