documentation-editor 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9adeb1522ebc20f98a5bf3337866c999ed221292
4
- data.tar.gz: 709c5a01bbf17f910067b724470918197d5dc862
3
+ metadata.gz: f1d11c9e046b823acea840a344e93b4f3c4fb2e2
4
+ data.tar.gz: 8722bd73901e2cb8cc1a722b9926c482f7e76b85
5
5
  SHA512:
6
- metadata.gz: 438bcd626da3448ecc2a92a9e5a2025d3c9704c6eb2ddc8487256dd666b69e235fa010c2a392e2c33e699212525b416e4dd2a9b2f2616af3538070d92ccba09c
7
- data.tar.gz: c12da7e3dc4076d1ad433c913fe102e826f128a8fd849561fc99f1daf3fe5dd49c7d4a1e13a4c6ccfe12f08f068aae53d1887cff167bd6d90318d131affdb28c
6
+ metadata.gz: 50dfa6ea18a420ee9b62242da795db1b1d2571e4d44b3d8d4c62e97ddd2ff4c452a9522023752af97904e5cb16c1fe2a4bea0abc305517b6be4799676c18bb2e
7
+ data.tar.gz: cf05a99e8c27a12ebd73c0fe144be87f57598ad3bb51ac1f96396f4a28da6185e6bce1589d6beca260722639b827ff2684353d1d7101226302f993caae283a98
@@ -111,6 +111,37 @@ module DocumentationEditor
111
111
  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)
112
112
  end
113
113
 
114
+ def export
115
+ pages = Page.all.map do |p|
116
+ {
117
+ slug: p.slug,
118
+ created_at: p.created_at,
119
+ title: p.title,
120
+ languages: p.languages,
121
+ description: p.description,
122
+ section: p.section,
123
+ position: p.position,
124
+ content: p.revisions.last.try(:content)
125
+ }
126
+ end
127
+ send_data JSON.pretty_generate(pages), type: :json, disposition: 'attachment', filename: "export-#{DateTime.now}.json"
128
+ end
129
+
130
+ def import
131
+ JSON.parse(params[:file][:content].read).each do |page|
132
+ p = Page.find_or_initialize_by(slug: params[:slug])
133
+ p.created_at = page['created_at']
134
+ p.title = page['title']
135
+ p.languages = page['langauges']
136
+ p.description = page['description']
137
+ p.section = page['section']
138
+ p.position = page['position']
139
+ p.save!
140
+ p.add_revision!(page['content'], true)
141
+ end
142
+ redirect_to :admin
143
+ end
144
+
114
145
  private
115
146
  def setup_page
116
147
  @page = Page.find(params[:id])
@@ -3,9 +3,19 @@
3
3
  %h1 Edit documentation
4
4
 
5
5
  .editor-content
6
- = link_to '#', class: 'btn btn-success pull-right', onclick: '$("#modal-new-page").modal("show"); return false;' do
7
- %i.fa.fa-plus-circle
8
- Add a new page
6
+ %ul.list-inline.pull-right
7
+ %li
8
+ = link_to '#', class: 'btn btn-success pull-right', onclick: '$("#modal-new-page").modal("show"); return false;' do
9
+ %i.fa.fa-plus-circle
10
+ Add a new page
11
+ %li
12
+ = link_to export_path, class: 'btn btn-default pull-right' do
13
+ %i.fa.fa-download
14
+ Export
15
+ %li
16
+ = link_to '#', class: 'btn btn-default pull-right', onclick: '$("#modal-import").modal("show"); return false;' do
17
+ %i.fa.fa-upload
18
+ Import
9
19
  %h3 Pages
10
20
  %table.table.table-striped.pages
11
21
  %thead
@@ -72,11 +82,25 @@
72
82
  %button.close{type: 'button', 'data-dismiss' => 'modal', 'aria-label' => 'Close'}
73
83
  %span{'aria-hidden' => true} ×
74
84
  %h4.modal-title Create a new page
75
- .modal-body
76
- = form_for DocumentationEditor::Page.new, url: admin_path, html: { class: 'form' } do |f|
85
+ = form_for DocumentationEditor::Page.new, url: admin_path, html: { class: 'form' } do |f|
86
+ .modal-body
77
87
  %p= f.text_field :title, placeholder: 'Title', class: 'form-control'
78
88
  %p= f.text_field :slug, placeholder: 'Slug (ex: tutorials/my-tutorial)', class: 'form-control'
79
89
  %p= f.text_field :description, placeholder: 'Description', class: 'form-control'
80
90
  %p= f.text_field :languages_raw, placeholder: 'Languages (ex: ruby, php, python)', class: 'form-control'
81
91
  %p= f.text_field :section, placeholder: 'Section name (ex: getting-started)', class: 'form-control'
82
- %p.text-center= f.submit 'Create', class: 'btn btn-success'
92
+ .modal-footer
93
+ = f.submit 'Create', class: 'btn btn-success'
94
+
95
+ .modal.fade#modal-import
96
+ .modal-dialog
97
+ .modal-content
98
+ .modal-header
99
+ %button.close{type: 'button', 'data-dismiss' => 'modal', 'aria-label' => 'Close'}
100
+ %span{'aria-hidden' => true} ×
101
+ %h4.modal-title Import pages
102
+ = form_tag import_path, multipart: true, class: 'form' do
103
+ .modal-body
104
+ %p= file_field :file, :content, class: 'form-control'
105
+ .modal-footer
106
+ = submit_tag 'Upload', class: 'btn btn-success'
data/config/routes.rb CHANGED
@@ -5,6 +5,9 @@ DocumentationEditor::Engine.routes.draw do
5
5
 
6
6
  post '/images', as: :upload_image, :controller => 'pages', :action => 'upload_image'
7
7
 
8
+ get '/export', as: :export, :controller => 'pages', :action => 'export'
9
+ post '/import', as: :import, :controller => 'pages', :action => 'import'
10
+
8
11
  get '/:id', :controller => 'pages', :action => 'source'
9
12
  get '/:id/edit', as: :edit_page, :controller => 'pages', :action => 'edit'
10
13
  put '/:id', as: :update, :controller => 'pages', :action => 'update'
@@ -1,3 +1,3 @@
1
1
  module DocumentationEditor
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: documentation-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-22 00:00:00.000000000 Z
11
+ date: 2016-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails