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.
Files changed (75) hide show
  1. data/app/controllers/refinery/admin/resources_controller.rb +87 -0
  2. data/app/models/refinery/resource.rb +49 -0
  3. data/app/views/refinery/admin/resources/_actions.html.erb +8 -0
  4. data/app/views/{admin → refinery/admin}/resources/_existing_resource.html.erb +7 -13
  5. data/app/views/{admin → refinery/admin}/resources/_form.html.erb +14 -18
  6. data/app/views/refinery/admin/resources/_records.html.erb +16 -0
  7. data/app/views/refinery/admin/resources/_resource.html.erb +20 -0
  8. data/app/views/{admin → refinery/admin}/resources/_resources.html.erb +2 -2
  9. data/app/views/refinery/admin/resources/edit.html.erb +1 -0
  10. data/app/views/refinery/admin/resources/index.html.erb +6 -0
  11. data/app/views/{admin → refinery/admin}/resources/insert.html.erb +10 -13
  12. data/app/views/refinery/admin/resources/new.html.erb +1 -0
  13. data/config/locales/bg.yml +30 -29
  14. data/config/locales/cs.yml +32 -30
  15. data/config/locales/da.yml +30 -29
  16. data/config/locales/de.yml +30 -29
  17. data/config/locales/el.yml +30 -29
  18. data/config/locales/en.yml +30 -29
  19. data/config/locales/es.yml +31 -30
  20. data/config/locales/fi.yml +30 -29
  21. data/config/locales/fr.yml +30 -29
  22. data/config/locales/it.yml +41 -39
  23. data/config/locales/ja.yml +36 -0
  24. data/config/locales/ko.yml +36 -0
  25. data/config/locales/lt.yml +30 -29
  26. data/config/locales/lv.yml +30 -29
  27. data/config/locales/nb.yml +30 -29
  28. data/config/locales/nl.yml +29 -28
  29. data/config/locales/pl.yml +31 -30
  30. data/config/locales/pt-BR.yml +30 -29
  31. data/config/locales/rs.yml +30 -30
  32. data/config/locales/ru.yml +30 -29
  33. data/config/locales/sk.yml +30 -29
  34. data/config/locales/sl.yml +29 -28
  35. data/config/locales/sv.yml +30 -29
  36. data/config/locales/vi.yml +30 -29
  37. data/config/locales/zh-CN.yml +30 -29
  38. data/config/locales/zh-TW.yml +30 -29
  39. data/config/routes.rb +4 -8
  40. data/db/migrate/20100913234709_create_refinerycms_resources_schema.rb +8 -16
  41. data/lib/generators/refinery/resources/resources_generator.rb +10 -0
  42. data/lib/generators/refinery/resources/templates/config/initializers/refinery/resources.rb.erb +26 -0
  43. data/lib/refinery/resources/configuration.rb +43 -0
  44. data/lib/refinery/resources/dragonfly.rb +52 -0
  45. data/lib/refinery/resources/engine.rb +38 -0
  46. data/lib/refinery/resources/validators/file_size_validator.rb +19 -0
  47. data/lib/refinery/resources/validators.rb +7 -0
  48. data/lib/refinery/resources.rb +25 -0
  49. data/lib/refinerycms-resources.rb +1 -75
  50. data/refinerycms-resources.gemspec +14 -83
  51. data/spec/factories/resource.rb +5 -0
  52. data/{features/uploads → spec/fixtures}/refinery_is_awesome.txt +0 -0
  53. data/spec/fixtures/refinery_is_awesome2.txt +1 -0
  54. data/spec/lib/generators/refinery/resources/resources_generator_spec.rb +29 -0
  55. data/spec/models/refinery/resource_spec.rb +118 -0
  56. data/spec/requests/refinery/admin/resources_spec.rb +148 -0
  57. metadata +111 -101
  58. data/app/controllers/admin/resources_controller.rb +0 -87
  59. data/app/models/resource.rb +0 -54
  60. data/app/views/admin/resources/_actions.html.erb +0 -11
  61. data/app/views/admin/resources/_records.html.erb +0 -16
  62. data/app/views/admin/resources/_resource.html.erb +0 -17
  63. data/app/views/admin/resources/edit.html.erb +0 -1
  64. data/app/views/admin/resources/index.html.erb +0 -6
  65. data/app/views/admin/resources/new.html.erb +0 -1
  66. data/config/locales/jp.yml +0 -35
  67. data/config/locales/lolcat.yml +0 -35
  68. data/features/manage_files.feature +0 -43
  69. data/features/step_definitions/file_steps.rb +0 -21
  70. data/features/support/paths.rb +0 -17
  71. data/features/uploads/beach.jpeg +0 -0
  72. data/lib/gemspec.rb +0 -38
  73. data/lib/generators/refinerycms_resources_generator.rb +0 -8
  74. data/spec/models/resource_spec.rb +0 -78
  75. data/spec/uploads/refinery_is_awesome.txt +0 -1
@@ -1,87 +0,0 @@
1
- module Admin
2
- class ResourcesController < Admin::BaseController
3
-
4
- crudify :resource,
5
- :order => "updated_at DESC",
6
- :xhr_paging => true
7
-
8
- before_filter :init_dialog
9
-
10
- def new
11
- @resource = Resource.new if @resource.nil?
12
-
13
- @url_override = admin_resources_path(:dialog => from_dialog?)
14
- end
15
-
16
- def create
17
- @resources = Resource.create_resources(params[:resource])
18
- @resource = @resources.detect { |r| !r.valid? }
19
-
20
- unless params[:insert]
21
- if @resources.all?(&:valid?)
22
- flash.notice = t('created', :scope => 'refinery.crudify', :what => "'#{@resources.collect{|r| r.title}.join("', '")}'")
23
- unless from_dialog?
24
- redirect_to :action => 'index'
25
- else
26
- render :text => "<script>parent.window.location = '#{admin_resources_url}';</script>"
27
- end
28
- else
29
- self.new # important for dialogs
30
- render :action => 'new'
31
- end
32
- else
33
- if @resources.all?(&:valid?)
34
- @resource_id = @resources.detect(&:persisted?).id
35
- @resource = nil
36
-
37
- redirect_to request.query_parameters.merge(:action => 'insert')
38
- else
39
- self.insert
40
- end
41
- end
42
- end
43
-
44
- def insert
45
- self.new if @resource.nil?
46
-
47
- @url_override = admin_resources_path(request.query_parameters.merge(:insert => true))
48
-
49
- if params[:conditions].present?
50
- extra_condition = params[:conditions].split(',')
51
-
52
- extra_condition[1] = true if extra_condition[1] == "true"
53
- extra_condition[1] = false if extra_condition[1] == "false"
54
- extra_condition[1] = nil if extra_condition[1] == "nil"
55
- paginate_resources({extra_condition[0].to_sym => extra_condition[1]})
56
- else
57
- paginate_resources
58
- end
59
- render :action => "insert"
60
- end
61
-
62
- protected
63
-
64
- def init_dialog
65
- @app_dialog = params[:app_dialog].present?
66
- @field = params[:field]
67
- @update_resource = params[:update_resource]
68
- @update_text = params[:update_text]
69
- @thumbnail = params[:thumbnail]
70
- @callback = params[:callback]
71
- @conditions = params[:conditions]
72
- @current_link = params[:current_link]
73
- end
74
-
75
- def restrict_controller
76
- super unless action_name == 'insert'
77
- end
78
-
79
- def paginate_resources(conditions={})
80
- @resources = Resource.paginate :page => (@paginate_page_number ||= params[:page]),
81
- :conditions => conditions,
82
- :order => 'created_at DESC',
83
- :per_page => Resource.per_page(from_dialog?)
84
- end
85
-
86
- end
87
- end
@@ -1,54 +0,0 @@
1
- class Resource < ActiveRecord::Base
2
-
3
- attr_accessible :id, :file
4
- # What is the max resource size a user can upload
5
- MAX_SIZE_IN_MB = 50
6
-
7
- resource_accessor :file
8
-
9
- validates :file, :presence => {},
10
- :length => { :maximum => MAX_SIZE_IN_MB.megabytes }
11
-
12
- # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
13
- acts_as_indexed :fields => [:file_name, :title, :type_of_content]
14
-
15
- # when a dialog pops up with resources, how many resources per page should there be
16
- PAGES_PER_DIALOG = 12
17
-
18
- # when listing resources out in the admin area, how many resources should show per page
19
- PAGES_PER_ADMIN_INDEX = 20
20
-
21
- delegate :ext, :size, :mime_type, :url, :to => :file
22
-
23
- # used for searching
24
- def type_of_content
25
- mime_type.split("/").join(" ")
26
- end
27
-
28
- # Returns a titleized version of the filename
29
- # my_file.pdf returns My File
30
- def title
31
- CGI::unescape(file_name.to_s).gsub(/\.\w+$/, '').titleize
32
- end
33
-
34
- class << self
35
- # How many resources per page should be displayed?
36
- def per_page(dialog = false)
37
- dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
38
- end
39
-
40
- def create_resources(params)
41
- resources = []
42
-
43
- unless params.present? and params[:file].is_a?(Array)
44
- resources << create(params)
45
- else
46
- params[:file].each do |resource|
47
- resources << create(:file => resource)
48
- end
49
- end
50
-
51
- resources
52
- end
53
- end
54
- end
@@ -1,11 +0,0 @@
1
- <ul>
2
- <li>
3
- <%= render :partial => "/shared/admin/search", :locals => {:url => admin_resources_url} %>
4
- </li>
5
- <li>
6
- <%= link_to t('.upload_new'), new_admin_resource_url(:dialog => true,
7
- :width => 600,
8
- :height => 300),
9
- :class => "add_icon" %>
10
- </li>
11
- </ul>
@@ -1,16 +0,0 @@
1
- <% if searching? %>
2
- <h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2>
3
- <% end %>
4
- <% if @resources.any? %>
5
- <div class='pagination_container'>
6
- <%= render :partial => 'resources' %>
7
- </div>
8
- <% else %>
9
- <p>
10
- <% unless searching? %>
11
- <strong><%= t('.no_files_yet') %></strong>
12
- <% else %>
13
- <%= t('no_results', :scope => 'shared.admin.search') %>
14
- <% end %>
15
- </p>
16
- <% end %>
@@ -1,17 +0,0 @@
1
- <li class='clearfix record <%= cycle("on", "on-hover") %>'>
2
- <span class='title <%= resource.ext %>'>
3
- <%= resource.title %>.<%= resource.ext %>
4
- <span class="preview">- <%= number_to_human_size(resource.size) %></span>
5
- </span>
6
- <span class='actions'>
7
- <%= link_to refinery_icon_tag('page_white_put.png'), resource.url,
8
- :title => t('.download', :size => number_to_human_size(resource.size)) %>
9
- <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_resource_path(resource),
10
- :title => t('edit', :scope => 'admin.resources') %>
11
- <%= link_to refinery_icon_tag('delete.png'), admin_resource_path(resource),
12
- :class => "cancel confirm-delete",
13
- :title => t('delete', :scope => 'admin.resources'),
14
- :confirm => t('message', :scope => 'shared.admin.delete', :title => resource.title),
15
- :method => :delete %>
16
- </span>
17
- </li>
@@ -1 +0,0 @@
1
- <%= render :partial => "form" -%>
@@ -1,6 +0,0 @@
1
- <div id='records' class='files'>
2
- <%= render :partial => 'records' %>
3
- </div>
4
- <div id='actions'>
5
- <%= render :partial => 'actions' %>
6
- </div>
@@ -1 +0,0 @@
1
- <%= render :partial => "form" -%>
@@ -1,35 +0,0 @@
1
- jp:
2
- plugins:
3
- refinery_files:
4
- title: ファイル
5
- description: ファイルのアップロードと管理
6
- admin:
7
- resources:
8
- delete: ファイルを削除
9
- edit: ファイルを変更
10
- form:
11
- download_current: ファイルをダウンロード
12
- or: または
13
- replace: "このファイルと差し替える"
14
- maximum_file_size: "ファイルは最大で%{megabytes}MBまでです。"
15
- resource:
16
- download: "ファイルをダウンロードする(%{size})"
17
- actions:
18
- upload_new: ファイルをアップロードする
19
- records:
20
- no_files_yet: まだファイルはありません。「ファイルをアップロードする」をクリックして下さい。
21
- insert:
22
- existing: 既存のファイル
23
- new: 新規のファイル
24
- no_files: ファイルはありません。
25
- existing_resource:
26
- link_to_file: このファイルにリンクする
27
- button_text: 挿入
28
- activerecord:
29
- models:
30
- resource: ファイル
31
- errors:
32
- models:
33
- resource:
34
- blank: アップロードするファイルを指定して下さい。
35
- too_long: "ファイルは最大で%{count}までです。"
@@ -1,35 +0,0 @@
1
- lolcat:
2
- plugins:
3
- refinery_files:
4
- title: FILEZ
5
- description: UPLOAD AN LINK 2 FILEZ
6
- admin:
7
- resources:
8
- delete: REMOOV DIS FILE FOREVR
9
- edit: EDIT DIS FILE
10
- form:
11
- download_current: DOWNLOAD CURRENT FILE
12
- or: OR
13
- replace: " REPLACE IT WIF DIS WAN..."
14
- maximum_file_size: TEH MAXIMUM FILE SIZE IZ %{megabytes} MEGABYTEZ.
15
- resource:
16
- download: DOWNLOAD DIS FILE (%{size})
17
- actions:
18
- upload_new: UPLOAD NEW FILE
19
- records:
20
- no_files_yet: THAR R NO FILEZ YET. CLICK "UPLOAD NEW FILEZ" 2 ADD UR FURST FILE.
21
- insert:
22
- existing: EXISTIN FILE
23
- new: NEW FILE
24
- no_files: THAR R NO FILEZ.
25
- existing_resource:
26
- link_to_file: LINK 2 DIS FILE
27
- button_text: INSERT
28
- activerecord:
29
- models:
30
- resource: FILE
31
- errors:
32
- models:
33
- resource:
34
- blank: U MUST SPECIFY FILE 4 UPLOAD
35
- too_long: FILE SHUD BE SMALLR THAN %{count} IN SIZE
@@ -1,43 +0,0 @@
1
- @refinerycms @files @files-manage @resources @resources-manage @manage
2
- Feature: Manage Files
3
- In order to control the content on my website
4
- As an administrator
5
- I want to create and manage files
6
-
7
- Background:
8
- Given I am a logged in refinery user
9
- And I have no files
10
-
11
- @files-valid @valid
12
- Scenario: Create Valid File
13
- When I go to the list of files
14
- And I follow "Upload new file"
15
- And I attach the file at "refinery_is_awesome.txt"
16
- And I press "Save"
17
- Then the file "refinery_is_awesome.txt" should have uploaded successfully
18
- And I should have 1 file
19
-
20
- @files-edit @edit
21
- Scenario: Edit Existing File
22
- When I upload the file at "refinery_is_awesome.txt"
23
- And I go to the list of files
24
- And I follow "Edit this file"
25
- And I attach the file at "beach.jpeg"
26
- And I press "Save"
27
- Then the file "beach.jpeg" should have uploaded successfully
28
- And I should have 1 file
29
-
30
- @files-show @show
31
- Scenario: Download Existing File
32
- When I upload the file at "refinery_is_awesome.txt"
33
- And I go to the list of files
34
- And I follow "Download this file"
35
- Then I should see "http://www.refineryhq.com/"
36
-
37
- @files-delete @delete
38
- Scenario: Files Delete
39
- When I upload the file at "refinery_is_awesome.txt"
40
- And I go to the list of files
41
- And I follow "Remove this file forever"
42
- Then I should see "'Refinery Is Awesome' was successfully removed."
43
- And I should have 0 files
@@ -1,21 +0,0 @@
1
- Given /^I have no files$/ do
2
- Resource.destroy_all
3
- end
4
-
5
- When /^I attach the file at "([^\"]*)"$/ do |file_path|
6
- attach_file('resource_file', File.join(File.expand_path('../../uploads/', __FILE__), file_path))
7
- end
8
-
9
- Then /^the file "([^\"]*)" should have uploaded successfully$/ do |file_name|
10
- Resource.find_by_file_name(file_name).nil?.should == false
11
- end
12
-
13
- And /^I should have ([0-9]+) files?$/ do |number|
14
- Resource.count.should == number.to_i
15
- end
16
-
17
- When /^I upload the file at "([^\"]*)"$/ do |file_path|
18
- visit new_admin_resource_path
19
- attach_file('resource_file', File.join(File.expand_path('../../uploads/', __FILE__), file_path))
20
- click_button 'Save'
21
- end
@@ -1,17 +0,0 @@
1
- module NavigationHelpers
2
- module Refinery
3
- module Resources
4
- def path_to(page_name)
5
- case page_name
6
- when /the list of files/
7
- admin_resources_path
8
-
9
- when /the new file form/
10
- new_admin_resource_path
11
- else
12
- nil
13
- end
14
- end
15
- end
16
- end
17
- end
Binary file
data/lib/gemspec.rb DELETED
@@ -1,38 +0,0 @@
1
- # Encoding: UTF-8
2
- require 'pathname'
3
- gempath = Pathname.new(File.expand_path('../../', __FILE__))
4
- require gempath.join('..', 'base', 'lib', 'base', 'refinery')
5
-
6
- gemspec = <<EOF
7
- # Encoding: UTF-8
8
- # DO NOT EDIT THIS FILE DIRECTLY! Instead, use lib/gemspec.rb to generate it.
9
-
10
- Gem::Specification.new do |s|
11
- s.name = %q{#{gemname = 'refinerycms-resources'}}
12
- s.version = %q{#{::Refinery.version}}
13
- s.summary = %q{Resources engine for Refinery CMS}
14
- s.description = %q{Handles all file upload and processing functionality in Refinery CMS.}
15
- s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
16
- s.email = %q{info@refinerycms.com}
17
- s.homepage = %q{http://refinerycms.com}
18
- s.rubyforge_project = %q{refinerycms}
19
- s.authors = ['Resolve Digital', 'Philip Arndt', 'David Jones', 'Steven Heidel', 'Uģis Ozols']
20
- s.license = %q{MIT}
21
- s.require_paths = %w(lib)
22
- s.executables = %w(#{Pathname.glob(gempath.join('bin/*')).map{|d| d.relative_path_from(gempath)}.sort.join(" ")})
23
-
24
- s.files = [
25
- '#{%w( **/{*,.rspec,.gitignore,.yardopts} ).map { |file| Pathname.glob(gempath.join(file)) }.flatten.reject{|f|
26
- !f.exist? or f.to_s =~ /(\.(gem|rbc)|tmp(\/.*)?|spec\/lib\/tmp(\/.*)?)$/ or (f.directory? and f.children.empty?)
27
- }.map{|d| d.relative_path_from(gempath)}.uniq.sort.join("',\n '")}'
28
- ]
29
-
30
- s.add_dependency 'refinerycms-core', '= #{::Refinery::Version}'
31
- s.add_dependency 'activerecord', '~> 3.0.10'
32
- s.add_dependency 'dragonfly', '~> 0.9.0'
33
- s.add_dependency 'rack-cache', '>= 0.5.3'
34
- end
35
- EOF
36
-
37
- (gemfile = gempath.join("#{gemname}.gemspec")).open('w') {|f| f.puts(gemspec)}
38
- puts `cd #{gempath} && gem build #{gemfile}` if ARGV.any?{|a| a == "BUILD=true"}
@@ -1,8 +0,0 @@
1
- require 'refinery/generators'
2
-
3
- class RefinerycmsResources < ::Refinery::Generators::EngineInstaller
4
-
5
- source_root File.expand_path('../../../', __FILE__)
6
- engine_name "resources"
7
-
8
- end
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Resource do
4
-
5
- let(:resource) do
6
- Resource.create!(:id => 1,
7
- :file => File.new(File.expand_path('../../uploads/refinery_is_awesome.txt', __FILE__)))
8
- end
9
-
10
- context "with valid attributes" do
11
- it "should create successfully" do
12
- resource.errors.should be_empty
13
- end
14
- end
15
-
16
- context "resource url" do
17
- it "should respond to .url" do
18
- resource.should respond_to(:url)
19
- end
20
-
21
- it "should not support thumbnailing like images do" do
22
- resource.should_not respond_to(:thumbnail)
23
- end
24
-
25
- it "should contain its filename at the end" do
26
- resource.url.split('/').last.should == resource.file_name
27
- end
28
- end
29
-
30
- describe "#type_of_content" do
31
- it "returns formated mime type" do
32
- resource.type_of_content.should == "text plain"
33
- end
34
- end
35
-
36
- describe "#title" do
37
- it "returns a titleized version of the filename" do
38
- resource.title.should == "Refinery Is Awesome"
39
- end
40
- end
41
-
42
- describe ".per_page" do
43
- context "dialog is true" do
44
- it "returns resource count specified by PAGES_PER_DIALOG constant" do
45
- Resource.per_page(true).should == Resource::PAGES_PER_DIALOG
46
- end
47
- end
48
-
49
- context "dialog is false" do
50
- it "returns resource count specified by PAGES_PER_ADMIN_INDEX constant" do
51
- Resource.per_page.should == Resource::PAGES_PER_ADMIN_INDEX
52
- end
53
- end
54
- end
55
-
56
- describe ".create_resources" do
57
- let(:file) { File.new(File.expand_path('../../uploads/refinery_is_awesome.txt', __FILE__)) }
58
-
59
- context "only one resource uploaded" do
60
- it "returns an array containing one resource" do
61
- Resource.create_resources(:file => file).should have(1).item
62
- end
63
- end
64
-
65
- context "many resources uploaded at once" do
66
- it "returns an array containing all those resources" do
67
- Resource.create_resources(:file => [file, file, file]).should have(3).items
68
- end
69
- end
70
-
71
- specify "each returned array item should be an instance of resource" do
72
- Resource.create_resources(:file => [file, file, file]).each do |r|
73
- r.should be_an_instance_of(Resource)
74
- end
75
- end
76
- end
77
-
78
- end
@@ -1 +0,0 @@
1
- http://www.refineryhq.com/