filepicker-rails 0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NWZhNzRjMzBjODI1OWM0ODUyYzFkZGI5OTRmOTU3MmY2YmYyZmJmNA==
5
- data.tar.gz: !binary |-
6
- NzY3MDZiNWE0NzA1Y2Y4NGI2OGM4YTkwMDIzN2QyZTJiNGQwNTE4YQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- Zjg2ZTFlZjc5MjJjYWM5YWFhNzZlNTMzZTBhYWM2NTFjMjY3OTJlNTc3ODYy
10
- NDc0NjVkNjA4MjUwNWI0MDc5MWQzMzRjZGY4ODRlYzMzY2IyZmFiODY1ZjM3
11
- NmI3YTIxZmFmMDlmN2YwYjk5YWZlNTNmMDdlNDlmOTA4ODE4OTY=
12
- data.tar.gz: !binary |-
13
- Y2NiZWQwN2IwNjEzOGMwYzk0MmVjNjk1MTk3YmY5ZjQ5NGM1ODUxNGE3Nzgw
14
- NDM4YTlhMDc0NDEzMWU4ZjU1Y2Q4ZDdiNTA0Yzg1YzM3NjkxMjc0NGRlMTkz
15
- NWNhZTU1NzkzOWNkNzhhNjczZDdmMmUwOTUyOGM2NjViMjQ0Mjg=
2
+ SHA1:
3
+ metadata.gz: 979f8cfcf39dc753cf3ce5c4894c41e22f4f3e8e
4
+ data.tar.gz: 58f4a611ca888ae433e3ccc0053e75797b52a22d
5
+ SHA512:
6
+ metadata.gz: af2f3c5751a991c5f92f4e7f1351b1ea98dabde485dd4eae557f9a1ea1bfabf4039bfba84cea899eef3627bbf2ef93b89be8e81da1c9cc9a22e29937b0148d12
7
+ data.tar.gz: c4cc2ebe154f5c6fef316fd3a115c5c08d0ebd7c67842ebe0a80c5e370c0992ef5e087c49decc459ed79ac15f1e8cc33d1581e31f4f447bbec80cc4641a5568c
@@ -1,6 +1,4 @@
1
- Copyright (c) 2012 Max Tilford
2
-
3
- MIT License
1
+ Copyright 2013 YOURNAME
4
2
 
5
3
  Permission is hereby granted, free of charge, to any person obtaining
6
4
  a copy of this software and associated documentation files (the
@@ -19,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
19
  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.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # Filepicker::Rails
2
+ [![RubyGems][gem_version_badge]][ruby_gems]
3
+ [![Travis CI][travis_ci_badge]][travis_ci]
4
+ [![Coveralls][coveralls_badge]][coveralls]
5
+ [![Code Climate][code_climate_badge]][code_climate]
2
6
 
3
7
  Adds form, image_tag, and download/save helpers to help you get up and running with [filepicker.io](http://filepicker.io) in Rails.
4
8
 
@@ -67,11 +71,15 @@ Full options list:
67
71
 
68
72
  * button_text - The text of the upload button.
69
73
  * button_class - The class of the upload button.
74
+ * extensions - The extensions of file types you want to support for this upload. Ex: ".png,.jpg".
70
75
  * mimetypes - The file types you want to support for this upload. Ex: "image/png,text/*".
71
76
  * container - Where to show the file picker dialog can be "modal", "window" or the
72
77
  of an iframe on the page.
73
78
  * multiple - (true or false) Whether or not multiple uploads can be saved at once.
74
79
  * services - What services your users can upload to. Ex: "BOX, COMPUTER, FACEBOOK".
80
+ * store_path - The path to store the file at within the specified file store.
81
+ * store_location - The file is not copied by default. It remains in the original location. If you wish you have the file copied onto your own storage, you can specify where we should put the copy. The only value at the moment is "S3".
82
+ * store_access - Should the underlying file be publicly available on its S3 link. Options are "public" and "private", defaults to 'private'.
75
83
  * dragdrop - (true or false) Whether or not to allow drag-and-drop uploads.
76
84
  * drag_text - The text of the dragdrop pane.
77
85
  * drag_class - The class of the dragdrop pane.
@@ -125,3 +133,29 @@ of an iframe on the page.
125
133
  ### Demo
126
134
 
127
135
  See a simple demo app [repo](https://github.com/maxtilford/filepicker-rails-demo)
136
+
137
+ ## Versioning
138
+
139
+ Filepicker::Rails follow the [Semantic Versioning](http://semver.org/).
140
+
141
+ ## Issues
142
+
143
+ If you have problems, please create a [Github Issue](https://github.com/Ink/filepicker-rails/issues).
144
+
145
+ ## Contributing
146
+
147
+ Please see [CONTRIBUTING.md](https://github.com/Ink/filepicker-rails/blob/master/CONTRIBUTING.md) for details.
148
+
149
+ ## Credits
150
+
151
+ Thank you to all the [contributors](https://github.com/Ink/filepicker-rails/graphs/contributors).
152
+
153
+ [gem_version_badge]: https://badge.fury.io/rb/filepicker-rails.png
154
+ [ruby_gems]: http://rubygems.org/gems/filepicker-rails
155
+ [travis_ci]: http://travis-ci.org/Ink/filepicker-rails
156
+ [travis_ci_badge]: https://secure.travis-ci.org/Ink/filepicker-rails.png
157
+ [code_climate]: https://codeclimate.com/github/Ink/filepicker-rails
158
+ [code_climate_badge]: https://codeclimate.com/github/Ink/filepicker-rails.png
159
+ [coveralls]: https://coveralls.io/r/Ink/filepicker-rails
160
+ [coveralls_badge]: https://coveralls.io/repos/Ink/filepicker-rails/badge.png?branch=master
161
+
data/Rakefile CHANGED
@@ -1,2 +1,25 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'FilepickerRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ require "rspec/core/rake_task"
21
+ RSpec::Core::RakeTask.new
22
+ task :default => [:spec]
23
+
24
+ Bundler::GemHelper.install_tasks
25
+
@@ -0,0 +1,76 @@
1
+ module FilepickerRails
2
+ module ApplicationHelper
3
+
4
+ def filepicker_js_include_tag
5
+ javascript_include_tag "//api.filepicker.io/v1/filepicker.js"
6
+ end
7
+
8
+ def filepicker_save_button(text, url, mimetype, options = {})
9
+ options[:data] ||= {}
10
+ container = options.delete(:container)
11
+ services = options.delete(:services)
12
+ save_as = options.delete(:save_as_name)
13
+
14
+ options[:data]['fp-url'] = url
15
+ options[:data]['fp-apikey'] = ::Rails.application.config.filepicker_rails.api_key
16
+ options[:data]['fp-mimetype'] = mimetype
17
+ options[:data]['fp-option-container'] = container if container
18
+ options[:data]['fp-option-services'] = Array(services).join(",") if services
19
+ options[:data]['fp-option-defaultSaveasName'] = save_as if save_as
20
+ button_tag(text, options)
21
+ end
22
+
23
+ # Allows options to be passed to filepicker_image_url and then falls back to normal Rails options
24
+ # for image_tag
25
+ # If specifying html width, height, pass it down to filepicker for optimization
26
+ def filepicker_image_tag(url, image_options={}, image_tag_options={})
27
+ image_tag(filepicker_image_url(url, image_options), image_tag_options)
28
+ end
29
+
30
+ # w - Resize the image to this width.
31
+ #
32
+ # h - Resize the image to this height.
33
+ #
34
+ # fit - Specifies how to resize the image. Possible values are:
35
+ # clip: Resizes the image to fit within the specified parameters without
36
+ # distorting, cropping, or changing the aspect ratio
37
+ # crop: Resizes the image to fit the specified parameters exactly by
38
+ # removing any parts of the image that don't fit within the boundaries
39
+ # scales: Resizes the image to fit the specified parameters exactly by
40
+ # scaling the image to the desired size
41
+ # Defaults to "clip".
42
+ # align - Determines how the image is aligned when resizing and using the "fit" parameter.
43
+ # Check API for details.
44
+ #
45
+ # cache - Specifies if the image should be cached or not.
46
+ #
47
+ # crop - Crops the image to a specified rectangle. The input to this parameter
48
+ # should be 4 numbers for 'x,y,width,height' - for example,
49
+ # 'crop=10,20,200,250' would select the 200x250 pixel rectangle starting
50
+ # from 10 pixels from the left edge and 20 pixels from the top edge of the
51
+ # image.
52
+ #
53
+ # format - Specifies what format the image should be converted to, if any.
54
+ # Possible values are "jpg" and "png". For "jpg" conversions, you
55
+ # can additionally specify a quality parameter.
56
+ #
57
+ # quality - For jpeg conversion, specifies the quality of the resultant image.
58
+ # Quality should be an integer between 1 and 100
59
+ #
60
+ # watermark - Adds the specified absolute url as a watermark on the image.
61
+ #
62
+ # watersize - This size of the watermark, as a percentage of the base
63
+ # image (not the original watermark).
64
+ #
65
+ # waterposition - Where to put the watermark relative to the base image.
66
+ # Possible values for vertical position are "top","middle",
67
+ # "bottom" and "left","center","right", for horizontal
68
+ # position. The two can be combined by separating vertical
69
+ # and horizontal with a comma. The default behavior
70
+ # is bottom,right
71
+ def filepicker_image_url(url, options = {})
72
+ query_params = options.slice(:w, :h, :fit, :align, :cache, :crop, :format, :quality, :watermark, :watersize, :waterposition).to_query
73
+ [url, "/convert?", query_params].join
74
+ end
75
+ end
76
+ end
@@ -1,36 +1,38 @@
1
- module Filepicker
2
- module Rails
3
- module FormBuilder
4
-
5
- def filepicker_field(method, options = {})
6
- type = options.delete(:dragdrop) ? 'filepicker-dragdrop' : 'filepicker'
7
-
8
- input_options = retrive_legacy_filepicker_options(options)
9
- input_options['data-fp-apikey'] ||= ::Rails.application.config.filepicker_rails.api_key
10
- input_options.merge!(secure_filepicker) unless input_options['data-fp-policy'].present?
11
-
12
- input_options['type'] = type
13
-
14
- if ::Rails.version.to_i >= 4
15
- ActionView::Helpers::Tags::TextField.new(@object_name, method, @template).tag('input', input_options)
16
- else
17
- ActionView::Helpers::InstanceTag.new(@object_name, method, @template).to_input_field_tag(type, input_options)
18
- end
1
+ module FilepickerRails
2
+ module FormHelper
3
+
4
+ def filepicker_field(method, options = {})
5
+ type = options.delete(:dragdrop) ? 'filepicker-dragdrop' : 'filepicker'
6
+
7
+ input_options = retrive_legacy_filepicker_options(options)
8
+ input_options['data-fp-apikey'] ||= ::Rails.application.config.filepicker_rails.api_key
9
+ input_options.merge!(secure_filepicker) unless input_options['data-fp-policy'].present?
10
+ input_options['type'] = type
11
+
12
+ if ::Rails.version.to_i >= 4
13
+ tag = ActionView::Helpers::Tags::TextField.new(@object_name, method, @template, objectify_options(input_options))
14
+ tag.send(:add_default_name_and_id, input_options)
15
+ tag.render
16
+ else
17
+ ActionView::Helpers::InstanceTag.new(@object_name, method, @template).to_input_field_tag(type, input_options)
19
18
  end
19
+ end
20
20
 
21
- private
21
+ private
22
22
 
23
23
  def retrive_legacy_filepicker_options(options)
24
24
  mappings = {
25
25
  :button_text => 'data-fp-button-text',
26
26
  :button_class => 'data-fp-button-class',
27
27
  :mimetypes => 'data-fp-mimetypes',
28
+ :extensions => 'data-fp-extensions',
28
29
  :container => 'data-fp-container',
29
30
  :services => 'data-fp-services',
30
31
  :drag_text => 'data-fp-drag-text',
31
32
  :drag_class => 'data-fp-drag-class',
32
33
  :store_path => 'data-fp-store-path',
33
34
  :store_location => 'data-fp-store-location',
35
+ :store_access => 'data-fp-store-access',
34
36
  :multiple => 'data-fp-multiple',
35
37
  :onchange => 'onchange',
36
38
  :class => 'class',
@@ -50,6 +52,5 @@ module Filepicker
50
52
  'data-fp-signature' => grant.signature
51
53
  }
52
54
  end
53
- end
54
55
  end
55
56
  end
@@ -1,11 +1,6 @@
1
- require "filepicker/rails/version"
2
- require "filepicker/rails/configuration"
3
- require "filepicker/rails/policy"
4
- require "filepicker/rails/form_builder"
5
- require "filepicker/rails/view_helpers"
6
- require "filepicker/rails/railtie"
1
+ require "filepicker_rails/configuration"
2
+ require "filepicker_rails/policy"
3
+ require "filepicker_rails/engine"
7
4
 
8
- module Filepicker
9
- module Rails
10
- end
5
+ module FilepickerRails
11
6
  end
@@ -0,0 +1,17 @@
1
+ module FilepickerRails
2
+ class Configuration
3
+ attr_writer :api_key, :secret_key, :default_expiry
4
+
5
+ def api_key
6
+ @api_key or raise "Set config.filepicker_rails.api_key"
7
+ end
8
+
9
+ def secret_key
10
+ @secret_key
11
+ end
12
+
13
+ def default_expiry
14
+ @default_expiry ||= 600
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module FilepickerRails
2
+ class Engine < ::Rails::Engine
3
+ config.filepicker_rails = FilepickerRails::Configuration.new
4
+ isolate_namespace FilepickerRails
5
+
6
+ initializer "filepicker_rails.form_builder" do
7
+ ActionView::Helpers::FormBuilder.send(:include, FilepickerRails::FormHelper)
8
+ end
9
+
10
+ initializer 'filepicker_rails.action_controller' do |app|
11
+ ActiveSupport.on_load(:action_controller) do
12
+ helper FilepickerRails::ApplicationHelper
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+
4
+ module FilepickerRails
5
+ class Policy
6
+ attr_accessor :expiry, :call, :handle, :maxsize, :minsize, :path
7
+
8
+ def initialize(options = {})
9
+ [:expiry, :call, :handle, :maxsize, :minsize, :path].each do |input|
10
+ send("#{input}=", options[input]) unless options[input].nil?
11
+ end
12
+ end
13
+
14
+ def policy
15
+ Base64.urlsafe_encode64(json_policy)
16
+ end
17
+
18
+ def signature
19
+ OpenSSL::HMAC.hexdigest('sha256', ::Rails.application.config.filepicker_rails.secret_key, policy)
20
+ end
21
+
22
+ private
23
+ def json_policy
24
+ hash = Hash.new
25
+
26
+ @expiry ||= Time.now.to_i + ::Rails.application.config.filepicker_rails.default_expiry
27
+
28
+ [:expiry, :call, :handle, :maxsize, :minsize, :path].each do |input|
29
+ hash[input] = send(input) unless send(input).nil?
30
+ end
31
+
32
+ MultiJson.dump(hash)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module FilepickerRails
2
+ VERSION = "1.0.0"
3
+ end
metadata CHANGED
@@ -1,49 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filepicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Tilford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-15 00:00:00.000000000 Z
11
+ date: 2013-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: railties
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.0
20
- - - <
21
- - !ruby/object:Gem::Version
22
- version: '5.0'
19
+ version: '3.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
28
32
  - !ruby/object:Gem::Version
29
- version: 3.1.0
30
- - - <
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
31
39
  - !ruby/object:Gem::Version
32
- version: '5.0'
40
+ version: '0'
33
41
  - !ruby/object:Gem::Dependency
34
- name: multi_json
42
+ name: sqlite3
35
43
  requirement: !ruby/object:Gem::Requirement
36
44
  requirements:
37
- - - ~>
45
+ - - '>='
38
46
  - !ruby/object:Gem::Version
39
- version: '1.6'
40
- type: :runtime
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
41
63
  prerelease: false
42
64
  version_requirements: !ruby/object:Gem::Requirement
43
65
  requirements:
44
- - - ~>
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: timecop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
45
74
  - !ruby/object:Gem::Version
46
- version: '1.6'
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
47
83
  description: Makes integrating filepicker.io with rails 4 easy
48
84
  email:
49
85
  - maxtilford@gmail.com
@@ -51,20 +87,17 @@ executables: []
51
87
  extensions: []
52
88
  extra_rdoc_files: []
53
89
  files:
54
- - .gitignore
55
- - Gemfile
56
- - LICENSE
57
- - README.md
58
- - Rakefile
59
- - filepicker-rails.gemspec
90
+ - app/helpers/filepicker_rails/application_helper.rb
91
+ - app/helpers/filepicker_rails/form_helper.rb
60
92
  - lib/filepicker-rails.rb
61
- - lib/filepicker/rails/configuration.rb
62
- - lib/filepicker/rails/form_builder.rb
63
- - lib/filepicker/rails/policy.rb
64
- - lib/filepicker/rails/railtie.rb
65
- - lib/filepicker/rails/version.rb
66
- - lib/filepicker/rails/view_helpers.rb
67
- homepage: https://github.com/Filepicker/filepicker-rails
93
+ - lib/filepicker_rails/configuration.rb
94
+ - lib/filepicker_rails/engine.rb
95
+ - lib/filepicker_rails/policy.rb
96
+ - lib/filepicker_rails/version.rb
97
+ - MIT-LICENSE
98
+ - Rakefile
99
+ - README.md
100
+ homepage: https://github.com/Ink/filepicker-rails
68
101
  licenses: []
69
102
  metadata: {}
70
103
  post_install_message:
@@ -73,17 +106,17 @@ require_paths:
73
106
  - lib
74
107
  required_ruby_version: !ruby/object:Gem::Requirement
75
108
  requirements:
76
- - - ! '>='
109
+ - - '>='
77
110
  - !ruby/object:Gem::Version
78
111
  version: '0'
79
112
  required_rubygems_version: !ruby/object:Gem::Requirement
80
113
  requirements:
81
- - - ! '>='
114
+ - - '>='
82
115
  - !ruby/object:Gem::Version
83
- version: 1.3.6
116
+ version: '0'
84
117
  requirements: []
85
118
  rubyforge_project:
86
- rubygems_version: 2.0.3
119
+ rubygems_version: 2.0.5
87
120
  signing_key:
88
121
  specification_version: 4
89
122
  summary: Makes integrating filepicker.io with rails 4 easy
data/.gitignore DELETED
@@ -1,17 +0,0 @@
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
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
@@ -1,20 +0,0 @@
1
- require File.expand_path('../lib/filepicker/rails/version', __FILE__)
2
-
3
- Gem::Specification.new do |gem|
4
- gem.authors = ["Max Tilford"]
5
- gem.email = ["maxtilford@gmail.com"]
6
- gem.description = %q{Makes integrating filepicker.io with rails 4 easy}
7
- gem.summary = %q{Makes integrating filepicker.io with rails 4 easy}
8
- gem.homepage = "https://github.com/Filepicker/filepicker-rails"
9
-
10
- gem.files = `git ls-files`.split($\)
11
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
- gem.name = "filepicker-rails"
14
- gem.require_paths = ["lib"]
15
- gem.version = Filepicker::Rails::VERSION
16
-
17
- gem.required_rubygems_version = ">= 1.3.6"
18
- gem.add_dependency "railties", ">= 3.1.0", "< 5.0"
19
- gem.add_dependency 'multi_json', '~> 1.6'
20
- end
@@ -1,19 +0,0 @@
1
- module Filepicker
2
- module Rails
3
- class Configuration
4
- attr_writer :api_key, :secret_key, :default_expiry
5
-
6
- def api_key
7
- @api_key or raise "Set config.filepicker_rails.api_key"
8
- end
9
-
10
- def secret_key
11
- @secret_key
12
- end
13
-
14
- def default_expiry
15
- @default_expiry ||= 600
16
- end
17
- end
18
- end
19
- end
@@ -1,37 +0,0 @@
1
- require 'base64'
2
- require 'openssl'
3
-
4
- module Filepicker
5
- module Rails
6
- class Policy
7
- attr_accessor :expiry, :call, :handle, :maxsize, :minsize, :path
8
-
9
- def initialize(options = {})
10
- [:expiry, :call, :handle, :maxsize, :minsize, :path].each do |input|
11
- send("#{input}=", options[input]) unless options[input].nil?
12
- end
13
- end
14
-
15
- def policy
16
- Base64.urlsafe_encode64(json_policy)
17
- end
18
-
19
- def signature
20
- OpenSSL::HMAC.hexdigest('sha256', ::Rails.application.config.filepicker_rails.secret_key, policy)
21
- end
22
-
23
- private
24
- def json_policy
25
- hash = Hash.new
26
-
27
- @expiry ||= Time.now.to_i + ::Rails.application.config.filepicker_rails.default_expiry
28
-
29
- [:expiry, :call, :handle, :maxsize, :minsize, :path].each do |input|
30
- hash[input] = send(input) unless send(input).nil?
31
- end
32
-
33
- MultiJson.dump(hash)
34
- end
35
- end
36
- end
37
- end
@@ -1,18 +0,0 @@
1
- module Filepicker
2
- module Rails
3
-
4
- class Railtie < ::Rails::Railtie
5
-
6
- config.filepicker_rails = Filepicker::Rails::Configuration.new
7
-
8
- initializer "filepicker_rails.view_helpers" do
9
- ActionView::Base.send(:include, Filepicker::Rails::ViewHelpers)
10
- end
11
-
12
- initializer "filepicker_rails.form_builder" do
13
- ActionView::Helpers::FormBuilder.send(:include, Filepicker::Rails::FormBuilder)
14
- end
15
- end
16
-
17
- end
18
- end
@@ -1,5 +0,0 @@
1
- module Filepicker
2
- module Rails
3
- VERSION = "0.1"
4
- end
5
- end
@@ -1,75 +0,0 @@
1
- module Filepicker
2
- module Rails
3
-
4
- module ViewHelpers
5
- def filepicker_js_include_tag
6
- javascript_include_tag "//api.filepicker.io/v1/filepicker.js"
7
- end
8
-
9
- def filepicker_save_button(text, url, mimetype, options = {})
10
- options[:data] ||= {}
11
- container = options.delete(:container)
12
- services = options.delete(:services)
13
- save_as = options.delete(:save_as_name)
14
-
15
- options[:data]['fp-url'] = url
16
- options[:data]['fp-apikey'] = ::Rails.application.config.filepicker_rails.api_key
17
- options[:data]['fp-mimetype'] = mimetype
18
- options[:data]['fp-option-container'] = container if container
19
- options[:data]['fp-option-services'] = Array(services).join(",") if services
20
- options[:data]['fp-option-defaultSaveasName'] = save_as if save_as
21
- button_tag(text, options)
22
- end
23
-
24
- # Allows options to be passed to filepicker_image_url and then falls back to normal Rails options for image_tag
25
- # If specifying html width, height, pass it down to filepicker for optimization
26
- def filepicker_image_tag(url, image_options={}, image_tag_options={})
27
- image_tag(filepicker_image_url(url, image_options), image_tag_options)
28
- end
29
-
30
- # w - Resize the image to this width.
31
- #
32
- # h - Resize the image to this height.
33
- #
34
- # fit - Specifies how to resize the image. Possible values are:
35
- # clip: Resizes the image to fit within the specified parameters without
36
- # distorting, cropping, or changing the aspect ratio
37
- # crop: Resizes the image to fit the specified parameters exactly by
38
- # removing any parts of the image that don't fit within the boundaries
39
- # scales: Resizes the image to fit the specified parameters exactly by
40
- # scaling the image to the desired size
41
- # Defaults to "clip".
42
- # align - Determines how the image is aligned when resizing and using the "fit" parameter. Check API for details.
43
- #
44
- # crop - Crops the image to a specified rectangle. The input to this parameter
45
- # should be 4 numbers for 'x,y,width,height' - for example,
46
- # 'crop=10,20,200,250' would select the 200x250 pixel rectangle starting
47
- # from 10 pixels from the left edge and 20 pixels from the top edge of the
48
- # image.
49
- #
50
- # format - Specifies what format the image should be converted to, if any.
51
- # Possible values are "jpg" and "png". For "jpg" conversions, you
52
- # can additionally specify a quality parameter.
53
- #
54
- # quality - For jpeg conversion, specifies the quality of the resultant image.
55
- # Quality should be an integer between 1 and 100
56
- #
57
- # watermark - Adds the specified absolute url as a watermark on the image.
58
- #
59
- # watersize - This size of the watermark, as a percentage of the base
60
- # image (not the original watermark).
61
- #
62
- # waterposition - Where to put the watermark relative to the base image.
63
- # Possible values for vertical position are "top","middle",
64
- # "bottom" and "left","center","right", for horizontal
65
- # position. The two can be combined by separating vertical
66
- # and horizontal with a comma. The default behavior
67
- # is bottom,right
68
- def filepicker_image_url(url, options = {})
69
- query_params = options.slice(:w, :h, :fit, :align, :crop, :format, :quality, :watermark, :watersize, :waterposition).to_query
70
- [url, "/convert?", query_params].join
71
- end
72
-
73
- end
74
- end
75
- end