documentation 1.0.1 → 1.0.2
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 +4 -4
- data/app/assets/javascripts/documentation/application.coffee +65 -1
- data/app/assets/stylesheets/documentation/application.scss +2 -0
- data/app/assets/stylesheets/documentation/page_form.scss +1 -0
- data/app/controllers/documentation/application_controller.rb +6 -0
- data/app/controllers/documentation/pages_controller.rb +19 -0
- data/app/models/documentation/screenshot.rb +14 -0
- data/app/views/documentation/pages/form.html.haml +6 -2
- data/app/views/documentation/pages/screenshot.html.haml +15 -0
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20140724111844_create_nifty_attachments_table.rb +16 -0
- data/db/migrate/20140724114255_create_documentation_screenshots.rb +7 -0
- data/lib/documentation.rb +2 -0
- data/lib/documentation/authorizer.rb +8 -0
- data/lib/documentation/version.rb +1 -1
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ee69981e399c23b45190208a36587d22ef937fa
|
4
|
+
data.tar.gz: c681d1aa01d8d237697e5fd742cfb26620f11f74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b73915ea29d76182c81f0b8f2aee4986bdbbf0794c08a4571817df2539405cabe4658521c31f963c053f81dac9dbc490eac724446c85f18f995a2f966b44c670
|
7
|
+
data.tar.gz: ac5424d483dff52ec3e1ec9dcb5a05a7e3c99a1e34282009667626972bcb59cda977251506465ac7b26c2e9492db45f3fc8bda33d152329cfc3a7493e10887b1
|
@@ -2,6 +2,7 @@
|
|
2
2
|
#= require jquery_ujs
|
3
3
|
#= require documentation/jquery-ui
|
4
4
|
#= require documentation/jquery.autosize
|
5
|
+
#= require nifty/dialog
|
5
6
|
|
6
7
|
$ ->
|
7
8
|
$('form.pageForm textarea').autosize({append: '\n\n'})
|
@@ -11,4 +12,67 @@ $ ->
|
|
11
12
|
form = $(this).parents('form')
|
12
13
|
url = form.attr('action')
|
13
14
|
$.post(url, form.serialize());
|
14
|
-
|
15
|
+
|
16
|
+
$('.js-screenshot').on 'click', (e)->
|
17
|
+
e.preventDefault()
|
18
|
+
openUploadDialog()
|
19
|
+
|
20
|
+
$('.edit-article').on 'drop', (e)->
|
21
|
+
e.stopPropagation()
|
22
|
+
e.preventDefault()
|
23
|
+
|
24
|
+
file = e.originalEvent.dataTransfer.files[0]
|
25
|
+
|
26
|
+
openUploadDialog(file)
|
27
|
+
|
28
|
+
openUploadDialog = (file)->
|
29
|
+
editForm = $('.edit-article').find('form')
|
30
|
+
contentArea = editForm.find('#page_content')
|
31
|
+
caretPosition = contentArea.get(0).selectionStart
|
32
|
+
content = contentArea.val()
|
33
|
+
|
34
|
+
uploadFormUrl = editForm.find('.js-screenshot').attr('href')
|
35
|
+
uploadFormUrl = uploadFormUrl + "?filename=#{file.name}" if file?
|
36
|
+
|
37
|
+
Nifty.Dialog.open
|
38
|
+
url: uploadFormUrl
|
39
|
+
afterLoad: (dialog)->
|
40
|
+
form = dialog.find('form')
|
41
|
+
form.find('#screenshot_alt_text').focus()
|
42
|
+
|
43
|
+
dialog.on 'submit', 'form', (e)->
|
44
|
+
form = $(this)
|
45
|
+
formData = new FormData(form.get(0))
|
46
|
+
|
47
|
+
if file?
|
48
|
+
filename = file.name
|
49
|
+
formData.append('screenshot[upload_file]', file)
|
50
|
+
else
|
51
|
+
filename = form.find('#screenshot_upload_file').val()
|
52
|
+
|
53
|
+
fileExt = filename.split('.').pop().toLowerCase()
|
54
|
+
if $.inArray(fileExt, ['gif','png','jpg','jpeg']) == -1
|
55
|
+
alert("Invalid file extension (allowed: gif, png, jpg, jpeg)")
|
56
|
+
return false
|
57
|
+
|
58
|
+
$.ajax
|
59
|
+
url: form.attr('action')
|
60
|
+
type: form.attr('method')
|
61
|
+
data: formData
|
62
|
+
processData: false
|
63
|
+
contentType: false
|
64
|
+
success: (data)->
|
65
|
+
screenshotLink = ""
|
66
|
+
newContent = content.substring(0, caretPosition) + screenshotLink + content.substring(caretPosition)
|
67
|
+
newCaretPosition = (content.substring(0, caretPosition) + screenshotLink).length
|
68
|
+
contentArea.val(newContent)
|
69
|
+
|
70
|
+
contentArea.focus()
|
71
|
+
contentArea.get(0).setSelectionRange(newCaretPosition, newCaretPosition)
|
72
|
+
|
73
|
+
Nifty.Dialog.closeTopDialog()
|
74
|
+
|
75
|
+
error: (xhr, status, errorThrown)->
|
76
|
+
console.log xhr.responseText
|
77
|
+
|
78
|
+
false
|
@@ -1,5 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
*= require documentation/reset
|
3
|
+
*= require nifty/dialog
|
3
4
|
*= require_self
|
4
5
|
*= require documentation/markdown
|
5
6
|
*= require documentation/page_form
|
@@ -193,6 +194,7 @@ a.button, input.button {
|
|
193
194
|
border-radius:5px;
|
194
195
|
margin-left:5px;
|
195
196
|
appearance:none;
|
197
|
+
vertical-align:middle;
|
196
198
|
&.delete {
|
197
199
|
color:#F6744F;
|
198
200
|
border-color:lighten(#F6744F, 20%);
|
@@ -9,6 +9,12 @@ module Documentation
|
|
9
9
|
render :template => 'documentation/shared/not_found', :layout => false
|
10
10
|
end
|
11
11
|
|
12
|
+
before_filter do
|
13
|
+
unless authorizer.can_use_ui?
|
14
|
+
render :template => 'documentation/shared/not_found', :layout => false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
private
|
13
19
|
|
14
20
|
def authorizer
|
@@ -44,6 +44,21 @@ module Documentation
|
|
44
44
|
redirect_to @page.parent ? page_path(@page.parent.full_permalink) : root_path, :notice => "Page has been removed successfully."
|
45
45
|
end
|
46
46
|
|
47
|
+
def screenshot
|
48
|
+
authorizer.check! :upload, @page
|
49
|
+
if request.post?
|
50
|
+
@screenshot = Screenshot.new(screenshot_params)
|
51
|
+
if @screenshot.save
|
52
|
+
render :json => { :id => @screenshot.id, :title => @screenshot.alt_text, :path => @screenshot.upload.path }, :status => :created
|
53
|
+
else
|
54
|
+
render :json => { :errors => @screenshot.errors }, :status => :unprocessible_entity
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@screenshot = Screenshot.new
|
58
|
+
render 'screenshot', :layout => false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
47
62
|
def positioning
|
48
63
|
authorizer.check! :reposition_page, @page
|
49
64
|
@pages = @page ? @page.children : Page.roots
|
@@ -70,5 +85,9 @@ module Documentation
|
|
70
85
|
params.require(:page).permit(:title, :permalink, :content, :favourite)
|
71
86
|
end
|
72
87
|
|
88
|
+
def screenshot_params
|
89
|
+
params.require(:screenshot).permit(:upload_file, :alt_text)
|
90
|
+
end
|
91
|
+
|
73
92
|
end
|
74
93
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
- @page_title = @page.breadcrumb.reverse.map(&:title).join(" - ")
|
2
2
|
|
3
|
-
%section.content
|
3
|
+
%section.content.edit-article
|
4
4
|
= documentation_breadcrumb_for @page
|
5
5
|
= form_for @page, :url => @page.new_record? ? new_page_path(@page.parent ? @page.parent.full_permalink : nil) : edit_page_path(@page.full_permalink), :html => {:class => 'pageForm'} do |f|
|
6
6
|
= error_messages_for @page
|
@@ -9,4 +9,8 @@
|
|
9
9
|
%dl
|
10
10
|
%dt= f.label :permalink
|
11
11
|
%dd= f.text_field :permalink, :placeholder => t('.permalink_placeholder')
|
12
|
-
|
12
|
+
|
13
|
+
%p.submit
|
14
|
+
- if authorizer.can_upload?(@page)
|
15
|
+
= link_to t('.add_screenshot'), upload_screenshot_path, :class => 'button preview js-screenshot'
|
16
|
+
= f.submit t('.save'), :class => 'button'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
= form_for @screenshot, :url => upload_screenshot_path, :html => {:class => 'pageForm'} do |f|
|
2
|
+
%dl
|
3
|
+
%dt= f.label :upload_file, "Upload File"
|
4
|
+
%dd.padded
|
5
|
+
- if params[:filename]
|
6
|
+
= params[:filename]
|
7
|
+
- else
|
8
|
+
= f.file_field :upload_file
|
9
|
+
|
10
|
+
%dl
|
11
|
+
%dt= f.label :alt_text, "Screenshot Title"
|
12
|
+
%dd= f.text_field :alt_text
|
13
|
+
|
14
|
+
%p.submit
|
15
|
+
= f.submit "Upload Screenshot", :class => 'button'
|
data/config/locales/en.yml
CHANGED
data/config/routes.rb
CHANGED
@@ -4,6 +4,7 @@ Documentation::Engine.routes.draw do
|
|
4
4
|
match 'positioning(/*path)', :to => 'pages#positioning', :as => 'page_positioning', :via => [:get, :post]
|
5
5
|
match 'edit(/*path)', :to => 'pages#edit', :as => 'edit_page', :via => [:get, :patch]
|
6
6
|
match 'delete(/*path)', :to => 'pages#destroy', :as => 'delete_page', :via => [:delete]
|
7
|
+
match 'screenshot', :to => 'pages#screenshot', :as => 'upload_screenshot', :via => [:get, :post]
|
7
8
|
get 'search', :to => 'pages#search', :as => 'search'
|
8
9
|
get '*path' => 'pages#show', :as => 'page'
|
9
10
|
root :to => 'pages#index'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateNiftyAttachmentsTable < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def up
|
4
|
+
create_table :nifty_attachments do |t|
|
5
|
+
t.integer :parent_id
|
6
|
+
t.string :parent_type, :token, :digest, :role, :file_name, :file_type
|
7
|
+
t.binary :data, :limit => 10.megabytes
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def down
|
13
|
+
drop_table :nifty_attachments
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/documentation.rb
CHANGED
@@ -25,10 +25,18 @@ module Documentation
|
|
25
25
|
true
|
26
26
|
end
|
27
27
|
|
28
|
+
def can_upload?(page)
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
28
32
|
def can_search?
|
29
33
|
true
|
30
34
|
end
|
31
35
|
|
36
|
+
def can_use_ui?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
32
40
|
def check!(action, object = :none)
|
33
41
|
action_method_name = "can_#{action}?"
|
34
42
|
if self.respond_to?(action_method_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: documentation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -166,6 +166,34 @@ dependencies:
|
|
166
166
|
- - "<"
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '1.0'
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: nifty-attachments
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: 1.0.3
|
176
|
+
type: :runtime
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: 1.0.3
|
183
|
+
- !ruby/object:Gem::Dependency
|
184
|
+
name: nifty-dialog
|
185
|
+
requirement: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - "~>"
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '1'
|
190
|
+
type: :runtime
|
191
|
+
prerelease: false
|
192
|
+
version_requirements: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - "~>"
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '1'
|
169
197
|
- !ruby/object:Gem::Dependency
|
170
198
|
name: sqlite3
|
171
199
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,10 +235,12 @@ files:
|
|
207
235
|
- app/controllers/documentation/pages_controller.rb
|
208
236
|
- app/helpers/documentation/application_helper.rb
|
209
237
|
- app/models/documentation/page.rb
|
238
|
+
- app/models/documentation/screenshot.rb
|
210
239
|
- app/views/documentation/pages/_admin_buttons.html.haml
|
211
240
|
- app/views/documentation/pages/form.html.haml
|
212
241
|
- app/views/documentation/pages/index.html.haml
|
213
242
|
- app/views/documentation/pages/positioning.html.haml
|
243
|
+
- app/views/documentation/pages/screenshot.html.haml
|
214
244
|
- app/views/documentation/pages/search.html.haml
|
215
245
|
- app/views/documentation/pages/show.html.haml
|
216
246
|
- app/views/documentation/shared/access_denied.html.haml
|
@@ -221,6 +251,8 @@ files:
|
|
221
251
|
- config/locales/en.yml
|
222
252
|
- config/routes.rb
|
223
253
|
- db/migrate/20140711185212_create_documentation_pages.rb
|
254
|
+
- db/migrate/20140724111844_create_nifty_attachments_table.rb
|
255
|
+
- db/migrate/20140724114255_create_documentation_screenshots.rb
|
224
256
|
- db/seeds.rb
|
225
257
|
- lib/documentation.rb
|
226
258
|
- lib/documentation/authorizer.rb
|