[TxMt] Blogging bundle: support for dragging files that are not images?

Brett Terpstra brett at circlesixdesign.com
Thu Nov 2 02:27:29 UTC 2006


This just needs a couple of tweaks.  First, the upload_name_for_path  
should be rewritten for this purpose to preserve the filename  
whenever possible, replace Upload Image in the dialog box with Upload  
File, and indicate that the text entered will be the text of the  
URL.  The HTML portion that you've included is incorrect and needs to  
be something more like: print %Q{<a href="#{url}">#{alt}</a>}.  Alt  
could come back as just plain text without underscores or anything  
and there's no need for width and height.

Your def is also missing two end statements at the end of it... just  
for reference ;-).

I also think that, for the sake of inclusiveness, the command should  
be scoped to handle just about anything besides images but ask first  
before uploading with a quick yes/no dialog.

I've got a working version right now but am adding some of the above  
ideas. If anyone is interested I'll tweak it up and send it along to  
add to the discussion.

Brett

On Nov 1, 2006, at 2:03 PM, Daniel Käsmayr wrote:

> Hello Allan,
>
> I don't know about patches, but this will, at least upload files  
> and insert Markdown/<a href> links to the uploaded file… I don't  
> know about textile, so feel free to add that. Of course, it would  
> be much more clean if one had just one method for uploading but the  
> hack works, I believe.
>
> As for the dragged URLs: this would need to be done on a TextMate  
> level, but the dragged item should be noted as URL by the OS, and  
> as such we would just need some mechanism for accepting it ;) I  
> guess it would take Allan about -56 seconds to do so, and yes I  
> have read the "bug reporting how to" by ranchero.com ;)
>
> Just add this to blogging.rb
>
>   def upload_file
>     require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb"
>     require "#{ENV['TM_SUPPORT_PATH']}/lib/escape.rb"
>     require 'xmlrpc/base64'
>
>     # Makes sure endpoint is determined and elements are parsed
>     current_password = password
>
>     # The packet we will be constructing
>     data = {}
>
>     full_path = ENV['TM_DROPPED_FILEPATH']
>     upload_name, alt = upload_name_for_path(full_path)
>
>     data['name'] = upload_name
>     data['bits'] = XMLRPC::Base64.new(IO.read(full_path))
>
>     TextMate.call_with_progress(:title => "Upload File", :message  
> => "Uploading to Server “#{@host}”…") do
>       begin
>         result = client.newMediaObject(self.blog_id, self.username,  
> current_password, data)
>         url = result['url']
>         if url
>           case ENV['TM_SCOPE']
>             when /\.markdown/
>               print "[${1:#{alt}}](#{url})"
>             else
>               print %Q{<a href="#{url}" alt="${1:#{CGI::escapeHTML  
> alt}}"#{height_width}#{ENV['TM_XHTML']}>}
>           end
>         else
>           TextMate.exit_show_tool_tip("Error uploading file.")
>         end
>       rescue XMLRPC::FaultException => e
>         TextMate.exit_show_tool_tip("Error uploading file. Check  
> your configuration and try again.")
>       end
>
> Dan
>
> PS: Thanks to the original blogging.rb code and the fact that ruby  
> is so easy to read and understand, even for non-rubyists like  
> myself ;)
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate

Brett Terpstra : Art Director
Circle Six Design, Inc.
111 Riverfront Dr, Suite 204
..................................................
p: 507.459.4398
     877.858.4332
f: 1.866.540.3063
e: brett at circlesixdesign.com
http://www.circlesixdesign.com
..................................................





More information about the textmate mailing list