refinerycms-resources 1.0.11 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/controllers/refinery/admin/resources_controller.rb +87 -0
- data/app/models/refinery/resource.rb +49 -0
- data/app/views/refinery/admin/resources/_actions.html.erb +8 -0
- data/app/views/{admin → refinery/admin}/resources/_existing_resource.html.erb +7 -13
- data/app/views/{admin → refinery/admin}/resources/_form.html.erb +14 -18
- data/app/views/refinery/admin/resources/_records.html.erb +16 -0
- data/app/views/refinery/admin/resources/_resource.html.erb +20 -0
- data/app/views/{admin → refinery/admin}/resources/_resources.html.erb +2 -2
- data/app/views/refinery/admin/resources/edit.html.erb +1 -0
- data/app/views/refinery/admin/resources/index.html.erb +6 -0
- data/app/views/{admin → refinery/admin}/resources/insert.html.erb +10 -13
- data/app/views/refinery/admin/resources/new.html.erb +1 -0
- data/config/locales/bg.yml +30 -29
- data/config/locales/cs.yml +32 -30
- data/config/locales/da.yml +30 -29
- data/config/locales/de.yml +30 -29
- data/config/locales/el.yml +30 -29
- data/config/locales/en.yml +30 -29
- data/config/locales/es.yml +31 -30
- data/config/locales/fi.yml +30 -29
- data/config/locales/fr.yml +30 -29
- data/config/locales/it.yml +41 -39
- data/config/locales/ja.yml +36 -0
- data/config/locales/ko.yml +36 -0
- data/config/locales/lt.yml +30 -29
- data/config/locales/lv.yml +30 -29
- data/config/locales/nb.yml +30 -29
- data/config/locales/nl.yml +29 -28
- data/config/locales/pl.yml +31 -30
- data/config/locales/pt-BR.yml +30 -29
- data/config/locales/rs.yml +30 -30
- data/config/locales/ru.yml +30 -29
- data/config/locales/sk.yml +30 -29
- data/config/locales/sl.yml +29 -28
- data/config/locales/sv.yml +30 -29
- data/config/locales/vi.yml +30 -29
- data/config/locales/zh-CN.yml +30 -29
- data/config/locales/zh-TW.yml +30 -29
- data/config/routes.rb +4 -8
- data/db/migrate/20100913234709_create_refinerycms_resources_schema.rb +8 -16
- data/lib/generators/refinery/resources/resources_generator.rb +10 -0
- data/lib/generators/refinery/resources/templates/config/initializers/refinery/resources.rb.erb +26 -0
- data/lib/refinery/resources/configuration.rb +43 -0
- data/lib/refinery/resources/dragonfly.rb +52 -0
- data/lib/refinery/resources/engine.rb +38 -0
- data/lib/refinery/resources/validators/file_size_validator.rb +19 -0
- data/lib/refinery/resources/validators.rb +7 -0
- data/lib/refinery/resources.rb +25 -0
- data/lib/refinerycms-resources.rb +1 -75
- data/refinerycms-resources.gemspec +14 -83
- data/spec/factories/resource.rb +5 -0
- data/{features/uploads → spec/fixtures}/refinery_is_awesome.txt +0 -0
- data/spec/fixtures/refinery_is_awesome2.txt +1 -0
- data/spec/lib/generators/refinery/resources/resources_generator_spec.rb +29 -0
- data/spec/models/refinery/resource_spec.rb +118 -0
- data/spec/requests/refinery/admin/resources_spec.rb +148 -0
- metadata +111 -101
- data/app/controllers/admin/resources_controller.rb +0 -87
- data/app/models/resource.rb +0 -54
- data/app/views/admin/resources/_actions.html.erb +0 -11
- data/app/views/admin/resources/_records.html.erb +0 -16
- data/app/views/admin/resources/_resource.html.erb +0 -17
- data/app/views/admin/resources/edit.html.erb +0 -1
- data/app/views/admin/resources/index.html.erb +0 -6
- data/app/views/admin/resources/new.html.erb +0 -1
- data/config/locales/jp.yml +0 -35
- data/config/locales/lolcat.yml +0 -35
- data/features/manage_files.feature +0 -43
- data/features/step_definitions/file_steps.rb +0 -21
- data/features/support/paths.rb +0 -17
- data/features/uploads/beach.jpeg +0 -0
- data/lib/gemspec.rb +0 -38
- data/lib/generators/refinerycms_resources_generator.rb +0 -8
- data/spec/models/resource_spec.rb +0 -78
- data/spec/uploads/refinery_is_awesome.txt +0 -1
data/config/locales/vi.yml
CHANGED
@@ -1,35 +1,36 @@
|
|
1
1
|
vi:
|
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
|
-
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
refinery_files:
|
5
|
+
title: Các tập tin
|
6
|
+
description: Tải lên và liên kết đến tập tin
|
7
|
+
admin:
|
8
|
+
resources:
|
9
|
+
delete: Hủy bỏ tập tin này mãi mãi
|
10
|
+
edit: Sửa tập tin này
|
11
|
+
form:
|
12
|
+
download_current: Tải tập tin hiện tại
|
13
|
+
or: hoặc
|
14
|
+
replace: " thay thế nó bằng này..."
|
15
|
+
maximum_file_size: Kích thước file tối đa là %{bytes}.
|
16
|
+
resource:
|
17
|
+
download: Tải về file này (%{size})
|
18
|
+
actions:
|
19
|
+
upload_new: Tải lên tập tin mới
|
20
|
+
records:
|
21
|
+
no_files_yet: Chưa có tập tin nào. Nhấp vào "Tải lên tập tin mới" để thêm tập tin đầu tiên của bạn.
|
22
|
+
insert:
|
23
|
+
existing: Tập tin đang tồn tại
|
24
|
+
new: Tập tin mới
|
25
|
+
no_files: Không có tập tin nào.
|
26
|
+
existing_resource:
|
27
|
+
link_to_file: Liên kết đến tập tin này.
|
28
|
+
button_text: Chèn
|
28
29
|
activerecord:
|
29
30
|
models:
|
30
|
-
resource: tập tin
|
31
|
+
refinery/resource: tập tin
|
31
32
|
errors:
|
32
33
|
models:
|
33
|
-
resource:
|
34
|
+
refinery/resource:
|
34
35
|
blank: Bạn phải xác định tập tin để tải lên
|
35
|
-
|
36
|
+
too_big: Tập tin phải nhỏ hơn %{size} bytes về kích thước
|
data/config/locales/zh-CN.yml
CHANGED
@@ -1,35 +1,36 @@
|
|
1
1
|
zh-CN:
|
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
|
-
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
refinery_files:
|
5
|
+
title: 文件
|
6
|
+
description: 上传与连接文件
|
7
|
+
admin:
|
8
|
+
resources:
|
9
|
+
delete: 永久删除此文件
|
10
|
+
edit: 编辑此文件
|
11
|
+
form:
|
12
|
+
download_current: 下载当前文件
|
13
|
+
or: 或
|
14
|
+
replace: " 用这个来替换..."
|
15
|
+
maximum_file_size: 最大的文件大小是 %{bytes}.
|
16
|
+
resource:
|
17
|
+
download: 下载此文件 (%{size})
|
18
|
+
actions:
|
19
|
+
upload_new: 上传新文件
|
20
|
+
records:
|
21
|
+
no_files_yet: 这里还没有文件. 点击 "上传新文件" 去添加您第一个文件.
|
22
|
+
insert:
|
23
|
+
existing: 已存在的文件
|
24
|
+
new: 新文件
|
25
|
+
no_files: 没有文件.
|
26
|
+
existing_resource:
|
27
|
+
link_to_file: 连接到此文件
|
28
|
+
button_text: 插入
|
28
29
|
activerecord:
|
29
30
|
models:
|
30
|
-
resource: 文件
|
31
|
+
refinery/resource: 文件
|
31
32
|
errors:
|
32
33
|
models:
|
33
|
-
resource:
|
34
|
+
refinery/resource:
|
34
35
|
blank: 您必须选择一个文件来上传
|
35
|
-
|
36
|
+
too_big: 文件应该小于 %{size} MB 大小
|
data/config/locales/zh-TW.yml
CHANGED
@@ -1,35 +1,36 @@
|
|
1
1
|
zh-TW:
|
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
|
-
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
refinery_files:
|
5
|
+
title: 檔案
|
6
|
+
description: 上傳與連結檔案
|
7
|
+
admin:
|
8
|
+
resources:
|
9
|
+
delete: 永遠地移除這個檔案
|
10
|
+
edit: 編輯檔案
|
11
|
+
form:
|
12
|
+
download_current: 下載目前檔案
|
13
|
+
or: 或
|
14
|
+
replace: " 用這個來取代..."
|
15
|
+
maximum_file_size: 檔案大小限制為 %{bytes}
|
16
|
+
resource:
|
17
|
+
download: 下載這個檔案 (%{size})
|
18
|
+
actions:
|
19
|
+
upload_new: 上傳新檔案
|
20
|
+
records:
|
21
|
+
no_files_yet: 目前沒有任何的檔案. 點選 "上傳新檔案" 來加入您的第一個檔案.
|
22
|
+
insert:
|
23
|
+
existing: 已存在的檔案
|
24
|
+
new: 新檔案
|
25
|
+
no_files: 目前沒有檔案.
|
26
|
+
existing_resource:
|
27
|
+
link_to_file: 此檔案連結
|
28
|
+
button_text: 插入
|
28
29
|
activerecord:
|
29
30
|
models:
|
30
|
-
resource: 檔案
|
31
|
+
refinery/resource: 檔案
|
31
32
|
errors:
|
32
33
|
models:
|
33
|
-
resource:
|
34
|
+
refinery/resource:
|
34
35
|
blank: 您必須選取檔案來上傳
|
35
|
-
|
36
|
+
too_big: 檔案必須要小於 %{size} MB 這個大小
|
data/config/routes.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
-
|
1
|
+
Refinery::Core::Engine.routes.draw do
|
2
|
+
match '/system/resources/*dragonfly', :to => Dragonfly[:refinery_resources]
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
|
4
|
+
namespace :admin, :path => 'refinery' do
|
6
5
|
resources :resources, :except => :show do
|
7
|
-
collection
|
8
|
-
get :insert
|
9
|
-
end
|
6
|
+
get :insert, :on => :collection
|
10
7
|
end
|
11
8
|
end
|
12
|
-
|
13
9
|
end
|
@@ -1,21 +1,13 @@
|
|
1
1
|
class CreateRefinerycmsResourcesSchema < ActiveRecord::Migration
|
2
|
-
def
|
3
|
-
create_table
|
4
|
-
t.string
|
5
|
-
t.string
|
6
|
-
t.integer
|
7
|
-
t.
|
8
|
-
t.
|
9
|
-
t.string "file_uid"
|
10
|
-
t.string "file_ext"
|
11
|
-
end
|
12
|
-
end
|
2
|
+
def change
|
3
|
+
create_table :refinery_resources do |t|
|
4
|
+
t.string :file_mime_type
|
5
|
+
t.string :file_name
|
6
|
+
t.integer :file_size
|
7
|
+
t.string :file_uid
|
8
|
+
t.string :file_ext
|
13
9
|
|
14
|
-
|
15
|
-
[::Resource].reject{|m|
|
16
|
-
!(defined?(m) and m.respond_to?(:table_name))
|
17
|
-
}.each do |model|
|
18
|
-
drop_table model.table_name
|
10
|
+
t.timestamps
|
19
11
|
end
|
20
12
|
end
|
21
13
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Refinery
|
2
|
+
class ResourcesGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
def generate_resources_initializer
|
6
|
+
template "config/initializers/refinery/resources.rb.erb", File.join(destination_root, "config", "initializers", "refinery", "resources.rb")
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
data/lib/generators/refinery/resources/templates/config/initializers/refinery/resources.rb.erb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Refinery::Resources.configure do |config|
|
2
|
+
# Configures the maximum allowed upload size (in bytes) for a file upload
|
3
|
+
# config.max_file_size = <%= Refinery::Resources.max_file_size.inspect %>
|
4
|
+
|
5
|
+
# Configure how many resources per page should be displayed when a dialog is presented that contains resources
|
6
|
+
# config.pages_per_dialog = <%= Refinery::Resources.pages_per_dialog.inspect %>
|
7
|
+
|
8
|
+
# Configure how many resources per page should be displayed in the list of resources in the admin area
|
9
|
+
# config.pages_per_admin_index = <%= Refinery::Resources.pages_per_admin_index.inspect %>
|
10
|
+
|
11
|
+
# Configure S3 (you can also use ENV for this)
|
12
|
+
# The s3_backend setting by default defers to the core setting for this but can be set just for resources.
|
13
|
+
# config.s3_backend = Refinery::Core.s3_backend
|
14
|
+
# config.s3_bucket_name = ENV['S3_BUCKET']
|
15
|
+
# config.s3_access_key_id = ENV['S3_KEY']
|
16
|
+
# config.s3_secret_access_key = ENV['S3_SECRET']
|
17
|
+
# config.s3_region = ENV['S3_REGION]
|
18
|
+
|
19
|
+
# Configure Dragonfly
|
20
|
+
# This is where in the middleware stack to insert the Dragonfly middleware
|
21
|
+
# config.dragonfly_insert_before = <%= Refinery::Resources.dragonfly_insert_before.inspect %>
|
22
|
+
# config.dragonfly_secret = <%= Refinery::Resources.dragonfly_secret.inspect %>
|
23
|
+
# config.dragonfly_url_format = <%= Refinery::Resources.dragonfly_url_format.inspect %>
|
24
|
+
# config.datastore_root_path = <%= Refinery::Resources.datastore_root_path.inspect %>
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Resources
|
3
|
+
include ActiveSupport::Configurable
|
4
|
+
|
5
|
+
config_accessor :dragonfly_insert_before, :dragonfly_secret, :dragonfly_url_format,
|
6
|
+
:max_file_size, :pages_per_dialog, :pages_per_admin_index,
|
7
|
+
:s3_backend, :s3_bucket_name, :s3_region,
|
8
|
+
:s3_access_key_id, :s3_secret_access_key,
|
9
|
+
:datastore_root_path
|
10
|
+
|
11
|
+
self.dragonfly_insert_before = 'ActionDispatch::Callbacks'
|
12
|
+
self.dragonfly_secret = Refinery::Core.dragonfly_secret
|
13
|
+
self.dragonfly_url_format = '/system/resources/:job/:basename.:format'
|
14
|
+
|
15
|
+
self.max_file_size = 52428800
|
16
|
+
self.pages_per_dialog = 12
|
17
|
+
self.pages_per_admin_index = 20
|
18
|
+
|
19
|
+
# We have to configure these settings after Rails is available.
|
20
|
+
# But a non-nil custom option can still be provided
|
21
|
+
class << self
|
22
|
+
def datastore_root_path
|
23
|
+
config.datastore_root_path || (Rails.root.join('public', 'system', 'refinery', 'resources').to_s if Rails.root)
|
24
|
+
end
|
25
|
+
|
26
|
+
def s3_backend
|
27
|
+
config.s3_backend.nil? ? Refinery::Core.s3_backend : config.s3_backend
|
28
|
+
end
|
29
|
+
|
30
|
+
def s3_bucket_name
|
31
|
+
config.s3_bucket_name.nil? ? Refinery::Core.s3_bucket_name : config.s3_bucket_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def s3_access_key_id
|
35
|
+
config.s3_access_key_id.nil? ? Refinery::Core.s3_access_key_id : config.s3_access_key_id
|
36
|
+
end
|
37
|
+
|
38
|
+
def s3_secret_access_key
|
39
|
+
config.s3_secret_access_key.nil? ? Refinery::Core.s3_secret_access_key : config.s3_secret_access_key
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'dragonfly'
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
module Resources
|
5
|
+
module Dragonfly
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def setup!
|
9
|
+
app_resources = ::Dragonfly[:refinery_resources]
|
10
|
+
|
11
|
+
app_resources.define_macro(::Refinery::Core::BaseModel, :resource_accessor)
|
12
|
+
|
13
|
+
app_resources.analyser.register(::Dragonfly::Analysis::FileCommandAnalyser)
|
14
|
+
app_resources.content_disposition = :attachment
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure!
|
18
|
+
app_resources = ::Dragonfly[:refinery_resources]
|
19
|
+
app_resources.configure_with(:rails) do |c|
|
20
|
+
c.datastore.root_path = Refinery::Resources.datastore_root_path
|
21
|
+
c.url_format = Refinery::Resources.dragonfly_url_format
|
22
|
+
c.secret = Refinery::Resources.dragonfly_secret
|
23
|
+
end
|
24
|
+
|
25
|
+
if ::Refinery::Resources.s3_backend
|
26
|
+
app_resources.datastore = ::Dragonfly::DataStorage::S3DataStore.new
|
27
|
+
app_resources.datastore.configure do |s3|
|
28
|
+
s3.bucket_name = Refinery::Resources.s3_bucket_name
|
29
|
+
s3.access_key_id = Refinery::Resources.s3_access_key_id
|
30
|
+
s3.secret_access_key = Refinery::Resources.s3_secret_access_key
|
31
|
+
# S3 Region otherwise defaults to 'us-east-1'
|
32
|
+
s3.region = Refinery::Resources.s3_region if Refinery::Resources.s3_region
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def attach!(app)
|
38
|
+
### Extend active record ###
|
39
|
+
app.config.middleware.insert_before Refinery::Resources.dragonfly_insert_before,
|
40
|
+
'Dragonfly::Middleware', :refinery_resources
|
41
|
+
|
42
|
+
app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
|
43
|
+
:verbose => Rails.env.development?,
|
44
|
+
:metastore => "file:#{URI.encode(Rails.root.join('tmp', 'dragonfly', 'cache', 'meta').to_s)}",
|
45
|
+
:entitystore => "file:#{URI.encode(Rails.root.join('tmp', 'dragonfly', 'cache', 'body').to_s)}"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Resources
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
include Refinery::Engine
|
5
|
+
|
6
|
+
isolate_namespace Refinery
|
7
|
+
engine_name :refinery_resources
|
8
|
+
|
9
|
+
config.autoload_paths += %W( #{config.root}/lib )
|
10
|
+
|
11
|
+
initializer 'setup-refinery-resources-with-dragonfly', :before => :load_config_initializers do |app|
|
12
|
+
::Refinery::Resources::Dragonfly.setup!
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer 'attach-refinery-resources-with-dragonfly', :after => :load_config_initializers do |app|
|
16
|
+
::Refinery::Resources::Dragonfly.configure!
|
17
|
+
::Refinery::Resources::Dragonfly.attach!(app)
|
18
|
+
end
|
19
|
+
|
20
|
+
initializer "register refinery_files plugin" do
|
21
|
+
Refinery::Plugin.register do |plugin|
|
22
|
+
plugin.pathname = root
|
23
|
+
plugin.name = 'refinery_files'
|
24
|
+
plugin.menu_match = /refinery\/(refinery_)?(files|resources)$/
|
25
|
+
plugin.version = %q{2.0.0}
|
26
|
+
plugin.activity = {
|
27
|
+
:class_name => :'refinery/resource'
|
28
|
+
}
|
29
|
+
plugin.url = { :controller => '/refinery/admin/resources' }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
config.after_initialize do
|
34
|
+
Refinery.register_extension(Refinery::Resources)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Resources
|
3
|
+
module Validators
|
4
|
+
class FileSizeValidator < ActiveModel::Validator
|
5
|
+
|
6
|
+
def validate(record)
|
7
|
+
file = record.file
|
8
|
+
|
9
|
+
if file.respond_to?(:length) && file.length > Resources.max_file_size
|
10
|
+
record.errors[:file] << ::I18n.t('too_big',
|
11
|
+
:scope => 'activerecord.errors.models.refinery/resource',
|
12
|
+
:size => Resources.max_file_size)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'refinerycms-core'
|
2
|
+
require 'dragonfly'
|
3
|
+
require 'rack/cache'
|
4
|
+
|
5
|
+
module Refinery
|
6
|
+
autoload :ResourcesGenerator, 'generators/refinery/resources/resources_generator'
|
7
|
+
|
8
|
+
module Resources
|
9
|
+
require 'refinery/resources/engine'
|
10
|
+
require 'refinery/resources/configuration'
|
11
|
+
|
12
|
+
autoload :Dragonfly, 'refinery/resources/dragonfly'
|
13
|
+
autoload :Validators, 'refinery/resources/validators'
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def root
|
17
|
+
@root ||= Pathname.new(File.expand_path('../../../', __FILE__))
|
18
|
+
end
|
19
|
+
|
20
|
+
def factory_paths
|
21
|
+
@factory_paths ||= [ root.join("spec/factories").to_s ]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,75 +1 @@
|
|
1
|
-
require '
|
2
|
-
require 'rack/cache'
|
3
|
-
require 'refinerycms-core'
|
4
|
-
|
5
|
-
module Refinery
|
6
|
-
module Resources
|
7
|
-
|
8
|
-
class << self
|
9
|
-
attr_accessor :root
|
10
|
-
def root
|
11
|
-
@root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class Engine < ::Rails::Engine
|
16
|
-
|
17
|
-
initializer 'serve static assets' do |app|
|
18
|
-
app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
|
19
|
-
end
|
20
|
-
|
21
|
-
initializer 'resources-with-dragonfly' do |app|
|
22
|
-
app_resources = Dragonfly[:resources]
|
23
|
-
app_resources.configure_with(:rails) do |c|
|
24
|
-
c.datastore.root_path = Rails.root.join('public', 'system', 'resources').to_s
|
25
|
-
# This url_format makes it so that dragonfly urls work in traditional
|
26
|
-
# situations where the filename and extension are required, e.g. lightbox.
|
27
|
-
# What this does is takes the url that is about to be produced e.g.
|
28
|
-
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
|
29
|
-
# and adds the filename onto the end (say the file was 'refinery_is_awesome.pdf')
|
30
|
-
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.pdf
|
31
|
-
c.url_format = '/system/resources/:job/:basename.:format'
|
32
|
-
c.secret = RefinerySetting.find_or_set(:dragonfly_secret,
|
33
|
-
Array.new(24) { rand(256) }.pack('C*').unpack('H*').first)
|
34
|
-
end
|
35
|
-
|
36
|
-
if Refinery.s3_backend
|
37
|
-
app_resources.configure_with(:heroku, ENV['S3_BUCKET'])
|
38
|
-
# Dragonfly doesn't set the S3 region, so we have to do this manually
|
39
|
-
app_resources.datastore.configure do |d|
|
40
|
-
d.region = ENV['S3_REGION'] if ENV['S3_REGION'] # defaults to 'us-east-1'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
app_resources.define_macro(ActiveRecord::Base, :resource_accessor)
|
45
|
-
app_resources.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)
|
46
|
-
app_resources.content_disposition = :attachment
|
47
|
-
|
48
|
-
### Extend active record ###
|
49
|
-
|
50
|
-
app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :resources
|
51
|
-
|
52
|
-
app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
|
53
|
-
:verbose => Rails.env.development?,
|
54
|
-
:metastore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'meta')}",
|
55
|
-
:entitystore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'body')}"
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
config.after_initialize do
|
60
|
-
::Refinery::Plugin.register do |plugin|
|
61
|
-
plugin.pathname = root
|
62
|
-
plugin.name = 'refinery_files'
|
63
|
-
plugin.url = {:controller => '/admin/resources', :action => 'index'}
|
64
|
-
plugin.menu_match = /(refinery|admin)\/(refinery_)?(files|resources)$/
|
65
|
-
plugin.version = %q{1.0.0}
|
66
|
-
plugin.activity = {
|
67
|
-
:class => Resource
|
68
|
-
}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
::Refinery.engines << 'resources'
|
1
|
+
require 'refinery/resources'
|