refinerycms-resources 0.9.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/app/controllers/admin/resources_controller.rb +89 -0
  2. data/app/models/resource.rb +53 -0
  3. data/app/views/admin/resources/_existing_resource.html.erb +32 -0
  4. data/app/views/admin/resources/_form.html.erb +55 -0
  5. data/app/views/admin/resources/_resource.html.erb +17 -0
  6. data/app/views/admin/resources/_resources.html.erb +10 -0
  7. data/app/views/admin/resources/edit.html.erb +1 -0
  8. data/app/views/admin/resources/index.html.erb +31 -0
  9. data/app/views/admin/resources/insert.html.erb +54 -0
  10. data/app/views/admin/resources/new.html.erb +1 -0
  11. data/config/locales/cs.yml +34 -0
  12. data/config/locales/da.yml +34 -0
  13. data/config/locales/de.yml +34 -0
  14. data/config/locales/el.yml +34 -0
  15. data/config/locales/en.yml +34 -0
  16. data/config/locales/es.yml +33 -0
  17. data/config/locales/fr.yml +34 -0
  18. data/config/locales/it.yml +43 -0
  19. data/config/locales/lolcat.yml +34 -0
  20. data/config/locales/lt.yml +34 -0
  21. data/config/locales/lv.yml +34 -0
  22. data/config/locales/nb.yml +34 -0
  23. data/config/locales/nl.yml +33 -0
  24. data/config/locales/pl.yml +35 -0
  25. data/config/locales/pt-BR.yml +34 -0
  26. data/config/locales/rs.yml +35 -0
  27. data/config/locales/ru.yml +34 -0
  28. data/config/locales/sl.yml +33 -0
  29. data/config/locales/sv.yml +34 -0
  30. data/config/locales/vi.yml +34 -0
  31. data/config/locales/zh-CN.yml +34 -0
  32. data/config/locales/zh-TW.yml +34 -0
  33. data/config/routes.rb +13 -0
  34. data/db/migrate/20100913234709_create_refinerycms_resources_schema.rb +21 -0
  35. data/features/manage_files.feature +43 -0
  36. data/features/step_definitions/file_steps.rb +21 -0
  37. data/features/support/paths.rb +17 -0
  38. data/features/uploads/beach.jpeg +0 -0
  39. data/features/uploads/refinery_is_awesome.txt +1 -0
  40. data/lib/gemspec.rb +35 -0
  41. data/lib/generators/refinerycms_resources_generator.rb +8 -0
  42. data/lib/refinerycms-resources.rb +68 -0
  43. data/license.md +21 -0
  44. data/readme.md +9 -0
  45. data/refinerycms-resources.gemspec +90 -0
  46. data/spec/models/resource_spec.rb +91 -0
  47. data/spec/uploads/refinery_is_awesome.txt +1 -0
  48. metadata +137 -0
@@ -0,0 +1,68 @@
1
+ require 'rack/cache'
2
+ require 'dragonfly'
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
+ initializer 'resources-with-dragonfly' do |app|
17
+ app_resources = Dragonfly[:resources]
18
+ app_resources.configure_with(:rails) do |c|
19
+ c.datastore.root_path = Rails.root.join('public', 'system', 'resources').to_s
20
+ c.url_path_prefix = '/system/resources'
21
+ c.secret = RefinerySetting.find_or_set(:dragonfly_secret,
22
+ Array.new(24) { rand(256) }.pack('C*').unpack('H*').first)
23
+ end
24
+ app_resources.configure_with(:heroku, ENV['S3_BUCKET']) if Refinery.s3_backend
25
+
26
+ app_resources.define_macro(ActiveRecord::Base, :resource_accessor)
27
+ app_resources.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)
28
+ app_resources.content_disposition = :attachment
29
+
30
+ # This url_suffix makes it so that dragonfly urls work in traditional
31
+ # situations where the filename and extension are required, e.g. lightbox.
32
+ # What this does is takes the url that is about to be produced e.g.
33
+ # /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
34
+ # and adds the filename onto the end (say the file was 'refinery_is_awesome.pdf')
35
+ # /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.pdf
36
+ # Officially the way to do it, from: http://markevans.github.com/dragonfly/file.URLs.html
37
+ app_resources.url_suffix = proc{|job|
38
+ object_file_name = job.uid_basename.gsub(%r{^(\d{4}|\d{2})[_/]\d{2}[_/]\d{2}[_/]\d{2,3}[_/](\d{2}/\d{2}/\d{3}/)?}, '')
39
+ "/#{object_file_name}#{job.encoded_extname || job.uid_extname}"
40
+ }
41
+
42
+ ### Extend active record ###
43
+
44
+ app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :resources, '/system/resources'
45
+
46
+ app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
47
+ :verbose => Rails.env.development?,
48
+ :metastore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'meta')}",
49
+ :entitystore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'body')}"
50
+ }
51
+ end
52
+
53
+ config.after_initialize do
54
+ ::Refinery::Plugin.register do |plugin|
55
+ plugin.name = "refinery_files"
56
+ plugin.url = {:controller => '/admin/resources', :action => 'index'}
57
+ plugin.menu_match = /(refinery|admin)\/(refinery_)?(files|resources)$/
58
+ plugin.version = %q{0.9.9}
59
+ plugin.activity = {
60
+ :class => Resource
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ ::Refinery.engines << 'resources'
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2005-2010 [Resolve Digital](http://www.resolvedigital.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,9 @@
1
+ # Resources (Files)
2
+
3
+ ## About
4
+
5
+ The Resources plugin allows you to upload files such as PDFs and other files you want your users to download.
6
+
7
+ ## How it works
8
+
9
+ The resources plugin uses [dragonfly](http://github.com/markevans/dragonfly) to handle the storage of files. This plugin is mainly comprised of the [Crudfiy mixin](http://github.com/resolve/refinerycms/blob/master/vendor/plugins/refinery/crud.md).
@@ -0,0 +1,90 @@
1
+ # DO NOT EDIT THIS FILE DIRECTLY! Instead, use lib/gemspec.rb to generate it.
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{refinerycms-resources}
5
+ s.version = %q{0.9.9.1}
6
+ s.summary = %q{Resources engine for Refinery CMS}
7
+ s.description = %q{Handles all file upload and processing functionality in Refinery CMS.}
8
+ s.date = %q{2011-02-15}
9
+ s.email = %q{info@refinerycms.com}
10
+ s.homepage = %q{http://refinerycms.com}
11
+ s.rubyforge_project = %q{refinerycms}
12
+ s.authors = ['Resolve Digital', 'Philip Arndt', 'David Jones', 'Steven Heidel']
13
+ s.license = %q{MIT}
14
+ s.require_paths = %w(lib)
15
+ s.executables = %w()
16
+
17
+ s.files = [
18
+ 'app',
19
+ 'app/controllers',
20
+ 'app/controllers/admin',
21
+ 'app/controllers/admin/resources_controller.rb',
22
+ 'app/models',
23
+ 'app/models/resource.rb',
24
+ 'app/views',
25
+ 'app/views/admin',
26
+ 'app/views/admin/resources',
27
+ 'app/views/admin/resources/_existing_resource.html.erb',
28
+ 'app/views/admin/resources/_form.html.erb',
29
+ 'app/views/admin/resources/_resource.html.erb',
30
+ 'app/views/admin/resources/_resources.html.erb',
31
+ 'app/views/admin/resources/edit.html.erb',
32
+ 'app/views/admin/resources/index.html.erb',
33
+ 'app/views/admin/resources/insert.html.erb',
34
+ 'app/views/admin/resources/new.html.erb',
35
+ 'config',
36
+ 'config/locales',
37
+ 'config/locales/cs.yml',
38
+ 'config/locales/da.yml',
39
+ 'config/locales/de.yml',
40
+ 'config/locales/el.yml',
41
+ 'config/locales/en.yml',
42
+ 'config/locales/es.yml',
43
+ 'config/locales/fr.yml',
44
+ 'config/locales/it.yml',
45
+ 'config/locales/lolcat.yml',
46
+ 'config/locales/lt.yml',
47
+ 'config/locales/lv.yml',
48
+ 'config/locales/nb.yml',
49
+ 'config/locales/nl.yml',
50
+ 'config/locales/pl.yml',
51
+ 'config/locales/pt-BR.yml',
52
+ 'config/locales/rs.yml',
53
+ 'config/locales/ru.yml',
54
+ 'config/locales/sl.yml',
55
+ 'config/locales/sv.yml',
56
+ 'config/locales/vi.yml',
57
+ 'config/locales/zh-CN.yml',
58
+ 'config/locales/zh-TW.yml',
59
+ 'config/routes.rb',
60
+ 'db',
61
+ 'db/migrate',
62
+ 'db/migrate/20100913234709_create_refinerycms_resources_schema.rb',
63
+ 'features',
64
+ 'features/manage_files.feature',
65
+ 'features/step_definitions',
66
+ 'features/step_definitions/file_steps.rb',
67
+ 'features/support',
68
+ 'features/support/paths.rb',
69
+ 'features/uploads',
70
+ 'features/uploads/beach.jpeg',
71
+ 'features/uploads/refinery_is_awesome.txt',
72
+ 'lib',
73
+ 'lib/gemspec.rb',
74
+ 'lib/generators',
75
+ 'lib/generators/refinerycms_resources_generator.rb',
76
+ 'lib/refinerycms-resources.rb',
77
+ 'license.md',
78
+ 'readme.md',
79
+ 'refinerycms-resources.gemspec',
80
+ 'spec',
81
+ 'spec/models',
82
+ 'spec/models/resource_spec.rb',
83
+ 'spec/uploads',
84
+ 'spec/uploads/refinery_is_awesome.txt'
85
+ ]
86
+
87
+ s.add_dependency 'refinerycms-core', '~> 0.9.9.1'
88
+ s.add_dependency 'dragonfly', '~> 0.8.2'
89
+ s.add_dependency 'rack-cache', '~> 0.5.2'
90
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource do
4
+
5
+ def reset_resource(options = {})
6
+ @valid_attributes = {
7
+ :id => 1,
8
+ :file => File.new(File.expand_path('../../uploads/refinery_is_awesome.txt', __FILE__))
9
+ }.merge(options)
10
+
11
+ @resource.destroy if @resource
12
+ @resource = Resource.create!(@valid_attributes)
13
+ end
14
+
15
+ def resource_can_be_destroyed
16
+ @resource.destroy.should == true
17
+ end
18
+
19
+ before(:each) do
20
+ reset_resource
21
+ end
22
+
23
+ context "with valid attributes" do
24
+ it "should create successfully" do
25
+ @resource.errors.empty?
26
+ end
27
+ end
28
+
29
+ context "resource url" do
30
+ it "should respond to .url" do
31
+ @resource.respond_to?(:url).should == true
32
+ end
33
+
34
+ it "should not support thumbnailing like images do" do
35
+ @resource.respond_to?(:thumbnail).should == false
36
+ end
37
+
38
+ it "should contain its filename at the end" do
39
+ @resource.url.split('/').last.should == @resource.file_name
40
+ end
41
+ end
42
+
43
+ describe "#type_of_content" do
44
+ it "returns formated mime type" do
45
+ @resource.type_of_content.should == "text plain"
46
+ end
47
+ end
48
+
49
+ describe "#title" do
50
+ it "returns a titleized version of the filename" do
51
+ @resource.title.should == "Refinery Is Awesome"
52
+ end
53
+ end
54
+
55
+ describe ".per_page" do
56
+ context "dialog is true" do
57
+ it "returns resource count specified by PAGES_PER_DIALOG constant" do
58
+ Resource.per_page(true).should == Resource::PAGES_PER_DIALOG
59
+ end
60
+ end
61
+
62
+ context "dialog is false" do
63
+ it "returns resource count specified by PAGES_PER_ADMIN_INDEX constant" do
64
+ Resource.per_page.should == Resource::PAGES_PER_ADMIN_INDEX
65
+ end
66
+ end
67
+ end
68
+
69
+ describe ".create_resources" do
70
+ let(:file) { File.new(File.expand_path('../../uploads/refinery_is_awesome.txt', __FILE__)) }
71
+
72
+ context "only one resource uploaded" do
73
+ it "returns an array containing one resource" do
74
+ Resource.create_resources(:file => file).should have(1).item
75
+ end
76
+ end
77
+
78
+ context "many resources uploaded at once" do
79
+ it "returns an array containing all those resources" do
80
+ Resource.create_resources(:file => [file, file, file]).should have(3).items
81
+ end
82
+ end
83
+
84
+ specify "each returned array item should be an instance of resource" do
85
+ Resource.create_resources(:file => [file, file, file]).each do |resource|
86
+ resource.should be_an_instance_of(Resource)
87
+ end
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1 @@
1
+ http://www.refineryhq.com/
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-resources
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.9.9.1
6
+ platform: ruby
7
+ authors:
8
+ - Resolve Digital
9
+ - Philip Arndt
10
+ - David Jones
11
+ - Steven Heidel
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-02-15 00:00:00 +13:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: refinerycms-core
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.9.9.1
28
+ type: :runtime
29
+ version_requirements: *id001
30
+ - !ruby/object:Gem::Dependency
31
+ name: dragonfly
32
+ prerelease: false
33
+ requirement: &id002 !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 0.8.2
39
+ type: :runtime
40
+ version_requirements: *id002
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-cache
43
+ prerelease: false
44
+ requirement: &id003 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 0.5.2
50
+ type: :runtime
51
+ version_requirements: *id003
52
+ description: Handles all file upload and processing functionality in Refinery CMS.
53
+ email: info@refinerycms.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - app/controllers/admin/resources_controller.rb
62
+ - app/models/resource.rb
63
+ - app/views/admin/resources/_existing_resource.html.erb
64
+ - app/views/admin/resources/_form.html.erb
65
+ - app/views/admin/resources/_resource.html.erb
66
+ - app/views/admin/resources/_resources.html.erb
67
+ - app/views/admin/resources/edit.html.erb
68
+ - app/views/admin/resources/index.html.erb
69
+ - app/views/admin/resources/insert.html.erb
70
+ - app/views/admin/resources/new.html.erb
71
+ - config/locales/cs.yml
72
+ - config/locales/da.yml
73
+ - config/locales/de.yml
74
+ - config/locales/el.yml
75
+ - config/locales/en.yml
76
+ - config/locales/es.yml
77
+ - config/locales/fr.yml
78
+ - config/locales/it.yml
79
+ - config/locales/lolcat.yml
80
+ - config/locales/lt.yml
81
+ - config/locales/lv.yml
82
+ - config/locales/nb.yml
83
+ - config/locales/nl.yml
84
+ - config/locales/pl.yml
85
+ - config/locales/pt-BR.yml
86
+ - config/locales/rs.yml
87
+ - config/locales/ru.yml
88
+ - config/locales/sl.yml
89
+ - config/locales/sv.yml
90
+ - config/locales/vi.yml
91
+ - config/locales/zh-CN.yml
92
+ - config/locales/zh-TW.yml
93
+ - config/routes.rb
94
+ - db/migrate/20100913234709_create_refinerycms_resources_schema.rb
95
+ - features/manage_files.feature
96
+ - features/step_definitions/file_steps.rb
97
+ - features/support/paths.rb
98
+ - features/uploads/beach.jpeg
99
+ - features/uploads/refinery_is_awesome.txt
100
+ - lib/gemspec.rb
101
+ - lib/generators/refinerycms_resources_generator.rb
102
+ - lib/refinerycms-resources.rb
103
+ - license.md
104
+ - readme.md
105
+ - refinerycms-resources.gemspec
106
+ - spec/models/resource_spec.rb
107
+ - spec/uploads/refinery_is_awesome.txt
108
+ has_rdoc: true
109
+ homepage: http://refinerycms.com
110
+ licenses:
111
+ - MIT
112
+ post_install_message:
113
+ rdoc_options: []
114
+
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project: refinerycms
132
+ rubygems_version: 1.5.2
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Resources engine for Refinery CMS
136
+ test_files: []
137
+