forked from galetahub/ckeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
212 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Ckeditor | ||
module Helpers | ||
module Controllers | ||
extend ActiveSupport::Concern | ||
|
||
protected | ||
|
||
def ckeditor_before_create_asset(asset) | ||
asset.assetable = current_user if respond_to?(:current_user) | ||
return true | ||
end | ||
|
||
def ckeditor_authenticate(asset) | ||
# TODO: | ||
end | ||
|
||
def ckeditor_pictures_scope(options = {}) | ||
ckeditor_filebrowser_scope(options) | ||
end | ||
|
||
def ckeditor_attachment_files_scope(options = {}) | ||
ckeditor_filebrowser_scope(options) | ||
end | ||
|
||
def ckeditor_filebrowser_scope(options = {}) | ||
{ :order => [:id, :desc] }.merge(options) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'test_helper' | ||
|
||
class PicturesControllerTest < ActionController::TestCase | ||
tests Ckeditor::PicturesController | ||
|
||
def setup | ||
@image = fixture_file_upload('files/rails.png', 'image/png') | ||
end | ||
|
||
test "index action" do | ||
get :index | ||
|
||
assert_equal 200, @response.status | ||
assert_template "ckeditor/pictures/index" | ||
end | ||
|
||
test "create action via filebrowser" do | ||
assert_difference 'Ckeditor::Picture.count' do | ||
post :create, :qqfile => @image | ||
end | ||
|
||
assert_equal 200, @response.status | ||
end | ||
|
||
test "create action via CKEditor upload form" do | ||
assert_difference 'Ckeditor::Picture.count' do | ||
post :create, :upload => @image, :CKEditor => 'ckeditor_field' | ||
end | ||
|
||
assert_equal 200, @response.status | ||
end | ||
|
||
test "invalid params for create action" do | ||
assert_no_difference 'Ckeditor::Picture.count' do | ||
post :create, :qqfile => nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'mime/types' | ||
|
||
class Ckeditor::Asset < ActiveRecord::Base | ||
include Ckeditor::Orm::ActiveRecord::AssetBase | ||
|
||
attr_accessible :data, :assetable_type, :assetable_id, :assetable | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Ckeditor::AttachmentFile < Ckeditor::Asset | ||
has_attached_file :data, | ||
:url => "/ckeditor_assets/attachments/:id/:filename", | ||
:path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename" | ||
|
||
validates_attachment_size :data, :less_than => 100.megabytes | ||
validates_attachment_presence :data | ||
|
||
def url_thumb | ||
@url_thumb ||= begin | ||
extname = File.extname(filename).gsub(/^\./, '') | ||
"/javascripts/ckeditor/filebrowser/images/thumbs/#{extname}.gif" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Ckeditor::Picture < Ckeditor::Asset | ||
has_attached_file :data, | ||
:url => "/ckeditor_assets/pictures/:id/:style_:basename.:extension", | ||
:path => ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension", | ||
:styles => { :content => '800>', :thumb => '118x100#' } | ||
|
||
validates_attachment_size :data, :less_than => 2.megabytes | ||
validates_attachment_presence :data | ||
|
||
def url_content | ||
url(:content) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Use this hook to configure ckeditor | ||
if Object.const_defined?("Ckeditor") | ||
Ckeditor.setup do |config| | ||
# ==> ORM configuration | ||
# Load and configure the ORM. Supports :active_record (default), :mongo_mapper and | ||
# :mongoid (bson_ext recommended) by default. Other ORMs may be | ||
# available as additional gems. | ||
require 'ckeditor/orm/active_record' | ||
|
||
# Allowed image file types for upload. | ||
# Set to nil or [] (empty array) for all file types | ||
# config.image_file_types = ["jpg", "jpeg", "png", "gif", "tiff"] | ||
|
||
# Allowed attachment file types for upload. | ||
# Set to nil or [] (empty array) for all file types | ||
# config.attachment_file_types = ["doc", "docx", "rar", "zip", "xls", "swf"] | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
test/dummy/db/migrate/20110705195648_create_ckeditor_assets.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class CreateCkeditorAssets < ActiveRecord::Migration | ||
def self.up | ||
create_table :ckeditor_assets do |t| | ||
t.string :data_file_name, :null => false | ||
t.string :data_content_type | ||
t.integer :data_file_size | ||
|
||
t.integer :assetable_id | ||
t.string :assetable_type, :limit => 30 | ||
t.string :type, :limit => 30 | ||
|
||
# Uncomment it to save images dimensions, if your need it | ||
# t.integer :width | ||
# t.integer :height | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index "ckeditor_assets", ["assetable_type", "type", "assetable_id"], :name => "idx_ckeditor_assetable_type" | ||
add_index "ckeditor_assets", ["assetable_type", "assetable_id"], :name => "idx_ckeditor_assetable" | ||
end | ||
|
||
def self.down | ||
drop_table :ckeditor_assets | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.