redactor-rails-paperclip 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/.gitignore +19 -0
  2. data/Gemfile +24 -0
  3. data/MIT-LICENSE +22 -0
  4. data/README.md +106 -0
  5. data/Rakefile +3 -0
  6. data/app/controller/redactor_rails/base_controller.rb +27 -0
  7. data/app/controller/redactor_rails/documents_controller.rb +3 -0
  8. data/app/controller/redactor_rails/pictures_controller.rb +3 -0
  9. data/config/routes.rb +4 -0
  10. data/lib/generators/redactor/config_generator.rb +17 -0
  11. data/lib/generators/redactor/install_generator.rb +67 -0
  12. data/lib/generators/redactor/templates/active_record/carrierwave/migration.rb +25 -0
  13. data/lib/generators/redactor/templates/active_record/carrierwave/redactor/asset.rb +5 -0
  14. data/lib/generators/redactor/templates/active_record/carrierwave/redactor/document.rb +11 -0
  15. data/lib/generators/redactor/templates/active_record/carrierwave/redactor/picture.rb +7 -0
  16. data/lib/generators/redactor/templates/active_record/paperclip/migration.rb +26 -0
  17. data/lib/generators/redactor/templates/active_record/paperclip/redactor/asset.rb +4 -0
  18. data/lib/generators/redactor/templates/active_record/paperclip/redactor/document.rb +13 -0
  19. data/lib/generators/redactor/templates/active_record/paperclip/redactor/picture.rb +13 -0
  20. data/lib/generators/redactor/templates/base/carrierwave/uploaders/redactor_rails_document_uploader.rb +15 -0
  21. data/lib/generators/redactor/templates/base/carrierwave/uploaders/redactor_rails_picture_uploader.rb +53 -0
  22. data/lib/generators/redactor/templates/config.js +17 -0
  23. data/lib/generators/redactor/templates/mongoid/carrierwave/redactor/asset.rb +9 -0
  24. data/lib/generators/redactor/templates/mongoid/carrierwave/redactor/document.rb +14 -0
  25. data/lib/generators/redactor/templates/mongoid/carrierwave/redactor/picture.rb +7 -0
  26. data/lib/redactor-rails.rb +34 -0
  27. data/lib/redactor-rails/backend/carrierwave.rb +64 -0
  28. data/lib/redactor-rails/backend/paperclip.rb +56 -0
  29. data/lib/redactor-rails/engine.rb +10 -0
  30. data/lib/redactor-rails/helper.rb +19 -0
  31. data/lib/redactor-rails/http.rb +89 -0
  32. data/lib/redactor-rails/orm/active_record.rb +24 -0
  33. data/lib/redactor-rails/orm/base.rb +38 -0
  34. data/lib/redactor-rails/orm/mongoid.rb +37 -0
  35. data/lib/redactor-rails/version.rb +3 -0
  36. data/redactor-rails.gemspec +20 -0
  37. data/vendor/assets/javascripts/redactor-rails/config.js +15 -0
  38. data/vendor/assets/javascripts/redactor-rails/css/docstyle.css +139 -0
  39. data/vendor/assets/javascripts/redactor-rails/css/style.css +26 -0
  40. data/vendor/assets/javascripts/redactor-rails/css/wym.css +151 -0
  41. data/vendor/assets/javascripts/redactor-rails/index.js +2 -0
  42. data/vendor/assets/javascripts/redactor-rails/langs/ar.js +66 -0
  43. data/vendor/assets/javascripts/redactor-rails/langs/ba.js +69 -0
  44. data/vendor/assets/javascripts/redactor-rails/langs/bg.js +67 -0
  45. data/vendor/assets/javascripts/redactor-rails/langs/by.js +65 -0
  46. data/vendor/assets/javascripts/redactor-rails/langs/cs.js +77 -0
  47. data/vendor/assets/javascripts/redactor-rails/langs/da.js +66 -0
  48. data/vendor/assets/javascripts/redactor-rails/langs/de.js +70 -0
  49. data/vendor/assets/javascripts/redactor-rails/langs/en.js +66 -0
  50. data/vendor/assets/javascripts/redactor-rails/langs/eo.js +66 -0
  51. data/vendor/assets/javascripts/redactor-rails/langs/es.js +66 -0
  52. data/vendor/assets/javascripts/redactor-rails/langs/fa.js +66 -0
  53. data/vendor/assets/javascripts/redactor-rails/langs/fi.js +69 -0
  54. data/vendor/assets/javascripts/redactor-rails/langs/fr.js +76 -0
  55. data/vendor/assets/javascripts/redactor-rails/langs/hr.js +69 -0
  56. data/vendor/assets/javascripts/redactor-rails/langs/hu.js +67 -0
  57. data/vendor/assets/javascripts/redactor-rails/langs/id.js +66 -0
  58. data/vendor/assets/javascripts/redactor-rails/langs/it.js +68 -0
  59. data/vendor/assets/javascripts/redactor-rails/langs/ja.js +66 -0
  60. data/vendor/assets/javascripts/redactor-rails/langs/ko.js +66 -0
  61. data/vendor/assets/javascripts/redactor-rails/langs/lv.js +65 -0
  62. data/vendor/assets/javascripts/redactor-rails/langs/nl.js +69 -0
  63. data/vendor/assets/javascripts/redactor-rails/langs/pl.js +66 -0
  64. data/vendor/assets/javascripts/redactor-rails/langs/pt_br.js +72 -0
  65. data/vendor/assets/javascripts/redactor-rails/langs/ro.js +66 -0
  66. data/vendor/assets/javascripts/redactor-rails/langs/ru.js +66 -0
  67. data/vendor/assets/javascripts/redactor-rails/langs/sk.js +66 -0
  68. data/vendor/assets/javascripts/redactor-rails/langs/sq.js +69 -0
  69. data/vendor/assets/javascripts/redactor-rails/langs/sr-cir.js +69 -0
  70. data/vendor/assets/javascripts/redactor-rails/langs/sr-lat.js +69 -0
  71. data/vendor/assets/javascripts/redactor-rails/langs/sv.js +66 -0
  72. data/vendor/assets/javascripts/redactor-rails/langs/tr.js +66 -0
  73. data/vendor/assets/javascripts/redactor-rails/langs/ua.js +67 -0
  74. data/vendor/assets/javascripts/redactor-rails/langs/vi.js +65 -0
  75. data/vendor/assets/javascripts/redactor-rails/langs/zh_cn.js +70 -0
  76. data/vendor/assets/javascripts/redactor-rails/langs/zh_tw.js +66 -0
  77. data/vendor/assets/javascripts/redactor-rails/redactor.js +4210 -0
  78. data/vendor/assets/javascripts/redactor-rails/redactor.min.js +12 -0
  79. data/vendor/assets/stylesheets/redactor-rails/css/redactor.css +692 -0
  80. data/vendor/assets/stylesheets/redactor-rails/css/style.css +26 -0
  81. data/vendor/assets/stylesheets/redactor-rails/index.css +1 -0
  82. metadata +161 -0
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ /.idea/*
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redactor-rails.gemspec
4
+ gemspec
5
+ gem "rails", "3.2.3"
6
+
7
+
8
+ platforms :ruby do
9
+ gem "sqlite3"
10
+
11
+ group :development do
12
+ gem "unicorn", "~> 4.0.1"
13
+ end
14
+
15
+ group :development, :test do
16
+ gem "capybara", ">= 0.4.0"
17
+ gem "mynyml-redgreen", "~> 0.7.1", :require => 'redgreen'
18
+ end
19
+
20
+ group :active_record do
21
+ gem "paperclip"
22
+ end
23
+
24
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sammy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Rails 3.2 Integration for Redactor (NO Devise Edition)
2
+
3
+ The redactor-rails gem integrates the [Redactor](http://redactorjs.com/) editor with the Rails 3.2 asset pipeline.
4
+
5
+ This gem bundles Redactor version 8.2.2 which is the most recent version as of January 20, 2013. Check [Redactor's changelog](http://imperavi.com/redactor/log/) for further updates.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'redactor-rails', github: 'sergio1990/redactor-rails', branch: :paperclip
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ ### Now generate models for store uploading files
18
+
19
+ #### ActiveRecord + carrierwave
20
+
21
+ gem "carrierwave"
22
+ gem "mini_magick"
23
+
24
+ $ rails generate redactor:install
25
+
26
+ $ rake db:migrate
27
+
28
+ #### ActiveRecord + paperclip
29
+
30
+ gem "paperclip"
31
+
32
+ $ rails generate redactor:install --backend=paperclip
33
+
34
+ $ rake db:migrate
35
+
36
+ #### Mongoid + carrierwave
37
+ gem "carrierwave"
38
+ gem "carrierwave-mongoid", require: "carrierwave/mongoid"
39
+ gem "mini_magick"
40
+
41
+ $ rails generate redactor:install
42
+
43
+ ### Include the Redactor assets
44
+
45
+ Add to your `application.js`:
46
+
47
+ //= require redactor-rails
48
+
49
+ Add to your `application.css`:
50
+
51
+ *= require redactor-rails
52
+
53
+ ### Initialize Redactor
54
+
55
+ For each textarea that you want to use with Redactor, add the "redactor" class and ensure it has a unique ID:
56
+
57
+ <%= text_area_tag :editor, "", class: "redactor", rows: 40, cols: 120 %>
58
+
59
+ ### Custom Your redactor
60
+
61
+ If you need change some config in redactor, you can
62
+
63
+ $ rails generate redactor:config
64
+
65
+ Then generate `app\assets\redactor-rails\config.js`.
66
+
67
+ See the [Redactor Documentation](http://redactorjs.com/docs/settings/) for a full list of configuration options.
68
+
69
+
70
+ If You Want To setup a new language in Redactor you should do two things:
71
+
72
+ In you file `app\assets\redactor-rails\config.js` set option
73
+
74
+ "lang":'zh_tw'
75
+
76
+ and
77
+
78
+ Add to your layout
79
+
80
+ <%= redactor_lang('zh_tw') %>
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create new Pull Request
89
+
90
+ ## Special Thanks
91
+
92
+ [wildjcrt (Jerry Lee)](https://github.com/wildjcrt/)
93
+ ## Statement
94
+
95
+ `redactor-rails` part of reference [galetahub/ckeditor](https://github.com/galetahub/ckeditor) project.
96
+
97
+ `redactor-rails` uses MIT-LICENSE. Rock!!!!!
98
+
99
+ ## License
100
+
101
+ the `redactor-rails` project is MIT-LICENSE.
102
+
103
+ You may use `Redactor` for non-commercial websites for free, however, we do not guarantee any technical support.
104
+
105
+ Redactor has [3 different licenses](http://redactorjs.com/download/) for commercial use.
106
+ For details please see [License Agreement](http://redactorjs.com/download/).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler"
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,27 @@
1
+ class RedactorRails::BaseController < ApplicationController
2
+
3
+ def index
4
+ @redactors = controller_model.order :id
5
+ render json: @redactors.to_json
6
+ end
7
+
8
+ def create
9
+ @redactor = controller_model.new
10
+
11
+ file = params[:file]
12
+ @redactor.data = RedactorRails::Http.normalize_param(file, request)
13
+
14
+ if @redactor.save
15
+ render text: { filelink: @redactor.url }.to_json
16
+ else
17
+ render nothing: true
18
+ end
19
+ end
20
+
21
+ protected
22
+
23
+ def controller_model
24
+ self.class.to_s.sub('Controller', '').singularize.constantize
25
+ end
26
+
27
+ end
@@ -0,0 +1,3 @@
1
+ class RedactorRails::DocumentsController < RedactorRails::BaseController
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class RedactorRails::PicturesController < RedactorRails::BaseController
2
+
3
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ RedactorRails::Engine.routes.draw do
2
+ resources :pictures, only: [:index, :create]
3
+ resources :documents, only: [:index, :create]
4
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails/generators'
2
+ module Redactor
3
+ module Generators
4
+ class ConfigGenerator < ::Rails::Generators::Base
5
+ desc "Generates redactor-rails config"
6
+
7
+ def self.source_root
8
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
9
+ end
10
+
11
+
12
+ def create_config
13
+ template "config.js", File.join('app/assets/javascripts/redactor-rails', "config.js")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,67 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ module Redactor
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ include ::Rails::Generators::Migration
7
+ desc "Generates migration for Tag and Tagging models"
8
+
9
+ class_option :orm, type: :string, default: "active_record", desc: "Backend processor for upload support"
10
+
11
+ class_option :backend, type: :string, default: 'carrierwave', desc: "carrierwave(default)"
12
+
13
+ def self.source_root
14
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
15
+ end
16
+
17
+ def self.next_migration_number(dirname)
18
+ Time.now.strftime("%Y%m%d%H%M%S")
19
+ end
20
+
21
+ def mount_engine
22
+ route "mount RedactorRails::Engine => '/redactor_rails'"
23
+ end
24
+
25
+ def create_models
26
+ [:asset, :picture, :document].each do |filename|
27
+ template "#{generator_dir}/redactor/#{filename}.rb", File.join('app/models', redactor_dir, "#{filename}.rb")
28
+ end
29
+
30
+ if backend == "carrierwave"
31
+ [:picture, :document].each do |filename|
32
+ template "#{uploaders_dir}/uploaders/redactor_rails_#{filename}_uploader.rb", File.join("app/uploaders", "redactor_rails_#{filename}_uploader.rb")
33
+ end
34
+ end
35
+ end
36
+
37
+ def create_migration
38
+ if orm.to_s == "active_record"
39
+ migration_template "#{generator_dir}/migration.rb", File.join('db/migrate', "create_redactor_assets.rb")
40
+ end
41
+ end
42
+
43
+ protected
44
+
45
+ def redactor_dir
46
+ 'redactor_rails'
47
+ end
48
+
49
+ def generator_dir
50
+ @generator_dir ||= [orm, backend].join('/')
51
+ end
52
+
53
+ def uploaders_dir
54
+ @uploaders_dir ||= ['base', 'carrierwave'].join('/')
55
+ end
56
+
57
+ def orm
58
+ options[:orm] || "active_record"
59
+ end
60
+
61
+ def backend
62
+ options[:backend] || "carrierwave"
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ class CreateRedactorAssets < ActiveRecord::Migration
2
+ def change
3
+ create_table :redactor_assets do |t|
4
+ t.string :data_file_name, null: false
5
+ t.string :data_content_type
6
+ t.integer :data_file_size
7
+
8
+ t.integer :assetable_id
9
+ t.string :assetable_type, limit: 30
10
+ t.string :type, limit: 30
11
+
12
+ # Uncomment it to save images dimensions, if your need it
13
+ t.integer :width
14
+ t.integer :height
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ # Uncomment it to add foreign key. gem 'foreigner' is required in your .Gemfile
20
+ # add_foreign_key(:redactor_assets, :users, dependent: :delete)
21
+ add_index "redactor_assets", ["assetable_type", "type", "assetable_id"], name: "idx_redactor_assetable_type"
22
+ add_index "redactor_assets", ["assetable_type", "assetable_id"], name: "idx_redactor_assetable"
23
+ end
24
+ end
25
+
@@ -0,0 +1,5 @@
1
+ class RedactorRails::Asset < ActiveRecord::Base
2
+ include RedactorRails::Orm::ActiveRecord::AssetBase
3
+ delegate :url, :current_path, :size, :content_type, :filename, to: :data
4
+ validates_presence_of :data
5
+ end
@@ -0,0 +1,11 @@
1
+ class RedactorRails::Document < RedactorRails::Asset
2
+ mount_uploader :data, RedactorRailsDocumentUploader, mount_on: :data_file_name
3
+
4
+ def url_content
5
+ url(:content)
6
+ end
7
+
8
+ def as_json_methods
9
+ [:image]
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ class RedactorRails::Picture < RedactorRails::Asset
2
+ mount_uploader :data, RedactorRailsPictureUploader, mount_on: :data_file_name
3
+
4
+ def url_content
5
+ url(:content)
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ class CreateRedactorAssets < ActiveRecord::Migration
2
+ def change
3
+ create_table :redactor_assets do |t|
4
+ t.string :data_file_name, null: false
5
+ t.string :data_content_type
6
+ t.integer :data_file_size
7
+ t.datetime :data_updated_at
8
+
9
+ t.integer :assetable_id
10
+ t.string :assetable_type, limit: 30
11
+ t.string :type, limit: 30
12
+
13
+ # Uncomment it to save images dimensions, if your need it
14
+ t.integer :width
15
+ t.integer :height
16
+
17
+ t.timestamps
18
+ end
19
+
20
+ # Uncomment it to add foreign key. gem 'foreigner' is required in your .Gemfile
21
+ # add_foreign_key(:redactor_assets, :users, dependent: :delete)
22
+ add_index "redactor_assets", ["assetable_type", "type", "assetable_id"], name: "idx_redactor_assetable_type"
23
+ add_index "redactor_assets", ["assetable_type", "assetable_id"], name: "idx_redactor_assetable"
24
+ end
25
+ end
26
+
@@ -0,0 +1,4 @@
1
+ class RedactorRails::Asset < ActiveRecord::Base
2
+ include RedactorRails::Orm::ActiveRecord::AssetBase
3
+ include RedactorRails::Backend::Paperclip
4
+ end
@@ -0,0 +1,13 @@
1
+ class RedactorRails::Document < RedactorRails::Asset
2
+ has_attached_file :data,
3
+ url: "/redactor_rails/attachments/:id/:filename",
4
+ path: ":rails_root/public/redactor_rails/attachments/:id/:filename"
5
+
6
+ validates_attachment_size :data, less_than: 100.megabytes
7
+ validates_attachment_presence :data
8
+
9
+ def url_content
10
+ url(:content)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ class RedactorRails::Picture < RedactorRails::Asset
2
+ has_attached_file :data,
3
+ url: "/redactor_rails/pictures/:id/:style_:basename.:extension",
4
+ path: ":rails_root/public/redactor_rails/pictures/:id/:style_:basename.:extension",
5
+ styles: { content: '800>', thumb: '118x100#' }
6
+
7
+ validates_attachment_size :data, less_than: 2.megabytes
8
+ validates_attachment_presence :data
9
+
10
+ def url_content
11
+ url(:content)
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ class RedactorRailsDocumentUploader < CarrierWave::Uploader::Base
3
+ include RedactorRails::Backend::CarrierWave
4
+
5
+ # storage :fog
6
+ storage :file
7
+
8
+ def store_dir
9
+ "system/redactor_assets/documents/#{model.id}"
10
+ end
11
+
12
+ def extension_white_list
13
+ RedactorRails.document_file_types
14
+ end
15
+ end