[TxMt] Blogging bundle: support for dragging files that are not images?
Daniel Käsmayr
daniel at kaesmayr.net
Wed Nov 1 20:03:36 UTC 2006
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 ;)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3996 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20061101/51896cd6/attachment.p7s>
More information about the textmate
mailing list