bcms_tools 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bcms_tools.gemspec +6 -2
- data/bcms_tools.vpj +90 -0
- data/bcms_tools.vpw +6 -0
- data/lib/bcms_tools/bcms_thumbnails.rb +11 -1
- data/lib/bcms_tools/form_helpers.rb +107 -0
- data/lib/bcms_tools/view_helpers.rb +63 -3
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
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.
|
8
|
+
s.version = "0.0.4"
|
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-
|
12
|
+
s.date = %q{2010-02-15}
|
13
13
|
s.description = %q{Tools for BrowserCms.}
|
14
14
|
s.email = %q{contact@buzzware.com.au}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,9 +24,13 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"bcms_tools.gemspec",
|
27
|
+
"bcms_tools.vpj",
|
28
|
+
"bcms_tools.vpw",
|
27
29
|
"lib/bcms_tools.rb",
|
28
30
|
"lib/bcms_tools/bcms_thumbnails.rb",
|
29
31
|
"lib/bcms_tools/bcms_thumbnails.rb",
|
32
|
+
"lib/bcms_tools/form_helpers.rb",
|
33
|
+
"lib/bcms_tools/form_helpers.rb",
|
30
34
|
"lib/bcms_tools/view_helpers.rb",
|
31
35
|
"lib/bcms_tools/view_helpers.rb",
|
32
36
|
"lib/bcms_tools_dev.rb",
|
data/bcms_tools.vpj
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
2
|
+
<Project
|
3
|
+
Version="10.0"
|
4
|
+
VendorName="SlickEdit"
|
5
|
+
WorkingDir=".">
|
6
|
+
<Config
|
7
|
+
Name="Release"
|
8
|
+
OutputFile=""
|
9
|
+
CompilerConfigName="Latest Version">
|
10
|
+
<Menu>
|
11
|
+
<Target
|
12
|
+
Name="Compile"
|
13
|
+
MenuCaption="&Compile"
|
14
|
+
CaptureOutputWith="ProcessBuffer"
|
15
|
+
SaveOption="SaveCurrent"
|
16
|
+
RunFromDir="%rw">
|
17
|
+
<Exec/>
|
18
|
+
</Target>
|
19
|
+
<Target
|
20
|
+
Name="Build"
|
21
|
+
MenuCaption="&Build"
|
22
|
+
CaptureOutputWith="ProcessBuffer"
|
23
|
+
SaveOption="SaveWorkspaceFiles"
|
24
|
+
RunFromDir="%rw">
|
25
|
+
<Exec/>
|
26
|
+
</Target>
|
27
|
+
<Target
|
28
|
+
Name="Rebuild"
|
29
|
+
MenuCaption="&Rebuild"
|
30
|
+
CaptureOutputWith="ProcessBuffer"
|
31
|
+
SaveOption="SaveWorkspaceFiles"
|
32
|
+
RunFromDir="%rw">
|
33
|
+
<Exec/>
|
34
|
+
</Target>
|
35
|
+
<Target
|
36
|
+
Name="Debug"
|
37
|
+
MenuCaption="&Debug"
|
38
|
+
SaveOption="SaveNone"
|
39
|
+
RunFromDir="%rw">
|
40
|
+
<Exec/>
|
41
|
+
</Target>
|
42
|
+
<Target
|
43
|
+
Name="Execute"
|
44
|
+
MenuCaption="E&xecute"
|
45
|
+
SaveOption="SaveNone"
|
46
|
+
RunFromDir="%rw">
|
47
|
+
<Exec CmdLine='"FrescoClient.exe"'/>
|
48
|
+
</Target>
|
49
|
+
</Menu>
|
50
|
+
</Config>
|
51
|
+
<CustomFolders>
|
52
|
+
<Folder
|
53
|
+
Name="Source Files"
|
54
|
+
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl"/>
|
55
|
+
<Folder
|
56
|
+
Name="Header Files"
|
57
|
+
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if"/>
|
58
|
+
<Folder
|
59
|
+
Name="Resource Files"
|
60
|
+
Filters="*.ico;*.cur;*.dlg"/>
|
61
|
+
<Folder
|
62
|
+
Name="Bitmaps"
|
63
|
+
Filters="*.bmp"/>
|
64
|
+
<Folder
|
65
|
+
Name="Other Files"
|
66
|
+
Filters="">
|
67
|
+
</Folder>
|
68
|
+
</CustomFolders>
|
69
|
+
<Files AutoFolders="DirectoryView">
|
70
|
+
<Folder Name="lib">
|
71
|
+
<F
|
72
|
+
N="lib/*"
|
73
|
+
Recurse="1"
|
74
|
+
Refilter="0"
|
75
|
+
Excludes=""/>
|
76
|
+
</Folder>
|
77
|
+
<Folder Name="test">
|
78
|
+
<F
|
79
|
+
N="test/*"
|
80
|
+
Recurse="1"
|
81
|
+
Refilter="0"
|
82
|
+
Excludes=""/>
|
83
|
+
</Folder>
|
84
|
+
<F
|
85
|
+
N="*"
|
86
|
+
Recurse="0"
|
87
|
+
Refilter="0"
|
88
|
+
Excludes=""/>
|
89
|
+
</Files>
|
90
|
+
</Project>
|
data/bcms_tools.vpw
ADDED
@@ -13,7 +13,7 @@ module BcmsTools
|
|
13
13
|
|
14
14
|
def self.thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
15
15
|
extThumb = aAttachment.file_extension
|
16
|
-
size = "#{aWidth}x#{aHeight}"
|
16
|
+
size = "#{aWidth.to_s}x#{aHeight.to_s}"
|
17
17
|
return File.basename(aAttachment.file_location)+'-'+size+'.'+extThumb
|
18
18
|
end
|
19
19
|
|
@@ -31,7 +31,17 @@ module BcmsTools
|
|
31
31
|
return att && att.full_file_location
|
32
32
|
end
|
33
33
|
|
34
|
+
# Scale given aWidth,aHeight up to fit within aDestWidth,aDestHeight
|
35
|
+
# return original width and height if nil given for both aDestWidth & aDestHeight
|
36
|
+
# If either aDestWidth or aDestHeight are nil, it will scale to fit the other dimension
|
34
37
|
def self.scale_to_fit(aWidth,aHeight,aDestWidth,aDestHeight)
|
38
|
+
if aDestWidth.nil? && aDestHeight.nil?
|
39
|
+
wRatio = 1
|
40
|
+
hRatio = 1
|
41
|
+
else
|
42
|
+
wRatio = aDestWidth / aWidth unless aDestWidth.nil?
|
43
|
+
hRatio = (aDestHeight.nil? ? wRatio : (aDestHeight / aHeight))
|
44
|
+
end
|
35
45
|
wRatio = aDestWidth / aWidth
|
36
46
|
hRatio = aDestHeight / aHeight
|
37
47
|
ratio = (wRatio < hRatio ? wRatio : hRatio)
|
@@ -0,0 +1,107 @@
|
|
1
|
+
Cms::FormBuilder.class_eval do
|
2
|
+
|
3
|
+
attr_reader :template
|
4
|
+
|
5
|
+
# ensure the related css is included
|
6
|
+
def ensure_css
|
7
|
+
template.content_for :html_head do
|
8
|
+
template.stylesheet_link_tag("for_bcms_tools.css")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove_check_box()
|
13
|
+
"#{check_box('_destroy')} Remove ?"
|
14
|
+
end
|
15
|
+
|
16
|
+
def jquery_escape(aString)
|
17
|
+
# from http://samuelsjoberg.com/archive/2009/09/escape-jquery-selectors
|
18
|
+
# return str.replace(/([#;&,\.\+\*\~':"\!\^$\[\]\(\)=>\|])/g, "\\$1");
|
19
|
+
aString.gsub(/([#;&,\.\+\*\~':"\!\^$\[\]\(\)=>\|])/) {|c| '\\\\'+c}
|
20
|
+
end
|
21
|
+
|
22
|
+
# standard original file upload
|
23
|
+
#
|
24
|
+
#//<![CDATA[
|
25
|
+
#
|
26
|
+
# jQuery(function($) {
|
27
|
+
# $('#mock_stock_image_attachment_file') // <input type="text"
|
28
|
+
# .focus(function() {this.blur()})
|
29
|
+
# .mousedown(function() {this.blur()})
|
30
|
+
# $('#stock_image_attachment_file').change(function() { // <input type="file"
|
31
|
+
# $('#mock_stock_image_attachment_file') // <input type="text"
|
32
|
+
# .attr('value', $(this).attr('value'))
|
33
|
+
# })
|
34
|
+
# })
|
35
|
+
#
|
36
|
+
#//]]>
|
37
|
+
#
|
38
|
+
#<div class="fields file_fields">
|
39
|
+
#
|
40
|
+
# <label for="stock_image_attachment_file">File</label>
|
41
|
+
#
|
42
|
+
# <div class="file_inputs" id="stock_image_attachment_file_div">
|
43
|
+
# <input type="file" tabindex="3" size="1" name="stock_image[attachment_file]" id="stock_image_attachment_file" class="file">
|
44
|
+
# <div class="fakefile">
|
45
|
+
# <input type="text" id="mock_stock_image_attachment_file" class="mock" name="temp">
|
46
|
+
# <img src="/images/cms/browse.gif?1261031544" alt="Browse">
|
47
|
+
# </div>
|
48
|
+
# </div>
|
49
|
+
#
|
50
|
+
#</div>
|
51
|
+
|
52
|
+
def thumbnail_upload_field(aOptions)
|
53
|
+
ensure_css
|
54
|
+
aOptions[:label] ||= "Upload Image"
|
55
|
+
result = cms_file_field(:attachment_file, aOptions) + '<br clear="all" />'
|
56
|
+
method = 'attachment_file'
|
57
|
+
|
58
|
+
underscore_id = object_name+'_'+options[:index].to_s+'_'+method
|
59
|
+
underscore_id_esc = jquery_escape(underscore_id)
|
60
|
+
underscore_id_nobrac = underscore_id.gsub('[','_').gsub(']','')
|
61
|
+
|
62
|
+
template.content_for :html_head do
|
63
|
+
template.javascript_tag do
|
64
|
+
<<-EOS
|
65
|
+
jQuery(function($) {
|
66
|
+
$('input#mock_#{underscore_id_esc}') // <input type="text"
|
67
|
+
.focus(function() {this.blur()})
|
68
|
+
.mousedown(function() {this.blur()})
|
69
|
+
$('input##{underscore_id_nobrac}').change(function() { // <input type="file"
|
70
|
+
$('input#mock_#{underscore_id_esc}') // <input type="text"
|
71
|
+
.attr('value', $(this).attr('value'))
|
72
|
+
})
|
73
|
+
})
|
74
|
+
EOS
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
thumbnail = if object.attachment
|
79
|
+
"<img class=\"thumbnail\" src=\"#{Cms::PageHelper.attachment_cropped_src(object.attachment,64,64)}\" width=\"64\" height=\"64\"/>"
|
80
|
+
else
|
81
|
+
'<div style="width: 64px; height: 64px; position:static; display: block; float: left; border-style: solid; border-width: 1px; border-color: gray"></div>'
|
82
|
+
end
|
83
|
+
result = result.sub('</label>','</label>'+thumbnail)
|
84
|
+
result = result.gsub(object_name+'_'+method,underscore_id)
|
85
|
+
result = StringUtils.split3(result,/<div class="fields file_fields.*?>/) {|h,m,t| XmlUtils.quick_join_att(m,'class','thumbnail_upload',' ') }
|
86
|
+
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
|
+
return result
|
88
|
+
end
|
89
|
+
|
90
|
+
# surround child fields with an appropriate div
|
91
|
+
# usage :
|
92
|
+
#<% f.child_fields do %>
|
93
|
+
# <% f.fields_for( :stock_images_attributes, img, :index => i ) do |image_form| %>
|
94
|
+
# <%= image_form.cms_text_field :name, :label => "name (short)" %>
|
95
|
+
# <%= image_form.cms_text_field :caption, :label => 'caption' %>
|
96
|
+
# <% end %>
|
97
|
+
#<% end %>
|
98
|
+
def child_fields(aClass='child_fields', &block)
|
99
|
+
content = template.capture(&block)
|
100
|
+
template.concat("<div class=\"#{aClass}\">")
|
101
|
+
template.concat(content)
|
102
|
+
template.concat("</div>")
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module ActionView
|
2
2
|
module Helpers
|
3
|
-
|
3
|
+
|
4
|
+
# makes these accessible via ActionView::Helpers.function
|
5
|
+
module_function
|
6
|
+
|
4
7
|
def google_analytics(aTrackingId = nil)
|
5
8
|
return '' if request.host.begins_with?('cms.')
|
6
9
|
aTrackingId ||= APP_CONFIG[:google_analytics_tracking_id]
|
@@ -23,7 +26,7 @@ module ActionView
|
|
23
26
|
def default_content_for(name, &block)
|
24
27
|
name = name.kind_of?(Symbol) ? ":#{name}" : name
|
25
28
|
out = eval("yield #{name}", block.binding)
|
26
|
-
concat(out || capture(&block)
|
29
|
+
concat(out || capture(&block))
|
27
30
|
end
|
28
31
|
|
29
32
|
#render_menu(), or more precisely menu_items() doesn't seem to work well
|
@@ -47,7 +50,8 @@ module ActionView
|
|
47
50
|
|
48
51
|
selected_page = opts[:page] || @page
|
49
52
|
ancestors = selected_page.ancestors
|
50
|
-
top_section = ancestors[opts[:from_top]]
|
53
|
+
top_section = ancestors[opts[:from_top].to_i]
|
54
|
+
return '' unless top_section
|
51
55
|
opts[:path] = top_section.path
|
52
56
|
|
53
57
|
ancestors << selected_page if (selected_page.section == top_section) || (selected_page != selected_page.section.pages.first)
|
@@ -61,6 +65,62 @@ module ActionView
|
|
61
65
|
render_menu opts
|
62
66
|
end
|
63
67
|
|
68
|
+
# Construct tree_nodes, an array of arrays - each array a level in tree.
|
69
|
+
# Each level is a list children to the parents in the level before
|
70
|
+
def construct_category_tree(aRootCategory)
|
71
|
+
aRootCategory = Category.find_by_name(aRootCategory) unless aRootCategory.is_a? Category
|
72
|
+
tree_nodes = []
|
73
|
+
level_nodes = [aRootCategory]
|
74
|
+
begin
|
75
|
+
tree_nodes << level_nodes
|
76
|
+
ids = level_nodes.map {|n| n.id}
|
77
|
+
level_nodes = Category.find_all_by_parent_id(ids) #Category.all({:conditions => ['parent_id in (?)',ids.join(',')]})
|
78
|
+
end while !level_nodes.empty?
|
79
|
+
tree_nodes
|
80
|
+
end
|
81
|
+
|
82
|
+
# :base_url (String) : prepended to menu urls eg. /products
|
83
|
+
# :category (String) : name of current category eg. 'Shoes'
|
84
|
+
# :id_prefix (String) : will be prepended to ids of menu eg. 'section_'
|
85
|
+
def category_menu_items(aRootCategory, aOptions={})
|
86
|
+
aBaseUrl = (aOptions[:base_url] || '')
|
87
|
+
aIdPrefix = (aOptions[:id_prefix] || '')
|
88
|
+
category = aOptions[:category]
|
89
|
+
category = category.name.urlize('+') if category.is_a?(Category)
|
90
|
+
tree_nodes = construct_category_tree(aRootCategory)
|
91
|
+
|
92
|
+
# now turn tree_nodes into menu items, still as array of levels
|
93
|
+
tree_items = []
|
94
|
+
last_lvl = nil
|
95
|
+
tree_nodes.each do |lvl|
|
96
|
+
item_level = []
|
97
|
+
lvl.each do |node|
|
98
|
+
name = (node.name.index('/') ? File.basename(node.name) : node.name)
|
99
|
+
item = {:id => aIdPrefix+node.id.to_s, :name => name }
|
100
|
+
item[:node] = node
|
101
|
+
if last_lvl && parent_item = last_lvl.find {|i| i[:node].id == node.parent_id}
|
102
|
+
parent_item[:children] ||= []
|
103
|
+
parent_item[:children] << item
|
104
|
+
item[:url] = parent_item[:url]
|
105
|
+
item[:url] += '+' unless item[:url]=='' || item[:url].ends_with?('/') || item[:url].ends_with?('+')
|
106
|
+
item[:url] += name.urlize('-')
|
107
|
+
else
|
108
|
+
item[:url] = aBaseUrl
|
109
|
+
end
|
110
|
+
item[:selected] = true if category && category==node.name.urlize('+')
|
111
|
+
item_level << item
|
112
|
+
end
|
113
|
+
tree_items << item_level
|
114
|
+
last_lvl = item_level
|
115
|
+
end
|
116
|
+
|
117
|
+
# clean
|
118
|
+
tree_items.each do |lvl|
|
119
|
+
lvl.each{|i| i.filter_include!([:url,:selected,:id,:name,:children])}
|
120
|
+
end
|
121
|
+
tree_items.first
|
122
|
+
end
|
123
|
+
|
64
124
|
module CaptureHelper
|
65
125
|
def set_content_for(name, content = nil, &block)
|
66
126
|
ivar = "@content_for_#{name}"
|
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.
|
4
|
+
version: 0.0.4
|
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-
|
12
|
+
date: 2010-02-15 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -59,8 +59,11 @@ files:
|
|
59
59
|
- Rakefile
|
60
60
|
- VERSION
|
61
61
|
- bcms_tools.gemspec
|
62
|
+
- bcms_tools.vpj
|
63
|
+
- bcms_tools.vpw
|
62
64
|
- lib/bcms_tools.rb
|
63
65
|
- lib/bcms_tools/bcms_thumbnails.rb
|
66
|
+
- lib/bcms_tools/form_helpers.rb
|
64
67
|
- lib/bcms_tools/view_helpers.rb
|
65
68
|
- lib/bcms_tools_dev.rb
|
66
69
|
- rails/init.rb
|