dragonfly-styles 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
File without changes
@@ -0,0 +1,4 @@
1
+ require 'dragonfly'
2
+ require File.dirname(__FILE__) + '/dragonfly/app'
3
+ require File.dirname(__FILE__) + '/dragonfly/active_record_extensions/attachment'
4
+ require File.dirname(__FILE__) + '/dragonfly/active_record_extensions/class_methods'
@@ -0,0 +1,29 @@
1
+ module Dragonfly
2
+ module ActiveModelExtensions
3
+ class Attachment
4
+ class InvaidGeometryOrStyleNameError < StandardError; end
5
+
6
+ def style style_name_or_geometry, format=nil
7
+ scope = case style_name_or_geometry
8
+ when Symbol # style_name => :small_rectangle
9
+ style current_styles[style_name_or_geometry], format
10
+ when String # geometry => '100x80'
11
+ job.thumb style_name_or_geometry
12
+ when Array # geometry + format => ['100x80', :gif]
13
+ style *style_name_or_geometry
14
+ when Proc # Proc for style => lambda { thumb('100x80').process(:greyscale).encode(:png) }
15
+ job.instance_eval &style_name_or_geometry
16
+ else
17
+ raise InvaidGeometryOrStyleNameError
18
+ end
19
+ scope = scope.encode(format) if format
20
+ scope
21
+ end
22
+
23
+ def current_styles
24
+ parent_model.class.dragonfly_styles_for_attributes[attribute_name.to_sym] || {}
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ module Dragonfly
2
+ module ActiveModelExtensions
3
+ module ClassMethods
4
+ def register_dragonfly_styles macro_name, app
5
+ (class << self; self; end).class_eval do
6
+ # Defines e.g. 'image_styles' for any activerecord class body
7
+ define_method macro_name do |attribute, styles|
8
+ # Register the new styles
9
+ dragonfly_styles_for_attributes[attribute] = styles
10
+ end
11
+ end
12
+ app
13
+ end
14
+
15
+ def dragonfly_styles_for_attributes
16
+ @dragonfly_styles_for_attributes ||= begin
17
+ parent_class = ancestors.select{|a| a.is_a?(Class) }[1]
18
+ parent_class.respond_to?(:dragonfly_styles_for_attributes) ? parent_class.dragonfly_styles_for_attributes.dup : {}
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ module Dragonfly
2
+ class App
3
+ def define_styles_macro mod, macro_name
4
+ already_extended = (class << mod; self; end).included_modules.include?(ActiveModelExtensions)
5
+ mod.extend(ActiveModelExtensions) unless already_extended
6
+ mod.register_dragonfly_styles(macro_name, self)
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dragonfly-styles
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 8
8
+ - 1
9
+ version: 0.8.1
10
+ platform: ruby
11
+ authors:
12
+ - Alex Neill
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-25 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: dragonfly
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description:
34
+ email: alex@rawnet.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README
41
+ files:
42
+ - lib/dragonfly-styles.rb
43
+ - lib/dragonfly/active_record_extensions/attachment.rb
44
+ - lib/dragonfly/active_record_extensions/class_methods.rb
45
+ - lib/dragonfly/app.rb
46
+ - README
47
+ has_rdoc: true
48
+ homepage: http://github.com/ajn/dragonfly-styles
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Extends Dragonfly to allow for paperclip-like style definitions.
79
+ test_files: []
80
+