carrierwave-filepickerio 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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ .rvmrc
4
+ Gemfile.lock
5
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in carrierwave-filepickerio.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Adam Burmister
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ carrierwave-filepickerio
2
+ ========================
3
+
4
+ FilePicker.io support for CarrierWave.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Install the latest stable release:
10
+
11
+ gem install carrierwave-filepickerio
12
+
13
+ In Rails, add it to your Gemfile:
14
+
15
+ gem 'carrierwave-filepickerio'
16
+
17
+ Configuration
18
+ -------------
19
+
20
+ Add your FilePicker.io API key to the CarrierWave initializer:
21
+
22
+ CarrierWave.configure do |config|
23
+ # ... add the following
24
+ config.filepickerio_api_key = '[Your API key]'
25
+ end
26
+
27
+ Usage
28
+ -----
29
+
30
+ After setting up your CarrierWave uploader as per normal (see the CarrierWave site for more information) you need to configure your page to use the Filepicker.io widget.
31
+
32
+ First of all, include the filepicker.io JavaScript library in your page (such as your application.html.erb layout):
33
+
34
+ ```erb
35
+ <%= javascript_include_tag "//api.filepicker.io/v0/filepicker.js" %>
36
+ ```
37
+
38
+ ... or, if you're not using the asset pipeline, you can use the expansion:
39
+
40
+ ```erb
41
+ <%= javascript_include_tag :filepickerio %>
42
+ ```
43
+
44
+ Form Builders
45
+ -------------
46
+
47
+ To use the FilePicker.io uploader you need to call the view helper like so:
48
+
49
+ ```erb
50
+ <%= form_for @entry do |f| %>
51
+ <%= f.fp_file_field :image %>
52
+ <%= f.fp_save_button :image, "Save existing image to cloud", 'image/jpeg' %>
53
+ <%- end %>
54
+ ```
55
+
56
+ You can change the button text by passing along a string as the first parameter
57
+
58
+ ```erb
59
+ <%= f.fp_file_field :image, "Pick a picture" %>
60
+ ```
61
+
62
+ To include a drag-n-drop area pass the dragdrop parameter in the options hash, which is the last parameter.
63
+
64
+ ```erb
65
+ <%= f.fp_file_field :image, "Pick a picture", dragdrop: true %>
66
+ ```
67
+
68
+ You can also attach any other events to the input as normal, for instance you can listen to change events:
69
+
70
+ ```erb
71
+ <%= f.fp_file_field :image, "Pick a picture", dragdrop: true, onchange: '$("#pic").attr("src", arguments[0].files[0].url)' %>
72
+ ```
73
+
74
+ Specify any Filepicker.io additional data options in the data hash
75
+
76
+ ```erb
77
+ <%= f.fp_file_field :image, "Pick a picture", data: { 'fp-mimetypes' => 'image/jpeg,image/png' } %>
78
+ ```
79
+
80
+ You may include any of the additional parameters...
81
+
82
+ Additional Options
83
+ ------------------
84
+
85
+ Any additional Filepicker.io configuration can be passed within an optional data hash passed to the view helper method.
86
+
87
+ ```erb
88
+ <%= f.fp_file_field :image, data: { "fp-button-text" => "Pick a lolcat to upload" } %>
89
+ ```
90
+
91
+ See [https://developers.filepicker.io/docs/web/](https://developers.filepicker.io/docs/web/) for a full list of configuration options.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "carrierwave-filepickerio/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "carrierwave-filepickerio"
7
+ s.version = CarrierWave::Filepickerio::VERSION
8
+ s.authors = ["Adam Burmister"]
9
+ s.email = ["adam.burmister@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{FilePicker.io support for CarrierWave}
12
+ s.description = %q{Upload files to your ruby web application using the FilePicker.io client-side JS libraries, picking files from not only the local file system, but also online services such as Facebook, Dropbox, Gmail, Flickr, and many more.}
13
+
14
+ s.rubyforge_project = "carrierwave-filepickerio"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.files.reject! { |fn| fn.include? "example" } # don't include our example rails project which is just for testing
18
+
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ # specify any dependencies here; for example:
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "rails"
26
+ s.add_dependency "filepickerio_rails", "~> 0.0.2"
27
+ s.add_dependency "carrierwave"
28
+ end
@@ -0,0 +1,32 @@
1
+ module CarrierWave
2
+ module Filepickerio
3
+ class ::ActionView::Helpers::FormBuilder
4
+
5
+ # Returns a input tag tailored for a Filepicker.io upload widget to be attached for the form object
6
+ def fp_file_field(method, text=nil, options={})
7
+ method = "remote_#{method.to_s}_url".to_sym if !method.to_s.ends_with?('_url')
8
+ @template.fp_file_field(@object_name, method, text, options)
9
+ end
10
+
11
+ def fp_save_button(method, text, mime, options={}, &block)
12
+ method = "#{method.to_s}_url".to_sym if !method.to_s.ends_with?('_url')
13
+ options[:type]='button'
14
+
15
+ # The URL value being used is not absolute, which is required by filepicker.io. So pull out the value
16
+ # from the object now, and make it full relative to the current asset host
17
+ value = options.fetch(:value){ ::ActionView::Helpers::InstanceTag::value_before_type_cast(@object, method.to_s) }
18
+ value &&= ERB::Util.html_escape(value)
19
+
20
+ options[:value] = @template.asset_path(value)
21
+
22
+ # If no asset host is set create a full url form the request
23
+ if !(options[:value].starts_with?('http://') || options[:value].starts_with?('https://'))
24
+ options[:value] = @template.instance_eval "request.protocol + request.host_with_port + asset_path(value)"
25
+ end
26
+
27
+ @template.fp_save_button(@object, method, text, mime, options, &block)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Filepickerio
5
+ class Railtie < Rails::Railtie
6
+
7
+ # Lazy load the form builder with action_view
8
+ initializer 'carrierwave-filepickerio.action_view' do
9
+ ActiveSupport.on_load :action_view do
10
+ require 'carrierwave-filepickerio/form_builder'
11
+ end
12
+ end
13
+
14
+ config.after_initialize do
15
+ FilepickerioRails.configure do |config|
16
+ config.api_key = CarrierWave::Uploader::Base.filepickerio_api_key
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Filepickerio
5
+ module Uploader
6
+ module Configuration
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ add_config :filepickerio_api_key
11
+ reset_direct_config
12
+ end
13
+
14
+ module ClassMethods
15
+ def reset_direct_config
16
+ configure do |config|
17
+ config.filepickerio_api_key = nil
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Filepickerio
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'carrierwave-filepickerio/version'
4
+
5
+ require 'carrierwave'
6
+ require 'filepickerio_rails'
7
+ require 'carrierwave-filepickerio/railtie' if defined?(Rails)
8
+
9
+ module CarrierWave
10
+ module Filepickerio
11
+ module Uploader
12
+ # Add our filepickerio_api_key property to the CarrierWave configuration
13
+ autoload :Configuration, 'carrierwave-filepickerio/uploader/configuration'
14
+ CarrierWave::Uploader::Base.send(:include, Configuration)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe CarrierWave::Filepickerio::FormBuilder do
6
+ describe "#filepickerio_field" do
7
+
8
+ let :user do
9
+ mock_model("User", login: "Username", avatar: nil)
10
+ end
11
+
12
+ context "javascripts" do
13
+ it "should expand :filepickerio to the filepicker.io JS URL" do
14
+ javascript_include_tag(:filepickerio).should == ''
15
+ end
16
+ end
17
+
18
+ context "form field" do
19
+ let :template do
20
+ <<-EOTEMPLATE
21
+ <%= form_for(user) do |f| %>
22
+ <%= f.filepickerio_field(:avatar) %>
23
+ <%- end -%>
24
+ EOTEMPLATE
25
+ end
26
+
27
+ it "should render successfuly" do
28
+ render(inline: template, locals: { user: user })
29
+ rendered.should_not be_nil
30
+ end
31
+
32
+ it "should have a type of filepickerio" do
33
+ render(inline: template, locals: { user: user })
34
+ rendered.should have_xpath('//input[@type="filepicker"]')
35
+ end
36
+
37
+ it "should have the API key as a data property data-fp-apikey" do
38
+ render(inline: template, locals: { user: user })
39
+ rendered.should have_xpath("//input[@data-fp-apikey='#{test_api_key}']")
40
+ end
41
+
42
+ describe "with dragdrop:true" do
43
+ let :template do
44
+ <<-EOTEMPLATE
45
+ <%= form_for(user) do |f| %>
46
+ <%= f.filepickerio_field(:avatar, dragdrop: true) %>
47
+ <%- end -%>
48
+ EOTEMPLATE
49
+ end
50
+
51
+ it "should render the type as `filepicker-dragdrop`" do
52
+ render(inline: template, locals: { user: user })
53
+ rendered.should have_xpath('//input[@type="filepicker-dragdrop"]')
54
+ end
55
+ end
56
+
57
+ describe "with optional data params" do
58
+ let :template do
59
+ <<-EOTEMPLATE
60
+ <%= form_for(user) do |f| %>
61
+ <%= f.filepickerio_field(:avatar, data: { "data-fp-apikey" => "987654321", "data-fp-class" => "myCssClass", "data-fp-button-text" => "UploadFu" }) %>
62
+ <%- end -%>
63
+ EOTEMPLATE
64
+ end
65
+
66
+ it "should render any passed Filepicker.io configuration data options" do
67
+ render(inline: template, locals: { user: user })
68
+ rendered.should have_xpath('//input[@data-fp-class="myCssClass"]')
69
+ rendered.should have_xpath('//input[@data-fp-button-text="UploadFu"]')
70
+ end
71
+
72
+ it "should override the API key outputted if passed" do
73
+ render(inline: template, locals: { user: user })
74
+ rendered.should have_xpath('//input[@data-fp-apikey="987654321"]')
75
+ end
76
+ end
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'carrierwave-filepickerio'
4
+
5
+ #TODO Require classes to support tests
6
+
7
+ Dir[ File.dirname(__FILE__) << "/support/**/*.rb"].each {|file| require file }
8
+
9
+ # This file was generated by the `rspec --init` command. Conventionally, all
10
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
11
+ # Require this file using `require "spec_helper"` to ensure that it is only
12
+ # loaded once.
13
+ #
14
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
15
+ RSpec.configure do |config|
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+
20
+ config.order = 'random'
21
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ # Setup CarrierWave ready for testing with the API key
4
+ CarrierWave.configure do |config|
5
+ config.filepickerio_api_key = "TESTAPIKEY"
6
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'action_view'
4
+ require 'action_view/template'
5
+
6
+ require 'carrierwave-filepickerio/form_builder'
7
+
8
+ module FormBuilderHelpers
9
+ include ActionView::Helpers::FormHelper
10
+ include ActionView::Context
11
+ include ActionController::RecordIdentifier
12
+
13
+ def protect_against_forgery?
14
+ false
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-filepickerio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Burmister
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70292672181200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70292672181200
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70292672180400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70292672180400
36
+ - !ruby/object:Gem::Dependency
37
+ name: filepickerio_rails
38
+ requirement: &70292672114120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.2
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70292672114120
47
+ - !ruby/object:Gem::Dependency
48
+ name: carrierwave
49
+ requirement: &70292672112100 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70292672112100
58
+ description: Upload files to your ruby web application using the FilePicker.io client-side
59
+ JS libraries, picking files from not only the local file system, but also online
60
+ services such as Facebook, Dropbox, Gmail, Flickr, and many more.
61
+ email:
62
+ - adam.burmister@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - .rspec
69
+ - Gemfile
70
+ - LICENSE
71
+ - README.md
72
+ - Rakefile
73
+ - carrierwave-filepickerio.gemspec
74
+ - lib/carrierwave-filepickerio.rb
75
+ - lib/carrierwave-filepickerio/form_builder.rb
76
+ - lib/carrierwave-filepickerio/railtie.rb
77
+ - lib/carrierwave-filepickerio/uploader/configuration.rb
78
+ - lib/carrierwave-filepickerio/version.rb
79
+ - spec/form_builder_spec.rb
80
+ - spec/spec_helper.rb
81
+ - spec/support/carrierwave_config.rb
82
+ - spec/support/form_builder_helpers.rb
83
+ homepage: ''
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ segments:
96
+ - 0
97
+ hash: -514538051003963035
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: -514538051003963035
107
+ requirements: []
108
+ rubyforge_project: carrierwave-filepickerio
109
+ rubygems_version: 1.8.15
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: FilePicker.io support for CarrierWave
113
+ test_files:
114
+ - spec/form_builder_spec.rb
115
+ - spec/spec_helper.rb
116
+ - spec/support/carrierwave_config.rb
117
+ - spec/support/form_builder_helpers.rb