put textmate import stuff in extras directory

This commit is contained in:
capitaomorte 2009-08-26 07:00:27 +00:00
parent feefc950bb
commit 2739789231
2 changed files with 77 additions and 42 deletions

27
extras/textmate_mass_import.rb Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/ruby
require 'rubygems'
require 'curb'
require 'hpricot'
require 'plist'
begin
index = Curl::Easy.http_get("http://svn.textmate.org/trunk/Bundles/").body_str
parsed = Hpricot.parse(index)
bundles = (parsed/:a).map {|elem| elem.innerText}
bundles.select do |bundle|
bundle =~ /.tmbundle/
end.each do |bundle|
50.times do putc "-" end
puts
begin
info = Curl::Easy.http_get("http://svn.textmate.org/trunk/Bundles/#{bundle}/info.plist").body_str
parsed = Plist::parse_xml(info)
puts parsed["description"]
rescue RuntimeError
puts "Unknown description for #{bundle}"
end
end
rescue Exception => e
$stderr.puts "Oops... #{e.class}:#{e.message}"
end

View File

@ -82,16 +82,24 @@ end
class TmSnippet class TmSnippet
@@known_substitutions = { @@known_substitutions = {
"${TM_RAILS_TEMPLATE_START_RUBY_EXPR}" => "<%= ", "${TM_RAILS_TEMPLATE_START_RUBY_EXPR}" => "<%= ",
"${TM_RAILS_TEMPLATE_END_RUBY_EXPR}" => " %>", "${TM_RAILS_TEMPLATE_END_RUBY_EXPR}" => " %>",
"${TM_RAILS_TEMPLATE_START_RUBY_INLINE}" => "<% ", "${TM_RAILS_TEMPLATE_START_RUBY_INLINE}" => "<% ",
"${TM_RAILS_TEMPLATE_END_RUBY_INLINE}" => " -%>", "${TM_RAILS_TEMPLATE_END_RUBY_INLINE}" => " -%>",
"${TM_RAILS_TEMPLATE_END_RUBY_BLOCK}" => "end" , "${TM_RAILS_TEMPLATE_END_RUBY_BLOCK}" => "end" ,
/$\{TM_SELECTED_TEXT.*\}/ => "`yas/selected-text`" } /$\{TM_SELECTED_TEXT.*\}/ => "`yas/selected-text`" }
attr_reader :file
# Makes a TmSnippet
#
# * file is the .tmsnippet/.plist file path relative to cwd
# * optional info is a Plist.parsed info.plist found in the bundle dir
#
def initialize(file,info=nil) def initialize(file,info=nil)
@file = file
@info = info
@snippet = Plist::parse_xml(file) @snippet = Plist::parse_xml(file)
@info=info
end end
def name def name
@ -135,48 +143,48 @@ class TmSnippet
@@known_substitutions.each_pair { |k, v| self.content.gsub!(k,v) } @@known_substitutions.each_pair { |k, v| self.content.gsub!(k,v) }
doc << "#{self.content}" doc << "#{self.content}"
end end
def yasnippet_dir(dir)
dir = File.join(dir,File.dirname(@file))
dir = File.join(dir,group) if group
end
end end
def yasnippet_dir_and_name(dir, file)
dir = File.join(dir,File.dirname(file))
file = File.join(File.basename(file, File.extname(file))) << ".yasnippet"
[dir, file]
end
info_plist = Plist::parse_xml(Choice.choices.info_plist) if Choice.choices.info_plist
original_dir = Dir.pwd if $0 == __FILE__
Dir.chdir Choice.choices.snippet_dir info_plist = Plist::parse_xml(Choice.choices.info_plist) if Choice.choices.info_plist
snippet_files_glob = File.join("**", Choice.choices.snippet)
snippet_files = Dir.glob(snippet_files_glob)
puts "Will try to convert #{snippet_files.length} snippets...\n" original_dir = Dir.pwd
Dir.chdir Choice.choices.snippet_dir
snippet_files_glob = File.join("**", Choice.choices.snippet)
snippet_files = Dir.glob(snippet_files_glob)
snippet_files.each do |file| puts "Will try to convert #{snippet_files.length} snippets...\n"
puts "Processing \"#{File.join(Choice.choices.snippet_dir,file)}\"\n"
snippet = TmSnippet.new(file,info_plist) snippet_files.each do |file|
if Choice.choices.output_dir puts "Processing \"#{File.join(Choice.choices.snippet_dir,file)}\"\n"
begin snippet = TmSnippet.new(file,info_plist)
( dir_to_create, file_to_create ) = if Choice.choices.output_dir
yasnippet_dir_and_name(File.join(original_dir, begin
Choice.choices.output_dir, dir_to_create = snippet.yasnippet_dir(File.join(original_dir, Choice.choices.output_dir))
(snippet.group or "")), FileUtils.mkdir_p(dir_to_create)
file) File.open(File.join(dir_to_create,file_to_create), 'w') do |f|
FileUtils.mkdir_p(dir_to_create) f.write(snippet.to_yasnippet)
File.open(File.join(dir_to_create,file_to_create), 'w') do |f| end
f.write(snippet.to_yasnippet) rescue RuntimeError => e
$stderr.puts "Oops... #{e.class}:#{e.message}"
end end
rescue RuntimeError => error else
$stderr.print error.message + "\n" if Choice.choices.print_pretty
puts "--------------------------------------------"
end
puts snippet.to_yasnippet
if Choice.choices.print_pretty
puts "--------------------------------------------"
end
puts "\n\n"
end end
else
if Choice.choices.print_pretty
puts "--------------------------------------------"
end
puts snippet.to_yasnippet
if Choice.choices.print_pretty
puts "--------------------------------------------"
end
puts "\n\n"
end end
end end