bcms_tools 0.0.1

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2008-2009 Gary McGhee - Buzzware Solutions, Western Australia - gary@buzzware.com.au
2
+
3
+ MIT Licence
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.rdoc ADDED
@@ -0,0 +1,45 @@
1
+ = bcms_tools
2
+
3
+ * Author : http://www.buzzware.com.au
4
+
5
+ == DESCRIPTION:
6
+
7
+ Tools for BrowserCms by Browser Media
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * something
12
+
13
+ == REQUIREMENTS:
14
+
15
+ * tested on MacOS and Linux
16
+
17
+ == INSTALL:
18
+
19
+ sudo gem install bcms_tools
20
+
21
+ == LICENSE:
22
+
23
+ (The MIT License)
24
+
25
+ Copyright (c) 2010 Gary McGhee, Buzzware Solutions
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining
28
+ a copy of this software and associated documentation files (the
29
+ 'Software'), to deal in the Software without restriction, including
30
+ without limitation the rights to use, copy, modify, merge, publish,
31
+ distribute, sublicense, and/or sell copies of the Software, and to
32
+ permit persons to whom the Software is furnished to do so, subject to
33
+ the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be
36
+ included in all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
39
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
42
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
43
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
44
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45
+
data/Rakefile ADDED
@@ -0,0 +1,62 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "bcms_tools"
8
+ gem.summary = %Q{Tools for BrowserCms.}
9
+ gem.description = %Q{Tools for BrowserCms.}
10
+ gem.email = "contact@buzzware.com.au"
11
+ gem.homepage = "http://github.com/buzzware/bcms_tools"
12
+ gem.authors = ["buzzware"]
13
+ gem.add_dependency "buzzcore"
14
+ gem.add_dependency "browsercms"
15
+ gem.add_development_dependency "thoughtbot-shoulda"
16
+ gem.files.include %w(
17
+ lib/bcms_tools/*
18
+ )
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/*_test.rb'
30
+ test.verbose = true
31
+ end
32
+
33
+ begin
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/*_test.rb'
38
+ test.verbose = true
39
+ end
40
+ rescue LoadError
41
+ task :rcov do
42
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
+ end
44
+ end
45
+
46
+ task :test => :check_dependencies
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ if File.exist?('VERSION')
53
+ version = File.read('VERSION')
54
+ else
55
+ version = ""
56
+ end
57
+
58
+ rdoc.rdoc_dir = 'rdoc'
59
+ rdoc.title = "bcms_tools #{version}"
60
+ rdoc.rdoc_files.include('README*')
61
+ rdoc.rdoc_files.include('lib/**/*.rb')
62
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{bcms_tools}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["buzzware"]
12
+ s.date = %q{2010-01-12}
13
+ s.description = %q{Tools for BrowserCms.}
14
+ s.email = %q{contact@buzzware.com.au}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bcms_tools.gemspec",
27
+ "lib/bcms_tools.rb",
28
+ "lib/bcms_tools/bcms_thumbnails.rb",
29
+ "lib/bcms_tools/bcms_thumbnails.rb",
30
+ "lib/bcms_tools_dev.rb",
31
+ "rails/init.rb",
32
+ "test/bcms_tools_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/buzzware/bcms_tools}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{Tools for BrowserCms.}
40
+ s.test_files = [
41
+ "test/bcms_tools_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<buzzcore>, [">= 0"])
51
+ s.add_runtime_dependency(%q<browsercms>, [">= 0"])
52
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<buzzcore>, [">= 0"])
55
+ s.add_dependency(%q<browsercms>, [">= 0"])
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<buzzcore>, [">= 0"])
60
+ s.add_dependency(%q<browsercms>, [">= 0"])
61
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
62
+ end
63
+ end
@@ -0,0 +1,156 @@
1
+ module BcmsTools
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
+
14
+ def self.thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
15
+ extThumb = aAttachment.file_extension
16
+ size = "#{aWidth}x#{aHeight}"
17
+ return File.basename(aAttachment.file_location)+'-'+size+'.'+extThumb
18
+ end
19
+
20
+ def self.attachment_from_url(aUrl)
21
+ if aUrl.begins_with?('/cms/attachments/')
22
+ id,version = aUrl.scan(/\/cms\/attachments\/([0-9]+)\?version=([0-9]+)/).flatten.map {|i| i.to_i}
23
+ att = Attachment.find_by_id_and_version(id,version)
24
+ else
25
+ att = Attachment.find_live_by_file_path(aUrl)
26
+ end
27
+ end
28
+
29
+ def self.image_location_from_url(aUrl)
30
+ att = attachment_from_url(aUrl)
31
+ return att && att.full_file_location
32
+ end
33
+
34
+ def self.scale_to_fit(aWidth,aHeight,aDestWidth,aDestHeight)
35
+ wRatio = aDestWidth / aWidth
36
+ hRatio = aDestHeight / aHeight
37
+ ratio = (wRatio < hRatio ? wRatio : hRatio)
38
+ return aWidth*ratio,aHeight*ratio
39
+ end
40
+
41
+ end
42
+
43
+ module PageHelper
44
+
45
+ def container_sized(aName,aWidth,aHeight)
46
+ StringUtils.split3(container(aName),/<img.*?>/,-1) do |head,img,tail|
47
+ src = XmlUtils.quick_att_from_tag(img,'src')
48
+ if src.begins_with?('/images/cms/') # a cms button
49
+ img
50
+ else
51
+ thumberize_img(img,aWidth,aHeight) # an image in the container
52
+ end
53
+ end
54
+ end
55
+
56
+ # with_images( container(:image_bar) ) do |img|
57
+ # thumberize_img(img,width,height)
58
+ # end
59
+ def with_images(aContainer)
60
+ return nil if aContainer.nil?
61
+ result = aContainer.clone
62
+ offset = 0
63
+ aContainer.scan_md(/<img.*?>/).each do |img_md|
64
+ src = XmlUtils.quick_att_from_tag(img_md.to_s,'src')
65
+ next if !src || src.begins_with?('/images/cms/')
66
+ first,last = img_md.offset(0)
67
+ output = yield(img_md.to_s)
68
+ result[first+offset..last-1+offset] = output
69
+ offset += output.length - (last-first)
70
+ end
71
+ result
72
+ end
73
+
74
+ def thumberize_img(img,aWidth,aHeight)
75
+ begin
76
+ urlImage = XmlUtils.quick_att_from_tag(img,'src')
77
+
78
+ att = BcmsTools::Thumbnails::attachment_from_url(urlImage)
79
+ pathImage = att && att.full_file_location
80
+
81
+ throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
82
+ throw RuntimeError.new("could not get file geometry #{pathImage}") unless geomImage = Paperclip::Geometry.from_file(pathImage)
83
+
84
+ aDestWidth,aDestHeight = BcmsTools::Thumbnails::scale_to_fit(geomImage.width,geomImage.height,aWidth,aHeight).map {|i| i.to_i}
85
+
86
+ nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(att,aWidth,aHeight)
87
+
88
+ pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
89
+
90
+ if !File.exists?(pathThumb)
91
+ # generate thumbnail at size to fit container
92
+ throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aDestWidth}x#{aDestHeight}")
93
+ throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
94
+ FileUtils.mv(foThumb.path,pathThumb,:force => true)
95
+ POpen4::shell_out("sudo -u tca chgrp www-data #{pathThumb}; sudo -u tca chmod 644 #{pathThumb}")
96
+ end
97
+
98
+ img = XmlUtils.quick_set_att(img,'src',File.join(APP_CONFIG[:thumbs_url],nameThumb))
99
+ return HtmlUtils.fixed_frame_image(img,aWidth,aHeight,aDestWidth,aDestHeight)
100
+ rescue Exception => e
101
+ RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
102
+ RAILS_DEFAULT_LOGGER.debug e.backtrace
103
+ return img
104
+ end
105
+ end
106
+
107
+ def attachment_cropped_src(aAttachment,aWidth,aHeight)
108
+ begin
109
+ pathImage = aAttachment.full_file_location
110
+ throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
111
+ nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
112
+ pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
113
+ if !File.exists?(pathThumb)
114
+ # generate thumbnail at size to fit container
115
+ throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aWidth}x#{aHeight}#")
116
+ throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
117
+ FileUtils.mv(foThumb.path,pathThumb,:force => true)
118
+ end
119
+ return File.join(APP_CONFIG[:thumbs_url],nameThumb)
120
+ rescue Exception => e
121
+ RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
122
+ RAILS_DEFAULT_LOGGER.debug e.backtrace
123
+ return ''
124
+ end
125
+ end
126
+
127
+ def framed_attachment_img(aAttachment,aWidth,aHeight)
128
+ begin
129
+ pathImage = aAttachment.full_file_location
130
+
131
+ throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
132
+ throw RuntimeError.new("could not get file geometry #{pathImage}") unless geomImage = Paperclip::Geometry.from_file(pathImage)
133
+
134
+ aDestWidth,aDestHeight = BcmsTools::Thumbnails::scale_to_fit(geomImage.width,geomImage.height,aWidth,aHeight).map {|i| i.to_i}
135
+
136
+ nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
137
+
138
+ pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
139
+
140
+ if !File.exists?(pathThumb)
141
+ throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aDestWidth}x#{aDestHeight}")
142
+ throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
143
+ FileUtils.mv(foThumb.path,pathThumb,:force => true)
144
+ end
145
+
146
+ img = "<img src=\"#{File.join(APP_CONFIG[:thumbs_url],nameThumb)}\" width=\"#{aDestWidth}\" height=\"#{aDestHeight}\" />"
147
+ return HtmlUtils.fixed_frame_image(img,aWidth,aHeight,aDestWidth,aDestHeight)
148
+ rescue Exception => e
149
+ RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
150
+ RAILS_DEFAULT_LOGGER.debug e.backtrace
151
+ return ''
152
+ end
153
+ end
154
+
155
+ end
156
+ end
data/lib/bcms_tools.rb ADDED
@@ -0,0 +1,2 @@
1
+ Dir.chdir(File.dirname(__FILE__)) { Dir['bcms_tools/*'] }.each {|f| require f }
2
+
@@ -0,0 +1,5 @@
1
+ # when you want to load the live version of bcms_tools, not the gem :
2
+ # require File.join(File.dirname(__FILE__),'../../../../../bcms_tools/lib/bcms_tools_dev.rb');
3
+ require_paths_first '.'
4
+ require 'bcms_tools'
5
+
data/rails/init.rb ADDED
@@ -0,0 +1,11 @@
1
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2
+ Cms.add_to_rails_paths gem_root
3
+
4
+ throw RuntimeError.new('thumbs_cache folder must exist') unless File.exists? APP_CONFIG[:thumbs_cache]
5
+
6
+ Cms::PageHelper.module_eval do
7
+
8
+ extend BcmsTools::PageHelper
9
+
10
+ end
11
+
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class BcmsToolsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'bcms_tools'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcms_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - buzzware
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-12 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: buzzcore
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: browsercms
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: thoughtbot-shoulda
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Tools for BrowserCms.
46
+ email: contact@buzzware.com.au
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - bcms_tools.gemspec
62
+ - lib/bcms_tools.rb
63
+ - lib/bcms_tools/bcms_thumbnails.rb
64
+ - lib/bcms_tools_dev.rb
65
+ - rails/init.rb
66
+ - test/bcms_tools_test.rb
67
+ - test/test_helper.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/buzzware/bcms_tools
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.5
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Tools for BrowserCms.
96
+ test_files:
97
+ - test/bcms_tools_test.rb
98
+ - test/test_helper.rb