forked from larsklevan/yui_editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
95 lines (66 loc) · 2.8 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
YuiEditor
=========
Integrate the Yahoo Rich Text Editor (http://developer.yahoo.com/yui/editor/) into a Rails application.
- Integration of file uploads through the text editor. It can be used with whatever upload plugin for rails. But, i will describe how to make it work with Paparclip below.
- Functionality to load the js files as a combined download from Yahoo rather than downloading many files separately.
To force individual downloads, please remove or make false the combine_scripts directive in the config/yui_editor.yml file.
Example
=======
# Basic usage
blog_controller.rb:
class BlogController < ApplicationController
uses_yui_editor
end
new.html.erb:
<% form_for(@blog) do |f| %>
<%= f.text_area :post, :class => 'rich_text_editor' %>
<% end %>
blogs.html.erb:
<head>
<%= include_yui_editor_if_used %>
</head>
Simple method for upload controller:
Add this method to your paperclip upload image controller
def yui_upload
@uploaded_image = UploadedImage.new(params[:uploaded_image])
respond_to do |format|
if @uploaded_image.save
format.html do
render :text => "{status:'UPLOADED',image_url:'#{@uploaded_image.file.url}',large_image_url:'#{@uploaded_image.file.url(:large)}'}", :layout => false
end
else
format.html do
render :text => "{status:'Upload was unsuccessful.'}", :layout => false
end
end
end
end
decide on the image sizes you would like to return. In this case, i'm return the default image size for display "image_url", and :large size for url link "large_image_url"
# Customizing the configuration
default settings are in RAILS_ROOT/config/yui_editor.yml.
Edit the following line for the correct url for image uploads:
yuiImgUploader(editor, textArea.id, '/uploaded_images/yui_upload','uploaded_image[file]');
In the above example i have a controller called UploadedImages and a method yui_upload.
Also, its important to have the correct field name: uploaded_image[file]
you can override the editor defaults in each controller:
class BlogController < ApplicationController
uses_yui_editor(:only => [:new, :create, :edit, :update], :selector => 'blog_post')
end
Instructions for configuring the plugin:
http://wiki.github.com/larsklevan/yui_editor
Instructions for configuring the editor:
http://developer.yahoo.com/yui/docs/YAHOO.widget.Editor.html#configattributes
Instructions for configuring the toolbar:
http://developer.yahoo.com/yui/examples/editor/toolbar_editor.html
Installation
============
Rails >3
rails plugin install git://github.com/larsklevan/yui_editor.git
Rails <3
script/plugin install git://github.com/larsklevan/yui_editor.git
note: use the correct github branch.
Feedback
========
Send feedback and questions to:
tastybyte at gmail.com
Copyright (c) 2009 Lars Klevan, released under the MIT license