Skip to content

Commit

Permalink
Fixed upload of Image/Document sub-classes. Added PATH_mode.format op…
Browse files Browse the repository at this point in the history
…tion to img_tag_{mode}.
  • Loading branch information
gaspard committed Mar 6, 2013
1 parent 5eeaca2 commit 043e6d0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Fixed query_parse to convert dates to UTC.
* Fixed form preview inside block.
* Added unique id to img_tag_{mode} code generated 'UUID'. <== TODO: Document
* Added PATH_mode.format and [JS] marker to img_tag_{mode}.

== 1.2.2 2012-08-30

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def create
file, file_error = get_attachment
if file
attrs['file'] = file
attrs['klass'] = 'Document'
attrs['klass'] ||= 'Document'
end

attrs = secure(Node) { Node.transform_attributes(attrs) }
Expand Down
20 changes: 17 additions & 3 deletions lib/zena/use/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def icon_finder

module ImageTags
include Common
IMG_TAG_EXTRA_RE = %r{UUID|(PATH)_([a-z]+)\.([a-z]+)}
IMG_TAG_EXTRA_JS = %r{\[JS\](.*?)\[/JS\]}

# This is used by _crop.rhtml
def crop_formats(obj)
Expand Down Expand Up @@ -71,7 +73,19 @@ def asset_img_tag(obj, opts)
# Hand made image tag
if img_tag.kind_of?(String)
# We use code to make it raw.
return raw_content(img_tag.gsub('UUID', "img#{UUIDTools::UUID.random_create.to_s.gsub('-','')[0..6]}"))
uuid = "img#{UUIDTools::UUID.random_create.to_s.gsub('-','')[0..6]}"
tag = img_tag.gsub(IMG_TAG_EXTRA_RE) do
if $& == 'UUID'
uuid
elsif $1 == 'PATH'
zen_path(obj, :mode => $2, :format => $3)
end
end
tag.gsub!(IMG_TAG_EXTRA_JS) do
self.js_data << $1
''
end
return raw_content(tag)
end
elsif img_tag = obj.prop["img_tag"]
if img_tag.kind_of?(Hash) && img_tag = img_tag[opts[:mode] || 'std']
Expand Down Expand Up @@ -537,7 +551,7 @@ def extract_label(res, attribute)
# Insert javascript asset tags
def r_javascripts
if @params[:list] == 'all' || @params[:list].nil?
list = %w{ prototype effects dragdrop window zena grid }
list = %w{ prototype effects dragdrop window zena grid upload-progress }
else
list = @params[:list].split(',').map{|e| e.strip}
end
Expand Down Expand Up @@ -584,7 +598,7 @@ def r_javascripts
# Insert stylesheet asset tags
def r_stylesheets
if @params[:list] == 'all' || @params[:list].nil?
list = %w{ reset window zena code grid }
list = %w{ reset window zena code grid upload-progress }
else
list = @params[:list].split(',').map{|e| e.strip}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def form_hidden_fields(opts)
end

def r_upload_field
"<%= upload_field(:uuid => #{get_context_var('upload', 'uuid').inspect}) %>"
"<%= upload_field(:uuid => #{get_context_var('upload', 'uuid').inspect}, :dom => #{node.dom_prefix.inspect}) %>"
end

def r_textarea
Expand Down
5 changes: 3 additions & 2 deletions lib/zena/use/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def upload_form_tag(url_opts, html_opts = {})

def upload_field(opts = {})
uuid = opts[:uuid] || @uuid
dom = opts[:dom] || 'node'
case opts[:type].to_s
when 'onclick'
link = link_to_remote(_("change"), :update=>'upload_field', :url => get_uf_documents_path(:uuid => @uuid), :method => :get, :complete=>"['file', 'upload_field'].each(Element.toggle);")
Expand All @@ -203,10 +204,10 @@ def upload_field(opts = {})
TXT
else
attach_file_id, attach_url_id = "af#{uuid}", "au#{uuid}"
onchange = %Q{onchange="Zena.get_filename(this,'node_title'); $('node_title').focus(); $('node_title').select();"}
onchange = %Q{onchange="Zena.get_filename(this,'#{dom}_title'); $('#{dom}_title').focus(); $('#{dom}_title').select();"}
<<-TXT
<div id='#{attach_file_id}' class='attach'><label for='attachment' onclick=\"['#{attach_file_id}', '#{attach_url_id}'].each(Element.toggle);\">#{_('file')} / <span class='off'>#{_('url')}</span></label>
<input style='line-height:1.5em;' id="attachment#{uuid}" name="attachment" #{onchange} class='file' type="file" /></div>
<input style='line-height:1.5em;' id="attachment#{uuid}" name="attachment" #{onchange} class='file' type='file'/></div>
<div id='#{attach_url_id}' class='attach' style='display:none;'><label for='url' onclick=\"['#{attach_file_id}', '#{attach_url_id}'].each(Element.toggle);\"><span class='off'>#{_('file')}</span> / #{_('url')}</label>
<input style='line-height:1.5em;' size='30' id='attachment_url' type='text' #{onchange} name='attachment_url'/><br/></div>
Expand Down
9 changes: 7 additions & 2 deletions test/integration/zafu_compiler/display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,14 @@ each_alternate_by_hand:

with_a_custom_img_tag_field:
# img_tag field set in test.
src: "<r:zazen text='!22! !22_pv!'/> IMG: <r:img/>"
res: "<div class='zazen'><foobar>IMAGE</foobar> <a class='popup' href='/oo/status-title/status-title/page22.html' target='_blank'><img src='/images/ext/page_pv.png' width='70' height='70' alt='Page node' class='node'/></a></div> IMG: <foobar>IMAGE</foobar>"
src: "<r:zazen text='A:!22! B:!22_pv!'/> C:<r:img/>"
res: "/A:<foobar>PATH=.*page22_std.html uuid=img.*</foobar> B:.*<img src='/images/ext/page_pv.png'.*C:<foobar>PATH=.*page22_std.html uuid=img.*</foobar>/"

with_a_custom_img_tag_field_with_JS:
# img_tag field set in test.
src: "<r:zazen text='A:!22!'/> C:<r:img/>"
res: "<div class='zazen'><p>A:blah blah blah blah </p></div> C:blah blah blah blah "
js: "/\nsome js\nmore JS\nsome js\nmore JS\n/"
invalid_document:
src: "<r:zazen text='!21!'/>"
res: "/images/ext/project.png/"
11 changes: 10 additions & 1 deletion test/integration/zafu_compiler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,20 @@ def test_dates_time_year
def test_display_with_a_custom_img_tag_field
login(:lion)
node = secure(Node) { nodes(:status) }
node.prop['img_tag_std'] = "<foobar>IMAGE</foobar>"
node.prop['img_tag_std'] = "<foobar>PATH=PATH_std.html uuid=UUID</foobar>"
node.send(:dump_properties)
Zena::Db.execute "UPDATE versions SET properties = #{Zena::Db.quote(node.version[:properties])}"
yt_do_test('display', 'with_a_custom_img_tag_field')
end

def test_display_with_a_custom_img_tag_field_with_JS
login(:lion)
node = secure(Node) { nodes(:status) }
node.prop['img_tag_std'] = "blah blah [JS]some js[/JS]blah blah [JS]more JS[/JS]"
node.send(:dump_properties)
Zena::Db.execute "UPDATE versions SET properties = #{Zena::Db.quote(node.version[:properties])}"
yt_do_test('display', 'with_a_custom_img_tag_field_with_JS')
end

yt_make
end

0 comments on commit 043e6d0

Please sign in to comment.