lolita-file-upload 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,25 +1,21 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "lolita", ">=3.0.6"
3
+ gem "lolita", "~>3.1.8"
4
4
  gem "carrierwave", "~> 0.5.2"
5
5
  group :test do
6
- gem "rspec-rails", "~> 2.5"
6
+ gem "rspec-rails", "~> 2.6"
7
7
  gem "ffaker"
8
8
  gem "factory_girl"
9
9
  gem "sqlite3"
10
+ gem "rspec", "~> 2.6"
11
+ gem 'cover_me', '>= 1.0.0.rc6'
12
+ gem 'activerecord', "~> 3.0.7"
10
13
  end
11
14
 
12
15
  group :development do
13
16
  gem "cucumber", "~> 0.10"
14
- gem "cucumber-rails", "~> 0.4.0"
17
+ gem "cucumber-rails", "~> 0.5.2"
15
18
  gem "bundler", "~> 1.0"
16
19
  gem "jeweler", "~> 1.5"
17
20
  end
18
21
 
19
- group :test do
20
- gem "rspec", "~> 2.5"
21
- gem 'cover_me', '>= 1.0.0.rc6'
22
- gem 'activerecord', "~> 3.0", :require=>false
23
- end
24
-
25
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -0,0 +1,52 @@
1
+ module Lolita
2
+ module Upload
3
+ class ImagesController < ApplicationController
4
+
5
+ include Lolita::Controllers::UserHelpers
6
+ include Lolita::Controllers::InternalHelpers
7
+ before_filter :authenticate_lolita_user!
8
+ before_filter :get_or_build_resource, :only=>[:create,:edit,:update,:destroy]
9
+ before_filter :set_tab, :only=>[:edit,:update,:destroy,:create]
10
+
11
+ respond_to :js,:html
12
+
13
+ def create
14
+ @resource.send("#{params[:field]}=".to_sym, params[:file])
15
+ @resource.save!(:validate => false)
16
+ render_component @tab, :row, :file => @resource
17
+ end
18
+
19
+ def edit
20
+ render_component *@tab.build("",:edit,:file=>@file)
21
+ end
22
+
23
+ def update
24
+ @file.update_attributes!(params[:file])
25
+ render_component *@tab.build("",:update,:file=>@file)
26
+ end
27
+
28
+
29
+ def destroy
30
+ @file.destroy
31
+ render_component *@tab.build("",:destroy,:file=>@file)
32
+ end
33
+
34
+ private
35
+
36
+ def get_or_build_resource
37
+ @klass = params[:resource_class].camelize.constantize
38
+ @resource = if params[:many]
39
+ # @klass.new(params[:upload])
40
+ else
41
+ @klass.find_by_id(params[:resource_id])
42
+ end
43
+ end
44
+
45
+ def set_tab
46
+ @tab = @klass.lolita.tabs.select{|tab|
47
+ tab.type == :images && tab.tab_field == params[:field].to_sym
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -8,10 +8,19 @@ module Lolita
8
8
 
9
9
  validate :size_limit
10
10
  before_save :set_metadata
11
+ before_create :singularize_files
11
12
 
12
13
 
13
14
  private
14
15
 
16
+ def singularize_files
17
+ if self.fileable && lolita = self.fileable.class.lolita
18
+ if lolita.tabs.by_type(:files).association_type == :one
19
+ self.class.destroy_all(["fileable_type = :type AND fileable_id = :id AND fileable_id > 0",:type => fileable_type,:id => fileable_id])
20
+ end
21
+ end
22
+ end
23
+
15
24
  def size_limit
16
25
  if self.fileable && lolita=self.fileable.class.lolita
17
26
  maxsize=lolita.tabs.by_type(:files).maxfilesize
@@ -1,5 +1,5 @@
1
1
  class FileUploader < CarrierWave::Uploader::Base
2
- storage :file
2
+ storage :file
3
3
  def timestamp
4
4
  time=if model
5
5
  model.created_at || Time.now
@@ -4,8 +4,8 @@
4
4
  </div>
5
5
  <% end %>
6
6
  <div id="filelist">
7
- <%= render_component *tab.build("",:list)%>
7
+ <%= render_component tab,:list %>
8
8
  </div>
9
- <%= render_component *tab.build("",:upload_script,:container=>"file_upload_container")%>
9
+ <%= render_component tab, :upload_script, :container => "file_upload_container"%>
10
10
  <%= render_component :"lolita/configuration/tab", :fields, :tab=>tab %>
11
11
 
@@ -6,7 +6,8 @@
6
6
  </tr>
7
7
  </thead>
8
8
  <tbody>
9
- <% resource.send(tab.association.name).each do |file| %>
9
+ <% files = tab.association_type == :one ? [resource.send(tab.association.name)].compact : resource.send(tab.association.name)%>
10
+ <% files.each do |file| %>
10
11
  <%= render_component *tab.build("",:row,:file=>file,:value=>nil) %>
11
12
  <% end %>
12
13
  </tbody>
@@ -8,7 +8,6 @@
8
8
  <% unless Lolita.locale.to_s.downcase=="en" %>
9
9
  <script type="text/javascript" src="/javascripts/lolita/upload/I18n/<%=Lolita.locale%>.js"></script>
10
10
  <% end %>
11
-
12
11
  <script type="text/javascript">
13
12
  $(function(){
14
13
  $("#<%=container%>").plupload({
@@ -19,11 +18,18 @@
19
18
  chunk_size : '1mb',
20
19
  unique_names : true,
21
20
  rename: true,
21
+ <% if tab.extensions.any? %>
22
+ filters:[
23
+ <% tab.extensions.each do |ext_data| %>
24
+ {title: "<%=ext_data[:title]%>", extensions: "<%= ext_data[:extensions].is_a?(Array) ? ext_data[:extensions].join(",") : ext_data[:extensions] %>"},
25
+ <% end %>
26
+ ],
27
+ <% end %>
22
28
  multipart: true,
23
29
  multipart_params: {
24
30
  "authenticity_token" : '<%= form_authenticity_token %>',
25
- "<%="upload[#{tab.association.name.to_s.singularize}able_type]"%>": "<%=resource.class%>",
26
- "<%="upload[#{tab.association.name.to_s.singularize}able_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>"
31
+ "<%="upload[#{tab.association.options[:as]}_type]"%>": "<%=resource.class%>",
32
+ "<%="upload[#{tab.association.options[:as]}_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>"
27
33
  },
28
34
  headers:{
29
35
  "X-CSRF-Token": $("meta[name='csrf-token']").attr("content")
@@ -33,9 +39,20 @@
33
39
  flash_swf_url : '/javascripts/lolita/upload/plupload.flash.swf',
34
40
  init:{
35
41
  FileUploaded:function(uploader, file, info){
36
- $("#file_list_for_<%=tab.type%>>tbody").append(info.response)
42
+ <% if tab.association_type == :one %>
43
+ uploader.splice(0,10);
44
+ $("#file_list_for_<%=tab.type%>>tbody").html("")
45
+ $("#file_list_for_<%=tab.type%>>tbody").append(info.response)
46
+ <% else %>
47
+ $("#file_list_for_<%=tab.type%>>tbody").append(info.response)
48
+ <% end %>
49
+
50
+ <% if tab.association_type == :many %>
51
+ var ids="<%="#{resource_name}[#{tab.association.name}_ids][]"%>"
52
+ <% else %>
53
+ var ids = "<%="#{resource_name}[#{tab.association.name}_new]"%>"
54
+ <% end %>
37
55
 
38
- var ids="<%="#{resource_name}[#{tab.type.to_s.singularize}_ids][]"%>"
39
56
  var existing_ids=[]
40
57
  $("input.<%=tab.type%>-ids").each(function(){
41
58
  existing_ids.push($(this).val())
@@ -17,7 +17,11 @@ module Lolita
17
17
  module Configuration
18
18
  module Tab
19
19
  autoload :Files, "lolita-file-upload/configuration/tab/files"
20
+ autoload :Images, "lolita-file-upload/configuration/tab/images"
20
21
  end
22
+ # module Field
23
+ # autoload :Upload, "lolita-file-upload/configuration/field/upload"
24
+ # end
21
25
  end
22
26
  end
23
27
 
@@ -7,7 +7,7 @@ module Lolita
7
7
  class Files < Lolita::Configuration::Tab::Base
8
8
 
9
9
  lolita_accessor :extensions,:maxfilesize
10
- attr_reader :association
10
+ attr_reader :association, :association_type
11
11
 
12
12
  # As any other Lolita::Configuration::Tab this should receive _dbi_ object.
13
13
  # Additional _args_ that may represent methods, for details see Lolita::Configuration::Tab.
@@ -25,21 +25,24 @@ module Lolita
25
25
  # # using in lolita configuration definition
26
26
  # lolita do
27
27
  # tab(:file) do
28
- # extension :pdf
28
+ # extension "Images", "png,jpg"
29
29
  # end
30
30
  # end
31
31
  #
32
32
  # # using for object
33
33
  # Lolita::Configuration.FileTab.new(dbi).extension("pdf")
34
- def extension(value)
35
- @extensions << value
34
+ def extension(title, extensions)
35
+ @extensions << {:title => title, :extensions => extensions}
36
36
  end
37
37
 
38
38
  private
39
39
 
40
40
  def set_association
41
41
  @association=self.dbi.associations.detect{|k,assoc| assoc.class_name=="Lolita::Upload::File"}
42
- @association=@association.last if @association
42
+ if @association
43
+ @association=@association.last
44
+ @association_type = self.dbi.association_macro(@association)
45
+ end
43
46
  end
44
47
 
45
48
  def validate
@@ -0,0 +1,20 @@
1
+ module Lolita
2
+ module Configuration
3
+ module Tab
4
+ class Images < Lolita::Configuration::Tab::Base
5
+
6
+ def initialize dbi,type,tab_field,*args
7
+ @type=:images
8
+ @tab_field = tab_field
9
+ super
10
+ end
11
+
12
+ def tab_field
13
+ @tab_field
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lolita-file-upload}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ITHouse", "Arturs Meisters"]
12
- s.date = %q{2011-05-03}
12
+ s.date = %q{2011-06-15}
13
13
  s.description = %q{File upload gem for Lolita with with fulll integration - models, controller, views}
14
14
  s.email = %q{support@ithouse.lv}
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "app/controllers/lolita/upload/files_controller.rb",
28
+ "app/controllers/lolita/upload/images_controller.rb",
28
29
  "app/models/lolita/upload/file.rb",
29
30
  "app/uploaders/file_uploader.rb",
30
31
  "app/views/components/lolita/configuration/tab/files/_cells.html.erb",
@@ -50,6 +51,7 @@ Gem::Specification.new do |s|
50
51
  "lib/generators/lolita_file_upload/templates/migration.rb",
51
52
  "lib/lolita-file-upload.rb",
52
53
  "lib/lolita-file-upload/configuration/tab/files.rb",
54
+ "lib/lolita-file-upload/configuration/tab/images.rb",
53
55
  "lib/lolita-file-upload/module.rb",
54
56
  "lib/lolita-file-upload/rails.rb",
55
57
  "lib/lolita-file-upload/rails/file_upload_routes.rb",
@@ -66,6 +68,7 @@ Gem::Specification.new do |s|
66
68
  "public/images/lolita/upload/plupload/plupload.png",
67
69
  "public/images/lolita/upload/plupload/throbber.gif",
68
70
  "public/images/lolita/upload/plupload/transp50.png",
71
+ "public/javascripts/lolita/upload/I18n/lv.js",
69
72
  "public/javascripts/lolita/upload/I18n/ru.js",
70
73
  "public/javascripts/lolita/upload/jquery.ui.plupload.js",
71
74
  "public/javascripts/lolita/upload/plupload.flash.swf",
@@ -73,62 +76,64 @@ Gem::Specification.new do |s|
73
76
  "public/stylesheets/lolita/upload/jquery.ui.plupload.css",
74
77
  "public/stylesheets/lolita/upload/plupload.queue.css",
75
78
  "spec/configuration/tab/files_spec.rb",
79
+ "spec/configuration/tab/images_spec.rb",
76
80
  "spec/lolita/support/bytes_spec.rb",
77
81
  "spec/models/file_spec.rb",
78
82
  "spec/spec_helper.rb",
79
83
  "spec/support/post.rb",
80
84
  "spec/uploaders/file_uploader_spec.rb",
81
85
  "test_orm/active_record.rb",
86
+ "test_orm/active_record/news.rb",
82
87
  "test_orm/active_record/post.rb",
88
+ "test_orm/active_record/tag.rb",
83
89
  "test_orm/config/active_record.yml",
84
90
  "test_orm/coverage.rb",
85
91
  "test_orm/db/migrate/01_create_posts.rb",
86
92
  "test_orm/db/migrate/02_create_files.rb",
93
+ "test_orm/db/migrate/03_create_news.rb",
94
+ "test_orm/db/migrate/04_create_tags.rb",
87
95
  "test_orm/files/large_file.txt",
88
96
  "test_orm/files/normal_file.txt",
89
97
  "test_orm/rails/config/application.rb",
90
98
  "test_orm/rails/config/enviroment.rb",
91
99
  "test_orm/rails/config/routes.rb",
92
100
  "test_orm/rails/log/development.log",
93
- "test_orm/support.rb"
101
+ "test_orm/support.rb",
102
+ "test_orm/uploaders/list_image_uploader.rb",
103
+ "test_orm/uploaders/main_image_uploader.rb",
104
+ "upload/lolita/upload/file/201105/1/large_file.txt",
105
+ "upload/lolita/upload/file/201106/1/large_file.txt",
106
+ "upload/misc/large_file.txt"
94
107
  ]
95
108
  s.homepage = %q{http://github.com/ithouse/lolita-file-upload}
96
109
  s.licenses = ["MIT"]
97
110
  s.require_paths = ["lib"]
98
- s.rubygems_version = %q{1.6.1}
111
+ s.rubygems_version = %q{1.6.2}
99
112
  s.summary = %q{File upload gem for Lolita CMS}
100
- s.test_files = [
101
- "spec/configuration/tab/files_spec.rb",
102
- "spec/lolita/support/bytes_spec.rb",
103
- "spec/models/file_spec.rb",
104
- "spec/spec_helper.rb",
105
- "spec/support/post.rb",
106
- "spec/uploaders/file_uploader_spec.rb"
107
- ]
108
113
 
109
114
  if s.respond_to? :specification_version then
110
115
  s.specification_version = 3
111
116
 
112
117
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
113
- s.add_runtime_dependency(%q<lolita>, [">= 3.0.6"])
118
+ s.add_runtime_dependency(%q<lolita>, ["~> 3.1.8"])
114
119
  s.add_runtime_dependency(%q<carrierwave>, ["~> 0.5.2"])
115
120
  s.add_development_dependency(%q<cucumber>, ["~> 0.10"])
116
- s.add_development_dependency(%q<cucumber-rails>, ["~> 0.4.0"])
121
+ s.add_development_dependency(%q<cucumber-rails>, ["~> 0.5.2"])
117
122
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
118
123
  s.add_development_dependency(%q<jeweler>, ["~> 1.5"])
119
124
  else
120
- s.add_dependency(%q<lolita>, [">= 3.0.6"])
125
+ s.add_dependency(%q<lolita>, ["~> 3.1.8"])
121
126
  s.add_dependency(%q<carrierwave>, ["~> 0.5.2"])
122
127
  s.add_dependency(%q<cucumber>, ["~> 0.10"])
123
- s.add_dependency(%q<cucumber-rails>, ["~> 0.4.0"])
128
+ s.add_dependency(%q<cucumber-rails>, ["~> 0.5.2"])
124
129
  s.add_dependency(%q<bundler>, ["~> 1.0"])
125
130
  s.add_dependency(%q<jeweler>, ["~> 1.5"])
126
131
  end
127
132
  else
128
- s.add_dependency(%q<lolita>, [">= 3.0.6"])
133
+ s.add_dependency(%q<lolita>, ["~> 3.1.8"])
129
134
  s.add_dependency(%q<carrierwave>, ["~> 0.5.2"])
130
135
  s.add_dependency(%q<cucumber>, ["~> 0.10"])
131
- s.add_dependency(%q<cucumber-rails>, ["~> 0.4.0"])
136
+ s.add_dependency(%q<cucumber-rails>, ["~> 0.5.2"])
132
137
  s.add_dependency(%q<bundler>, ["~> 1.0"])
133
138
  s.add_dependency(%q<jeweler>, ["~> 1.5"])
134
139
  end
@@ -0,0 +1,22 @@
1
+ // Latvian
2
+ plupload.addI18n({
3
+ 'Select files' : 'Izvēlieties failu',
4
+ 'Add files to the upload queue and click the start button.' : 'Pievienojiet failu augšupielādes rindai un nospiediet pogu "Sākt augšupielādi".',
5
+ 'Filename' : 'Faila nosaukums',
6
+ 'Status' : 'Statuss',
7
+ 'Size' : 'Izmērs',
8
+ 'Add Files' : 'Pievienot failus',
9
+ 'Start Upload': "Sākt augšupielādi",
10
+ 'Stop current upload' : 'Apturēt augšupielādi',
11
+ 'Start uploading queue' : 'Sākt augšupielādēt rindu',
12
+ 'Uploaded %d/%d files': 'Augšupielādēti %d no %d failiem',
13
+ 'N/A' : 'N/A',
14
+ 'Drag files here.' : 'Pārvilkt failus šeit.',
15
+ 'File extension error.': 'Faila paplašinājuma kļūda.',
16
+ 'File size error.': 'Faila izmēra kļūda.',
17
+ 'Init error.': 'Inicializācijas kļūda.',
18
+ 'HTTP Error.': 'HTTP kļūda.',
19
+ 'Security error.': 'Drošības kļūda.',
20
+ 'Generic error.': 'Vispārīga kļūda.',
21
+ 'IO error.': 'Ievades-izvades kļūda.'
22
+ });
@@ -1,12 +1,12 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
- describe Lolita::Configuration::FilesTab do
3
+ describe Lolita::Configuration::Tab::Files do
4
4
 
5
5
  let(:dbi){Lolita::DBI::Base.new(Post)}
6
- let(:tab){Lolita::Configuration::FilesTab.new(dbi)}
6
+ let(:tab){Lolita::Configuration::Tab::Files.new(dbi)}
7
7
 
8
8
  it "should create new file tab" do
9
- Lolita::Configuration::FilesTab.new(dbi).type.should == :files
9
+ Lolita::Configuration::Tab::Files.new(dbi).type.should == :files
10
10
  end
11
11
 
12
12
  describe "extensions" do
@@ -21,8 +21,8 @@ describe Lolita::Configuration::FilesTab do
21
21
  end
22
22
 
23
23
  it "should allow to add new one" do
24
- tab.extension("pdf")
25
- tab.extensions.should == ["pdf"]
24
+ tab.extension("Image","pdf")
25
+ tab.extensions.should == [{:title=>"Image",:extensions=>"pdf"}]
26
26
  end
27
27
  end
28
28
 
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Lolita::Configuration::Tab::Images do
4
+
5
+ let(:dbi){Lolita::DBI::Base.new(News)}
6
+ let(:klass){Lolita::Configuration::Tab::Images}
7
+
8
+ it "should create new tab " do
9
+ klass.new(dbi,:images,:main_image)
10
+ end
11
+
12
+ it "should have tab_field for image tab" do
13
+ News.lolita.tabs.first.tab_field.should == :main_image
14
+ end
15
+
16
+ end