documentation-editor 0.3.3 → 0.4.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: 5bbdfb27873ed22418a32d32e221d4a9897b1dd0
4
- data.tar.gz: 8b288d1414343e4a2e94d30139a2eb429700f097
3
+ metadata.gz: b79d4a966c2746a06f7f13c50039e948196c10e5
4
+ data.tar.gz: 7a0c5c448291bde530f132e15fbc0922707ae850
5
5
  SHA512:
6
- metadata.gz: 71d2057ec92150f85dd3a64fa0876e170af978482eaa1f575897e5baf187a3759c6833261fc6b98b4b3be67d16a03787338bcede430a85cdbe9f5a7328383679
7
- data.tar.gz: 4bfd8ee057ca082d319e479ca55ef481520f93304553bfa8fdbb11761ffe13b83086e2dc7be58e18fdbcf7583ce4ead975ad2a55662bb49cc1fee9f1c7368d14
6
+ metadata.gz: 333b41db66a6c31912d1b1c2fdd243daccc34997053d7a0079bbbb20ec26fdb182524d51a16248491777ad7c68d9725eced7cff3df52d436bb48943258a40394
7
+ data.tar.gz: 7133b991b86e66e06ee55894424e1343ce6a1cc14948a1ea749c1efff5be69bcaf09f6bac0bb2d72a5b27e279d56389f1903a8ffb01add5158cb6457db35c2ef
@@ -13,6 +13,7 @@ angular.module('documentationEditorApp', ['ngFileUpload'])
13
13
  $scope.undoRedo = [];
14
14
  $scope.id = 0;
15
15
  $scope.slug = '';
16
+ $scope.thumbnailUrl = null;
16
17
  $scope.source = '';
17
18
 
18
19
  $scope.nextID = 0;
@@ -67,10 +68,11 @@ angular.module('documentationEditorApp', ['ngFileUpload'])
67
68
  return data.join("\n");
68
69
  }
69
70
 
70
- $scope.init = function(id, slug, path) {
71
+ $scope.init = function(id, slug, thumbnailUrl, path) {
71
72
  $scope.id = id;
72
73
  $scope.slug = slug;
73
74
  $scope.path = path;
75
+ $scope.thumbnailUrl = thumbnailUrl;
74
76
 
75
77
  $http.get($scope.path + '/admin/' + id).then(function(content) {
76
78
  $scope.source = content.data.source;
@@ -471,6 +473,30 @@ angular.module('documentationEditorApp', ['ngFileUpload'])
471
473
  }
472
474
  };
473
475
 
476
+ }]).controller('ThumbnailUploaderController', ['$scope', 'Upload', function($scope, Upload) {
477
+ $scope.file = null;
478
+
479
+ $scope.$watch('file', function () {
480
+ $scope.upload($scope.id, $scope.file);
481
+ });
482
+
483
+ $scope.upload = function(id, file) {
484
+ if (file && file.length === 1) {
485
+ file = file[0];
486
+ Upload.upload({
487
+ url: $scope.$parent.path + '/admin/' + id + '/thumbnail',
488
+ file: file
489
+ }).success(function (data, status, headers, config) {
490
+ console.log('uploaded', data);
491
+ $scope.thumbnailUrl = data.url;
492
+ $('#upload-thumbnail').modal('hide');
493
+ }).error(function (data, status, headers, config) {
494
+ console.log('error', data);
495
+ alert('Error status: ' + status);
496
+ })
497
+ }
498
+ };
499
+
474
500
  }]).controller('HistoryController', ['$scope', '$http', '$sce', function($scope, $http, $sce) {
475
501
  $scope.pages = [];
476
502
 
@@ -98,6 +98,10 @@
98
98
  margin: 0
99
99
  &:focus
100
100
  outline: none
101
+ .pages
102
+ img
103
+ width: 100px
104
+
101
105
  .images
102
106
  height: 150px
103
107
  overflow: auto
@@ -109,7 +113,6 @@
109
113
  border: 1px solid #DDD
110
114
  margin-right: 5px
111
115
 
112
-
113
116
  .markdown-page
114
117
  h1, h2, h3, h4, h5, h6
115
118
  position: relative
@@ -19,7 +19,7 @@ module DocumentationEditor
19
19
  before_filter DocumentationEditor::Config.before_filter, only: [:preview, :show]
20
20
  end
21
21
 
22
- before_filter :setup_page, only: [:edit, :source, :update, :commit, :preview, :destroy, :history, :versions]
22
+ before_filter :setup_page, only: [:edit, :source, :update, :commit, :preview, :destroy, :history, :versions, :upload_thumbnail]
23
23
 
24
24
  def index
25
25
  end
@@ -84,6 +84,13 @@ module DocumentationEditor
84
84
  render json: { id: image.id, url: image.image.url }
85
85
  end
86
86
 
87
+ def upload_thumbnail
88
+ thumb = @page.build_thumbnail
89
+ thumb.image = params[:file]
90
+ @page.save!
91
+ render json: { id: thumb.id, url: thumb.image.url }
92
+ end
93
+
87
94
  def history
88
95
  end
89
96
 
@@ -6,6 +6,8 @@ module DocumentationEditor
6
6
  has_many :revisions, class_name: 'Revision', dependent: :destroy
7
7
  belongs_to :published_revision, class_name: 'Revision', foreign_key: 'published_revision_id'
8
8
 
9
+ belongs_to :thumbnail, class_name: 'Image'
10
+
9
11
  def add_revision!(content, publish = false, author_id = nil)
10
12
  r = revisions.build
11
13
  r.author_id = author_id
@@ -18,5 +20,9 @@ module DocumentationEditor
18
20
  r
19
21
  end
20
22
 
23
+ def thumbnail_url
24
+ thumbnail.try(:image).try(:url)
25
+ end
26
+
21
27
  end
22
28
  end
@@ -1,5 +1,5 @@
1
1
  %div{"ng-app" => "documentationEditorApp"}
2
- %section#documentation-editor{"ng-controller" => 'EditorController', "ng-init" => "init(#{@page.id}, #{@page.slug.to_json}, '#{admin_path.gsub(/\/admin$/, '')}')"}
2
+ %section#documentation-editor{"ng-controller" => 'EditorController', "ng-init" => "init(#{@page.id}, #{@page.slug.to_json}, #{@page.thumbnail_url.to_json}, '#{admin_path.gsub(/\/admin$/, '')}')"}
3
3
  .editor-header
4
4
  %ul.list-inline.pull-right
5
5
  %li
@@ -22,6 +22,10 @@
22
22
  %a.btn.btn-default.btn-sm{href: '#', 'ng-click' => 'toggleView($event)'}
23
23
  %i.fa.fa-arrows-h
24
24
  Switch View
25
+ %li
26
+ %a.btn.btn-default.btn-sm{href: '#', 'data-toggle' => 'modal', "data-target" => "#upload-thumbnail"}
27
+ %i.fa.fa-upload
28
+ Thumbnail
25
29
  %li
26
30
  %a.btn.btn-default.btn-sm{href: history_path(@page)}
27
31
  %i.fa.fa-history
@@ -32,7 +36,9 @@
32
36
  Undo
33
37
  %h1
34
38
  Edit
35
- %small= page_path(@page.slug)
39
+ %small
40
+ = page_path('')
41
+ = @page.slug
36
42
 
37
43
  .editor-content{"ng-cloak" => true}
38
44
  %textarea.markdown{"ng-if" => "rawView", "ng-model" => "$parent.source"}
@@ -154,3 +160,18 @@
154
160
  %input.form-control{type: 'text', 'ng-model' => 'caption', placeholder: 'Optional caption'}
155
161
  .text-center.form-group
156
162
  .btn.btn-success{"ngf-select" => true, "ng-model" => 'files'} Select image
163
+
164
+ #upload-thumbnail.modal.fade{"ng-controller" => "ThumbnailUploaderController"}
165
+ .modal-dialog
166
+ .modal-content
167
+ .modal-header
168
+ %button.close{type: "button", "data-dismiss" => "modal", "aria-label" => "Close"}
169
+ %span{"aria-hidden" => true} ×
170
+ %h4 Configure the page thumbnail
171
+ .modal-body
172
+ .text-center.images
173
+ %img{src: '{{ thumbnailUrl }}'}
174
+ .form
175
+ .text-center.form-group
176
+ .btn.btn-success{"ngf-select" => true, "ng-model" => 'file', "ngf-multiple" => false} Select thumbnail
177
+
@@ -10,7 +10,9 @@
10
10
  Back to Admin
11
11
  %h1
12
12
  History of
13
- %small= page_path(@page.slug)
13
+ %small
14
+ = page_path('')
15
+ = @page.slug
14
16
  .editor-content
15
17
  .row{"ng-controller" => 'HistoryController', "ng-init" => "init(#{@page.id}, '#{admin_path.gsub(/\/admin$/, '')}')"}
16
18
  .col-sm-3
@@ -4,9 +4,10 @@
4
4
 
5
5
  .editor-content
6
6
  %h3 Pages
7
- %table.table.table-striped
7
+ %table.table.table-striped.pages
8
8
  %thead
9
9
  %tr
10
+ %th Thumbnail
10
11
  %th Title
11
12
  %th Slug
12
13
  %th Last modification
@@ -16,6 +17,9 @@
16
17
  %tbody
17
18
  - DocumentationEditor::Page.order('id DESC').each do |p|
18
19
  %tr
20
+ %td
21
+ - if p.thumbnail
22
+ = image_tag p.thumbnail_url
19
23
  %td= best_in_place p, :title, url: update_path(p)
20
24
  %td= best_in_place p, :slug, url: update_path(p)
21
25
  %td= l p.created_at, format: :short
data/config/routes.rb CHANGED
@@ -9,6 +9,7 @@ DocumentationEditor::Engine.routes.draw do
9
9
  get '/:id/edit', as: :edit_page, :controller => 'pages', :action => 'edit'
10
10
  put '/:id', as: :update, :controller => 'pages', :action => 'update'
11
11
  post '/:id', :controller => 'pages', :action => 'commit'
12
+ post '/:id/thumbnail', as: :upload_thumbnail, :controller => 'pages', :action => 'upload_thumbnail'
12
13
  delete '/:id', as: :delete_page, :controller => 'pages', :action => 'destroy'
13
14
  get '/:id/preview', as: :preview_page, :controller => 'pages', :action => 'preview'
14
15
  get '/:prev/:cur/diff', :controller => 'pages', :action => 'diff'
@@ -0,0 +1,5 @@
1
+ class AddThumbnailIdToPages < ActiveRecord::Migration
2
+ def change
3
+ add_column :documentation_editor_pages, :thumbnail_id, :integer
4
+ end
5
+ end
@@ -21,6 +21,10 @@ class Kramdown::Parser::BlockKramdown < Kramdown::Parser::Kramdown
21
21
  code ||= content['codes'].detect { |code| code['language'].end_with?("|*") }
22
22
  @tree.children << Element.new(:html_element, 'pre')
23
23
  @tree.children.last.children << Element.new(:raw, code ? highlight(code['language'].split('|').first, code['code']) : "FIXME:#{@language}")
24
+ elsif content['codes'].size == 1
25
+ code = content['codes'].first
26
+ @tree.children << Element.new(:html_element, 'pre')
27
+ @tree.children.last.children << Element.new(:raw, highlight(code['language'].split('|').first, code['code']))
24
28
  else
25
29
  ul = Element.new(:html_element, 'ul', { class: 'nav nav-tabs' })
26
30
  tab_content = Element.new(:html_element, 'div', { class: 'tab-content' })
@@ -1,3 +1,3 @@
1
1
  module DocumentationEditor
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.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.3.3
4
+ version: 0.4.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: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -158,6 +158,7 @@ files:
158
158
  - db/migrate/20150725063642_create_documentation_editor_images.rb
159
159
  - db/migrate/20150728040718_create_documentation_editor_revisions.rb
160
160
  - db/migrate/20150818102838_add_title_to_pages.rb
161
+ - db/migrate/20150903121913_add_thumbnail_id_to_pages.rb
161
162
  - lib/documentation-editor.rb
162
163
  - lib/documentation_editor.rb
163
164
  - lib/documentation_editor/configuration.rb