smartthumbs 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -11,19 +11,21 @@ This Gem helps you create any kind of thumbnails on-the-fly.
11
11
 
12
12
  ## Install
13
13
  Add the Gem to your Gemfile:
14
- gem "smartthumbs"
14
+
15
+ gem "smartthumbs"
15
16
 
16
17
  and run
17
- bundle install
18
+
19
+ bundle install
18
20
 
19
21
 
20
22
  Afterwards you should create an initializer-script in config/initializers:
21
23
 
22
- Smartthumbs::Config.run do |config|
23
- config[:valid_classes] = ["Image"]
24
- # optional
25
- config[:assume_klass] = "Image"
26
- end
24
+ Smartthumbs::Config.run do |config|
25
+ config[:valid_classes] = ["Image"]
26
+
27
+ config[:assume_klass] = "Image" # optional
28
+ end
27
29
 
28
30
  Smartthumbs needs to know all classes that you want to use smartthumbs with.
29
31
  Pass them as an array of strings via :valid_classes .
@@ -16,15 +16,24 @@ private
16
16
  def parse_params
17
17
  parsed = params[:path].split(".")[0..-2].first.split("/")
18
18
 
19
- if parsed.length < 3 && Smartthumbs::Config.options[:assume_klass].present?
19
+ if parsed.length < 3 && Smartthumbs::Config.get_option(:assume_klass).present?
20
20
  parsed.unshift(
21
- Smartthumbs::Config.options[:assume_klass]
21
+ Smartthumbs::Config.get_option(:assume_klass)
22
22
  )
23
23
  else
24
24
  parsed[0] = parsed.first.gsub("-", "/").classify
25
25
  end
26
26
 
27
- unless Smartthumbs::Config.options[:valid_classes].include?(parsed[0])
27
+ if Smartthumbs::Config.get_option(:valid_classes).blank?
28
+ msg = <<-INIT_DOC
29
+ Smartthumbs::Config.run do |config|
30
+ config[:valid_classes] = ["Image"]
31
+ end
32
+ INIT_DOC
33
+ raise "You need to define all valid_classes inside of an initializer script:\n\n#{msg}"
34
+ end
35
+
36
+ unless Smartthumbs::Config.get_option(:valid_classes).include?(parsed[0])
28
37
  raise "Bad Request"
29
38
  else
30
39
  parsed[0] = parsed.first.constantize
data/lib/smartthumbs.rb CHANGED
@@ -22,6 +22,11 @@ module Smartthumbs
22
22
  self.options ||= {}
23
23
  yield self.options
24
24
  end
25
+
26
+ def get_option(key)
27
+ self.options ||= {}
28
+ self.options[key]
29
+ end
25
30
  end
26
31
  end
27
32
 
@@ -90,7 +90,7 @@ module Smartthumbs
90
90
  # this one has to be route from which the image is
91
91
  # availabe - otherwise the caching benefit is gone
92
92
  def thumb_url_for(format)
93
- if Smartthumbs::Config.options[:assume_klass] == self.class.to_s
93
+ if Smartthumbs::Config.get_option(:assume_klass).to_s == self.class.to_s
94
94
  "/th/#{format.to_s}/#{self.id}.#{st_extension}"
95
95
  else
96
96
  "/th/#{self.class.to_s.underscore.parameterize}/#{format.to_s}/#{self.id}.#{st_extension}"
@@ -1,3 +1,3 @@
1
1
  module Smartthumbs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartthumbs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Pauly