Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #606 from artempartos/feature/support_refile
add base refile support
- Loading branch information
Showing
13 changed files
with
152 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Ckeditor | ||
module Backend | ||
module Refile | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
validates :data, presence: true | ||
delegate :rewind, :download, :to_io, :exists?, :delete, :size, :close, :eof?, :read, to: :data | ||
alias_attribute :data_file_name, :data_filename | ||
alias_attribute :data_file_size, :data_size | ||
end | ||
|
||
class_methods do | ||
def attachment_file_types | ||
@attachment_file_types ||= Ckeditor.attachment_file_types.map(&:to_s) | ||
end | ||
|
||
def image_file_types | ||
@image_file_types ||= Ckeditor.image_file_types.map(&:to_s) | ||
end | ||
end | ||
|
||
def url(*attrs) | ||
::Refile.attachment_url(self, :data, *attrs) | ||
end | ||
|
||
def read_dimensions | ||
if model.image? && model.has_dimensions? | ||
magick = MiniMagick::Image.open(model.to_io) | ||
model.width = magick.width | ||
model.height = magick.height | ||
end | ||
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
4 changes: 4 additions & 0 deletions
4
lib/generators/ckeditor/templates/active_record/refile/ckeditor/asset.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,4 @@ | ||
class Ckeditor::Asset < ActiveRecord::Base | ||
include Ckeditor::Backend::Refile | ||
include Ckeditor::Orm::ActiveRecord::AssetBase | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/generators/ckeditor/templates/active_record/refile/ckeditor/attachment_file.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,7 @@ | ||
class Ckeditor::AttachmentFile < Ckeditor::Asset | ||
attachment :data, extension: attachment_file_types | ||
|
||
def url_thumb | ||
@url_thumb ||= Ckeditor::Utils.filethumb(filename) | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
lib/generators/ckeditor/templates/active_record/refile/ckeditor/picture.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,11 @@ | ||
class Ckeditor::Picture < Ckeditor::Asset | ||
attachment :data, extension: image_file_types | ||
|
||
def url_content | ||
url | ||
end | ||
|
||
def url_thumb | ||
url(:fill, 118, 100) | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
lib/generators/ckeditor/templates/active_record/refile/migration.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,28 @@ | ||
class CreateCkeditorAssets < ActiveRecord::Migration | ||
def self.up | ||
create_table :ckeditor_assets do |t| | ||
t.string :data_id, :null => false | ||
t.string :data_filename, :null => false | ||
t.integer :data_size | ||
t.string :data_content_type | ||
|
||
|
||
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
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