file_share 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +16 -0
- data/Gemfile.lock +147 -0
- data/README +0 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/app/controllers/application_controller.rb +4 -0
- data/app/controllers/file_attachments_controller.rb +123 -0
- data/app/controllers/file_share/application_controller.rb +5 -0
- data/app/helpers/file_attachments_helper.rb +9 -0
- data/app/helpers/file_share/application_helper.rb +60 -0
- data/app/models/file_attachment.rb +104 -0
- data/app/models/file_container.rb +30 -0
- data/app/views/file-share-shared/_flash.html.erb +7 -0
- data/app/views/file-share-shared/_main_menu.html.erb +3 -0
- data/app/views/file-share-shared/_navigation.html.erb +2 -0
- data/app/views/file_attachments/_file_attachment.html.erb +17 -0
- data/app/views/file_attachments/_file_attachments.html.erb +52 -0
- data/app/views/file_attachments/_file_container_option.html.erb +4 -0
- data/app/views/file_attachments/_file_container_select.html.erb +14 -0
- data/app/views/file_attachments/_plupload_with_listing.html.erb +142 -0
- data/app/views/file_attachments/_upload_form.html.erb +22 -0
- data/app/views/file_attachments/edit.html.erb +32 -0
- data/app/views/file_attachments/index.html.erb +1 -0
- data/app/views/file_attachments/update.js.rjs +13 -0
- data/app/views/layouts/application.html.erb +56 -0
- data/config/application.rb +42 -0
- data/config/blueprint_settings.yml +9 -0
- data/config/boot.rb +13 -0
- data/config/cucumber.yml +8 -0
- data/config/database.example.yml +22 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +26 -0
- data/config/environments/production.rb +49 -0
- data/config/environments/test.rb +35 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/inflections.rb +10 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/secret_token.rb +9 -0
- data/config/initializers/session_store.rb +10 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +64 -0
- data/db/migrate/20101020002635_create_file_attachments.rb +19 -0
- data/db/schema.rb +27 -0
- data/db/seeds.rb +7 -0
- data/lib/file_share.rb +3 -0
- data/lib/file_share/engine.rb +25 -0
- data/lib/generators/file_share/install/USAGE +5 -0
- data/lib/generators/file_share/install/install_generator.rb +19 -0
- data/lib/generators/file_share/install/templates/file_share.rake +169 -0
- data/lib/tasks/blueprint.rake +25 -0
- data/lib/tasks/cucumber.rake +53 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +26 -0
- data/public/favicon.ico +0 -0
- data/public/images/rails.png +0 -0
- data/public/javascripts/file_share.js +62 -0
- data/public/javascripts/file_share_behaviors.js +131 -0
- data/public/javascripts/idselector.js +538 -0
- data/public/javascripts/jquery-1.3.2.min.js +19 -0
- data/public/javascripts/jquery-ui-1.7.2.custom.min.js +298 -0
- data/public/javascripts/jquery.clonePosition.js +27 -0
- data/public/javascripts/jquery.js +154 -0
- data/public/javascripts/jquery.qtip-1.0.0-rc3.js +2149 -0
- data/public/javascripts/jquery.qtip-1.0.0-rc3.min.js +15 -0
- data/public/javascripts/jquery.string.1.0-min.js +6 -0
- data/public/javascripts/jquery.tablesorter.min.js +2 -0
- data/public/javascripts/lowpro.jquery.js +224 -0
- data/public/javascripts/plupload/gears_init.js +86 -0
- data/public/javascripts/plupload/jquery.plupload.queue.min.js +202 -0
- data/public/javascripts/plupload/plupload.browserplus.min.js +1 -0
- data/public/javascripts/plupload/plupload.flash.min.js +1 -0
- data/public/javascripts/plupload/plupload.flash.swf +0 -0
- data/public/javascripts/plupload/plupload.full.min.js +1 -0
- data/public/javascripts/plupload/plupload.gears.min.js +1 -0
- data/public/javascripts/plupload/plupload.html4.min.js +1 -0
- data/public/javascripts/plupload/plupload.html5.min.js +1 -0
- data/public/javascripts/plupload/plupload.min.js +1 -0
- data/public/javascripts/plupload/plupload.silverlight.min.js +1 -0
- data/public/javascripts/plupload/plupload.silverlight.xap +0 -0
- data/public/javascripts/rails.js +132 -0
- data/public/robots.txt +5 -0
- data/public/stylesheets/blueprint/grid.css +290 -0
- data/public/stylesheets/blueprint/icons/cross.png +0 -0
- data/public/stylesheets/blueprint/icons/doc.png +0 -0
- data/public/stylesheets/blueprint/icons/email.png +0 -0
- data/public/stylesheets/blueprint/icons/external.png +0 -0
- data/public/stylesheets/blueprint/icons/feed.png +0 -0
- data/public/stylesheets/blueprint/icons/im.png +0 -0
- data/public/stylesheets/blueprint/icons/key.png +0 -0
- data/public/stylesheets/blueprint/icons/pdf.png +0 -0
- data/public/stylesheets/blueprint/icons/tick.png +0 -0
- data/public/stylesheets/blueprint/icons/visited.png +0 -0
- data/public/stylesheets/blueprint/icons/xls.png +0 -0
- data/public/stylesheets/blueprint/ie.css +36 -0
- data/public/stylesheets/blueprint/oldgrid.css +161 -0
- data/public/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
- data/public/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
- data/public/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
- data/public/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
- data/public/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
- data/public/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
- data/public/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
- data/public/stylesheets/blueprint/plugins/link-icons/screen.css +40 -0
- data/public/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
- data/public/stylesheets/blueprint/plugins/rtl/screen.css +110 -0
- data/public/stylesheets/blueprint/plugins/silksprite/sprite.css +1 -0
- data/public/stylesheets/blueprint/plugins/silksprite/sprites.png +0 -0
- data/public/stylesheets/blueprint/print.css +29 -0
- data/public/stylesheets/blueprint/readme.txt +12 -0
- data/public/stylesheets/blueprint/screen.css +402 -0
- data/public/stylesheets/error_messages.css +65 -0
- data/public/stylesheets/formtastic.css +138 -0
- data/public/stylesheets/formtastic_changes.css +33 -0
- data/public/stylesheets/main_elements.css +26 -0
- data/public/stylesheets/plupload/backgrounds.gif +0 -0
- data/public/stylesheets/plupload/buttons-disabled.png +0 -0
- data/public/stylesheets/plupload/buttons.png +0 -0
- data/public/stylesheets/plupload/delete.gif +0 -0
- data/public/stylesheets/plupload/done.gif +0 -0
- data/public/stylesheets/plupload/error.gif +0 -0
- data/public/stylesheets/plupload/screen.css +172 -0
- data/public/stylesheets/plupload/transp50.png +0 -0
- data/public/stylesheets/reset.css +60 -0
- data/public/stylesheets/scaffold.css +55 -0
- data/public/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/public/stylesheets/smoothness/jquery-ui-1.7.2.custom.css +406 -0
- data/public/stylesheets/tablesorter/blue/asc.gif +0 -0
- data/public/stylesheets/tablesorter/blue/bg.gif +0 -0
- data/public/stylesheets/tablesorter/blue/desc.gif +0 -0
- data/public/stylesheets/tablesorter/blue/style.css +39 -0
- data/public/stylesheets/text_and_colors.css +49 -0
- data/spec/controllers/file_attachments_controller_spec.rb +305 -0
- data/spec/fixtures/file_share_file_attachments.yml +2 -0
- data/spec/fixtures/somefile.txt +1 -0
- data/spec/helpers/file_attachments_helper_spec.rb +11 -0
- data/spec/models/file_attachment_spec.rb +57 -0
- data/spec/models/file_container_spec.rb +23 -0
- data/spec/spec_helper.rb +27 -0
- metadata +474 -0
data/config/boot.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Set up gems listed in the Gemfile.
|
4
|
+
gemfile = File.expand_path('../../Gemfile', __FILE__)
|
5
|
+
begin
|
6
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
7
|
+
require 'bundler'
|
8
|
+
Bundler.setup
|
9
|
+
rescue Bundler::GemNotFound => e
|
10
|
+
STDERR.puts e.message
|
11
|
+
STDERR.puts "Try running `bundle install`."
|
12
|
+
exit!
|
13
|
+
end if File.exist?(gemfile)
|
data/config/cucumber.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<%
|
2
|
+
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
3
|
+
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
4
|
+
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
|
5
|
+
%>
|
6
|
+
default: <%= std_opts %> features
|
7
|
+
wip: --tags @wip:3 --wip features
|
8
|
+
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|
@@ -0,0 +1,26 @@
|
|
1
|
+
FileShare::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
FileShare::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
FileShare::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
if defined?(FileShare::Application)
|
8
|
+
FileShare::Application.config.secret_token = 'bbce55f6968bd726783655882cc294e651853a2deb82d5853867023359e3fca0c01486b0fe9158af6d29fde3dc7347b6029917742f64a66fc2d58712d99565cb'
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
if defined?(FileShare::Application)
|
4
|
+
FileShare::Application.config.session_store :cookie_store, :key => '_file-share_session'
|
5
|
+
end
|
6
|
+
|
7
|
+
# Use the database for sessions instead of the cookie-based default,
|
8
|
+
# which shouldn't be used to store highly confidential information
|
9
|
+
# (create the session table with "rake db:sessions:create")
|
10
|
+
# FileShare::Application.config.session_store :active_record_store
|
data/config/routes.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
root :to => "file_attachments#index"
|
3
|
+
resources :file_attachments do
|
4
|
+
member do
|
5
|
+
get :download
|
6
|
+
end
|
7
|
+
end
|
8
|
+
# The priority is based upon order of creation:
|
9
|
+
# first created -> highest priority.
|
10
|
+
|
11
|
+
# Sample of regular route:
|
12
|
+
# match 'products/:id' => 'catalog#view'
|
13
|
+
# Keep in mind you can assign values other than :controller and :action
|
14
|
+
|
15
|
+
# Sample of named route:
|
16
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
17
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
18
|
+
|
19
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
20
|
+
# resources :products
|
21
|
+
|
22
|
+
# Sample resource route with options:
|
23
|
+
# resources :products do
|
24
|
+
# member do
|
25
|
+
# get 'short'
|
26
|
+
# post 'toggle'
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# collection do
|
30
|
+
# get 'sold'
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Sample resource route with sub-resources:
|
35
|
+
# resources :products do
|
36
|
+
# resources :comments, :sales
|
37
|
+
# resource :seller
|
38
|
+
# end
|
39
|
+
|
40
|
+
# Sample resource route with more complex sub-resources
|
41
|
+
# resources :products do
|
42
|
+
# resources :comments
|
43
|
+
# resources :sales do
|
44
|
+
# get 'recent', :on => :collection
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
|
48
|
+
# Sample resource route within a namespace:
|
49
|
+
# namespace :admin do
|
50
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
51
|
+
# # (app/controllers/admin/products_controller.rb)
|
52
|
+
# resources :products
|
53
|
+
# end
|
54
|
+
|
55
|
+
# You can have the root of your site routed with "root"
|
56
|
+
# just remember to delete public/index.html.
|
57
|
+
# root :to => "welcome#index"
|
58
|
+
|
59
|
+
# See how all your routes lay out with "rake routes"
|
60
|
+
|
61
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
62
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
63
|
+
# match ':controller(/:action(/:id(.:format)))'
|
64
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateFileAttachments < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :file_share_file_attachments do |t|
|
4
|
+
t.string :name
|
5
|
+
t.text :description
|
6
|
+
t.string :filepath
|
7
|
+
t.integer :attachable_id
|
8
|
+
t.string :attachable_type
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :file_share_file_attachments, :attachable_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :file_share_file_attachments
|
18
|
+
end
|
19
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(:version => 20101020002635) do
|
14
|
+
|
15
|
+
create_table "file_share_file_attachments", :force => true do |t|
|
16
|
+
t.string "name"
|
17
|
+
t.text "description"
|
18
|
+
t.string "filepath"
|
19
|
+
t.integer "attachable_id"
|
20
|
+
t.string "attachable_type"
|
21
|
+
t.datetime "created_at"
|
22
|
+
t.datetime "updated_at"
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index "file_share_file_attachments", ["attachable_id"], :name => "index_file_share_file_attachments_on_attachable_id"
|
26
|
+
|
27
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
data/lib/file_share.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "file_share"
|
2
|
+
require "rails"
|
3
|
+
|
4
|
+
module FileShare
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
ASSET_PREFIX = "file_share"
|
7
|
+
ENGINEER_VERSION = "0.2.3"
|
8
|
+
|
9
|
+
initializer "file_share.require_dependencies" do
|
10
|
+
require 'bundler'
|
11
|
+
gemfile = Bundler::Definition.build(root.join('Gemfile'), root.join('Gemfile.lock'), {})
|
12
|
+
specs = gemfile.dependencies.select do |d|
|
13
|
+
d.name != 'engineer' and (d.groups & [:default, :production]).any?
|
14
|
+
end
|
15
|
+
|
16
|
+
specs.collect { |s| s.autorequire || [s.name] }.flatten.each do |r|
|
17
|
+
require r
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
initializer "file_share.asset_path" do |app|
|
22
|
+
app.config.middleware.use ::ActionDispatch::Static, "#{root}/public"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FileShare
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def install_rake_tasks
|
10
|
+
directory '.', File.join("lib", "tasks")
|
11
|
+
end
|
12
|
+
|
13
|
+
def rake_engine_install
|
14
|
+
rake "file_share:install"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
if defined? FileShare::Engine
|
2
|
+
namespace "file_share" do
|
3
|
+
|
4
|
+
# Migrate after schema in case there is no engine schema: at least we'll get the migrations.
|
5
|
+
task :install => %w{assets db:schema db:migrate db:migrate:seed}
|
6
|
+
|
7
|
+
desc "Import file_share's assets and new db migrations"
|
8
|
+
task :update => %w{assets db:migrate}
|
9
|
+
|
10
|
+
namespace :db do #
|
11
|
+
|
12
|
+
def host_migration(new_migration_name, &block)
|
13
|
+
require 'rails/generators/active_record'
|
14
|
+
db_migrate = File.join Rails.root, *%w{db migrate}
|
15
|
+
mkdir_p db_migrate unless File.exists? db_migrate
|
16
|
+
|
17
|
+
# TODO Kill after https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4412
|
18
|
+
sleep 1 # wait for timestamp to change.
|
19
|
+
|
20
|
+
migration_number = ActiveRecord::Generators::Base.next_migration_number(db_migrate)
|
21
|
+
new_migration = File.join db_migrate, "#{migration_number}_#{new_migration_name}.rb"
|
22
|
+
tmp_migration = File.join Dir::tmpdir, "#{migration_number}_#{new_migration_name}.rb"
|
23
|
+
|
24
|
+
File.open(tmp_migration, "w") do |f|
|
25
|
+
f << block.call
|
26
|
+
end
|
27
|
+
|
28
|
+
cp tmp_migration, new_migration
|
29
|
+
end
|
30
|
+
|
31
|
+
def import_migration(original_file, new_migration_name, &block)
|
32
|
+
host_migration new_migration_name do
|
33
|
+
block.call File.read original_file
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Import file_share's new db migrations"
|
38
|
+
task :migrate do
|
39
|
+
require 'rails/generators/active_record'
|
40
|
+
db_migrate = File.join Rails.root, *%w{db migrate}
|
41
|
+
|
42
|
+
# Consider the set of engine migrations, in chronological order.
|
43
|
+
migrations = Dir[File.join FileShare::Engine.root, *%w{db migrate [0-9]*_*.rb}]
|
44
|
+
migrations.sort!
|
45
|
+
|
46
|
+
# See if the host already has a schema migration.
|
47
|
+
last_migration_in_schema = migrations.reverse.detect do |migration|
|
48
|
+
name = File.basename(migration).match(/\d+_(.*)\.rb/)[1]
|
49
|
+
Dir[File.join(db_migrate, "[0-9]*_file_share_schema_after_#{name}.rb")].any?
|
50
|
+
end
|
51
|
+
|
52
|
+
# If so, do not import any migrations implied by the schema
|
53
|
+
# (recall slice! *removes* the indicated range, leaving the rest.)
|
54
|
+
migrations.slice! 0..migrations.index(last_migration_in_schema) if last_migration_in_schema
|
55
|
+
|
56
|
+
# Of the remainder
|
57
|
+
migrations.each do |old_migration|
|
58
|
+
old_name = File.basename(old_migration).match(/\d+_(.*)\.rb/)[1]
|
59
|
+
new_name = "file_share_#{old_name}"
|
60
|
+
|
61
|
+
# Skip this single migration if we already have it
|
62
|
+
next if Dir[File.join(db_migrate, "[0-9]*_#{new_name}.rb")].any?
|
63
|
+
|
64
|
+
import_migration old_migration, new_name do |migration_source|
|
65
|
+
migration_source.gsub "class #{old_name.camelize}", "class #{new_name.camelize}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Import file_share's schema as a db migration"
|
71
|
+
task :schema do
|
72
|
+
schema = File.join FileShare::Engine.root, *%w{db schema.rb}
|
73
|
+
if File.exist? schema
|
74
|
+
migrations = Dir[File.join FileShare::Engine.root, *%w{db migrate [0-9]*_*.rb}]
|
75
|
+
latest_migration = migrations.sort.last
|
76
|
+
|
77
|
+
migration_name = if latest_migration
|
78
|
+
latest_migration_name = File.basename(latest_migration).match(/^\d+_(.+)\.rb$/)[1]
|
79
|
+
"file_share_schema_after_#{latest_migration_name}"
|
80
|
+
else
|
81
|
+
"file_share_schema"
|
82
|
+
end
|
83
|
+
|
84
|
+
import_migration schema, migration_name do |schema_source|
|
85
|
+
# Strip schema declaration
|
86
|
+
schema_source.gsub! /\A.*^ActiveRecord::Schema.define\(:version => \d+\) do/m, ''
|
87
|
+
schema_source.strip!.gsub!(/^end\Z/m, '').strip!
|
88
|
+
|
89
|
+
# Indent everything 2 and strip trailing white space
|
90
|
+
schema_source.gsub!(/^/, ' ').gsub!(/[\t ]+$/, '')
|
91
|
+
|
92
|
+
# Wrap with migration class declaration
|
93
|
+
<<-EOF
|
94
|
+
class #{migration_name.camelize} < ActiveRecord::Migration
|
95
|
+
def self.up
|
96
|
+
#{schema_source}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
EOF
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
task "migrate:seed" do
|
105
|
+
migration_name = "file_share_seed"
|
106
|
+
if File.exist? File.join(FileShare::Engine.root, 'db', 'seeds.rb')
|
107
|
+
host_migration migration_name do
|
108
|
+
<<-EOF
|
109
|
+
class #{migration_name.camelize} < ActiveRecord::Migration
|
110
|
+
def self.up
|
111
|
+
load File.join(FileShare::Engine.root, 'db', 'seeds.rb')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
EOF
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "Load file_share's seed data"
|
120
|
+
task :seed => :environment do
|
121
|
+
seed_file = File.join(FileShare::Engine.root, 'db', 'seeds.rb')
|
122
|
+
load(seed_file) if File.exist?(seed_file)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "Link (or copy) file_share's static assets"
|
128
|
+
task :assets, [:copy] => :environment do |t, args|
|
129
|
+
engine_asset_path = File.join(
|
130
|
+
Rails.application.paths.public.to_a.first,
|
131
|
+
FileShare::Engine::ASSET_PREFIX)
|
132
|
+
|
133
|
+
rm_rf engine_asset_path
|
134
|
+
host_asset_path = FileShare::Engine.paths.public.to_a.first
|
135
|
+
|
136
|
+
link = lambda do
|
137
|
+
begin
|
138
|
+
ln_s host_asset_path, engine_asset_path
|
139
|
+
true
|
140
|
+
rescue NotImplementedError
|
141
|
+
false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
copy = lambda { cp_r host_asset_path, engine_asset_path }
|
146
|
+
|
147
|
+
not args[:copy] and link.call or copy.call
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
namespace :engines do
|
153
|
+
|
154
|
+
desc "Load seed data from all engines"
|
155
|
+
task "db:seed" => "file_share:db:seed"
|
156
|
+
|
157
|
+
desc "Import new migrations from all engines"
|
158
|
+
task "db:migrate" => "file_share:db:migrate"
|
159
|
+
|
160
|
+
desc "Link (or copy) static assets from all engines"
|
161
|
+
task :assets, [:copy] => "file_share:assets"
|
162
|
+
|
163
|
+
desc "Import assets and new db migrations from all engines"
|
164
|
+
task :update => "file_share:update"
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
task "db:seed" => "engines:db:seed"
|
169
|
+
end
|