mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
textmate_import.rb now reads info.plist and creates groups (still buggy)
This commit is contained in:
parent
6c88b24bf8
commit
feefc950bb
@ -1,7 +1,6 @@
|
|||||||
#name : -module().
|
#name : -module().
|
||||||
#contributor : hitesh <hitesh.jasani@gmail.com>
|
#contributor : hitesh <hitesh.jasani@gmail.com>
|
||||||
# --
|
# --
|
||||||
-module(${1:$(file-name-nondirectory
|
-module(${1:`(file-name-nondirectory
|
||||||
(file-name-sans-extension (buffer-file-name)))}).
|
(file-name-sans-extension (or (buffer-file-name) (buffer-name))))`}).
|
||||||
$0
|
$0
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
# -f, --file=SNIPPET FILE NAME A specific snippet that you want to copy or a glob for various files
|
# -f, --file=SNIPPET FILE NAME A specific snippet that you want to copy or a glob for various files
|
||||||
# -p, --print-pretty Pretty prints multiple snippets when printing to standard out
|
# -p, --print-pretty Pretty prints multiple snippets when printing to standard out
|
||||||
# -b, --convert-bindings TextMate "keyEquivalent" keys are translated to YASnippet "# binding :" directives
|
# -b, --convert-bindings TextMate "keyEquivalent" keys are translated to YASnippet "# binding :" directives
|
||||||
|
# -g, --info-plist=INFO Attempt to derive group information from "info.plist" type-file PLIST
|
||||||
#
|
#
|
||||||
# Common options:
|
# Common options:
|
||||||
# --help Show this message
|
# --help Show this message
|
||||||
@ -63,6 +64,12 @@ Choice.options do
|
|||||||
desc "TextMate \"keyEquivalent\" keys are translated to YASnippet \"# binding :\" directives"
|
desc "TextMate \"keyEquivalent\" keys are translated to YASnippet \"# binding :\" directives"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
option :info_plist do
|
||||||
|
short '-g'
|
||||||
|
long '--info-plist'
|
||||||
|
desc "Attempt to derive group information from \"info.plist\" type-file PLIST"
|
||||||
|
end
|
||||||
|
|
||||||
separator ''
|
separator ''
|
||||||
separator 'Common options: '
|
separator 'Common options: '
|
||||||
|
|
||||||
@ -82,14 +89,29 @@ class TmSnippet
|
|||||||
"${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`" }
|
||||||
|
|
||||||
def initialize(file)
|
def initialize(file,info=nil)
|
||||||
@snippet = Plist::parse_xml(file)
|
@snippet = Plist::parse_xml(file)
|
||||||
|
@info=info
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
@snippet["name"]
|
@snippet["name"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def group
|
||||||
|
if @info
|
||||||
|
submenus = @info["mainMenu"]["submenus"]
|
||||||
|
container = submenus.keys.find do |submenu|
|
||||||
|
submenus[submenu]["items"].member?(uuid)
|
||||||
|
end
|
||||||
|
submenus[container]["name"] if container;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def uuid
|
||||||
|
@snippet["uuid"]
|
||||||
|
end
|
||||||
|
|
||||||
def tab_trigger
|
def tab_trigger
|
||||||
@snippet["tabTrigger"]
|
@snippet["tabTrigger"]
|
||||||
end
|
end
|
||||||
@ -115,36 +137,14 @@ class TmSnippet
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# def yasnippet_file_name(dir, snippet, ext=nil)
|
|
||||||
# begin
|
|
||||||
# file = ""
|
|
||||||
# shortname = (snippet.tab_trigger or
|
|
||||||
# snippet.name.gsub(/[^a-z0-9_-].*/,""))
|
|
||||||
# if ext
|
|
||||||
# file = File.join(dir, shortname + "." + ext.to_s)
|
|
||||||
# else
|
|
||||||
# file = File.join(dir, shortname)
|
|
||||||
# end
|
|
||||||
# if File.exist?(file)
|
|
||||||
# if ext
|
|
||||||
# file = yasnippet_file_name(dir,snippet, ext+1)
|
|
||||||
# else
|
|
||||||
# file = yasnippet_file_name(dir,snippet, 1)
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# # puts "returning #{file} since shortname is #{shortname}\n"
|
|
||||||
# file
|
|
||||||
# rescue TypeError
|
|
||||||
# raise "Cannot convert " + snippet.name + " (probably no tab-trigger)"
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
def yasnippet_dir_and_name(dir, file)
|
def yasnippet_dir_and_name(dir, file)
|
||||||
dir = File.join(dir,File.dirname(file))
|
dir = File.join(dir,File.dirname(file))
|
||||||
file = File.join(File.basename(file, File.extname(file))) << ".yasnippet"
|
file = File.join(File.basename(file, File.extname(file))) << ".yasnippet"
|
||||||
[dir, file]
|
[dir, file]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
info_plist = Plist::parse_xml(Choice.choices.info_plist) if Choice.choices.info_plist
|
||||||
|
|
||||||
original_dir = Dir.pwd
|
original_dir = Dir.pwd
|
||||||
Dir.chdir Choice.choices.snippet_dir
|
Dir.chdir Choice.choices.snippet_dir
|
||||||
snippet_files_glob = File.join("**", Choice.choices.snippet)
|
snippet_files_glob = File.join("**", Choice.choices.snippet)
|
||||||
@ -154,12 +154,13 @@ puts "Will try to convert #{snippet_files.length} snippets...\n"
|
|||||||
|
|
||||||
snippet_files.each do |file|
|
snippet_files.each do |file|
|
||||||
puts "Processing \"#{File.join(Choice.choices.snippet_dir,file)}\"\n"
|
puts "Processing \"#{File.join(Choice.choices.snippet_dir,file)}\"\n"
|
||||||
snippet = TmSnippet.new(file)
|
snippet = TmSnippet.new(file,info_plist)
|
||||||
if Choice.choices.output_dir
|
if Choice.choices.output_dir
|
||||||
begin
|
begin
|
||||||
( dir_to_create, file_to_create ) =
|
( dir_to_create, file_to_create ) =
|
||||||
yasnippet_dir_and_name(File.join(original_dir,
|
yasnippet_dir_and_name(File.join(original_dir,
|
||||||
Choice.choices.output_dir),
|
Choice.choices.output_dir,
|
||||||
|
(snippet.group or "")),
|
||||||
file)
|
file)
|
||||||
FileUtils.mkdir_p(dir_to_create)
|
FileUtils.mkdir_p(dir_to_create)
|
||||||
File.open(File.join(dir_to_create,file_to_create), 'w') do |f|
|
File.open(File.join(dir_to_create,file_to_create), 'w') do |f|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user