bcms_tools 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1,2 +1,2 @@
1
- 0.0.12
1
+ 0.0.13
2
2
 
data/bcms_tools.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bcms_tools}
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["buzzware"]
12
- s.date = %q{2010-03-17}
12
+ s.date = %q{2010-04-21}
13
13
  s.description = %q{Tools for BrowserCms.}
14
14
  s.email = %q{contact@buzzware.com.au}
15
15
  s.extra_rdoc_files = [
data/bcms_tools.vpj CHANGED
@@ -74,6 +74,9 @@
74
74
  Refilter="0"
75
75
  Excludes=""/>
76
76
  </Folder>
77
+ <Folder Name="rails">
78
+ <F N="rails/init.rb"/>
79
+ </Folder>
77
80
  <Folder Name="test">
78
81
  <F
79
82
  N="test/*"
@@ -1,16 +1,6 @@
1
1
  module BcmsTools
2
2
  module Thumbnails
3
-
4
- # for future bcms tools gem
5
- #http://snippets.dzone.com/posts/show/295
6
- #def close_tags(text)
7
- # open_tags = []
8
- # text.scan(/\<([^\>\s\/]+)[^\>\/]*?\>/).each { |t| open_tags.unshift(t) }
9
- # text.scan(/\<\/([^\>\s\/]+)[^\>]*?\>/).each { |t| open_tags.slice!(open_tags.index(t)) }
10
- # open_tags.each {|t| text += "</#{t}>" }
11
- # text
12
- #end
13
-
3
+
14
4
  def self.thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
15
5
  extThumb = aAttachment.file_extension
16
6
  size = "#{aWidth.to_s}x#{aHeight.to_s}"
@@ -49,15 +39,13 @@ module BcmsTools
49
39
  # If both are non-nil, the maximum scaled size that will fit inside the given width and height will be returned.
50
40
  def self.scale_to_fit(aWidth,aHeight,aDestWidth,aDestHeight)
51
41
  if aDestWidth.nil? && aDestHeight.nil?
52
- wRatio = 1
53
- hRatio = 1
42
+ ratio = 1
54
43
  else
55
- wRatio = aDestWidth / aWidth unless aDestWidth.nil?
44
+ wRatio = aDestWidth && (aDestWidth / aWidth)
56
45
  hRatio = (aDestHeight.nil? ? wRatio : (aDestHeight / aHeight))
46
+ wRatio ||= hRatio
47
+ ratio = Math.min(wRatio,hRatio)
57
48
  end
58
- wRatio = aDestWidth / aWidth
59
- hRatio = aDestHeight / aHeight
60
- ratio = (wRatio < hRatio ? wRatio : hRatio)
61
49
  return aWidth*ratio,aHeight*ratio
62
50
  end
63
51
 
@@ -154,6 +142,49 @@ module BcmsTools
154
142
  end
155
143
  end
156
144
 
145
+ def image_max_src(aImagePath,aWidth,aHeight)
146
+ return '' if !aImagePath
147
+ begin
148
+ pathImage = aImagePath
149
+ throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
150
+ throw RuntimeError.new("could not get file geometry #{pathImage}") unless geomImage = Paperclip::Geometry.from_file(pathImage)
151
+ #nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
152
+ #def self.thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
153
+ extThumb = MiscUtils.file_extension(File.basename(aImagePath)).downcase
154
+ size = "#{aWidth.to_s}x#{aHeight.to_s}"
155
+ nameThumb = MiscUtils.file_no_extension(File.basename(aImagePath))+'-'
156
+ nameThumb += if aWidth || aHeight
157
+ size+'.'+extThumb
158
+ else
159
+ '*'
160
+ end
161
+ #result
162
+ #end
163
+
164
+
165
+
166
+
167
+
168
+ pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
169
+
170
+ aDestWidth,aDestHeight = BcmsTools::Thumbnails::scale_to_fit(geomImage.width,geomImage.height,aWidth,aHeight).map {|i| i.to_i}
171
+ if !File.exists?(pathThumb)
172
+ # generate thumbnail at size to fit container
173
+ throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aDestWidth}x#{aDestHeight}")
174
+ throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
175
+ FileUtils.cp(foThumb.path,pathThumb)
176
+ FileUtils.chmod(0644,pathThumb)
177
+ FileUtils.rm(foThumb.path)
178
+ end
179
+ return File.join(APP_CONFIG[:thumbs_url],nameThumb)
180
+ rescue Exception => e
181
+ RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
182
+ RAILS_DEFAULT_LOGGER.debug e.backtrace
183
+ return ''
184
+ end
185
+ end
186
+
187
+
157
188
  def attachment_max_src(aAttachment,aWidth,aHeight)
158
189
  return '' if !aAttachment
159
190
  begin
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcms_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - buzzware
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-17 00:00:00 +08:00
12
+ date: 2010-04-21 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency