mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
put textmate import stuff in extras directory
This commit is contained in:
parent
feefc950bb
commit
2739789231
27
extras/textmate_mass_import.rb
Executable file
27
extras/textmate_mass_import.rb
Executable 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
|
@ -89,9 +89,17 @@ class TmSnippet
|
||||
"${TM_RAILS_TEMPLATE_END_RUBY_BLOCK}" => "end" ,
|
||||
/$\{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)
|
||||
@file = file
|
||||
@info = info
|
||||
@snippet = Plist::parse_xml(file)
|
||||
@info=info
|
||||
end
|
||||
|
||||
def name
|
||||
@ -135,39 +143,38 @@ class TmSnippet
|
||||
@@known_substitutions.each_pair { |k, v| self.content.gsub!(k,v) }
|
||||
doc << "#{self.content}"
|
||||
end
|
||||
|
||||
def yasnippet_dir(dir)
|
||||
dir = File.join(dir,File.dirname(@file))
|
||||
dir = File.join(dir,group) if group
|
||||
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
|
||||
Dir.chdir Choice.choices.snippet_dir
|
||||
snippet_files_glob = File.join("**", Choice.choices.snippet)
|
||||
snippet_files = Dir.glob(snippet_files_glob)
|
||||
if $0 == __FILE__
|
||||
info_plist = Plist::parse_xml(Choice.choices.info_plist) if Choice.choices.info_plist
|
||||
|
||||
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"
|
||||
|
||||
snippet_files.each do |file|
|
||||
puts "Processing \"#{File.join(Choice.choices.snippet_dir,file)}\"\n"
|
||||
snippet = TmSnippet.new(file,info_plist)
|
||||
if Choice.choices.output_dir
|
||||
begin
|
||||
( dir_to_create, file_to_create ) =
|
||||
yasnippet_dir_and_name(File.join(original_dir,
|
||||
Choice.choices.output_dir,
|
||||
(snippet.group or "")),
|
||||
file)
|
||||
dir_to_create = snippet.yasnippet_dir(File.join(original_dir, Choice.choices.output_dir))
|
||||
FileUtils.mkdir_p(dir_to_create)
|
||||
File.open(File.join(dir_to_create,file_to_create), 'w') do |f|
|
||||
f.write(snippet.to_yasnippet)
|
||||
end
|
||||
rescue RuntimeError => error
|
||||
$stderr.print error.message + "\n"
|
||||
rescue RuntimeError => e
|
||||
$stderr.puts "Oops... #{e.class}:#{e.message}"
|
||||
end
|
||||
else
|
||||
if Choice.choices.print_pretty
|
||||
@ -179,4 +186,5 @@ snippet_files.each do |file|
|
||||
end
|
||||
puts "\n\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user