ample_assets 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.textile +68 -0
  3. data/Rakefile +38 -0
  4. data/app/assets/images/ample_assets/bg-noise.png +0 -0
  5. data/app/assets/images/ample_assets/btn-next.png +0 -0
  6. data/app/assets/images/ample_assets/btn-prev.png +0 -0
  7. data/app/assets/images/ample_assets/btn-select-files.png +0 -0
  8. data/app/assets/images/ample_assets/cancel.png +0 -0
  9. data/app/assets/images/ample_assets/closelabel.png +0 -0
  10. data/app/assets/images/ample_assets/collapse.png +0 -0
  11. data/app/assets/images/ample_assets/gravity.png +0 -0
  12. data/app/assets/images/ample_assets/icon_other.gif +0 -0
  13. data/app/assets/images/ample_assets/icon_pdf.gif +0 -0
  14. data/app/assets/images/ample_assets/icon_swf.gif +0 -0
  15. data/app/assets/images/ample_assets/loading.gif +0 -0
  16. data/app/assets/images/ample_assets/play.png +0 -0
  17. data/app/assets/images/ample_assets/prev-next.png +0 -0
  18. data/app/assets/images/ample_assets/reload.png +0 -0
  19. data/app/assets/images/ample_assets/remove.png +0 -0
  20. data/app/assets/javascripts/ample_assets.js +1 -0
  21. data/app/assets/javascripts/ample_assets/application.js +18 -0
  22. data/app/assets/javascripts/ample_assets/classes/ample_assets_gravity.js.coffee +86 -0
  23. data/app/assets/javascripts/ample_assets/classes/ample_assets_toolbar.js.coffee +769 -0
  24. data/app/assets/javascripts/ample_assets/classes/ample_assets_uploadify.js.coffee +30 -0
  25. data/app/assets/javascripts/ample_assets/files.js.coffee +5 -0
  26. data/app/assets/stylesheets/ample_assets.css +3 -0
  27. data/app/assets/stylesheets/ample_assets/application.css +8 -0
  28. data/app/assets/stylesheets/ample_assets/bourbon/css3/_border-radius.scss +59 -0
  29. data/app/assets/stylesheets/ample_assets/bourbon/css3/_box-shadow.scss +11 -0
  30. data/app/assets/stylesheets/ample_assets/custom_mixins.scss +47 -0
  31. data/app/assets/stylesheets/ample_assets/facebox.css +79 -0
  32. data/app/assets/stylesheets/ample_assets/files.css.scss +750 -0
  33. data/app/assets/swf/ample_assets/expressInstall.swf +0 -0
  34. data/app/assets/swf/ample_assets/uploadify.swf +0 -0
  35. data/app/controllers/ample_assets/application_controller.rb +4 -0
  36. data/app/controllers/ample_assets/files_controller.rb +109 -0
  37. data/app/helpers/ample_assets/application_helper.rb +4 -0
  38. data/app/models/ample_assets/file.rb +79 -0
  39. data/app/views/ample_assets/files/_drop.html.erb +12 -0
  40. data/app/views/ample_assets/files/_file.html.erb +1 -0
  41. data/app/views/ample_assets/files/_file.js.erb +3 -0
  42. data/app/views/ample_assets/files/index.html.erb +6 -0
  43. data/app/views/ample_assets/files/new.html.erb +21 -0
  44. data/app/views/ample_assets/files/recent.html.erb +1 -0
  45. data/app/views/ample_assets/files/show.html.erb +1 -0
  46. data/app/views/layouts/ample_assets/application.html.erb +14 -0
  47. data/config/routes.rb +27 -0
  48. data/lib/ample_assets.rb +26 -0
  49. data/lib/ample_assets/configuration.rb +73 -0
  50. data/lib/ample_assets/custom_processor.rb +29 -0
  51. data/lib/ample_assets/devise_constraint.rb +9 -0
  52. data/lib/ample_assets/engine.rb +36 -0
  53. data/lib/ample_assets/form_builder.rb +19 -0
  54. data/lib/ample_assets/form_helper.rb +14 -0
  55. data/lib/ample_assets/plugin_methods.rb +11 -0
  56. data/lib/ample_assets/version.rb +3 -0
  57. data/lib/ample_assets/view_helper.rb +80 -0
  58. data/lib/generators/ample_assets/install_generator.rb +25 -0
  59. data/lib/generators/ample_assets/templates/migration.rb +16 -0
  60. data/lib/generators/ample_assets/utils.rb +15 -0
  61. data/test/dummy/Rakefile +7 -0
  62. data/test/dummy/app/assets/images/rails.png +0 -0
  63. data/test/dummy/app/assets/javascripts/application.js +11 -0
  64. data/test/dummy/app/assets/sample.pdf +0 -0
  65. data/test/dummy/app/assets/stylesheets/application.css +8 -0
  66. data/test/dummy/app/controllers/application_controller.rb +7 -0
  67. data/test/dummy/app/controllers/public/pages_controller.rb +32 -0
  68. data/test/dummy/app/controllers/public_controller.rb +6 -0
  69. data/test/dummy/app/helpers/application_helper.rb +11 -0
  70. data/test/dummy/app/models/page.rb +7 -0
  71. data/test/dummy/app/views/layouts/application.html.erb +17 -0
  72. data/test/dummy/app/views/public/index.html.erb +0 -0
  73. data/test/dummy/app/views/public/pages/_form.html.erb +18 -0
  74. data/test/dummy/app/views/public/pages/edit.html.erb +1 -0
  75. data/test/dummy/app/views/public/pages/index.html.erb +8 -0
  76. data/test/dummy/app/views/public/pages/new.html.erb +1 -0
  77. data/test/dummy/app/views/public/pages/show.html.erb +3 -0
  78. data/test/dummy/config.ru +4 -0
  79. data/test/dummy/config/application.rb +45 -0
  80. data/test/dummy/config/boot.rb +10 -0
  81. data/test/dummy/config/database.yml +25 -0
  82. data/test/dummy/config/environment.rb +5 -0
  83. data/test/dummy/config/environments/development.rb +30 -0
  84. data/test/dummy/config/environments/production.rb +60 -0
  85. data/test/dummy/config/environments/test.rb +39 -0
  86. data/test/dummy/config/initializers/ample_assets.rb +4 -0
  87. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  88. data/test/dummy/config/initializers/inflections.rb +10 -0
  89. data/test/dummy/config/initializers/mime_types.rb +5 -0
  90. data/test/dummy/config/initializers/secret_token.rb +7 -0
  91. data/test/dummy/config/initializers/session_store.rb +8 -0
  92. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  93. data/test/dummy/config/locales/en.yml +5 -0
  94. data/test/dummy/config/routes.rb +8 -0
  95. data/test/dummy/db/migrate/20120105034123_create_pages.rb +9 -0
  96. data/test/dummy/db/migrate/20120106192233_create_ample_assets_tables.rb +16 -0
  97. data/test/dummy/db/schema.rb +37 -0
  98. data/test/dummy/public/404.html +26 -0
  99. data/test/dummy/public/422.html +26 -0
  100. data/test/dummy/public/500.html +26 -0
  101. data/test/dummy/public/favicon.ico +0 -0
  102. data/test/dummy/script/rails +6 -0
  103. data/test/functional/ample_assets/files_controller_test.rb +49 -0
  104. data/test/integration/ample_assets/admin_test.rb +96 -0
  105. data/test/integration/ample_assets/public_test.rb +7 -0
  106. data/test/integration_test_helper.rb +24 -0
  107. data/test/test_helper.rb +25 -0
  108. data/test/unit/ample_assets/configuration_test.rb +35 -0
  109. data/test/unit/ample_assets/file_test.rb +14 -0
  110. data/test/unit/ample_assets/plugin_methods_test.rb +30 -0
  111. data/test/unit/helpers/ample_assets/form_builder_test.rb +11 -0
  112. data/test/unit/helpers/ample_assets/form_helper_test.rb +23 -0
  113. data/test/unit/helpers/ample_assets/view_helper_test.rb +128 -0
  114. metadata +395 -0
@@ -0,0 +1,36 @@
1
+ require 'ample_assets'
2
+ require 'rails'
3
+ require 'rack/cache'
4
+ require 'acts_as_indexed'
5
+ require 'ample_assets/custom_processor'
6
+ require 'will_paginate'
7
+ require 'will_paginate/array'
8
+ require 'coffee_cup'
9
+
10
+ module AmpleAssets
11
+ class Engine < Rails::Engine
12
+ isolate_namespace AmpleAssets
13
+
14
+ initializer 'ample_assets: configure rack/cache' do |app|
15
+ app.middleware.insert 0, ::Rack::Cache, {
16
+ :verbose => false,
17
+ :metastore => "file:#{Rails.root}/tmp/dragonfly/cache/meta",
18
+ :entitystore => "file:#{Rails.root}/tmp/dragonfly/cache/body"
19
+ }
20
+ end
21
+
22
+ initializer 'ample_assets: configure dragonfly' do |app|
23
+ AmpleAssets.dfly.define_macro ActiveRecord::Base, :image_accessor
24
+ AmpleAssets.dfly.register_mime_type(:swf, 'application/x-shockwave-flash')
25
+ AmpleAssets.dfly.configure_with(:imagemagick)
26
+ AmpleAssets.dfly.configure_with(:rails)
27
+ AmpleAssets.dfly.processor.register(CustomProcessor)
28
+ app.middleware.insert_after ::Rack::Cache, ::Dragonfly::Middleware, :images
29
+ end
30
+
31
+ initializer 'ample_assets: cleanup configuration' do |app|
32
+ AmpleAssets.mount_at += '/' unless AmpleAssets.mount_at.last == '/'
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ module AmpleAssets
2
+ module FormBuilder
3
+
4
+ def asset_drop(method, options = {})
5
+ if options.delete(:serialized)
6
+ begin
7
+ object = AmpleAssets::File.find(options[:value])
8
+ rescue ActiveRecord::RecordNotFound
9
+ object = @object
10
+ end
11
+ options.merge!(:object => object)
12
+ else
13
+ options.merge!(:object => @object.send(method.to_s.gsub(/_id$/, '')))
14
+ end
15
+ @template.asset_drop(@object_name, method, options)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module AmpleAssets
2
+ module FormHelper
3
+
4
+ def asset_drop(object_name, method, options = {})
5
+ render :partial => 'ample_assets/files/drop',
6
+ :object => options[:object],
7
+ :locals => {
8
+ :object_name => object_name,
9
+ :method => method
10
+ }
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module AmpleAssets
2
+ module PluginMethods
3
+
4
+ def has_asset(name = 'file', options = {})
5
+ configuration = { :foreign_key => "#{name}_id", :class_name => 'AmpleAssets::File' }
6
+ configuration.update(options) if options.is_a?(Hash)
7
+ self.belongs_to name, configuration
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module AmpleAssets
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,80 @@
1
+ module AmpleAssets
2
+ module ViewHelper
3
+
4
+ def assets_toolbar(tabs = nil)
5
+ tabs = AmpleAssets.tabs if tabs.nil?
6
+ script = "var ample_assets = {}; ample_assets.load = true; "
7
+ script += "ample_assets.mount_at = '#{AmpleAssets.mount_at}'; "
8
+ script += "ample_assets.pages = #{tabs.to_json}"
9
+ content_tag :script, script.html_safe, :type => "text/javascript"
10
+ end
11
+
12
+ # Returns image tag for an object's attachment, with optional link element wrapped around it.
13
+ #
14
+ # @param Object - Required
15
+ # @param String :alt - Defaults to object.title
16
+ # @param String :title
17
+ # @param String :class
18
+ # @param String :style
19
+ # @param String :dimensions - Dragonfly-esque dimensions... @see http://markevans.github.com/dragonfly/file.Processing.html
20
+ # @param String :link - Destination for link_to tag
21
+ # @param Symbol :encode - :gif, :jpg, :png, etc. Defaults to :png
22
+ # @param Object :object - Dragonfly object, defaults to object.file
23
+ # @param Boolean :video - Link to an iframe lightbox?
24
+ # @param String :video_dimensions - (width)x(height), defaults to 500x350
25
+ #
26
+ def image_asset(object, args={})
27
+
28
+ # Gracefully handle nil
29
+ return if object.try(:file).nil? && args[:object].nil?
30
+
31
+ # Define default opts and merge with parameter args
32
+ opts = {
33
+ :alt => '',
34
+ :video_dimensions => '500x350',
35
+ :encode => :png
36
+ }.merge(args)
37
+
38
+ # Override alt text with object title if it exists
39
+ opts[:alt] = escape_javascript(object.title) if object.respond_to?('title')
40
+
41
+ # See if optional file object actually contains a dfly instance
42
+ if opts[:object]
43
+ attachment = opts[:object].attachment
44
+ attachment_gravity = opts[:object].attachment_gravity
45
+ else
46
+ attachment = object.file.attachment
47
+ attachment_gravity = object.file.attachment_gravity
48
+ end
49
+
50
+ # If this is a crop, try to add gravity
51
+ if opts.try(:[], :dimensions) && opts[:dimensions].include?('#')
52
+ # Strip out image geometry
53
+ opts[:size] = /[0-9]{1,}x[0-9]{1,}/.match(opts[:dimensions]).try(:[], 0)
54
+ width, height = opts[:size].split('x')
55
+ image = attachment.process(:resize_and_crop, :width => width, :height => height, :gravity => attachment_gravity).encode(opts[:encode])
56
+ else
57
+ image = opts.try(:[], :dimensions) ? attachment.process(:thumb, opts[:dimensions]).encode(opts[:encode]) : attachment.encode(opts[:encode])
58
+ end
59
+
60
+ # Create default rails image_tag dimension
61
+ opts[:size] ||= "#{image.width}x#{image.height}"
62
+
63
+ # Determine which opts ultimately get passed to image_tag
64
+ valid_opts = [:alt, :class, :style, :title]
65
+ valid_opts.push(:size) unless args[:size] == false
66
+
67
+ # Create image tag
68
+ img_tag = image_tag(image.url, opts.slice(*valid_opts))
69
+
70
+ # If this is a video link
71
+ if opts[:video]
72
+ link_to img_tag, opts[:link], :rel => 'facebox', :rev => "iframe|#{opts[:video_dimensions]}"
73
+ else
74
+ link_to_if opts[:link], img_tag, opts[:link]
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require File.expand_path('../utils', __FILE__)
4
+
5
+ module AmpleAssets
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ desc "Copies migrations file for AmpleAssets."
10
+
11
+ source_root File.expand_path('../templates', __FILE__)
12
+ class << self
13
+ include Generators::Utils
14
+ end
15
+
16
+ def self.source_root
17
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
18
+ end
19
+
20
+ def create_migration_file
21
+ migration_template 'migration.rb', 'db/migrate/create_ample_assets_tables.rb' rescue p $!.message
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ class CreateAmpleAssetsTables < ActiveRecord::Migration
2
+ def change
3
+ create_table :ample_assets_files do |t|
4
+ t.string :keywords
5
+ t.string :alt_text
6
+ t.string :attachment_uid
7
+ t.string :attachment_mime_type
8
+ t.string :attachment_ext
9
+ t.string :attachment_name
10
+ t.integer :attachment_width
11
+ t.integer :attachment_height
12
+ t.string :attachment_gravity
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module AmpleAssets
2
+ module Generators
3
+ module Utils
4
+ def next_migration_number(dirname)
5
+ if ActiveRecord::Base.timestamped_migrations
6
+ migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
7
+ migration_number += 1
8
+ migration_number.to_s
9
+ else
10
+ "%.3d" % (current_migration_number(dirname) + 1)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,11 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require jquery-ui
10
+ //= require ample_assets
11
+ //= require_tree .
Binary file
@@ -0,0 +1,8 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require ample_assets
7
+ *= require_tree .
8
+ */
@@ -0,0 +1,7 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ def index
5
+ end
6
+
7
+ end
@@ -0,0 +1,32 @@
1
+ class Public::PagesController < PublicController
2
+
3
+ def create
4
+ @current_page = Page.new params[:page]
5
+ if @current_page.save
6
+ flash[:notice] = "Page saved!"
7
+ redirect_to :action => :index
8
+ else
9
+ flash[:error] = "There was a problem"
10
+ end
11
+ end
12
+
13
+ def update
14
+ if current_page.update_attributes(params[:page])
15
+ flash[:notice] = "Page updated!"
16
+ redirect_to :action => :index
17
+ else
18
+ flash[:error] = "There was a problem"
19
+ render :action => :edit
20
+ end
21
+
22
+ end
23
+
24
+ protected
25
+
26
+ helper_method :current_page
27
+
28
+ def current_page
29
+ @current_page ||= params[:id] ? Page.find(params[:id]) : Page.new
30
+ end
31
+
32
+ end
@@ -0,0 +1,6 @@
1
+ class PublicController < ApplicationController
2
+
3
+ def index
4
+ end
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ module ApplicationHelper
2
+
3
+ def show_flashes
4
+ messages = ''.html_safe
5
+ flash.collect { |k,v|
6
+ messages << content_tag(:div, v.html_safe, :class => "flash #{k}" )
7
+ }
8
+ content_tag(:div, messages, :id => 'notifications')
9
+ end
10
+
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'ample_assets'
2
+
3
+ class Page < ActiveRecord::Base
4
+
5
+ has_asset
6
+
7
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= content_tag :div, :class => :container do %>
12
+ <%= show_flashes %>
13
+ <%= yield %>
14
+ <% end %>
15
+
16
+ </body>
17
+ </html>
File without changes
@@ -0,0 +1,18 @@
1
+ <%= form_for current_page do |f| %>
2
+
3
+ <p><%= f.label :title %><br /><%= f.text_field :title %></p>
4
+
5
+ <% unless f.object.new_record? %>
6
+
7
+ <%# asset_drop(:page, :file_id) %>
8
+ <%= f.asset_drop(:file_id) %>
9
+
10
+ <p><%= text_area_tag :body, nil, :class => :textile %></p>
11
+
12
+ <% end %>
13
+
14
+ <%= f.submit %>
15
+
16
+ <% end %>
17
+
18
+ <%= assets_toolbar %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,8 @@
1
+ <%= link_to 'Create New Page', new_page_path %>
2
+
3
+ <ul>
4
+ <% Page.all.each do |page| %>
5
+ <%= content_tag :li, link_to(page.title, edit_page_path(page)) %>
6
+ <% end %>
7
+ </ul>
8
+
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,3 @@
1
+ <%= content_tag :h1, current_page.title %>
2
+
3
+ <%= image_asset current_page, :dimensions => '200x200#' %>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+ require "jquery-rails" # this should be auto-included with the Bundler.require :default, Rails.env, but it's not happening
5
+ Bundler.require
6
+ require "ample_assets"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Custom directories with classes and modules you want to be autoloadable.
15
+ # config.autoload_paths += %W(#{config.root}/extras)
16
+
17
+ # Only load the plugins named here, in the order given (default is alphabetical).
18
+ # :all can be used as a placeholder for all plugins not explicitly named.
19
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
+
21
+ # Activate observers that should always be running.
22
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
+
24
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
+ # config.time_zone = 'Central Time (US & Canada)'
27
+
28
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
+ # config.i18n.default_locale = :de
31
+
32
+ # Configure the default encoding used in templates for Ruby 1.9.
33
+ config.encoding = "utf-8"
34
+
35
+ # Configure sensitive parameters which will be filtered from the log file.
36
+ config.filter_parameters += [:password]
37
+
38
+ # Enable the asset pipeline
39
+ config.assets.enabled = true
40
+
41
+ # Version of your assets, change this if you want to expire all your assets
42
+ config.assets.version = '1.0'
43
+ end
44
+ end
45
+