spud_media 0.4.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.
@@ -0,0 +1,49 @@
1
+ class Spud::Admin::MediaController < Spud::Admin::ApplicationController
2
+ layout 'spud/admin/cms/detail'
3
+ add_breadcrumb "Media", :spud_admin_media_path
4
+ belongs_to_spud_app :media
5
+ before_filter :load_media,:only => [:edit,:update,:show,:destroy]
6
+ def index
7
+ @media = SpudMedia.order("created_at DESC").paginate :page => params[:page]
8
+ respond_with @media
9
+ end
10
+
11
+ def new
12
+ @page_name = "New Media"
13
+ add_breadcrumb "New", :new_spud_admin_medium_path
14
+ @media = SpudMedia.new
15
+ respond_with @media
16
+ end
17
+
18
+ def create
19
+ @page_name = "New Media"
20
+ add_breadcrumb "New", :new_spud_admin_medium_path
21
+ @media = SpudMedia.new(params[:spud_media])
22
+ flash[:notice] = "File uploaded successfully" if @media.save
23
+
24
+ respond_with @media, :location => spud_admin_media_url
25
+ end
26
+
27
+ def show
28
+ @page_name = "Media: #{@media.attachment_file_name}"
29
+ add_breadcrumb @media.attachment_file_name, :new_spud_admin_media_path
30
+ respond_with @media
31
+ end
32
+
33
+ def update
34
+ end
35
+
36
+ def destroy
37
+ flash[:notice] = "File successfully destroyed" if @media.destroy
38
+ respond_with @media, :location => spud_admin_media_url
39
+ end
40
+ private
41
+ def load_media
42
+ @media = SpudMedia.where(:id => params[:id]).first
43
+ if @media.blank?
44
+ flash[:error] = "Media Asset not found!"
45
+ redirect_to spud_admin_media_url() and return
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::UsersHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::UserSessionsHelper
2
+ end
@@ -0,0 +1,47 @@
1
+ class SpudMedia < ActiveRecord::Base
2
+ has_attached_file :attachment,
3
+ :storage => Spud::Media.paperclip_storage,
4
+ :s3_credentials => Spud::Media.s3_credentials,
5
+ :path => ":class/:id/attachment/:basename.:extension"
6
+
7
+ def image_from_type
8
+ if self.attachment_content_type.blank?
9
+ return "spud/admin/files_thumbs/dat_thumb.png"
10
+ end
11
+
12
+ if self.attachment_content_type.match(/jpeg|jpg/)
13
+ return "spud/admin/files_thumbs/jpg_thumb.png"
14
+ end
15
+
16
+
17
+
18
+ if self.attachment_content_type.match(/png/)
19
+ return "spud/admin/files_thumbs/png_thumb.png"
20
+ end
21
+
22
+ if self.attachment_content_type.match(/zip|tar|tar\.gz|gz/)
23
+ return "spud/admin/files_thumbs/zip_thumb.png"
24
+ end
25
+
26
+ if self.attachment_content_type.match(/xls|xlsx/)
27
+ return "spud/admin/files_thumbs/xls_thumb.png"
28
+ end
29
+ if self.attachment_content_type.match(/doc|docx/)
30
+ return "spud/admin/files_thumbs/doc_thumb.png"
31
+ end
32
+ if self.attachment_content_type.match(/ppt|pptx/)
33
+ return "spud/admin/files_thumbs/ppt_thumb.png"
34
+ end
35
+ if self.attachment_content_type.match(/txt|text/)
36
+ return "spud/admin/files_thumbs/txt_thumb.png"
37
+ end
38
+ if self.attachment_content_type.match(/pdf|ps/)
39
+ return "spud/admin/files_thumbs/pdf_thumb.png"
40
+ end
41
+ if self.attachment_content_type.match(/mp3|wav|aac/)
42
+ return "spud/admin/files_thumbs/mp3_thumb.png"
43
+ end
44
+
45
+ return "spud/admin/files_thumbs/dat_thumb.png"
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ <%=content_for :data_controls do%>
2
+ <%=link_to "Upload File",new_spud_admin_medium_path(),:class => "button",:title => "Upload File"%>
3
+ <%end%>
4
+ <%=content_for :detail do%>
5
+ <div class="page_list">
6
+ <%@media.each do |media|%>
7
+ <div class="page_row">
8
+
9
+ <span class="row_meta"><%=image_tag(media.image_from_type,:height => 50)%><%=link_to media.attachment.url.split("/").last,media.attachment.url%></span>
10
+
11
+ <span class="edit_controls"><%=link_to "Remove",spud_admin_medium_path(:id => media.id),:method => :delete,:class => 'button',:confirm => "Are you sure you want to remove this file?"%></span>
12
+ <br style="clear:both;"/>
13
+ </div>
14
+ <%end%>
15
+ <%=will_paginate @media%>
16
+
17
+ </div>
18
+
19
+ <%end%>
@@ -0,0 +1,22 @@
1
+
2
+
3
+
4
+ <%=form_for @media,:url => spud_admin_media_path(),:html=>{:class=>"right_aligned_form", :multipart => true} do |f|%>
5
+ <fieldset>
6
+ <legend>Upload Media</legend>
7
+ <ol>
8
+ <li>
9
+ <%=f.label :attachment, "Choose File"%>
10
+ <%=f.file_field :attachment%>
11
+ </li>
12
+ </ol>
13
+ </fieldset>
14
+
15
+ <fieldset class="submit"><%=f.submit%> or <%=link_to "cancel",request.referer%></fieldset>
16
+ <%end%>
17
+
18
+ <script type="text/javascript">
19
+ $('input[type=submit],.close_dialog').button();
20
+
21
+ </script>
22
+
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ if defined?(Bundler)
6
+ # If you precompile assets before deploying to production, use this line
7
+ Bundler.require *Rails.groups(:assets => %w(development test))
8
+ # If you want your assets lazily compiled in production, use this line
9
+ # Bundler.require(:default, :assets, Rails.env)
10
+ end
11
+
12
+ module Spud
13
+ module Media
14
+ class Application < Rails::Application
15
+ # Settings in config/environments/* take precedence over those specified here.
16
+ # Application configuration should go into files in config/initializers
17
+ # -- all .rb files in that directory are automatically loaded.
18
+
19
+ # Custom directories with classes and modules you want to be autoloadable.
20
+ # config.autoload_paths += %W(#{config.root}/extras)
21
+
22
+ # Only load the plugins named here, in the order given (default is alphabetical).
23
+ # :all can be used as a placeholder for all plugins not explicitly named.
24
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
25
+
26
+ # Activate observers that should always be running.
27
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
28
+
29
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
30
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
31
+ # config.time_zone = 'Central Time (US & Canada)'
32
+
33
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
34
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
35
+ # config.i18n.default_locale = :de
36
+
37
+ # Configure the default encoding used in templates for Ruby 1.9.
38
+ config.encoding = "utf-8"
39
+
40
+ # Configure sensitive parameters which will be filtered from the log file.
41
+ config.filter_parameters += [:password]
42
+
43
+ # Enable the asset pipeline
44
+ config.assets.enabled = true
45
+
46
+ # Version of your assets, change this if you want to expire all your assets
47
+ config.assets.version = '1.0'
48
+ end
49
+ end
50
+ end
data/config/boot.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ Rails.application.routes.draw do
2
+ namespace :spud do
3
+ namespace :admin do
4
+ resources :media
5
+ end
6
+ end
7
+
8
+ end
9
+
@@ -0,0 +1,8 @@
1
+ module Spud
2
+ module Media
3
+ include ActiveSupport::Configurable
4
+ config_accessor :paperclip_storage,:s3_credentials
5
+ self.paperclip_storage = :filesystem
6
+ self.s3_credentials = "#{Rails.root}/config/s3.yml"
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ require 'spud_core'
2
+ require 'paperclip'
3
+ module Spud
4
+ module Media
5
+ class Engine < Rails::Engine
6
+ engine_name :spud_media
7
+ initializer :admin do
8
+ Spud::Core.configure do |config|
9
+ config.admin_applications += [{:name => "Media",:thumbnail => "spud/admin/media_thumb.png",:url => "/spud/admin/media",:order => 3}]
10
+ end
11
+ end
12
+ initializer :assets do |config|
13
+ Rails.application.config.assets.precompile += [
14
+ "spud/admin/media*"
15
+ ]
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/spud_media.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Spud
2
+ module Media
3
+ require 'spud_media/configuration'
4
+ require 'spud_media/engine' if defined?(Rails)
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spud_media
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Estes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spud_core
16
+ requirement: &70161148194620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70161148194620
25
+ - !ruby/object:Gem::Dependency
26
+ name: paperclip
27
+ requirement: &70161148193760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70161148193760
36
+ description:
37
+ email: destes@redwindsw.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - app/assets/images/spud/admin/files_thumbs/dat_thumb.png
43
+ - app/assets/images/spud/admin/files_thumbs/doc_thumb.png
44
+ - app/assets/images/spud/admin/files_thumbs/jpg_thumb.png
45
+ - app/assets/images/spud/admin/files_thumbs/mp3_thumb.png
46
+ - app/assets/images/spud/admin/files_thumbs/pdf_thumb.png
47
+ - app/assets/images/spud/admin/files_thumbs/png_thumb.png
48
+ - app/assets/images/spud/admin/files_thumbs/ppt_thumb.png
49
+ - app/assets/images/spud/admin/files_thumbs/txt_thumb.png
50
+ - app/assets/images/spud/admin/files_thumbs/xls_thumb.png
51
+ - app/assets/images/spud/admin/files_thumbs/zip_thumb.png
52
+ - app/assets/images/spud/admin/media_thumb.png
53
+ - app/controllers/spud/admin/media_controller.rb
54
+ - app/helpers/spud/admin/users_helper.rb
55
+ - app/helpers/spud/user_sessions_helper.rb
56
+ - app/models/spud_media.rb
57
+ - app/views/spud/admin/media/index.html.erb
58
+ - app/views/spud/admin/media/new.html.erb
59
+ - config/application.rb
60
+ - config/boot.rb
61
+ - config/routes.rb
62
+ - lib/spud_media.rb
63
+ - lib/spud_media/configuration.rb
64
+ - lib/spud_media/engine.rb
65
+ homepage:
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.15
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Spud Media File Upload/Storage Engine
89
+ test_files: []