-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgix.rb
42 lines (34 loc) · 929 Bytes
/
imgix.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'erb'
require 'imgix/version'
require 'imgix/style'
require 'imgix/attachment'
require 'imgix/attachment_options'
require 'imgix/instance_methods'
require 'imgix/view_helpers/imgix_tag'
module Imgix
def self.options
@options ||= {
:protocol => "https",
:base_url => "imgix.net"
}
end
module ClassMethods
def has_imgix_attachment(name, options = {})
include InstanceMethods
class_attribute :options
self.options = options
define_method(name) do |*args|
a = attachment_for(name)
(args.length > 0) ? a.to_s(args.first) : a
end
define_method "#{name}=" do |file|
attachment_for(name).assign(file)
end
define_method "#{name}?" do
attachment_for(name).file?
end
end
end
end
ActiveRecord::Base.send(:extend, Imgix::ClassMethods)
ActionView::Base.send(:include, Imgix::ViewHelpers)