inkfilepicker-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDMwZGNjNmQ5MmYyNGEyMjU4ODk1NGExZDZhZTQyMmQzNjE3NzkzZQ==
5
+ data.tar.gz: !binary |-
6
+ YmI0YTk5ODNkNDlhODhiZmY2OTg3OTM4NGJmNWRlYmM4NmY2MTU4ZQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZmE3NDQxNjg0YzViMWU0M2JkNGRhNzQ1Mjc2Y2QyZjI2NjE3MGIxOWQ2N2Y2
10
+ NGRhZjFmM2Y5MDQzNTc2OTMxMDdkMzczZTNjNzg1YmIxOTZmZTJkMWNhM2Nh
11
+ M2ViMzM3ZmY2M2U5OGFmODZmMmZkMjM0YjcxYzYzZWZlNGJlZjE=
12
+ data.tar.gz: !binary |-
13
+ MWRlMDNiYTQ0YzZhYzkwYmU3NTg1ZWVhOGUwMTcyMWU5ZWI5N2IwMWJiMTUw
14
+ NmE1ODhlMGFmOGI2ZTkyZWU3MGI1NGRlYWIyMjE2YTdkYzNmOWRmYzcxZDQw
15
+ YzhhZmY3YzY1OTc2ZGU0OGNjODY2M2RkZWE3MmI1YWMwMTE2MDQ=
@@ -0,0 +1,6 @@
1
+ require 'inkfilepicker/version'
2
+ require 'inkfilepicker/inkfilepicker'
3
+ require 'inkfilepicker/policy'
4
+ require 'inkfilepicker/form_builder'
5
+ require 'inkfilepicker/view_helpers'
6
+ require 'inkfilepicker/railtie'
@@ -0,0 +1,54 @@
1
+ module Inkfilepicker
2
+ module FormBuilder
3
+
4
+ def inkfilepicker_field(method, options = {})
5
+ type = options.delete(:dragdrop) ? 'filepicker-dragdrop' : 'filepicker'
6
+
7
+ input_options = retrive_filepicker_options(options)
8
+ input_options['data-fp-apikey'] ||= Inkfilepicker.api_key
9
+ input_options.merge!(secure_filepicker) unless input_options['data-fp-policy'].present?
10
+
11
+ input_options['type'] = type
12
+
13
+ if ::Rails.version.to_i >= 4
14
+ ActionView::Helpers::Tags::TextField.new(@object_name, method, @template).tag('input', input_options)
15
+ else
16
+ ActionView::Helpers::InstanceTag.new(@object_name, method, @template).to_input_field_tag(type, input_options)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def retrive_filepicker_options(options)
23
+ mappings = {
24
+ :button_text => 'data-fp-button-text',
25
+ :button_class => 'data-fp-button-class',
26
+ :mimetypes => 'data-fp-mimetypes',
27
+ :extensions => 'data-fp-extensions',
28
+ :container => 'data-fp-container',
29
+ :services => 'data-fp-services',
30
+ :drag_text => 'data-fp-drag-text',
31
+ :drag_class => 'data-fp-drag-class',
32
+ :store_path => 'data-fp-store-path',
33
+ :store_location => 'data-fp-store-location',
34
+ :multiple => 'data-fp-multiple',
35
+ :onchange => 'onchange',
36
+ :class => 'class',
37
+ :value => 'value'
38
+ }
39
+
40
+ Hash[options.map {|k, v| [mappings[k] || k, v] }]
41
+ end
42
+
43
+ def secure_filepicker
44
+ return {} unless Inkfilepicker.secret_key.present?
45
+ grant = Policy.new
46
+ grant.call = [:pick, :store]
47
+
48
+ {
49
+ 'data-fp-policy' => grant.policy,
50
+ 'data-fp-signature' => grant.signature
51
+ }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,28 @@
1
+ module Inkfilepicker
2
+
3
+ class << self
4
+ attr_accessor :api_key, :secret_key, :api_url, :default_expiry
5
+ end
6
+
7
+ self.api_key = nil
8
+ self.secret_key = nil
9
+ self.api_url = nil
10
+ self.default_expiry = nil
11
+
12
+ def self.api_key
13
+ @api_key || ENV['INKFILEPICKER_API_KEY']
14
+ end
15
+
16
+ def self.secret_key
17
+ @secret_key || ENV['INKFILEPICKER_SECRET_KEY']
18
+ end
19
+
20
+ def self.api_url
21
+ @api_url || '//api.filepicker.io/v1/filepicker.js'
22
+ end
23
+
24
+ def self.default_expiry
25
+ @default_expiry || 600
26
+ end
27
+
28
+ end
@@ -0,0 +1,36 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+
4
+ module Inkfilepicker
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', Inkfilepicker.secret_key, policy)
20
+ end
21
+
22
+ private
23
+ def json_policy
24
+ hash = Hash.new
25
+
26
+ @expiry ||= Time.now.to_i + Inkfilepicker.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
+
36
+ end
@@ -0,0 +1,14 @@
1
+ module Inkfilepicker
2
+
3
+ class Railtie < ::Rails::Railtie
4
+
5
+ initializer "inkfilepicker.view_helpers" do
6
+ ActionView::Base.send(:include, Inkfilepicker::ViewHelpers)
7
+ end
8
+
9
+ initializer "inkfilepicker.form_builder" do
10
+ ActionView::Helpers::FormBuilder.send(:include, Inkfilepicker::FormBuilder)
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,3 @@
1
+ module Inkfilepicker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,76 @@
1
+ module Inkfilepicker
2
+
3
+ module ViewHelpers
4
+ def inkfilepicker_js_include_tag
5
+ javascript_include_tag "#{Inkfilepicker.api_url}"
6
+ end
7
+
8
+ def inkfilepicker_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'] = Inkfilepicker.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 inkfilepicker_image_url and then falls back to normal Rails options for image_tag
24
+ # If specifying html width, height, pass it down to inkfilepicker for optimization
25
+ def inkfilepicker_image_tag(url, image_options={}, image_tag_options={})
26
+ image_tag(inkfilepicker_image_url(url, image_options), image_tag_options)
27
+ end
28
+
29
+ # w - Resize the image to this width.
30
+ #
31
+ # h - Resize the image to this height.
32
+ #
33
+ # fit - Specifies how to resize the image. Possible values are:
34
+ # clip: Resizes the image to fit within the specified parameters without
35
+ # distorting, cropping, or changing the aspect ratio
36
+ # crop: Resizes the image to fit the specified parameters exactly by
37
+ # removing any parts of the image that don't fit within the boundaries
38
+ # scales: Resizes the image to fit the specified parameters exactly by
39
+ # scaling the image to the desired size
40
+ # Defaults to "clip".
41
+ # align - Determines how the image is aligned when resizing and using the "fit" parameter. Check API for details.
42
+ #
43
+ # cache - Specifies if the image should be cached or not.
44
+ #
45
+ # crop - Crops the image to a specified rectangle. The input to this parameter
46
+ # should be 4 numbers for 'x,y,width,height' - for example,
47
+ # 'crop=10,20,200,250' would select the 200x250 pixel rectangle starting
48
+ # from 10 pixels from the left edge and 20 pixels from the top edge of the
49
+ # image.
50
+ #
51
+ # format - Specifies what format the image should be converted to, if any.
52
+ # Possible values are "jpg" and "png". For "jpg" conversions, you
53
+ # can additionally specify a quality parameter.
54
+ #
55
+ # quality - For jpeg conversion, specifies the quality of the resultant image.
56
+ # Quality should be an integer between 1 and 100
57
+ #
58
+ # watermark - Adds the specified absolute url as a watermark on the image.
59
+ #
60
+ # watersize - This size of the watermark, as a percentage of the base
61
+ # image (not the original watermark).
62
+ #
63
+ # waterposition - Where to put the watermark relative to the base image.
64
+ # Possible values for vertical position are "top","middle",
65
+ # "bottom" and "left","center","right", for horizontal
66
+ # position. The two can be combined by separating vertical
67
+ # and horizontal with a comma. The default behavior
68
+ # is bottom,right
69
+ def inkfilepicker_image_url(url, options = {})
70
+ query_params = options.slice(:w, :h, :fit, :align, :cache, :crop, :format, :quality, :watermark, :watersize, :waterposition).to_query
71
+ [url, "/convert?", query_params].join
72
+ end
73
+
74
+ end
75
+
76
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inkfilepicker-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott V. Rosenthal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
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
+ description: Makes integrating inkfilepicker.com api service with rails easy
56
+ email: sr7575@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/inkfilepicker/form_builder.rb
62
+ - lib/inkfilepicker/inkfilepicker.rb
63
+ - lib/inkfilepicker/policy.rb
64
+ - lib/inkfilepicker/railtie.rb
65
+ - lib/inkfilepicker/version.rb
66
+ - lib/inkfilepicker/view_helpers.rb
67
+ - lib/inkfilepicker-rails.rb
68
+ homepage: https://github.com/scottvrosenthal/inkfilepicker-rails
69
+ licenses:
70
+ - MIT
71
+ - GPL-2
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: 1.9.3
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: 1.8.11
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Makes integrating inkfilepicker.com api service with rails easy
93
+ test_files: []