bcms_tools 0.0.6 → 0.0.7

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 CHANGED
@@ -1,2 +1,2 @@
1
- 0.0.6
1
+ 0.0.7
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.6"
8
+ s.version = "0.0.7"
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-01}
12
+ s.date = %q{2010-03-08}
13
13
  s.description = %q{Tools for BrowserCms.}
14
14
  s.email = %q{contact@buzzware.com.au}
15
15
  s.extra_rdoc_files = [
@@ -34,6 +34,7 @@ module BcmsTools
34
34
  # Scale given aWidth,aHeight up to fit within aDestWidth,aDestHeight
35
35
  # return original width and height if nil given for both aDestWidth & aDestHeight
36
36
  # If either aDestWidth or aDestHeight are nil, it will scale to fit the other dimension
37
+ # If both are non-nil, the maximum scaled size that will fit inside the given width and height will be returned.
37
38
  def self.scale_to_fit(aWidth,aHeight,aDestWidth,aDestHeight)
38
39
  if aDestWidth.nil? && aDestHeight.nil?
39
40
  wRatio = 1
@@ -51,6 +52,8 @@ module BcmsTools
51
52
  end
52
53
 
53
54
  module PageHelper
55
+
56
+ module_function # this makes these methods callable as BcmsTools::PageHelper.method
54
57
 
55
58
  def container_sized(aName,aWidth,aHeight)
56
59
  StringUtils.split3(container(aName),/<img.*?>/,-1) do |head,img,tail|
@@ -117,6 +120,7 @@ module BcmsTools
117
120
  end
118
121
 
119
122
  def attachment_cropped_src(aAttachment,aWidth,aHeight)
123
+ return '' if !aAttachment
120
124
  begin
121
125
  pathImage = aAttachment.full_file_location
122
126
  throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
@@ -138,6 +142,33 @@ module BcmsTools
138
142
  end
139
143
  end
140
144
 
145
+ def attachment_max_src(aAttachment,aWidth,aHeight)
146
+ return '' if !aAttachment
147
+ begin
148
+ pathImage = aAttachment.full_file_location
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
+ pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
153
+
154
+ aDestWidth,aDestHeight = BcmsTools::Thumbnails::scale_to_fit(geomImage.width,geomImage.height,aWidth,aHeight).map {|i| i.to_i}
155
+ if !File.exists?(pathThumb)
156
+ # generate thumbnail at size to fit container
157
+ throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aDestWidth}x#{aDestHeight}")
158
+ throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
159
+ FileUtils.cp(foThumb.path,pathThumb)
160
+ FileUtils.chmod(0644,pathThumb)
161
+ FileUtils.rm(foThumb.path)
162
+ end
163
+ return File.join(APP_CONFIG[:thumbs_url],nameThumb)
164
+ rescue Exception => e
165
+ RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
166
+ RAILS_DEFAULT_LOGGER.debug e.backtrace
167
+ return ''
168
+ end
169
+ end
170
+
171
+
141
172
  def framed_attachment_img(aAttachment,aWidth,aHeight)
142
173
  begin
143
174
  pathImage = aAttachment.full_file_location
@@ -5,7 +5,7 @@ Cms::FormBuilder.class_eval do
5
5
  # ensure the related css is included
6
6
  def ensure_css
7
7
  template.content_for :html_head do
8
- template.stylesheet_link_tag("for_bcms_tools.css")
8
+ template.stylesheet_link_tag("bcms_tools.css")
9
9
  end
10
10
  end
11
11
 
@@ -52,10 +52,14 @@ Cms::FormBuilder.class_eval do
52
52
  def thumbnail_upload_field(aOptions)
53
53
  ensure_css
54
54
  aOptions[:label] ||= "Upload Image"
55
- result = cms_file_field(:attachment_file, aOptions) + '<br clear="all" />'
56
- method = 'attachment_file'
55
+ method = (aOptions.delete(:method) || :attachment)
56
+ method_file = (method.to_s + '_file').to_sym
57
+ _attachment = object.send(method)
58
+ result = cms_file_field(method_file.to_sym, aOptions) + '<br clear="all" />'
57
59
 
58
- underscore_id = object_name+'_'+options[:index].to_s+'_'+method
60
+ underscore_id = object_name
61
+ underscore_id += '_'+options[:index].to_s if options[:index]
62
+ underscore_id += '_'+method_file.to_s
59
63
  underscore_id_esc = jquery_escape(underscore_id)
60
64
  underscore_id_nobrac = underscore_id.gsub('[','_').gsub(']','')
61
65
 
@@ -75,13 +79,13 @@ Cms::FormBuilder.class_eval do
75
79
  end
76
80
  end
77
81
 
78
- thumbnail = if object.attachment
79
- "<img class=\"thumbnail\" src=\"#{Cms::PageHelper.attachment_cropped_src(object.attachment,64,64)}\" width=\"64\" height=\"64\"/>"
82
+ thumbnail = if _attachment
83
+ "<img class=\"thumbnail\" src=\"#{Cms::PageHelper.attachment_cropped_src(_attachment,64,64)}\" width=\"64\" height=\"64\"/>"
80
84
  else
81
85
  '<div style="width: 64px; height: 64px; position:static; display: block; float: left; border-style: solid; border-width: 1px; border-color: gray"></div>'
82
86
  end
83
87
  result = result.sub('</label>','</label>'+thumbnail)
84
- result = result.gsub(object_name+'_'+method,underscore_id)
88
+ result = result.gsub(object_name+'_'+method_file.to_s,underscore_id)
85
89
  result = StringUtils.split3(result,/<div class="fields file_fields.*?>/) {|h,m,t| XmlUtils.quick_join_att(m,'class','thumbnail_upload',' ') }
86
90
  result = '<div style="display: block; float: right; width: auto; height: auto;">'+remove_check_box()+'</div>' + result unless aOptions[:remove_check_box]==false || object.new_record?
87
91
  return result
@@ -102,6 +106,20 @@ Cms::FormBuilder.class_eval do
102
106
  template.concat("</div>")
103
107
  end
104
108
 
109
+ def text_display_field(aField,aOptions={})
110
+ template.concat('<div class="fields text_fields">')
111
+ if aOptions[:label]
112
+ label aField, aOptions[:label]
113
+ else
114
+ label aField
115
+ end
116
+ template.concat("<div id=\"artist_#{aField}\" class=\"text_display\">#{object.send(aField.to_sym)}</div>")
117
+
118
+ template.concat("<div class=\"instructions\">#{aOptions[:instructions]}</div>") if aOptions[:instructions]
119
+ template.concat("<br clear=\"all\" />") # Fixes issue with bad line wrapping
120
+ template.concat("</div>")
121
+ end
122
+
105
123
  end
106
124
 
107
125
 
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.6
4
+ version: 0.0.7
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-01 00:00:00 +08:00
12
+ date: 2010-03-08 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency