bcms_tools 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bcms_tools.gemspec +4 -3
- data/lib/bcms_tools/bcms_thumbnails.rb +35 -119
- data/lib/bcms_tools/category_utils.rb +17 -0
- metadata +5 -4
data/VERSION
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.5
|
|
2
2
|
|
data/bcms_tools.gemspec
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Generated by jeweler
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{bcms_tools}
|
|
8
|
-
s.version = "0.2.
|
|
8
|
+
s.version = "0.2.5"
|
|
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{
|
|
12
|
+
s.date = %q{2011-03-28}
|
|
13
13
|
s.description = %q{Tools for BrowserCms.}
|
|
14
14
|
s.email = %q{contact@buzzware.com.au}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
|
28
28
|
"bcms_tools.vpw",
|
|
29
29
|
"lib/bcms_tools.rb",
|
|
30
30
|
"lib/bcms_tools/bcms_thumbnails.rb",
|
|
31
|
+
"lib/bcms_tools/category_utils.rb",
|
|
31
32
|
"lib/bcms_tools/form_helpers.rb",
|
|
32
33
|
"lib/bcms_tools/migration_helpers.rb",
|
|
33
34
|
"lib/bcms_tools/view_helpers.rb",
|
|
@@ -191,8 +191,12 @@ module Buzzcore
|
|
|
191
191
|
if !File.exists?(pathThumb)
|
|
192
192
|
throw RuntimeError.new("Failed reading image #{aSource}") unless objThumb = Paperclip::Thumbnail.new(File.new(aSource), :geometry => resize_spec+resize_mod, :format => :jpg, :convert_options => '-quality 85')
|
|
193
193
|
objThumb.basename = MiscUtils.file_no_extension(nameThumb)
|
|
194
|
+
RAILS_DEFAULT_LOGGER.debug 'render_thumbnail: generating '+pathThumb
|
|
195
|
+
|
|
194
196
|
throw RuntimeError.new("Failed making thumbnail #{aSource}") unless objThumb.make_custom(pathThumb)
|
|
195
197
|
FileUtils.chmod(0644,pathThumb)
|
|
198
|
+
else
|
|
199
|
+
RAILS_DEFAULT_LOGGER.debug 'render_thumbnail: using cached '+pathThumb
|
|
196
200
|
end
|
|
197
201
|
src = File.join(aBaseUrl,nameThumb)
|
|
198
202
|
details.merge!({
|
|
@@ -222,7 +226,7 @@ module BcmsTools
|
|
|
222
226
|
def self.thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
|
223
227
|
extThumb = 'jpg' #aAttachment.file_extension
|
|
224
228
|
size = "#{aWidth.to_s}x#{aHeight.to_s}"
|
|
225
|
-
result =
|
|
229
|
+
result = MiscUtils.file_no_extension(aAttachment.file_path).bite('/').gsub('/','--')+'-'+aAttachment.file_location[-4,4]+'-'
|
|
226
230
|
result += if aWidth && aHeight
|
|
227
231
|
size+'.'+extThumb
|
|
228
232
|
else
|
|
@@ -231,6 +235,10 @@ module BcmsTools
|
|
|
231
235
|
result
|
|
232
236
|
end
|
|
233
237
|
|
|
238
|
+
def self.thumbnail_path_from_attachment(aAttachment,aWidth,aHeight)
|
|
239
|
+
File.join(APP_CONFIG[:thumbs_cache],thumbnail_name_from_attachment(aAttachment,aWidth,aHeight))
|
|
240
|
+
end
|
|
241
|
+
|
|
234
242
|
def self.remove_attachment_thumbnails(aAttachment)
|
|
235
243
|
nameThumb = thumbnail_name_from_attachment(aAttachment,nil,nil)
|
|
236
244
|
pathThumbWildcard = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
|
|
@@ -308,29 +316,6 @@ module BcmsTools
|
|
|
308
316
|
|
|
309
317
|
att = BcmsTools::Thumbnails::attachment_from_url(urlImage)
|
|
310
318
|
return img = framed_attachment_img(att,aWidth,aHeight,img)
|
|
311
|
-
|
|
312
|
-
#src = attachment_max_src(aAttachment,aWidth,aHeight,img)
|
|
313
|
-
#
|
|
314
|
-
#pathImage = att && att.full_file_location
|
|
315
|
-
#
|
|
316
|
-
#throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
|
|
317
|
-
#throw RuntimeError.new("could not get file geometry #{pathImage}") unless geomImage = Paperclip::Geometry.from_file(pathImage)
|
|
318
|
-
#
|
|
319
|
-
#aDestWidth,aDestHeight = BcmsTools::Thumbnails::scale_to_fit(geomImage.width,geomImage.height,aWidth,aHeight).map {|i| i.to_i}
|
|
320
|
-
#
|
|
321
|
-
#nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(att,aWidth,aHeight)
|
|
322
|
-
#
|
|
323
|
-
#pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
|
|
324
|
-
#
|
|
325
|
-
#if !File.exists?(pathThumb)
|
|
326
|
-
# # generate thumbnail at size to fit container
|
|
327
|
-
# throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aDestWidth}x#{aDestHeight}")
|
|
328
|
-
# throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
|
|
329
|
-
# FileUtils.cp(foThumb.path,pathThumb,:preserve => true)
|
|
330
|
-
# FileUtils.chmod(0644,pathThumb)
|
|
331
|
-
# FileUtils.rm(foThumb.path)
|
|
332
|
-
# #POpen4::shell_out("sudo -u tca chgrp www-data #{pathThumb}; sudo -u tca chmod 644 #{pathThumb}")
|
|
333
|
-
#end
|
|
334
319
|
|
|
335
320
|
#img = XmlUtils.quick_set_att(img,'src',src) # File.join(APP_CONFIG[:thumbs_url],nameThumb))
|
|
336
321
|
#return HtmlUtils.fixed_frame_image(img,aWidth,aHeight,aDestWidth,aDestHeight)
|
|
@@ -341,42 +326,6 @@ module BcmsTools
|
|
|
341
326
|
end
|
|
342
327
|
end
|
|
343
328
|
|
|
344
|
-
def attachment_cropped_src(aAttachment,aWidth,aHeight)
|
|
345
|
-
return '' if !aAttachment
|
|
346
|
-
|
|
347
|
-
Buzzcore::ImageUtils.render_thumbnail(
|
|
348
|
-
aAttachment.full_file_location,
|
|
349
|
-
APP_CONFIG[:thumbs_cache],
|
|
350
|
-
APP_CONFIG[:thumbs_url],
|
|
351
|
-
aWidth,
|
|
352
|
-
aHeight,
|
|
353
|
-
{
|
|
354
|
-
:name => BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight),
|
|
355
|
-
:resize_mode => :cropfill
|
|
356
|
-
}
|
|
357
|
-
)
|
|
358
|
-
|
|
359
|
-
#begin
|
|
360
|
-
# pathImage = aAttachment.full_file_location
|
|
361
|
-
# throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
|
|
362
|
-
# nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
|
363
|
-
# pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
|
|
364
|
-
# if !File.exists?(pathThumb)
|
|
365
|
-
# # generate thumbnail at size to fit container
|
|
366
|
-
# throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aWidth}x#{aHeight}#")
|
|
367
|
-
# throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
|
|
368
|
-
# FileUtils.cp(foThumb.path,pathThumb)
|
|
369
|
-
# FileUtils.chmod(0644,pathThumb)
|
|
370
|
-
# FileUtils.rm(foThumb.path)
|
|
371
|
-
# end
|
|
372
|
-
# return File.join(APP_CONFIG[:thumbs_url],nameThumb)
|
|
373
|
-
#rescue Exception => e
|
|
374
|
-
# RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
|
|
375
|
-
# RAILS_DEFAULT_LOGGER.debug e.backtrace
|
|
376
|
-
# return ''
|
|
377
|
-
#end
|
|
378
|
-
end
|
|
379
|
-
|
|
380
329
|
def shellescape(str)
|
|
381
330
|
# An empty argument will be skipped, so return empty quotes.
|
|
382
331
|
return "''" if str.empty?
|
|
@@ -398,70 +347,27 @@ module BcmsTools
|
|
|
398
347
|
result = shellescape(aString)
|
|
399
348
|
result.gsub!('\\','\\\\\\')
|
|
400
349
|
end
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
# resizes and crops to fill given size completely, probably losing part of the image
|
|
353
|
+
def attachment_cropped_src(aAttachment,aWidth,aHeight)
|
|
354
|
+
return '' if !aAttachment || !aAttachment.file_location
|
|
401
355
|
|
|
402
|
-
|
|
403
|
-
def image_max_src(aImagePath,aWidth,aHeight)
|
|
404
356
|
Buzzcore::ImageUtils.render_thumbnail(
|
|
405
|
-
|
|
357
|
+
aAttachment.full_file_location,
|
|
406
358
|
APP_CONFIG[:thumbs_cache],
|
|
407
359
|
APP_CONFIG[:thumbs_url],
|
|
408
360
|
aWidth,
|
|
409
|
-
aHeight
|
|
361
|
+
aHeight,
|
|
362
|
+
{
|
|
363
|
+
:name => BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight),
|
|
364
|
+
:resize_mode => :cropfill
|
|
365
|
+
}
|
|
410
366
|
)
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
# aSource, # source file
|
|
414
|
-
# aDestFolder, # folder to put new file in
|
|
415
|
-
# aBaseUrl, # equivalent URL for aDestFolder
|
|
416
|
-
# aWidth, # width (nil means auto)
|
|
417
|
-
# aHeight, # height (nil means auto)
|
|
418
|
-
# aOptions = nil
|
|
419
|
-
#)
|
|
420
|
-
#
|
|
421
|
-
#
|
|
422
|
-
#
|
|
423
|
-
# return '' if !aImagePath
|
|
424
|
-
# begin
|
|
425
|
-
# pathImage = aImagePath
|
|
426
|
-
# throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
|
|
427
|
-
# throw RuntimeError.new("could not get file geometry #{pathImage}") unless geomImage = Paperclip::Geometry.from_file(shellescape2(pathImage))
|
|
428
|
-
# #nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
|
429
|
-
# #def self.thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
|
430
|
-
# extThumb = MiscUtils.file_extension(File.basename(aImagePath)).downcase
|
|
431
|
-
# size = "#{aWidth.to_s}x#{aHeight.to_s}"
|
|
432
|
-
# nameThumb = MiscUtils.file_no_extension(File.basename(aImagePath))+'-'
|
|
433
|
-
# nameThumb += if aWidth || aHeight
|
|
434
|
-
# size+'.'+extThumb
|
|
435
|
-
# else
|
|
436
|
-
# '*'
|
|
437
|
-
# end
|
|
438
|
-
# #result
|
|
439
|
-
# #end
|
|
440
|
-
#
|
|
441
|
-
#
|
|
442
|
-
#
|
|
443
|
-
#
|
|
444
|
-
#
|
|
445
|
-
# pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
|
|
446
|
-
#
|
|
447
|
-
# aDestWidth,aDestHeight = BcmsTools::Thumbnails::scale_to_fit(geomImage.width,geomImage.height,aWidth,aHeight).map {|i| i.to_i}
|
|
448
|
-
# if !File.exists?(pathThumb)
|
|
449
|
-
# # generate thumbnail at size to fit container
|
|
450
|
-
# throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(shellescape2(pathImage)), "#{aDestWidth}x#{aDestHeight}")
|
|
451
|
-
# throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
|
|
452
|
-
# FileUtils.cp(foThumb.path,pathThumb)
|
|
453
|
-
# FileUtils.chmod(0644,pathThumb)
|
|
454
|
-
# FileUtils.rm(foThumb.path)
|
|
455
|
-
# end
|
|
456
|
-
# return File.join(APP_CONFIG[:thumbs_url],nameThumb)
|
|
457
|
-
# rescue Exception => e
|
|
458
|
-
# RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
|
|
459
|
-
# RAILS_DEFAULT_LOGGER.debug e.backtrace
|
|
460
|
-
# return ''
|
|
461
|
-
# end
|
|
462
|
-
#end
|
|
463
|
-
|
|
367
|
+
|
|
368
|
+
end
|
|
464
369
|
|
|
370
|
+
# fits entire image within available space, maintaining aspect, probably not filling the space
|
|
465
371
|
def attachment_max_src(aAttachment,aWidth,aHeight)
|
|
466
372
|
return '' if !aAttachment
|
|
467
373
|
Buzzcore::ImageUtils.render_thumbnail(
|
|
@@ -471,11 +377,21 @@ module BcmsTools
|
|
|
471
377
|
aWidth,
|
|
472
378
|
aHeight,
|
|
473
379
|
{
|
|
474
|
-
:name => BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
|
380
|
+
:name => BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight),
|
|
381
|
+
:resize_mode => :fit
|
|
475
382
|
}
|
|
476
383
|
)
|
|
477
384
|
end
|
|
478
|
-
|
|
385
|
+
|
|
386
|
+
def image_max_src(aImagePath,aWidth,aHeight)
|
|
387
|
+
Buzzcore::ImageUtils.render_thumbnail(
|
|
388
|
+
aImagePath,
|
|
389
|
+
APP_CONFIG[:thumbs_cache],
|
|
390
|
+
APP_CONFIG[:thumbs_url],
|
|
391
|
+
aWidth,
|
|
392
|
+
aHeight
|
|
393
|
+
)
|
|
394
|
+
end
|
|
479
395
|
|
|
480
396
|
def framed_attachment_img(aAttachment,aWidth,aHeight,aImg=nil)
|
|
481
397
|
return '' if !aAttachment
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Category.class_eval do
|
|
2
|
+
|
|
3
|
+
def self.create_chain(
|
|
4
|
+
aChain, # an array of names from leaf to root
|
|
5
|
+
aCatType # an object or id of CategoryRoot
|
|
6
|
+
)
|
|
7
|
+
aCatType = CategoryType.find_by_id(aCatType) if aCatType.is_a? Fixnum
|
|
8
|
+
parent = nil
|
|
9
|
+
aChain.each do |name|
|
|
10
|
+
currCat = Category.find_by_name(name) || aCatType.categories.create!(:name => name,:parent => parent)
|
|
11
|
+
parent = currCat
|
|
12
|
+
end
|
|
13
|
+
parent
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bcms_tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 29
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 2
|
|
9
|
-
-
|
|
10
|
-
version: 0.2.
|
|
9
|
+
- 5
|
|
10
|
+
version: 0.2.5
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- buzzware
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date:
|
|
18
|
+
date: 2011-03-28 00:00:00 +08:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -100,6 +100,7 @@ files:
|
|
|
100
100
|
- bcms_tools.vpw
|
|
101
101
|
- lib/bcms_tools.rb
|
|
102
102
|
- lib/bcms_tools/bcms_thumbnails.rb
|
|
103
|
+
- lib/bcms_tools/category_utils.rb
|
|
103
104
|
- lib/bcms_tools/form_helpers.rb
|
|
104
105
|
- lib/bcms_tools/migration_helpers.rb
|
|
105
106
|
- lib/bcms_tools/view_helpers.rb
|