Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. # Add to ~/Library/Application Support/Sublime Text 3/Packages/User/
  2.  
  3. import sublime
  4. import sublime_plugin
  5.  
  6. class RubyFileSaveListener(sublime_plugin.EventListener):
  7. def on_pre_save(self, view):
  8. file_name = view.file_name()
  9. if file_name.endswith('schema.rb'):
  10. return
  11.  
  12. if file_name.endswith('.rb'):
  13. sublime.active_window().run_command("add_frozen_string_comment")
  14.  
  15. class AddFrozenStringCommentCommand(sublime_plugin.TextCommand):
  16. COMMENT_STRING = "# frozen_string_literal: true"
  17.  
  18. def run(self, edit):
  19. file_name = self.view.file_name()
  20.  
  21. if file_name.endswith('.rb'):
  22. first_line = self.view.line(0)
  23. line_contents = self.view.substr(first_line)
  24. if (line_contents != self.COMMENT_STRING):
  25. self.view.insert(edit, 0, self.COMMENT_STRING + "\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement