lolita-file-upload 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.document +5 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +25 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +39 -0
  7. data/VERSION +1 -0
  8. data/app/controllers/lolita/upload/files_controller.rb +51 -0
  9. data/app/models/lolita/upload/file.rb +34 -0
  10. data/app/uploaders/file_uploader.rb +12 -0
  11. data/app/views/components/lolita/tab/_files.html.erb +13 -0
  12. data/app/views/components/lolita/tab/files/_cells.html.erb +5 -0
  13. data/app/views/components/lolita/tab/files/_destroy.js.erb +2 -0
  14. data/app/views/components/lolita/tab/files/_edit.js.erb +1 -0
  15. data/app/views/components/lolita/tab/files/_form.html.erb +3 -0
  16. data/app/views/components/lolita/tab/files/_list.html.erb +13 -0
  17. data/app/views/components/lolita/tab/files/_list_form.html.erb +6 -0
  18. data/app/views/components/lolita/tab/files/_row.html.erb +3 -0
  19. data/app/views/components/lolita/tab/files/_update.js.erb +1 -0
  20. data/app/views/components/lolita/tab/files/_upload_script.html.erb +60 -0
  21. data/config/locales/en.yml +19 -0
  22. data/features/configuration_for_tab.feature +26 -0
  23. data/features/connect_with_lolita.feature +14 -0
  24. data/features/extend_resources_with_new_routes.feature +17 -0
  25. data/features/step_definitions/lolita_steps.rb +112 -0
  26. data/features/support/env.rb +15 -0
  27. data/features/support_byte_converter.feature +31 -0
  28. data/features/upload_file.feature +16 -0
  29. data/lib/generators/lolita_file_upload/assets_generator.rb +12 -0
  30. data/lib/generators/lolita_file_upload/install_generator.rb +19 -0
  31. data/lib/generators/lolita_file_upload/templates/migration.rb +25 -0
  32. data/lib/lolita-file-upload/configuration/tab/files.rb +53 -0
  33. data/lib/lolita-file-upload/module.rb +6 -0
  34. data/lib/lolita-file-upload/rails/file_upload_routes.rb +20 -0
  35. data/lib/lolita-file-upload/rails.rb +8 -0
  36. data/lib/lolita-file-upload.rb +28 -0
  37. data/lib/support/bytes.rb +59 -0
  38. data/log/development.log +0 -0
  39. data/lolita-file-upload.gemspec +135 -0
  40. data/public/images/lolita/upload/plupload/backgrounds.gif +0 -0
  41. data/public/images/lolita/upload/plupload/buttons-disabled.png +0 -0
  42. data/public/images/lolita/upload/plupload/buttons.png +0 -0
  43. data/public/images/lolita/upload/plupload/delete.gif +0 -0
  44. data/public/images/lolita/upload/plupload/done.gif +0 -0
  45. data/public/images/lolita/upload/plupload/error.gif +0 -0
  46. data/public/images/lolita/upload/plupload/plupload-bw.png +0 -0
  47. data/public/images/lolita/upload/plupload/plupload.png +0 -0
  48. data/public/images/lolita/upload/plupload/throbber.gif +0 -0
  49. data/public/images/lolita/upload/plupload/transp50.png +0 -0
  50. data/public/javascripts/lolita/upload/I18n/ru.js +22 -0
  51. data/public/javascripts/lolita/upload/jquery.plupload.queue.min.js +1 -0
  52. data/public/javascripts/lolita/upload/jquery.ui.plupload.min.js +1 -0
  53. data/public/javascripts/lolita/upload/plupload.flash.swf +0 -0
  54. data/public/javascripts/lolita/upload/plupload.full.min.js +2 -0
  55. data/public/javascripts/lolita/upload/plupload.silverlight.xap +0 -0
  56. data/public/stylesheets/lolita/upload/jquery.ui.plupload.css +139 -0
  57. data/public/stylesheets/lolita/upload/plupload.queue.css +177 -0
  58. data/spec/configuration/tab/files_spec.rb +37 -0
  59. data/spec/lolita/support/bytes_spec.rb +36 -0
  60. data/spec/models/file_spec.rb +34 -0
  61. data/spec/spec_helper.rb +29 -0
  62. data/spec/support/post.rb +3 -0
  63. data/spec/uploaders/file_uploader_spec.rb +12 -0
  64. data/test_orm/active_record/post.rb +13 -0
  65. data/test_orm/active_record.rb +9 -0
  66. data/test_orm/config/active_record.yml +2 -0
  67. data/test_orm/coverage.rb +19 -0
  68. data/test_orm/db/migrate/01_create_posts.rb +15 -0
  69. data/test_orm/db/migrate/02_create_files.rb +17 -0
  70. data/test_orm/files/large_file.txt +201 -0
  71. data/test_orm/files/normal_file.txt +2 -0
  72. data/test_orm/rails/config/application.rb +8 -0
  73. data/test_orm/rails/config/enviroment.rb +5 -0
  74. data/test_orm/rails/config/routes.rb +3 -0
  75. data/test_orm/rails/log/development.log +0 -0
  76. data/test_orm/support.rb +27 -0
  77. metadata +195 -0
@@ -0,0 +1,15 @@
1
+ require File.expand_path('test_orm/coverage')
2
+ require File.expand_path("lib/lolita-file-upload")
3
+ require "carrierwave"
4
+
5
+ require "ruby-debug"
6
+ current_orm=:active_record
7
+ require 'carrierwave/orm/'+current_orm.to_s.gsub("_","")
8
+
9
+ require File.expand_path("test_orm/#{current_orm}")
10
+
11
+ require File.expand_path("test_orm/support")
12
+
13
+
14
+
15
+
@@ -0,0 +1,31 @@
1
+ Feature: convert bytes to biggest possible unit
2
+
3
+ In order to show file upload errors in human understendable way
4
+ There should be converter that converts bytes to kilobytes, megabytes, gigabytes.
5
+ Lolita::Suport::Bytes do that think, it is create by passing bytes, and return unit and values with
6
+ converted values
7
+
8
+ Scenario Outline: convert bytes
9
+ Given byte converter
10
+ When I humanize "<size>"
11
+ Then I should get "<unit>" and "<limit>"
12
+
13
+ Scenarios: to bytes
14
+ | size | unit | limit |
15
+ | 0 | bytes | 0.0 |
16
+ | 1023 | bytes | 1023.0 |
17
+
18
+ Scenarios: to kilobytes
19
+ | size | unit | limit |
20
+ | 1024 | kilobyte | 1.0 |
21
+ | 1024**2-1 | megabyte | 1.0 |
22
+
23
+ Scenarios: to megabytes
24
+ | size | unit | limit |
25
+ | 1024**2 | megabyte | 1.0 |
26
+ | 1024**3-1 | gigabyte | 1.0 |
27
+
28
+ Scenarios: to gigabytes
29
+ | size | unit | limit |
30
+ | 1024**3 | gigabyte | 1.0 |
31
+ | 1024**4-1 | gigabytes | 1024.0 |
@@ -0,0 +1,16 @@
1
+ Feature: upload file from lolita and manage file attributes
2
+
3
+ Files in lolita have name attribute. Any attributes can be changed after file is uploaded.
4
+ File always is related with some ORM class object.
5
+
6
+ Scenario: upload file
7
+ Given a lolita
8
+ And a rails
9
+ And rails application
10
+ And lolita-file-upload
11
+ And I visit new post
12
+ When I upload file normal_file.txt
13
+ Then I see normal_file
14
+ And I change file attribute name to my_file
15
+ And save file
16
+ Then I see my_file
@@ -0,0 +1,12 @@
1
+ require 'generators/helpers/file_helper'
2
+ module LolitaFileUpload
3
+ module Generators
4
+ class AssetsGenerator < Rails::Generators::Base
5
+ include Lolita::Generators::FileHelper
6
+ desc "Copy all from public directory to project public directory."
7
+ def copy_all
8
+ copy_dir("public")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module LolitaFileUpload
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ include Lolita::Generators::FileHelper
5
+ source_root File.expand_path("../templates", __FILE__)
6
+ desc "Copy assets and create migrations. "
7
+
8
+
9
+ def copy_assets
10
+ generate("lolita_file_upload:assets")
11
+ end
12
+
13
+ def copy_migration
14
+ copy_file "migration.rb", "db/migrate/#{Time.now.strftime("%Y%m%d%H%M%S")}_create_lolita_upload_files.rb"
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ class CreateLolitaUploadFiles < ActiveRecord::Migration
2
+ class << self
3
+
4
+ def up
5
+ create_table :lolita_files, :force=>true do |f|
6
+ f.string :asset
7
+ f.string :name
8
+ f.string :fileable_type
9
+ f.integer :fileable_id
10
+ f.string :asset_extension, :limit=>12
11
+ f.integer :asset_size
12
+ t.timestamps
13
+ end
14
+
15
+ add_index :lolita_files, [:fileable_type,:fileable_id]
16
+ add_index :lolita_files, :fileable_type
17
+ add_index :lolita_files,:asset_size
18
+ add_index :lolita_files, :created_at
19
+ end
20
+
21
+ def down
22
+ drop_table :lolita_files
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,53 @@
1
+ module Lolita
2
+ module Configuration
3
+ # FileTab extend Lolita default tab with new lolita accessors.
4
+ # * <tt>extensions</tt> - Array of extension white list
5
+ # * <tt>maxfilesize</tt> - uploaded file maximums size
6
+ class FilesTab < Lolita::Configuration::Tab
7
+
8
+ lolita_accessor :extensions,:maxfilesize
9
+ attr_reader :association
10
+
11
+ # As any other Lolita::Configuration::Tab this should receive _dbi_ object.
12
+ # Additional _args_ that may represent methods, for details see Lolita::Configuration::Tab.
13
+ # And block.
14
+ def initialize(dbi,*args,&block)
15
+ @type=:files
16
+ @extensions=[]
17
+ @dbi=dbi
18
+ set_association
19
+ super
20
+ end
21
+
22
+ # Add another extension to #extensions white list.
23
+ # ====Example
24
+ # # using in lolita configuration definition
25
+ # lolita do
26
+ # tab(:file) do
27
+ # extension :pdf
28
+ # end
29
+ # end
30
+ #
31
+ # # using for object
32
+ # Lolita::Configuration.FileTab.new(dbi).extension("pdf")
33
+ def extension(value)
34
+ @extensions << value
35
+ end
36
+
37
+ private
38
+
39
+ def set_association
40
+ @association=self.dbi.associations.detect{|k,assoc| assoc.class_name=="Lolita::Upload::File"}
41
+ @association=@association.last if @association
42
+ end
43
+
44
+ def validate
45
+ super
46
+ unless self.association
47
+ 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."
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+ Lolita.add_module Lolita::FileUpload, :nested=>false,:route=>lambda{|resource|
2
+ if resource.lolita.tabs.by_type(:files)
3
+ return :file_upload
4
+ end
5
+ }
6
+
@@ -0,0 +1,20 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+ protected
4
+
5
+ def lolita_file_upload_route
6
+ mapping=Lolita.add_mapping(:files,
7
+ :class_name=>"Lolita::Upload::File",
8
+ :path=>"lolita_upload"
9
+ )
10
+ lolita_scope mapping.name do
11
+ namespace "lolita" do
12
+ namespace "upload" do
13
+ resources mapping.plural
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ if defined?(Rails)
2
+ require "lolita-file-upload/rails/file_upload_routes"
3
+ module LolitaFileUpload
4
+ class Engine < Rails::Engine
5
+
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../../../lolita/lib/lolita',__FILE__) # TODO remove this
2
+
3
+ $:<<File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
4
+
5
+ I18n.load_path += Dir[File.expand_path("config/locales")+"/**/*.yml"]
6
+
7
+ module Lolita
8
+ module FileUpload
9
+ end
10
+ module Support
11
+ autoload :Bytes, "support/bytes"
12
+ end
13
+
14
+ module Configuration
15
+ autoload :FilesTab, "lolita-file-upload/configuration/tab/files"
16
+ end
17
+ end
18
+
19
+ require 'lolita-file-upload/module'
20
+
21
+ if defined?(Rails)
22
+ require "lolita-file-upload/rails"
23
+ end
24
+
25
+ # How to connect multimedia engine with lolita resources
26
+ # Detecting from tabs will not be very good idea because it will load many thing
27
+ # There should be the way to connect it on demand when realy multimedia tab is used for resource like
28
+ # lolita/posts/files/new[create,destroy,update, index]
@@ -0,0 +1,59 @@
1
+ module Lolita
2
+ module Support
3
+ # Convert bytes to closest possible unit.
4
+ # ====Example
5
+ # byte_converter=Lolita::FileUpload::Bytes.new(1024)
6
+ # byte_converter.unit #=> kilobytes
7
+ # byte_convertes.value #=> 1.0
8
+ class Bytes
9
+
10
+ @@default_unit="byte"
11
+ @@units=%w(kilobyte megabyte gigabyte)
12
+
13
+ def initialize(bytes)
14
+ @power=0
15
+ @bytes=bytes
16
+ end
17
+
18
+ # Return bytes
19
+ def bytes
20
+ @bytes
21
+ end
22
+
23
+ # Return unit name
24
+ def unit
25
+ @unit||=set_unit
26
+ end
27
+
28
+ # Return unit value
29
+ def value
30
+ @value||=set_value
31
+ end
32
+
33
+ private
34
+
35
+ def set_unit
36
+ count=self.value
37
+ system_name=([@@default_unit]+@@units)[@power]
38
+ I18n.t("lolita.support.bytes.#{system_name}",:count=>count)
39
+ end
40
+
41
+ def set_value(val=nil)
42
+ operation_value=val ? val : self.bytes
43
+ @@units.size.downto(1) do |pow|
44
+ if operation_value>=(1024**pow)
45
+ @power=pow
46
+ break
47
+ end
48
+ end
49
+ result= (operation_value.to_f/(1024**@power).to_f).round(2)
50
+ if val
51
+ result
52
+ else
53
+ set_value(result*1024**@power)
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+ end
File without changes
@@ -0,0 +1,135 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lolita-file-upload}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["ITHouse", "Arturs Meisters"]
12
+ s.date = %q{2011-03-29}
13
+ s.description = %q{File upload gem for Lolita with with fulll integration - models, controller, views}
14
+ s.email = %q{support@ithouse.lv}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "app/controllers/lolita/upload/files_controller.rb",
28
+ "app/models/lolita/upload/file.rb",
29
+ "app/uploaders/file_uploader.rb",
30
+ "app/views/components/lolita/tab/_files.html.erb",
31
+ "app/views/components/lolita/tab/files/_cells.html.erb",
32
+ "app/views/components/lolita/tab/files/_destroy.js.erb",
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",
40
+ "config/locales/en.yml",
41
+ "features/configuration_for_tab.feature",
42
+ "features/connect_with_lolita.feature",
43
+ "features/extend_resources_with_new_routes.feature",
44
+ "features/step_definitions/lolita_steps.rb",
45
+ "features/support/env.rb",
46
+ "features/support_byte_converter.feature",
47
+ "features/upload_file.feature",
48
+ "lib/generators/lolita_file_upload/assets_generator.rb",
49
+ "lib/generators/lolita_file_upload/install_generator.rb",
50
+ "lib/generators/lolita_file_upload/templates/migration.rb",
51
+ "lib/lolita-file-upload.rb",
52
+ "lib/lolita-file-upload/configuration/tab/files.rb",
53
+ "lib/lolita-file-upload/module.rb",
54
+ "lib/lolita-file-upload/rails.rb",
55
+ "lib/lolita-file-upload/rails/file_upload_routes.rb",
56
+ "lib/support/bytes.rb",
57
+ "log/development.log",
58
+ "lolita-file-upload.gemspec",
59
+ "public/images/lolita/upload/plupload/backgrounds.gif",
60
+ "public/images/lolita/upload/plupload/buttons-disabled.png",
61
+ "public/images/lolita/upload/plupload/buttons.png",
62
+ "public/images/lolita/upload/plupload/delete.gif",
63
+ "public/images/lolita/upload/plupload/done.gif",
64
+ "public/images/lolita/upload/plupload/error.gif",
65
+ "public/images/lolita/upload/plupload/plupload-bw.png",
66
+ "public/images/lolita/upload/plupload/plupload.png",
67
+ "public/images/lolita/upload/plupload/throbber.gif",
68
+ "public/images/lolita/upload/plupload/transp50.png",
69
+ "public/javascripts/lolita/upload/I18n/ru.js",
70
+ "public/javascripts/lolita/upload/jquery.plupload.queue.min.js",
71
+ "public/javascripts/lolita/upload/jquery.ui.plupload.min.js",
72
+ "public/javascripts/lolita/upload/plupload.flash.swf",
73
+ "public/javascripts/lolita/upload/plupload.full.min.js",
74
+ "public/javascripts/lolita/upload/plupload.silverlight.xap",
75
+ "public/stylesheets/lolita/upload/jquery.ui.plupload.css",
76
+ "public/stylesheets/lolita/upload/plupload.queue.css",
77
+ "spec/configuration/tab/files_spec.rb",
78
+ "spec/lolita/support/bytes_spec.rb",
79
+ "spec/models/file_spec.rb",
80
+ "spec/spec_helper.rb",
81
+ "spec/support/post.rb",
82
+ "spec/uploaders/file_uploader_spec.rb",
83
+ "test_orm/active_record.rb",
84
+ "test_orm/active_record/post.rb",
85
+ "test_orm/config/active_record.yml",
86
+ "test_orm/coverage.rb",
87
+ "test_orm/db/migrate/01_create_posts.rb",
88
+ "test_orm/db/migrate/02_create_files.rb",
89
+ "test_orm/files/large_file.txt",
90
+ "test_orm/files/normal_file.txt",
91
+ "test_orm/rails/config/application.rb",
92
+ "test_orm/rails/config/enviroment.rb",
93
+ "test_orm/rails/config/routes.rb",
94
+ "test_orm/rails/log/development.log",
95
+ "test_orm/support.rb"
96
+ ]
97
+ s.homepage = %q{http://github.com/ithouse/lolita-file-upload}
98
+ s.licenses = ["MIT"]
99
+ s.require_paths = ["lib"]
100
+ s.rubygems_version = %q{1.6.1}
101
+ s.summary = %q{File upload gem for Lolita CMS}
102
+ s.test_files = [
103
+ "spec/configuration/tab/files_spec.rb",
104
+ "spec/lolita/support/bytes_spec.rb",
105
+ "spec/models/file_spec.rb",
106
+ "spec/spec_helper.rb",
107
+ "spec/support/post.rb",
108
+ "spec/uploaders/file_uploader_spec.rb"
109
+ ]
110
+
111
+ if s.respond_to? :specification_version then
112
+ s.specification_version = 3
113
+
114
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
115
+ s.add_runtime_dependency(%q<carrierwave>, ["~> 0.5.2"])
116
+ s.add_development_dependency(%q<cucumber>, ["~> 0.10"])
117
+ s.add_development_dependency(%q<cucumber-rails>, ["~> 0.3.2"])
118
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
119
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5"])
120
+ else
121
+ s.add_dependency(%q<carrierwave>, ["~> 0.5.2"])
122
+ s.add_dependency(%q<cucumber>, ["~> 0.10"])
123
+ s.add_dependency(%q<cucumber-rails>, ["~> 0.3.2"])
124
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
125
+ s.add_dependency(%q<jeweler>, ["~> 1.5"])
126
+ end
127
+ else
128
+ s.add_dependency(%q<carrierwave>, ["~> 0.5.2"])
129
+ s.add_dependency(%q<cucumber>, ["~> 0.10"])
130
+ s.add_dependency(%q<cucumber-rails>, ["~> 0.3.2"])
131
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
132
+ s.add_dependency(%q<jeweler>, ["~> 1.5"])
133
+ end
134
+ end
135
+