Commits

Dan Peleg committed d265e5d

Initial Commit.

  • Participants

Comments (0)

Files changed (10)

Quick Rails.pyc

Binary file added.
+import sublime, sublime_plugin
+import re
+import os
+import os.path
+import time
+
+rails_root_cache = {}
+
+def rails_root(directory):
+    global rails_root_cache
+
+    retval = False
+    leaf_dir = directory
+
+    if leaf_dir in rails_root_cache and rails_root_cache[leaf_dir]['expires'] > time.time():
+        return rails_root_cache[leaf_dir]['retval']
+
+    while directory:
+        if os.path.exists(os.path.join(directory, '.idea')):
+            retval = directory
+            break
+        parent = os.path.realpath(os.path.join(directory, os.path.pardir))
+        if parent == directory:
+            # /.. == /
+            retval = False
+            break
+        directory = parent
+
+    rails_root_cache[leaf_dir] = {
+        'retval': retval,
+        'expires': time.time() + 5
+    }
+
+    return retval
+
+# for readability code
+def rails_root_exist(directory):
+    return rails_root(directory)
+
+def get_idea(directory):
+  root = rails_root(directory)
+  return os.path.join(root, '.idea')
+
+
+class QuickRailsWindowCommand(sublime_plugin.WindowCommand):
+  def active_view(self):
+    return self.window.active_view()
+
+  def _active_file_name(self):
+    view = self.active_view()
+    if view and view.file_name() and len(view.file_name()) > 0:
+      return view.file_name()
+
+  # If there is a file in the active view use that file's directory to
+  # search for the Rails root.  Otherwise, use the only folder that is
+  # open.
+  def get_working_dir(self):
+    file_name = self._active_file_name()
+    if file_name:
+      return os.path.realpath(os.path.dirname(file_name))
+    else:
+      try:  # handle case with no open folder
+        return self.window.folders()[0]
+      except IndexError:
+        return ''
+
+  # If there's no active view or the active view is not a file on the
+  # filesystem (e.g. a search results view)
+  def is_enabled(self):
+    if self._active_file_name() or len(self.window.folders()) == 1:
+      return rails_root(self.get_working_dir())
+
+  def run_shell_command(self, command, working_dir):
+    if not command:
+      return False
+    self.window.run_command("exec", {
+      "cmd": [command],
+      "shell": True,
+      "working_dir": working_dir,
+      "file_regex": r"([^ ]*\.rb):?(\d*)"
+    })
+    self.display_results()
+    return True

QuickRails.pyc

Binary file added.

QuickRails.sublime-commands

+[
+    {
+      "caption": "QuickRails: Generators",
+      "command": "quick_rails_generators"
+    },
+    {
+      "caption": "QuickRails: Rake Tasks",
+      "command": "quick_rails_rake_tasks"
+    }
+]

RailsQuick.pyc

Binary file added.
+import os
+import re
+
+import sublime
+from QuickRails import QuickRailsWindowCommand, get_idea
+import add
+
+class QuickRailsGeneratorsCommand(QuickRailsWindowCommand):
+  def run(self):
+    self.generators = self.get_available_generators()
+    self.window.show_quick_panel(self.generators, self.on_selected)
+
+  def on_selected(self, selected):
+     self.generate(self.generators[selected])
+
+  def generate(self, argument):
+    self.window.show_input_panel("rails generate", argument + " ", lambda s: self.run_generator(s), None, None)
+
+  def run_generator(self, argument):
+    command = 'rails generate {thing}'.format(thing=argument)
+    self.run_shell_command(command, self.window.folders()[0])
+
+  def get_available_generators(self):
+    f = open(os.path.join(get_idea(self.get_working_dir()), '.generators'), 'r')
+    data = f.read()
+    f.close()
+    return re.findall('Generator name="(.*?)"', data)

generators.pyc

Binary file added.
+{
+	"install": "messages/install.txt",
+	"1.0.0": "messages/1.1.1.txt"
+}

rails_quick.pyc

Binary file added.

rails_quick_generators.pyc

Binary file added.