lib/sublime_sunippetter.rb in sublime_sunippetter-0.0.4 vs lib/sublime_sunippetter.rb in sublime_sunippetter-0.0.5
- old
+ new
@@ -25,10 +25,13 @@
# add :hige
# if two args method and do-block
# add :hoge1, :args1, :args2, "block@d"
# if two args method and brace-block
# add :hoge2, :args1, :args2, "block@b"
+
+# require snippet
+# add_requires 'file1', 'file2'
EOS
# sublime sunippet template
SUNIPPET_TEMPLATE = <<-EOS
<snippet>
@@ -39,10 +42,22 @@
<scope><%= scope%></scope>
<description><%= method_name %> method</description>
</snippet>
EOS
+ # sublime sunippet require template
+ REQUIRE_SUNIPPET_TEMPLATE = <<-EOS
+<snippet>
+ <content><![CDATA[
+require '<%= require_file %>'
+]]></content>
+ <tabTrigger>require <%= require_file %></tabTrigger>
+ <scope><%= scope%></scope>
+ <description>require <%= require_file %></description>
+</snippet>
+ EOS
+
# generate Sunippetdefine to current directory.
def init
File.open("./#{DEFINE_FILE}", 'w') { |f|f.puts DEFINE_FILE_TEMPLATE }
end
@@ -60,10 +75,15 @@
dsl._scope
)
filename = "#{dsl._output_path}/#{m.method_name.to_s.tr('?', '')}.sublime-snippet"
File.open(filename, 'w:UTF-8') { |f|f.puts snippet }
end
+
+ dsl.requires.each do |r|
+ require_snippet = get_require_snippet(r, dsl._scope)
+ File.open("require_#{r}.sublime-snippet", 'w:UTF-8') { |f|f.puts require_snippet }
+ end
end
private
def read_sunippetdefine
unless File.exists? "./#{DEFINE_FILE}"
@@ -77,11 +97,11 @@
end
def get_args_names(method)
args = method.args
args_names = ' '
- args.each_with_index {|a, i|args_names << "${#{i + 1}:#{a}}, "}
+ args.each_with_index { |a, i|args_names << "${#{i + 1}:#{a}}, " }
args_names.chop!.chop! unless args.empty?
end
def get_do_block(method)
return '' unless method.has_do_block
@@ -93,9 +113,13 @@
end
def get_brace_block(method)
return '' unless method.has_brace_block
' { |${9:args}|${0:block} }'
+ end
+
+ def get_require_snippet(require_file, scope)
+ ERB.new(REQUIRE_SUNIPPET_TEMPLATE).result(binding)
end
end
class SunippetterError < StandardError; end
end