synapses-tinymce-rails-imageupload 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/CHANGELOG.markdown +17 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.markdown +85 -0
- data/Rakefile +1 -0
- data/lib/tinymce-rails-imageupload.rb +3 -0
- data/lib/tinymce-rails-imageupload/rails.rb +8 -0
- data/lib/tinymce-rails-imageupload/version.rb +7 -0
- data/synapses-tinymce-imageupload.gemspec +22 -0
- data/vendor/assets/javascripts/tinymce/plugins/uploadimage/dialog.html +70 -0
- data/vendor/assets/javascripts/tinymce/plugins/uploadimage/editor_plugin.js.coffee +40 -0
- data/vendor/assets/javascripts/tinymce/plugins/uploadimage/img/uploadimage.png +0 -0
- data/vendor/assets/javascripts/tinymce/plugins/uploadimage/langs/en.js +3 -0
- data/vendor/assets/javascripts/tinymce/plugins/uploadimage/langs/en_dlg.js +7 -0
- data/vendor/assets/javascripts/tinymce/plugins/uploadimage/langs/nb.js +3 -0
- data/vendor/assets/javascripts/tinymce/plugins/uploadimage/langs/nb_dlg.js +7 -0
- metadata +126 -0
data/.gitignore
ADDED
data/CHANGELOG.markdown
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
## 3.4.9.1 (April 24, 2012)
|
2
|
+
|
3
|
+
* Work with Rails' CSRF protection by copying the token into our form before submitting it
|
4
|
+
|
5
|
+
## 3.4.9 (April 5, 2012)
|
6
|
+
|
7
|
+
* Document how to use I18n with the gem
|
8
|
+
* Explicitly require tinymce-rails so tinymce-rails-imageupload can be alone in the gemfile
|
9
|
+
* Update dependency to tinymce-rails 3.4.9
|
10
|
+
|
11
|
+
## 3.4.8.1 (March 7, 2012)
|
12
|
+
|
13
|
+
* Added support for setting height and width for the inserted image
|
14
|
+
|
15
|
+
## 3.4.8 (February 29, 2012)
|
16
|
+
|
17
|
+
* Initial release
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2011 Per Christian B. Viken <perchr@northblue.org>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# tinymce-rails-imageupload
|
2
|
+
|
3
|
+
Simple plugin for TinyMCE that allows uploading images and inserting.
|
4
|
+
It makes no assumptions about how you store the images, but it POSTs to a URL and expects JSON back (see the Setup section).
|
5
|
+
|
6
|
+
This plugin borrows heavily from work done by [Peter Shoukry](http://77effects.com/).
|
7
|
+
|
8
|
+
The icon used for the button comes from the icon set [Silk by famfamfam](http://www.famfamfam.com/lab/icons/silk/)
|
9
|
+
|
10
|
+
## Requirements
|
11
|
+
|
12
|
+
* Rails >= 3.1
|
13
|
+
* TinyMCE using the advanced theme and jQuery
|
14
|
+
|
15
|
+
## Setup
|
16
|
+
|
17
|
+
Add the gem to your Gemfile
|
18
|
+
|
19
|
+
gem 'tinymce-rails-imageupload', '~> 3.4.8'
|
20
|
+
|
21
|
+
Set up TinyMCE as you would normally, but in the call to `.tinymce()`, add
|
22
|
+
|
23
|
+
plugins: "uploadimage"
|
24
|
+
# theme_advanced_buttonsX must include "uploadimage" somewhere to have the button appear
|
25
|
+
|
26
|
+
and the rest should happen automatically.
|
27
|
+
|
28
|
+
The plugin POSTs to `/tinymce_assets` by default, which is currently not configurable ([issue #3](https://github.com/PerfectlyNormal/tinymce-rails-imageupload/issues/3)).
|
29
|
+
Set it up using something similar in `routes.rb`
|
30
|
+
|
31
|
+
post '/tinymce_assets' => 'tinymce_assets#create'
|
32
|
+
|
33
|
+
This action gets called with a file parameter creatively called `file`, and must respond with JSON, containing the URL to the image.
|
34
|
+
The JSON has to be returned with a content type of "text/html" to work, which is going to be fixed as soon as possible ([issue #7](https://github.com/PerfectlyNormal/tinymce-rails-imageupload/issues/7)).
|
35
|
+
Example:
|
36
|
+
|
37
|
+
class TinymceAssetsController < ApplicationController
|
38
|
+
def create
|
39
|
+
# Take upload from params[:file] and store it somehow...
|
40
|
+
|
41
|
+
render json: {
|
42
|
+
image: {
|
43
|
+
url: view_context.image_url(image)
|
44
|
+
}
|
45
|
+
}, content_type: "text/html"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
If the JSON response contains a `width` and/or `height` key, those will be used in the inserted HTML (`<img src="..." width="..." height="...">`), but if those are not present, the inserted HTML is just `<img src="...">`.
|
50
|
+
|
51
|
+
## Internationalization
|
52
|
+
|
53
|
+
I18n is taken care of by `tinymce-rails`. This gem includes strings for English and Norwegian.
|
54
|
+
To add your own language, create the files `<code>.js` and `<code>_dlg.js` in `vendor/assets/javascripts/tinymce/plugins/uploadimage/langs` in your application,
|
55
|
+
or fork the gem and add your own translations there.
|
56
|
+
|
57
|
+
The available strings are listed below:
|
58
|
+
|
59
|
+
### en.js
|
60
|
+
|
61
|
+
tinyMCE.addI18n('en.uploadimage', {
|
62
|
+
desc: 'Insert an image from your computer'
|
63
|
+
});
|
64
|
+
|
65
|
+
### en_dlg.js
|
66
|
+
|
67
|
+
tinyMCE.addI18n('en.uploadimage_dlg', {
|
68
|
+
title: 'Insert image',
|
69
|
+
header: "Insert image",
|
70
|
+
input: "Choose an image",
|
71
|
+
insert: "Insert",
|
72
|
+
cancel: "Cancel"
|
73
|
+
});
|
74
|
+
|
75
|
+
## Versioning
|
76
|
+
|
77
|
+
The version of this gem will be mirroring the release of `tinymce-rails` it is tested against.
|
78
|
+
|
79
|
+
## Licensing
|
80
|
+
|
81
|
+
The plugin is released under the MIT license.
|
82
|
+
|
83
|
+
TinyMCE is released under the LGPL Version 2.1.
|
84
|
+
|
85
|
+
The icon used for the button comes from the icon set Silk from famfamfam, released under the [Creative Commons Attribution 3.0 License](http://creativecommons.org/licenses/by/3.0/)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tinymce-rails-imageupload/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "synapses-tinymce-rails-imageupload"
|
7
|
+
s.version = Tinymce::Rails::Imageupload::VERSION
|
8
|
+
s.authors = ["Synapses Group"]
|
9
|
+
s.email = ["tiago@synapses.com.br"]
|
10
|
+
s.homepage = "https://github.com/synapsesgroup/synapses-tinymce-imageupload"
|
11
|
+
s.summary = %q{TinyMCE plugin for taking image uploads in Rails >= 3.1}
|
12
|
+
s.description = %q{TinyMCE plugin for taking image uploads in Rails >= 3.1}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency "railties", ">= 3.1"
|
19
|
+
s.add_runtime_dependency "tinymce-rails", ">= 3.4.9"
|
20
|
+
s.add_development_dependency "bundler", "~> 1.0.0"
|
21
|
+
s.add_development_dependency "rails", ">= 3.1"
|
22
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>{#uploadimage_dlg.title}</title>
|
5
|
+
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
|
6
|
+
<script type="text/javascript">
|
7
|
+
tinyMCEPopup.requireLangPack();
|
8
|
+
|
9
|
+
function getFrameByName(name)
|
10
|
+
{
|
11
|
+
for (var i = 0; i < frames.length; i++)
|
12
|
+
if (frames[i].name == name)
|
13
|
+
return frames[i];
|
14
|
+
|
15
|
+
return null;
|
16
|
+
}
|
17
|
+
|
18
|
+
function uploadDone(name)
|
19
|
+
{
|
20
|
+
var frame = getFrameByName(name);
|
21
|
+
if(frame) {
|
22
|
+
ret = frame.document.getElementsByTagName("body")[0].innerHTML;
|
23
|
+
|
24
|
+
if(ret.length) {
|
25
|
+
var json = JSON.parse(ret);
|
26
|
+
var imgstr = "<br><img src='" + json["image"]["url"] + "'";
|
27
|
+
|
28
|
+
if(json["image"]["height"])
|
29
|
+
imgstr += " height='" + json["image"]["height"] + "'";
|
30
|
+
if(json["image"]["width"])
|
31
|
+
imgstr += " width='" + json["image"]["width"] + "'";
|
32
|
+
|
33
|
+
imgstr += "/>";
|
34
|
+
|
35
|
+
tinyMCE.execCommand('mceInsertContent', false, imgstr);
|
36
|
+
tinyMCEPopup.close();
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
var UploadImageDialog = {
|
42
|
+
init: function() {
|
43
|
+
var f = document.forms[0];
|
44
|
+
},
|
45
|
+
|
46
|
+
insert: function() {
|
47
|
+
document.getElementById("authenticity_token").value = tinyMCE.$("meta[name='csrf-token']")[0].content;
|
48
|
+
document.forms[0].submit();
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
tinyMCEPopup.onInit.add(UploadImageDialog.init, UploadImageDialog);
|
53
|
+
</script>
|
54
|
+
</head>
|
55
|
+
<body>
|
56
|
+
<form method="post" enctype='multipart/form-data' accept-charset="UTF-8" target="hidden_upload" action='/tinymce_assets' name="uploadimageForm">
|
57
|
+
<input type="hidden" name="utf8" value="✓">
|
58
|
+
<input type="hidden" name="authenticity_token" id="authenticity_token" value="">
|
59
|
+
<iframe id="hidden_upload" name="hidden_upload" src='' onload='uploadDone("hidden_upload")' style='width:0;height:0;border:0px solid #fff'></iframe>
|
60
|
+
|
61
|
+
<h1>{#uploadimage_dlg.header}</h1>
|
62
|
+
<p>{#uploadimage_dlg.input}: <input type="file" name='file' class="file_upload"></p>
|
63
|
+
|
64
|
+
<div class="mceActionPanel">
|
65
|
+
<input type="button" id="insert" name="insert" value="{#uploadimage_dlg.insert}" onclick="UploadImageDialog.insert();"/>
|
66
|
+
<input type="button" id="cancel" name="cancel" value="{#uploadimage_dlg.cancel}" onclick="tinyMCEPopup.close();" />
|
67
|
+
</div>
|
68
|
+
</form>
|
69
|
+
</body>
|
70
|
+
</html>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
(->
|
2
|
+
tinymce.PluginManager.requireLangPack('uploadimage')
|
3
|
+
|
4
|
+
tinymce.create 'tinymce.plugins.UploadImagePlugin', {
|
5
|
+
init: (ed, url) ->
|
6
|
+
ed.addCommand 'mceUploadImage', ->
|
7
|
+
ed.windowManager.open {
|
8
|
+
file: url + '/dialog.html',
|
9
|
+
width: 320 + parseInt(ed.getLang('uploadimage.delta_width', 0)),
|
10
|
+
height: 180 + parseInt(ed.getLang('uploadimage.delta_height', 0)),
|
11
|
+
inline: 1
|
12
|
+
}, {
|
13
|
+
plugin_url: url
|
14
|
+
}
|
15
|
+
|
16
|
+
ed.addButton 'uploadimage', {
|
17
|
+
title: 'uploadimage.desc',
|
18
|
+
cmd: 'mceUploadImage',
|
19
|
+
image: url + '/img/uploadimage.png'
|
20
|
+
}
|
21
|
+
|
22
|
+
# Selects the button in the UI when a image is selected
|
23
|
+
ed.onNodeChange.add (ed, cm, n) ->
|
24
|
+
cm.setActive('uploadimage', n.nodeName == 'IMG')
|
25
|
+
|
26
|
+
createControl: (n, cm) ->
|
27
|
+
null
|
28
|
+
|
29
|
+
getInfo: () ->
|
30
|
+
{
|
31
|
+
longname: 'UploadImage plugin',
|
32
|
+
author: 'Per Christian B. Viken (borrows heavily from work done by Peter Shoukry of 77effects.com)',
|
33
|
+
authorurl: 'eastblue.org/oss',
|
34
|
+
infourl: 'eastblue.org/oss',
|
35
|
+
version: '1.0'
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
tinymce.PluginManager.add 'uploadimage', tinymce.plugins.UploadImagePlugin
|
40
|
+
)()
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: synapses-tinymce-rails-imageupload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Synapses Group
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: tinymce-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.4.9
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.4.9
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rails
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.1'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.1'
|
78
|
+
description: TinyMCE plugin for taking image uploads in Rails >= 3.1
|
79
|
+
email:
|
80
|
+
- tiago@synapses.com.br
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- CHANGELOG.markdown
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.markdown
|
90
|
+
- Rakefile
|
91
|
+
- lib/tinymce-rails-imageupload.rb
|
92
|
+
- lib/tinymce-rails-imageupload/rails.rb
|
93
|
+
- lib/tinymce-rails-imageupload/version.rb
|
94
|
+
- synapses-tinymce-imageupload.gemspec
|
95
|
+
- vendor/assets/javascripts/tinymce/plugins/uploadimage/dialog.html
|
96
|
+
- vendor/assets/javascripts/tinymce/plugins/uploadimage/editor_plugin.js.coffee
|
97
|
+
- vendor/assets/javascripts/tinymce/plugins/uploadimage/img/uploadimage.png
|
98
|
+
- vendor/assets/javascripts/tinymce/plugins/uploadimage/langs/en.js
|
99
|
+
- vendor/assets/javascripts/tinymce/plugins/uploadimage/langs/en_dlg.js
|
100
|
+
- vendor/assets/javascripts/tinymce/plugins/uploadimage/langs/nb.js
|
101
|
+
- vendor/assets/javascripts/tinymce/plugins/uploadimage/langs/nb_dlg.js
|
102
|
+
homepage: https://github.com/synapsesgroup/synapses-tinymce-imageupload
|
103
|
+
licenses: []
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.8.24
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: TinyMCE plugin for taking image uploads in Rails >= 3.1
|
126
|
+
test_files: []
|