Skip to content

elfassy/yui_editor

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Integrate the Yahoo Rich Text Editor (http://developer.yahoo.com/yui/editor/) into a Rails application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%