lolita-file-upload 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/app/controllers/lolita/upload/files_controller.rb +4 -4
- data/app/models/lolita/upload/file.rb +2 -2
- data/app/uploaders/file_uploader.rb +11 -2
- data/app/views/components/lolita/{tab → configuration/tab}/files/_cells.html.erb +0 -0
- data/app/views/components/lolita/{tab → configuration/tab}/files/_destroy.js.erb +0 -0
- data/app/views/components/lolita/{tab/_files.html.erb → configuration/tab/files/_display.html.erb} +3 -5
- data/app/views/components/lolita/configuration/tab/files/_edit.js.erb +1 -0
- data/app/views/components/lolita/{tab → configuration/tab}/files/_form.html.erb +0 -0
- data/app/views/components/lolita/{tab → configuration/tab}/files/_list.html.erb +1 -1
- data/app/views/components/lolita/{tab → configuration/tab}/files/_list_form.html.erb +1 -1
- data/app/views/components/lolita/{tab → configuration/tab}/files/_row.html.erb +1 -1
- data/app/views/components/lolita/configuration/tab/files/_update.js.erb +1 -0
- data/app/views/components/lolita/{tab → configuration/tab}/files/_upload_script.html.erb +2 -2
- data/lib/generators/lolita_file_upload/assets_generator.rb +2 -1
- data/lib/generators/lolita_file_upload/templates/migration.rb +7 -7
- data/lib/lolita-file-upload.rb +7 -2
- data/lib/lolita-file-upload/configuration/tab/files.rb +44 -42
- data/lolita-file-upload.gemspec +15 -12
- data/test_orm/db/migrate/02_create_files.rb +3 -0
- metadata +34 -23
- data/app/views/components/lolita/tab/files/_edit.js.erb +0 -1
- data/app/views/components/lolita/tab/files/_update.js.erb +0 -1
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -13,22 +13,22 @@ module Lolita
|
|
13
13
|
def create
|
14
14
|
@file.asset = params[:file]
|
15
15
|
@file.save!
|
16
|
-
render_component
|
16
|
+
render_component *@tab.build("",:row,:file=>@file)
|
17
17
|
end
|
18
18
|
|
19
19
|
def edit
|
20
|
-
render_component
|
20
|
+
render_component *@tab.build("",:edit,:file=>@file)
|
21
21
|
end
|
22
22
|
|
23
23
|
def update
|
24
24
|
@file.update_attributes!(params[:file])
|
25
|
-
render_component
|
25
|
+
render_component *@tab.build("",:update,:file=>@file)
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
29
|
def destroy
|
30
30
|
@file.destroy
|
31
|
-
render_component
|
31
|
+
render_component *@tab.build("",:destroy,:file=>@file)
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
@@ -23,9 +23,9 @@ module Lolita
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def set_metadata
|
26
|
-
self.name||=::File.basename(self.asset.
|
26
|
+
self.name||=::File.basename(self.asset.store_path)
|
27
27
|
self.asset_size=self.asset.file.size
|
28
|
-
self.asset_extension=::File.extname(self.asset.
|
28
|
+
self.asset_extension=::File.extname(self.asset.store_path).gsub(".","")
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -1,12 +1,21 @@
|
|
1
1
|
class FileUploader < CarrierWave::Uploader::Base
|
2
2
|
storage :file
|
3
3
|
def timestamp
|
4
|
-
|
4
|
+
time=if model
|
5
|
+
model.created_at || Time.now
|
6
|
+
else
|
7
|
+
Time.now
|
8
|
+
end
|
9
|
+
time.strftime("%Y%m")
|
5
10
|
end
|
6
11
|
|
7
12
|
# With slash in first place it will be absolute url, otherwise relative to Rails.root+"/public"
|
8
13
|
def store_dir
|
9
|
-
|
14
|
+
if model
|
15
|
+
"upload/#{model.class.to_s.underscore}/#{timestamp}/#{model.id}"
|
16
|
+
else
|
17
|
+
"upload/misc"
|
18
|
+
end
|
10
19
|
end
|
11
20
|
|
12
21
|
end
|
File without changes
|
File without changes
|
data/app/views/components/lolita/{tab/_files.html.erb → configuration/tab/files/_display.html.erb}
RENAMED
@@ -4,10 +4,8 @@
|
|
4
4
|
</div>
|
5
5
|
<% end %>
|
6
6
|
<div id="filelist">
|
7
|
-
<%= render_component
|
7
|
+
<%= render_component *tab.build("",:list)%>
|
8
8
|
</div>
|
9
|
-
<%= render_component
|
10
|
-
|
11
|
-
%>
|
12
|
-
<%= render_component :"lolita/tab", :fields, :tab=>tab %>
|
9
|
+
<%= render_component *tab.build("",:upload_script,:container=>"file_upload_container")%>
|
10
|
+
<%= render_component :"lolita/configuration/tab", :fields, :tab=>tab %>
|
13
11
|
|
@@ -0,0 +1 @@
|
|
1
|
+
$("#upload_<%=tab.type%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(*tab.build("",:list_form,:file=>file,:format=>"html")))%>")
|
File without changes
|
@@ -7,7 +7,7 @@
|
|
7
7
|
</thead>
|
8
8
|
<tbody>
|
9
9
|
<% resource.send(tab.association.name).each do |file| %>
|
10
|
-
<%= render_component
|
10
|
+
<%= render_component *tab.build("",:row,:file=>file,:value=>nil) %>
|
11
11
|
<% end %>
|
12
12
|
</tbody>
|
13
13
|
</table>
|
@@ -0,0 +1 @@
|
|
1
|
+
$("#upload_<%=tab.type%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(*tab.build("",:cells,:file=>file,:format=>"html")))%>")
|
@@ -5,8 +5,8 @@
|
|
5
5
|
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
|
6
6
|
<script type="text/javascript" src="/javascripts/lolita/upload/plupload.full.min.js"></script>
|
7
7
|
<script type="text/javascript" src="/javascripts/lolita/upload/jquery.ui.plupload.min.js"></script>
|
8
|
-
<% unless
|
9
|
-
<script type="text/javascript" src="/javascripts/lolita/upload/I18n/<%=
|
8
|
+
<% unless Lolita.locale.to_s.downcase=="en" %>
|
9
|
+
<script type="text/javascript" src="/javascripts/lolita/upload/I18n/<%=Lolita.locale%>.js"></script>
|
10
10
|
<% end %>
|
11
11
|
|
12
12
|
<script type="text/javascript">
|
@@ -5,7 +5,8 @@ module LolitaFileUpload
|
|
5
5
|
include Lolita::Generators::FileHelper
|
6
6
|
desc "Copy all from public directory to project public directory."
|
7
7
|
def copy_all
|
8
|
-
|
8
|
+
root=File.expand_path("../../../../",__FILE__)
|
9
|
+
copy_dir("public",:root=>root)
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -2,13 +2,13 @@ class CreateLolitaUploadFiles < ActiveRecord::Migration
|
|
2
2
|
class << self
|
3
3
|
|
4
4
|
def up
|
5
|
-
create_table :lolita_files, :force=>true do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
create_table :lolita_files, :force=>true do |t|
|
6
|
+
t.string :asset
|
7
|
+
t.string :name
|
8
|
+
t.string :fileable_type
|
9
|
+
t.integer :fileable_id
|
10
|
+
t.string :asset_extension, :limit=>12
|
11
|
+
t.integer :asset_size
|
12
12
|
t.timestamps
|
13
13
|
end
|
14
14
|
|
data/lib/lolita-file-upload.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
#TODO add exception if lolita not found, show exception and msg that user should install this gem
|
2
2
|
# if files tab is defined, but there no tab for that, maybe check that through gem.
|
3
|
+
if !defined?(Lolita)
|
4
|
+
require "lolita"
|
5
|
+
end
|
3
6
|
$:<<File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
|
4
7
|
|
5
|
-
I18n.load_path += Dir[File.expand_path("config/locales")+"/**/*.yml"]
|
8
|
+
I18n.load_path += Dir[File.expand_path("config/locales")+"/**/*.yml"] if defined?(I18n)
|
6
9
|
|
7
10
|
module Lolita
|
8
11
|
module FileUpload
|
@@ -12,7 +15,9 @@ module Lolita
|
|
12
15
|
end
|
13
16
|
|
14
17
|
module Configuration
|
15
|
-
|
18
|
+
module Tab
|
19
|
+
autoload :Files, "lolita-file-upload/configuration/tab/files"
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
@@ -1,53 +1,55 @@
|
|
1
1
|
module Lolita
|
2
2
|
module Configuration
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module Tab
|
4
|
+
# FileTab extend Lolita default tab with new lolita accessors.
|
5
|
+
# * <tt>extensions</tt> - Array of extension white list
|
6
|
+
# * <tt>maxfilesize</tt> - uploaded file maximums size
|
7
|
+
class Files < Lolita::Configuration::Tab::Base
|
8
|
+
|
9
|
+
lolita_accessor :extensions,:maxfilesize
|
10
|
+
attr_reader :association
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
# As any other Lolita::Configuration::Tab this should receive _dbi_ object.
|
13
|
+
# Additional _args_ that may represent methods, for details see Lolita::Configuration::Tab.
|
14
|
+
# And block.
|
15
|
+
def initialize(dbi,*args,&block)
|
16
|
+
@type=:files
|
17
|
+
@extensions=[]
|
18
|
+
@dbi=dbi
|
19
|
+
set_association
|
20
|
+
super
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
23
|
+
# Add another extension to #extensions white list.
|
24
|
+
# ====Example
|
25
|
+
# # using in lolita configuration definition
|
26
|
+
# lolita do
|
27
|
+
# tab(:file) do
|
28
|
+
# extension :pdf
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # using for object
|
33
|
+
# Lolita::Configuration.FileTab.new(dbi).extension("pdf")
|
34
|
+
def extension(value)
|
35
|
+
@extensions << value
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
def set_association
|
41
|
+
@association=self.dbi.associations.detect{|k,assoc| assoc.class_name=="Lolita::Upload::File"}
|
42
|
+
@association=@association.last if @association
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def validate
|
46
|
+
super
|
47
|
+
unless self.association
|
48
|
+
raise Lolita::AssociationError, "#{self.dbi.klass} has no association with Lolita::Upload::File. Put has_many :files, :class_name=>'Lolita::Upload::File' to have one."
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
51
|
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/lolita-file-upload.gemspec
CHANGED
@@ -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.
|
8
|
+
s.version = "0.1.2"
|
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-
|
12
|
+
s.date = %q{2011-04-12}
|
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 = [
|
@@ -27,16 +27,16 @@ Gem::Specification.new do |s|
|
|
27
27
|
"app/controllers/lolita/upload/files_controller.rb",
|
28
28
|
"app/models/lolita/upload/file.rb",
|
29
29
|
"app/uploaders/file_uploader.rb",
|
30
|
-
"app/views/components/lolita/tab/
|
31
|
-
"app/views/components/lolita/tab/files/
|
32
|
-
"app/views/components/lolita/tab/files/
|
33
|
-
"app/views/components/lolita/tab/files/_edit.js.erb",
|
34
|
-
"app/views/components/lolita/tab/files/_form.html.erb",
|
35
|
-
"app/views/components/lolita/tab/files/_list.html.erb",
|
36
|
-
"app/views/components/lolita/tab/files/_list_form.html.erb",
|
37
|
-
"app/views/components/lolita/tab/files/_row.html.erb",
|
38
|
-
"app/views/components/lolita/tab/files/_update.js.erb",
|
39
|
-
"app/views/components/lolita/tab/files/_upload_script.html.erb",
|
30
|
+
"app/views/components/lolita/configuration/tab/files/_cells.html.erb",
|
31
|
+
"app/views/components/lolita/configuration/tab/files/_destroy.js.erb",
|
32
|
+
"app/views/components/lolita/configuration/tab/files/_display.html.erb",
|
33
|
+
"app/views/components/lolita/configuration/tab/files/_edit.js.erb",
|
34
|
+
"app/views/components/lolita/configuration/tab/files/_form.html.erb",
|
35
|
+
"app/views/components/lolita/configuration/tab/files/_list.html.erb",
|
36
|
+
"app/views/components/lolita/configuration/tab/files/_list_form.html.erb",
|
37
|
+
"app/views/components/lolita/configuration/tab/files/_row.html.erb",
|
38
|
+
"app/views/components/lolita/configuration/tab/files/_update.js.erb",
|
39
|
+
"app/views/components/lolita/configuration/tab/files/_upload_script.html.erb",
|
40
40
|
"config/locales/en.yml",
|
41
41
|
"features/configuration_for_tab.feature",
|
42
42
|
"features/connect_with_lolita.feature",
|
@@ -112,12 +112,14 @@ Gem::Specification.new do |s|
|
|
112
112
|
s.specification_version = 3
|
113
113
|
|
114
114
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
115
|
+
s.add_runtime_dependency(%q<lolita>, [">= 3.0.6"])
|
115
116
|
s.add_runtime_dependency(%q<carrierwave>, ["~> 0.5.2"])
|
116
117
|
s.add_development_dependency(%q<cucumber>, ["~> 0.10"])
|
117
118
|
s.add_development_dependency(%q<cucumber-rails>, ["~> 0.3.2"])
|
118
119
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
119
120
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5"])
|
120
121
|
else
|
122
|
+
s.add_dependency(%q<lolita>, [">= 3.0.6"])
|
121
123
|
s.add_dependency(%q<carrierwave>, ["~> 0.5.2"])
|
122
124
|
s.add_dependency(%q<cucumber>, ["~> 0.10"])
|
123
125
|
s.add_dependency(%q<cucumber-rails>, ["~> 0.3.2"])
|
@@ -125,6 +127,7 @@ Gem::Specification.new do |s|
|
|
125
127
|
s.add_dependency(%q<jeweler>, ["~> 1.5"])
|
126
128
|
end
|
127
129
|
else
|
130
|
+
s.add_dependency(%q<lolita>, [">= 3.0.6"])
|
128
131
|
s.add_dependency(%q<carrierwave>, ["~> 0.5.2"])
|
129
132
|
s.add_dependency(%q<cucumber>, ["~> 0.10"])
|
130
133
|
s.add_dependency(%q<cucumber-rails>, ["~> 0.3.2"])
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: lolita-file-upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- ITHouse
|
@@ -11,12 +11,23 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-
|
14
|
+
date: 2011-04-12 00:00:00 +03:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
|
-
name:
|
18
|
+
name: lolita
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.0.6
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *id001
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: carrierwave
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
20
31
|
none: false
|
21
32
|
requirements:
|
22
33
|
- - ~>
|
@@ -24,10 +35,10 @@ dependencies:
|
|
24
35
|
version: 0.5.2
|
25
36
|
type: :runtime
|
26
37
|
prerelease: false
|
27
|
-
version_requirements: *
|
38
|
+
version_requirements: *id002
|
28
39
|
- !ruby/object:Gem::Dependency
|
29
40
|
name: cucumber
|
30
|
-
requirement: &
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
31
42
|
none: false
|
32
43
|
requirements:
|
33
44
|
- - ~>
|
@@ -35,10 +46,10 @@ dependencies:
|
|
35
46
|
version: "0.10"
|
36
47
|
type: :development
|
37
48
|
prerelease: false
|
38
|
-
version_requirements: *
|
49
|
+
version_requirements: *id003
|
39
50
|
- !ruby/object:Gem::Dependency
|
40
51
|
name: cucumber-rails
|
41
|
-
requirement: &
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
42
53
|
none: false
|
43
54
|
requirements:
|
44
55
|
- - ~>
|
@@ -46,10 +57,10 @@ dependencies:
|
|
46
57
|
version: 0.3.2
|
47
58
|
type: :development
|
48
59
|
prerelease: false
|
49
|
-
version_requirements: *
|
60
|
+
version_requirements: *id004
|
50
61
|
- !ruby/object:Gem::Dependency
|
51
62
|
name: bundler
|
52
|
-
requirement: &
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
53
64
|
none: false
|
54
65
|
requirements:
|
55
66
|
- - ~>
|
@@ -57,10 +68,10 @@ dependencies:
|
|
57
68
|
version: "1.0"
|
58
69
|
type: :development
|
59
70
|
prerelease: false
|
60
|
-
version_requirements: *
|
71
|
+
version_requirements: *id005
|
61
72
|
- !ruby/object:Gem::Dependency
|
62
73
|
name: jeweler
|
63
|
-
requirement: &
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
64
75
|
none: false
|
65
76
|
requirements:
|
66
77
|
- - ~>
|
@@ -68,7 +79,7 @@ dependencies:
|
|
68
79
|
version: "1.5"
|
69
80
|
type: :development
|
70
81
|
prerelease: false
|
71
|
-
version_requirements: *
|
82
|
+
version_requirements: *id006
|
72
83
|
description: File upload gem for Lolita with with fulll integration - models, controller, views
|
73
84
|
email: support@ithouse.lv
|
74
85
|
executables: []
|
@@ -89,16 +100,16 @@ files:
|
|
89
100
|
- app/controllers/lolita/upload/files_controller.rb
|
90
101
|
- app/models/lolita/upload/file.rb
|
91
102
|
- app/uploaders/file_uploader.rb
|
92
|
-
- app/views/components/lolita/tab/
|
93
|
-
- app/views/components/lolita/tab/files/
|
94
|
-
- app/views/components/lolita/tab/files/
|
95
|
-
- app/views/components/lolita/tab/files/_edit.js.erb
|
96
|
-
- app/views/components/lolita/tab/files/_form.html.erb
|
97
|
-
- app/views/components/lolita/tab/files/_list.html.erb
|
98
|
-
- app/views/components/lolita/tab/files/_list_form.html.erb
|
99
|
-
- app/views/components/lolita/tab/files/_row.html.erb
|
100
|
-
- app/views/components/lolita/tab/files/_update.js.erb
|
101
|
-
- app/views/components/lolita/tab/files/_upload_script.html.erb
|
103
|
+
- app/views/components/lolita/configuration/tab/files/_cells.html.erb
|
104
|
+
- app/views/components/lolita/configuration/tab/files/_destroy.js.erb
|
105
|
+
- app/views/components/lolita/configuration/tab/files/_display.html.erb
|
106
|
+
- app/views/components/lolita/configuration/tab/files/_edit.js.erb
|
107
|
+
- app/views/components/lolita/configuration/tab/files/_form.html.erb
|
108
|
+
- app/views/components/lolita/configuration/tab/files/_list.html.erb
|
109
|
+
- app/views/components/lolita/configuration/tab/files/_list_form.html.erb
|
110
|
+
- app/views/components/lolita/configuration/tab/files/_row.html.erb
|
111
|
+
- app/views/components/lolita/configuration/tab/files/_update.js.erb
|
112
|
+
- app/views/components/lolita/configuration/tab/files/_upload_script.html.erb
|
102
113
|
- config/locales/en.yml
|
103
114
|
- features/configuration_for_tab.feature
|
104
115
|
- features/connect_with_lolita.feature
|
@@ -169,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
180
|
requirements:
|
170
181
|
- - ">="
|
171
182
|
- !ruby/object:Gem::Version
|
172
|
-
hash:
|
183
|
+
hash: -452058159
|
173
184
|
segments:
|
174
185
|
- 0
|
175
186
|
version: "0"
|
@@ -1 +0,0 @@
|
|
1
|
-
$("#upload_<%=tab.type%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(:"lolita/tab/files",:list_form,:tab=>tab,:file=>file,:format=>"html"))%>")
|
@@ -1 +0,0 @@
|
|
1
|
-
$("#upload_<%=tab.type%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(:"lolita/tab/files",:cells,:tab=>tab,:file=>file,:format=>"html"))%>")
|