refinerycms-images 1.0.11 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/app/controllers/refinery/admin/images_controller.rb +110 -0
  2. data/app/helpers/refinery/admin/images_helper.rb +24 -0
  3. data/app/models/refinery/image.rb +96 -0
  4. data/app/views/refinery/admin/images/_actions.html.erb +15 -0
  5. data/app/views/{admin → refinery/admin}/images/_existing_image.html.erb +13 -26
  6. data/app/views/{admin → refinery/admin}/images/_form.html.erb +11 -15
  7. data/app/views/{admin → refinery/admin}/images/_grid_view.html.erb +7 -5
  8. data/app/views/refinery/admin/images/_images.html.erb +2 -0
  9. data/app/views/{admin → refinery/admin}/images/_list_view.html.erb +0 -0
  10. data/app/views/{admin → refinery/admin}/images/_list_view_image.html.erb +7 -5
  11. data/app/views/refinery/admin/images/_records.html.erb +18 -0
  12. data/app/views/refinery/admin/images/edit.html.erb +1 -0
  13. data/app/views/refinery/admin/images/index.html.erb +6 -0
  14. data/app/views/{admin → refinery/admin}/images/insert.html.erb +10 -13
  15. data/app/views/refinery/admin/images/new.html.erb +1 -0
  16. data/config/locales/bg.yml +37 -36
  17. data/config/locales/cs.yml +37 -36
  18. data/config/locales/da.yml +37 -36
  19. data/config/locales/de.yml +37 -36
  20. data/config/locales/el.yml +37 -36
  21. data/config/locales/en.yml +37 -36
  22. data/config/locales/es.yml +38 -37
  23. data/config/locales/fi.yml +37 -36
  24. data/config/locales/fr.yml +37 -36
  25. data/config/locales/it.yml +47 -45
  26. data/config/locales/ja.yml +44 -0
  27. data/config/locales/ko.yml +44 -0
  28. data/config/locales/lt.yml +37 -36
  29. data/config/locales/lv.yml +37 -36
  30. data/config/locales/nb.yml +37 -37
  31. data/config/locales/nl.yml +36 -35
  32. data/config/locales/pl.yml +38 -37
  33. data/config/locales/pt-BR.yml +38 -37
  34. data/config/locales/rs.yml +37 -37
  35. data/config/locales/ru.yml +37 -36
  36. data/config/locales/sk.yml +37 -36
  37. data/config/locales/sl.yml +36 -35
  38. data/config/locales/sv.yml +37 -36
  39. data/config/locales/vi.yml +37 -36
  40. data/config/locales/zh-CN.yml +37 -36
  41. data/config/locales/zh-TW.yml +37 -36
  42. data/config/routes.rb +4 -7
  43. data/db/migrate/20100913234707_create_refinerycms_images_schema.rb +10 -18
  44. data/lib/generators/refinery/images/images_generator.rb +10 -0
  45. data/lib/generators/refinery/images/templates/config/initializers/refinery/images.rb.erb +41 -0
  46. data/lib/refinery/images.rb +25 -0
  47. data/lib/refinery/images/configuration.rb +54 -0
  48. data/lib/refinery/images/dragonfly.rb +54 -0
  49. data/lib/refinery/images/engine.rb +38 -0
  50. data/lib/refinery/images/validators.rb +7 -0
  51. data/lib/refinery/images/validators/image_size_validator.rb +19 -0
  52. data/lib/refinerycms-images.rb +1 -76
  53. data/refinerycms-images.gemspec +14 -91
  54. data/spec/factories/image.rb +5 -0
  55. data/{features/uploads → spec/fixtures}/beach.jpeg +0 -0
  56. data/spec/fixtures/fathead.png +0 -0
  57. data/spec/fixtures/image-with-dashes.jpg +0 -0
  58. data/spec/lib/generators/refinery/images/images_generator_spec.rb +29 -0
  59. data/spec/models/refinery/image_spec.rb +158 -0
  60. data/spec/requests/refinery/admin/images_spec.rb +103 -0
  61. metadata +116 -106
  62. data/app/controllers/admin/images_controller.rb +0 -106
  63. data/app/helpers/admin/images_helper.rb +0 -27
  64. data/app/models/image.rb +0 -116
  65. data/app/views/admin/images/_actions.html.erb +0 -16
  66. data/app/views/admin/images/_images.html.erb +0 -2
  67. data/app/views/admin/images/_records.html.erb +0 -18
  68. data/app/views/admin/images/edit.html.erb +0 -1
  69. data/app/views/admin/images/index.html.erb +0 -6
  70. data/app/views/admin/images/new.html.erb +0 -1
  71. data/config/locales/jp.yml +0 -43
  72. data/config/locales/lolcat.yml +0 -43
  73. data/features/manage_images.feature +0 -49
  74. data/features/step_definitions/image_steps.rb +0 -40
  75. data/features/support/factories.rb +0 -7
  76. data/features/support/paths.rb +0 -17
  77. data/features/uploads/id-rather-be-here.jpg +0 -0
  78. data/features/uploads/refinery_is_awesome.txt +0 -1
  79. data/lib/gemspec.rb +0 -38
  80. data/lib/generators/refinerycms_images_generator.rb +0 -8
  81. data/spec/models/image_spec.rb +0 -115
  82. data/spec/uploads/beach.jpeg +0 -0
@@ -1,43 +1,44 @@
1
1
  zh-TW:
2
- plugins:
3
- refinery_images:
4
- title: 圖片
5
- description: 管理圖片
6
- admin:
7
- images:
8
- delete: 永遠地移除這張圖片
9
- edit: 編輯圖片
10
- form:
11
- image: 圖片
12
- use_current_image: 使用目前圖片
13
- or:
14
- replace_image: " 用這個來取代..."
15
- current_image: 目前圖片
16
- maximum_image_size: 圖片大小限制為 %{megabytes} MB.
17
- actions:
18
- create_new_image: 新增圖片
19
- records:
20
- no_images_yet: 目前沒有任何圖片. 點選 "新增圖片" 來加入您的第一張圖片.
21
- index:
22
- view:
23
- switch_to: 切換到%{view_name}模式
24
- list: 列表
25
- grid: 格狀
26
- grid_view:
27
- view_live_html: 瀏覽圖片 <br/><em>在新視窗中開啟</em>
28
- existing_image:
29
- button_text: 插入
30
- resize_image: 調整圖片大小?
31
- size: 大小
32
- insert:
33
- existing_image: 圖片庫
34
- new_image: 上傳
2
+ refinery:
3
+ plugins:
4
+ refinery_images:
5
+ title: 圖片
6
+ description: 管理圖片
7
+ admin:
8
+ images:
9
+ delete: 永遠地移除這張圖片
10
+ edit: 編輯圖片
11
+ form:
12
+ image: 圖片
13
+ use_current_image: 使用目前圖片
14
+ or:
15
+ replace_image: " 用這個來取代..."
16
+ current_image: 目前圖片
17
+ maximum_image_size: 圖片大小限制為 %{bytes}.
18
+ actions:
19
+ create_new_image: 新增圖片
20
+ records:
21
+ no_images_yet: 目前沒有任何圖片. 點選 "新增圖片" 來加入您的第一張圖片.
22
+ index:
23
+ view:
24
+ switch_to: 切換到%{view_name}模式
25
+ list: 列表
26
+ grid: 格狀
27
+ grid_view:
28
+ view_live_html: 瀏覽圖片 <br/><em>在新視窗中開啟</em>
29
+ existing_image:
30
+ button_text: 插入
31
+ resize_image: 調整圖片大小?
32
+ size: 大小
33
+ insert:
34
+ existing_image: 圖片庫
35
+ new_image: 上傳
35
36
  activerecord:
36
37
  models:
37
- image: 圖片
38
+ refinery/image: 圖片
38
39
  errors:
39
40
  models:
40
- image:
41
+ refinery/image:
41
42
  blank: 您必須指定一張圖片來上傳
42
- too_long: 圖片必須小於 %{count} 這個大小
43
+ too_big: 圖片必須小於 %{size} MB 這個大小
43
44
  incorrect_format: '您的圖片必須是 JPG, PNG 或是 GIF'
data/config/routes.rb CHANGED
@@ -1,12 +1,9 @@
1
- ::Refinery::Application.routes.draw do
1
+ Refinery::Core::Engine.routes.draw do
2
+ match '/system/images/*dragonfly', :to => Dragonfly[:refinery_images]
2
3
 
3
- match '/system/images/*dragonfly', :to => Dragonfly[:images]
4
-
5
- scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
4
+ namespace :admin, :path => 'refinery' do
6
5
  resources :images, :except => :show do
7
- collection do
8
- get :insert
9
- end
6
+ get :insert, :on => :collection
10
7
  end
11
8
  end
12
9
  end
@@ -1,23 +1,15 @@
1
1
  class CreateRefinerycmsImagesSchema < ActiveRecord::Migration
2
- def self.up
3
- create_table ::Image.table_name, :force => true do |t|
4
- t.string "image_mime_type"
5
- t.string "image_name"
6
- t.integer "image_size"
7
- t.integer "image_width"
8
- t.integer "image_height"
9
- t.datetime "created_at"
10
- t.datetime "updated_at"
11
- t.string "image_uid"
12
- t.string "image_ext"
13
- end
14
- end
2
+ def change
3
+ create_table :refinery_images do |t|
4
+ t.string :image_mime_type
5
+ t.string :image_name
6
+ t.integer :image_size
7
+ t.integer :image_width
8
+ t.integer :image_height
9
+ t.string :image_uid
10
+ t.string :image_ext
15
11
 
16
- def self.down
17
- [::Image].reject{|m|
18
- !(defined?(m) and m.respond_to?(:table_name))
19
- }.each do |model|
20
- drop_table model.table_name
12
+ t.timestamps
21
13
  end
22
14
  end
23
15
  end
@@ -0,0 +1,10 @@
1
+ module Refinery
2
+ class ImagesGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def generate_images_initializer
6
+ template "config/initializers/refinery/images.rb.erb", File.join(destination_root, "config", "initializers", "refinery", "images.rb")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ Refinery::Images.configure do |config|
2
+ # Configures the maximum allowed upload size (in bytes) for an image
3
+ # config.max_image_size = <%= Refinery::Images.max_image_size.inspect %>
4
+
5
+ # Configure how many images per page should be displayed when a dialog is presented that contains images
6
+ # config.pages_per_dialog = <%= Refinery::Images.pages_per_dialog.inspect %>
7
+
8
+ # Configure how many images per page should be displayed when a dialog is presented that
9
+ # contains images and image resize options
10
+ # config.pages_per_dialog_that_have_size_options = <%= Refinery::Images.pages_per_dialog_that_have_size_options.inspect %>
11
+
12
+ # Configure how many images per page should be displayed in the list of images in the admin area
13
+ # config.pages_per_admin_index = <%= Refinery::Images.pages_per_admin_index.inspect %>
14
+
15
+ # Configure image sizes
16
+ # config.user_image_sizes = <%= Refinery::Images.user_image_sizes.inspect %>
17
+
18
+ # Configure image view options
19
+ # config.image_views = <%= Refinery::Images.image_views.inspect %>
20
+
21
+ # Configure default image view
22
+ # config.preferred_image_view = <%= Refinery::Images.preferred_image_view.inspect %>
23
+
24
+ # Configure S3 (you can also use ENV for this)
25
+ # The s3_backend setting by default defers to the core setting for this but can be set just for images.
26
+ # config.s3_backend = Refinery::Core.s3_backend
27
+ # config.s3_bucket_name = ENV['S3_BUCKET']
28
+ # config.s3_access_key_id = ENV['S3_KEY']
29
+ # config.s3_secret_access_key = ENV['S3_SECRET']
30
+ # config.s3_region = ENV['S3_REGION]
31
+
32
+ # Configure Dragonfly
33
+ # This is where in the middleware stack to insert the Dragonfly middleware
34
+ # config.dragonfly_insert_before = <%= Refinery::Images.dragonfly_insert_before.inspect %>
35
+ # config.dragonfly_secret = <%= Refinery::Images.dragonfly_secret.inspect %>
36
+ # If you decide to trust file extensions replace :ext below with :format
37
+ # config.dragonfly_url_format = <%= Refinery::Images.dragonfly_url_format.inspect %>
38
+ # config.datastore_root_path = <%= Refinery::Images.datastore_root_path.inspect %>
39
+ # config.trust_file_extensions = <%= Refinery::Images.trust_file_extensions.inspect %>
40
+
41
+ end
@@ -0,0 +1,25 @@
1
+ require 'refinerycms-core'
2
+ require 'dragonfly'
3
+ require 'rack/cache'
4
+
5
+ module Refinery
6
+ autoload :ImagesGenerator, 'generators/refinery/images/images_generator'
7
+
8
+ module Images
9
+ require 'refinery/images/engine'
10
+ require 'refinery/images/configuration'
11
+
12
+ autoload :Dragonfly, 'refinery/images/dragonfly'
13
+ autoload :Validators, 'refinery/images/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
@@ -0,0 +1,54 @@
1
+ module Refinery
2
+ module Images
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :dragonfly_insert_before, :dragonfly_secret, :dragonfly_url_format,
6
+ :max_image_size, :pages_per_dialog, :pages_per_admin_index,
7
+ :pages_per_dialog_that_have_size_options, :user_image_sizes,
8
+ :image_views, :preferred_image_view, :datastore_root_path,
9
+ :s3_backend, :s3_bucket_name, :s3_region,
10
+ :s3_access_key_id, :s3_secret_access_key, :trust_file_extensions
11
+
12
+ self.dragonfly_insert_before = 'ActionDispatch::Callbacks'
13
+ self.dragonfly_secret = Refinery::Core.dragonfly_secret
14
+ # If you decide to trust file extensions replace :ext below with :format
15
+ self.dragonfly_url_format = '/system/images/:job/:basename.:ext'
16
+ self.trust_file_extensions = false
17
+
18
+ self.max_image_size = 5242880
19
+ self.pages_per_dialog = 18
20
+ self.pages_per_dialog_that_have_size_options = 12
21
+ self.pages_per_admin_index = 20
22
+ self.user_image_sizes = {
23
+ :small => '110x110>',
24
+ :medium => '225x255>',
25
+ :large => '450x450>'
26
+ }
27
+ self.image_views = [:grid, :list]
28
+ self.preferred_image_view = :grid
29
+
30
+ # We have to configure these settings after Rails is available.
31
+ # But a non-nil custom option can still be provided
32
+ class << self
33
+ def datastore_root_path
34
+ config.datastore_root_path || (Rails.root.join('public', 'system', 'refinery', 'images').to_s if Rails.root)
35
+ end
36
+
37
+ def s3_backend
38
+ config.s3_backend.nil? ? Refinery::Core.s3_backend : config.s3_backend
39
+ end
40
+
41
+ def s3_bucket_name
42
+ config.s3_bucket_name.nil? ? Refinery::Core.s3_bucket_name : config.s3_bucket_name
43
+ end
44
+
45
+ def s3_access_key_id
46
+ config.s3_access_key_id.nil? ? Refinery::Core.s3_access_key_id : config.s3_access_key_id
47
+ end
48
+
49
+ def s3_secret_access_key
50
+ config.s3_secret_access_key.nil? ? Refinery::Core.s3_secret_access_key : config.s3_secret_access_key
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ require 'dragonfly'
2
+
3
+ module Refinery
4
+ module Images
5
+ module Dragonfly
6
+
7
+ class << self
8
+ def setup!
9
+ app_images = ::Dragonfly[:refinery_images]
10
+ app_images.configure_with(:imagemagick)
11
+
12
+ app_images.define_macro(::Refinery::Core::BaseModel, :image_accessor)
13
+
14
+ app_images.analyser.register(::Dragonfly::ImageMagick::Analyser)
15
+ app_images.analyser.register(::Dragonfly::Analysis::FileCommandAnalyser)
16
+ end
17
+
18
+ def configure!
19
+ app_images = ::Dragonfly[:refinery_images]
20
+ app_images.configure_with(:rails) do |c|
21
+ c.datastore.root_path = Refinery::Images.datastore_root_path
22
+ c.url_format = Refinery::Images.dragonfly_url_format
23
+ c.secret = Refinery::Images.dragonfly_secret
24
+ c.trust_file_extensions = Refinery::Images.trust_file_extensions
25
+ end
26
+
27
+ if ::Refinery::Images.s3_backend
28
+ app_images.datastore = ::Dragonfly::DataStorage::S3DataStore.new
29
+ app_images.datastore.configure do |s3|
30
+ s3.bucket_name = Refinery::Images.s3_bucket_name
31
+ s3.access_key_id = Refinery::Images.s3_access_key_id
32
+ s3.secret_access_key = Refinery::Images.s3_secret_access_key
33
+ # S3 Region otherwise defaults to 'us-east-1'
34
+ s3.region = Refinery::Images.s3_region if Refinery::Images.s3_region
35
+ end
36
+ end
37
+ end
38
+
39
+ def attach!(app)
40
+ ### Extend active record ###
41
+ app.config.middleware.insert_before Refinery::Resources.dragonfly_insert_before,
42
+ 'Dragonfly::Middleware', :refinery_images
43
+
44
+ app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
45
+ :verbose => Rails.env.development?,
46
+ :metastore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'meta')}",
47
+ :entitystore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'body')}"
48
+ }
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,38 @@
1
+ module Refinery
2
+ module Images
3
+ class Engine < ::Rails::Engine
4
+ include Refinery::Engine
5
+
6
+ isolate_namespace Refinery
7
+ engine_name :refinery_images
8
+
9
+ config.autoload_paths += %W( #{config.root}/lib )
10
+
11
+ initializer 'setup-refinery-images-with-dragonfly', :before => :load_config_initializers do |app|
12
+ ::Refinery::Images::Dragonfly.setup!
13
+ end
14
+
15
+ initializer 'attach-refinery-images-with-dragonfly', :after => :load_config_initializers do |app|
16
+ ::Refinery::Images::Dragonfly.configure!
17
+ ::Refinery::Images::Dragonfly.attach!(app)
18
+ end
19
+
20
+ initializer "register refinery_images plugin" do
21
+ Refinery::Plugin.register do |plugin|
22
+ plugin.pathname = root
23
+ plugin.name = 'refinery_images'
24
+ plugin.version = %q{2.0.0}
25
+ plugin.menu_match = %r{refinery/image(_dialog)?s$}
26
+ plugin.activity = {
27
+ :class_name => :'refinery/image'
28
+ }
29
+ plugin.url = { :controller => '/refinery/admin/images' }
30
+ end
31
+ end
32
+
33
+ config.after_initialize do
34
+ Refinery.register_extension(Refinery::Images)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module Refinery
2
+ module Images
3
+ module Validators
4
+ autoload :ImageSizeValidator, 'refinery/images/validators/image_size_validator'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module Refinery
2
+ module Images
3
+ module Validators
4
+ class ImageSizeValidator < ActiveModel::Validator
5
+
6
+ def validate(record)
7
+ image = record.image
8
+
9
+ if image.respond_to?(:length) && image.length > Images.max_image_size
10
+ record.errors[:image] << ::I18n.t('too_big',
11
+ :scope => 'activerecord.errors.models.refinery/image',
12
+ :size => Images.max_image_size)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,76 +1 @@
1
- require 'dragonfly'
2
- require 'rack/cache'
3
- require 'refinerycms-core'
4
-
5
- module Refinery
6
- module Images
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 'images-with-dragonfly' do |app|
22
- app_images = Dragonfly[:images]
23
- app_images.configure_with(:imagemagick)
24
- app_images.configure_with(:rails) do |c|
25
- c.datastore.root_path = Rails.root.join('public', 'system', 'images').to_s
26
- # This url_format it so that dragonfly urls work in traditional
27
- # situations where the filename and extension are required, e.g. lightbox.
28
- # What this does is takes the url that is about to be produced e.g.
29
- # /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
30
- # and adds the filename onto the end (say the image was 'refinery_is_awesome.jpg')
31
- # /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.jpg
32
- c.url_format = '/system/images/:job/:basename.:format'
33
- c.secret = RefinerySetting.find_or_set(:dragonfly_secret,
34
- Array.new(24) { rand(256) }.pack('C*').unpack('H*').first)
35
- end
36
-
37
- if Refinery.s3_backend
38
- app_images.configure_with(:heroku, ENV['S3_BUCKET'])
39
- # Dragonfly doesn't set the S3 region, so we have to do this manually
40
- app_images.datastore.configure do |d|
41
- d.region = ENV['S3_REGION'] if ENV['S3_REGION'] # otherwise defaults to 'us-east-1'
42
- end
43
- end
44
-
45
- app_images.define_macro(ActiveRecord::Base, :image_accessor)
46
- app_images.analyser.register(Dragonfly::ImageMagick::Analyser)
47
- app_images.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)
48
-
49
- ### Extend active record ###
50
-
51
- app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images
52
-
53
- app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
54
- :verbose => Rails.env.development?,
55
- :metastore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'meta')}",
56
- :entitystore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'body')}"
57
- }
58
- end
59
-
60
- config.after_initialize do
61
- ::Refinery::Plugin.register do |plugin|
62
- plugin.pathname = root
63
- plugin.name = 'refinery_images'
64
- plugin.directory = 'images'
65
- plugin.version = %q{1.0.0}
66
- plugin.menu_match = /(refinery|admin)\/image(_dialog)?s$/
67
- plugin.activity = {
68
- :class => Image
69
- }
70
- end
71
- end
72
- end
73
- end
74
- end
75
-
76
- ::Refinery.engines << 'dashboard'
1
+ require 'refinery/images'