Permalink
Browse files

Support listing of Rails views

  • Loading branch information...
noklesta committed Dec 28, 2011
1 parent 7a0aee6 commit 588b42b15701a7485438aa57cfeef16579f3a624
Showing with 14 additions and 5 deletions.
  1. +7 −2 ANRailsNav.py
  2. +4 −0 Default.sublime-commands
  3. +3 −3 recursive_glob.py
View
@@ -6,7 +6,7 @@
class RailsMixin:
- def show_files(self, segment):
+ def show_files(self, segment, file_pattern='\.rb$'):
self.root = self.rails_root()
if not self.root:
sublime.error_message('No Gemfile found. Not a Rails 3 application?')
@@ -15,7 +15,7 @@ def show_files(self, segment):
path = self.construct_glob_path(segment)
start_index = len(self.root) + 1
- self.files = rglob(path, '*.rb')
+ self.files = rglob(path, file_pattern)
relative_paths = map(lambda x: x[start_index:], self.files)
self.window.show_quick_panel(relative_paths, self.file_selected)
@@ -47,3 +47,8 @@ def run(self):
class ListRailsControllersCommand(sublime_plugin.WindowCommand, RailsMixin):
def run(self):
self.show_files('controllers')
+
+
+class ListRailsViewsCommand(sublime_plugin.WindowCommand, RailsMixin):
+ def run(self):
+ self.show_files('views', '\.erb$')
View
@@ -6,5 +6,9 @@
{
"caption": "ANRailsNav: List controllers",
"command": "list_rails_controllers"
+ },
+ {
+ "caption": "ANRailsNav: List views",
+ "command": "list_rails_views"
}
]
View
@@ -1,12 +1,12 @@
-# from http://stackoverflow.com/a/2186639
+# Inspired by http://stackoverflow.com/a/2186639
import os
-import fnmatch
+import re
def rglob(treeroot, pattern):
results = []
for base, dirs, files in os.walk(treeroot):
- goodfiles = fnmatch.filter(files, pattern)
+ goodfiles = filter(lambda x: re.search(pattern, x), files)
results.extend(os.path.join(base, f) for f in goodfiles)
return results

0 comments on commit 588b42b

Please sign in to comment.