media_include 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c313c973d329ee6871ced1ae4a1262782ab7638
4
+ data.tar.gz: 72061321122ca180c86223ce030334392e74c6a2
5
+ SHA512:
6
+ metadata.gz: 18d00b8ebae1e0438ef98da275a9c2d934c68ef0693f1e7734bf970466f9661d0b92ca02f1375b56b8211f5ae428e9b9c1ef0051012547f4d05dcd08523700b5
7
+ data.tar.gz: 833e2f832a98ccb6ad8c759aea29a366bfb92b9218b51a671625905f58f419c18d33075d8cf0d321779ffcffb9faf0ddaa1331a60f9e26b140028ed3291dfeb0
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>media_include</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ <nature>com.aptana.projects.webnature</nature>
11
+ <nature>org.radrails.rails.core.railsnature</nature>
12
+ <nature>com.aptana.ruby.core.rubynature</nature>
13
+ </natures>
14
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in media_include.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # MediaInclude
2
+
3
+ Includes Images and videos your models
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'media_include'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install media_include
18
+
19
+ ## Usage
20
+ To generate the image and video models
21
+
22
+ rails generate media_include:install
23
+ rake db:migrate
24
+
25
+ Now we are going to attach images to Post model
26
+
27
+ class Post < ActiveRecord::Base
28
+ attr_accessible :title
29
+ accept_images
30
+ end
31
+
32
+ In the form
33
+
34
+ = nested_form_for @post do |f|
35
+ = f.input :title
36
+ =render :partial => "layouts/load_images", :locals => {:f => f}
37
+
38
+ = f.button :submit
39
+
40
+
41
+
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
50
+
51
+
52
+
53
+ ## To do
54
+
55
+ Try version 14, if works uninstall and reset version to 1
56
+
57
+
58
+
59
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,38 @@
1
+ require 'rails/generators'
2
+
3
+ module MediaInclude
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ desc "Crea tabla images"
8
+
9
+ # Commandline options can be defined here using Thor-like options:
10
+ #class_option :my_opt, :type => :boolean, :default => false, :desc => "My Option"
11
+ # I can later access that option using:
12
+ # options[:my_opt]
13
+ ## Code goes here ;)
14
+ #source_root File.expand_path("../templates", __FILE__)
15
+ ruta_archivo = File.join(File.dirname(__FILE__), "templates/")
16
+ source_root ruta_archivo
17
+ puts ruta_archivo
18
+
19
+
20
+ def self.next_migration_number(path)
21
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
22
+ end
23
+
24
+
25
+ def copy_migration
26
+ migration_template 'migration.rb', "db/migrate/media_include_create_media"
27
+ template "image.rb", "app/models/image.rb"
28
+ template "video.rb", "app/models/video.rb"
29
+ template "_load_images.html.haml", "app/views/layouts/_load_images.html.haml"
30
+ template "_script_template.html.erb", "app/views/layouts/_script_template.html.erb"
31
+ template "_uploads.html.haml", "app/views/layouts/_uploads.html.haml"
32
+ template "s3.yml", "config/s3.yml"
33
+
34
+ end
35
+ # Generator Code. Remember this is just suped-up Thor so methods are executed in order
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ -if params[:id]
2
+ - model = controller_name.singularize.camelize.constantize.find(params[:id])
3
+ - images = model.images
4
+ - videos = model.videos
5
+ -i = 0
6
+ -i2 = 0
7
+
8
+
9
+ = f.simple_fields_for :images do |image|
10
+ = image.input :picture, :as => "file"
11
+ - if images && images[i]
12
+ = image_tag images[i].picture(:square), :class => "img-polaroid"
13
+ = #link_to "Crop", crop_image_path(:imagen => images[i].picture(:large)), :class => "btn btn-warning btn-mini", :method => :post
14
+ = image.link_to_remove "Eliminar foto", :class => "btn btn-danger"
15
+
16
+ - i = i + 1
17
+ %p= f.link_to_add "Agregar foto", :images, :class => "btn"
@@ -0,0 +1,63 @@
1
+ <!-- The template to display files available for upload -->
2
+ <script id="template-upload" type="text/x-tmpl">
3
+ {% for (var i=0, file; file=o.files[i]; i++) { %}
4
+ <tr class="template-upload fade">
5
+ <td class="preview"><span class="fade"></span></td>
6
+ <td class="name"><span>{%=file.name%}</span></td>
7
+ <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
8
+ {% if (file.error) { %}
9
+ <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
10
+ {% } else if (o.files.valid && !i) { %}
11
+ <td>
12
+ <div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div>
13
+ </td>
14
+ <td class="start">{% if (!o.options.autoUpload) { %}
15
+ <button class="btn btn-primary">
16
+ <i class="icon-upload icon-white"></i>
17
+ <span>{%=locale.fileupload.start%}</span>
18
+ </button>
19
+ {% } %}</td>
20
+ {% } else { %}
21
+ <td colspan="2"></td>
22
+ {% } %}
23
+ <td class="cancel">{% if (!i) { %}
24
+ <button class="btn btn-warning">
25
+ <i class="icon-ban-circle icon-white"></i>
26
+ <span>{%=locale.fileupload.cancel%}</span>
27
+ </button>
28
+ {% } %}</td>
29
+ </tr>
30
+ {% } %}
31
+ </script>
32
+
33
+
34
+
35
+ <!-- The template to display files available for download -->
36
+ <script id="template-download" type="text/x-tmpl">
37
+ {% for (var i=0, file; file=o.files[i]; i++) { %}
38
+ <tr class="template-download fade">
39
+ {% if (file.error) { %}
40
+ <td></td>
41
+ <td class="name"><span>{%=file.name%}</span></td>
42
+ <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
43
+ <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
44
+ {% } else { %}
45
+ <td class="preview">{% if (file.thumbnail_url) { %}
46
+ <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
47
+ {% } %}</td>
48
+ <td class="name">
49
+ <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
50
+ </td>
51
+ <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
52
+ <td colspan="2"></td>
53
+ {% } %}
54
+ <td class="delete">
55
+ <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
56
+ <i class="icon-trash icon-white"></i>
57
+ <span>{%=locale.fileupload.destroy%}</span>
58
+ </button>
59
+ <input type="checkbox" name="delete" value="1">
60
+ </td>
61
+ </tr>
62
+ {% } %}
63
+ </script>
@@ -0,0 +1,33 @@
1
+ %h2 Selecciona los archivos
2
+ = form_for Archivo.new, :html => { :multipart => true, :id => "fileupload" } do |f|
3
+ / The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload
4
+ .row.fileupload-buttonbar
5
+ .span7
6
+ / The fileinput-button span is used to style the file input field as button
7
+ %span.btn.btn-success.fileinput-button
8
+ %i.icon-plus.icon-white
9
+ %span Add files...
10
+ = f.file_field :file
11
+ %button.btn.btn-primary.start{:type => "submit"}
12
+ %i.icon-upload.icon-white
13
+ %span Start upload
14
+ %button.btn.btn-warning.cancel{:type => "reset"}
15
+ %i.icon-ban-circle.icon-white
16
+ %span Cancel upload
17
+ %button.btn.btn-danger.delete{:type => "button"}
18
+ %i.icon-trash.icon-white
19
+ %span Delete
20
+ %input.toggle{:type => "checkbox"}
21
+ .span5
22
+ / The global progress bar
23
+ .progress.progress-success.progress-striped.active.fade
24
+ .bar{:style => "width:0%;"}
25
+ / The loading indicator is shown during image processing
26
+ .fileupload-loading
27
+ %br
28
+ / The table listing the files available for upload/download
29
+ %table.table.table-striped
30
+ %tbody.files{"data-target" => "#modal-gallery", "data-toggle" => "modal-gallery"}
31
+ = render :partial => "layouts/script_template"
32
+
33
+
@@ -0,0 +1,27 @@
1
+ class Image < ActiveRecord::Base
2
+ attr_accessible :object, :picture
3
+
4
+ belongs_to :user
5
+ belongs_to :object, :polymorphic => true
6
+
7
+
8
+ has_attached_file :picture, :styles => {
9
+ :square=> "170x170#",
10
+ :rectangle=> "220x170#",
11
+ :large => "640x390#" },
12
+ #:default_url => "/images/:style/missing.png"
13
+ :storage => :s3,
14
+ :s3_credentials => "#{Rails.root}/config/s3.yml",
15
+ :path => "/:style/:id/:filename",
16
+ :bucket => lambda { |attachment| "#{attachment.instance.object_type.to_s.downcase}-images" },
17
+ :s3_protocol => 'https'
18
+
19
+
20
+ validates_attachment_presence :picture
21
+ validates_attachment_size :picture, :less_than => 5.megabytes, :message => 'Solo se permite archivo menor a 5 MB'
22
+ validates_attachment_content_type :picture, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/pjpeg', 'image/x-png']
23
+
24
+ validates :object_type, :presence => true
25
+
26
+
27
+ end
@@ -0,0 +1,19 @@
1
+ class MediaIncludeCreateMedia < ActiveRecord::Migration
2
+ def change
3
+ create_table :images do |t|
4
+ t.attachment :picture
5
+ t.string :description
6
+ t.references :object, :polymorphic => true
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ create_table :videos do |t|
12
+ t.attachment :video
13
+ t.string :url
14
+ t.string :description
15
+ t.references :object, :polymorphic => true
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ development:
2
+ access_key_id:
3
+ secret_access_key:
4
+ test:
5
+ access_key_id:
6
+ secret_access_key:
7
+ production:
8
+ access_key_id:
9
+ secret_access_key:
@@ -0,0 +1,5 @@
1
+ class Video < ActiveRecord::Base
2
+ attr_accessible :object, :video, :url
3
+ belongs_to :object, :polymorphic => true
4
+ # attr_accessible :title, :body
5
+ end
@@ -0,0 +1,22 @@
1
+ require "media_include/version"
2
+ require 'media_include/railtie' ##Esential!
3
+ module MediaInclude
4
+ require "rails"
5
+ # Your code goes here...
6
+ def accept_images
7
+ has_many :images, :as => :object
8
+ accepts_nested_attributes_for :images, :reject_if => proc { |attributes| attributes['picture'].blank? }, :allow_destroy => true
9
+ attr_accessible :images_attributes if Rails.version.to_i < 4
10
+ end
11
+
12
+ def accept_videos
13
+ has_many :videos, :as => :object
14
+ accepts_nested_attributes_for :videos, :allow_destroy => true
15
+ attr_accessible :videos_attributes if Rails.version.to_i < 4
16
+ end
17
+
18
+ def accept_images_and_videos
19
+ accept_images
20
+ accept_videos
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ module MediaInclude
2
+ ##Extends de module after active record loads
3
+ class Railtie < Rails::Railtie
4
+ ActiveSupport.on_load(:active_record) do
5
+ ActiveRecord::Base.send :extend, MediaInclude
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module MediaInclude
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'media_include/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "media_include"
8
+ gem.version = MediaInclude::VERSION
9
+ gem.platform = Gem::Platform::RUBY
10
+ gem.authors = ["Erick Garcia"]
11
+ gem.email = ["erick_8911@hotmail.com "]
12
+ gem.description = %q{includes images and videos to models alfa}
13
+ gem.summary = %q{includes images and videos to models}
14
+ gem.homepage = ""
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: media_include
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Erick Garcia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: includes images and videos to models alfa
14
+ email:
15
+ - 'erick_8911@hotmail.com '
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - .project
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/generators/media_include/install_generator.rb
27
+ - lib/generators/media_include/templates/_load_images.html.haml
28
+ - lib/generators/media_include/templates/_script_template.html.erb
29
+ - lib/generators/media_include/templates/_uploads.html.haml
30
+ - lib/generators/media_include/templates/image.rb
31
+ - lib/generators/media_include/templates/migration.rb
32
+ - lib/generators/media_include/templates/s3.yml
33
+ - lib/generators/media_include/templates/video.rb
34
+ - lib/media_include.rb
35
+ - lib/media_include/railtie.rb
36
+ - lib/media_include/version.rb
37
+ - media_include.gemspec
38
+ homepage: ''
39
+ licenses: []
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.0.5
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: includes images and videos to models
61
+ test_files: []