Sublime Text 2 plugin: Simple Rails Navigator

Simple plugin for navigating Ruby on Rails applications.


NOTE: The master branch is not compatible with Sublime Text 3, but there is now a separate ST3 branch (thanks @doz!) that works with ST3 (and is incompatible with ST2). Until Package Control for ST3 is ready, the ST3 version can be installed by cloning the GitHub repo (see Clone from GitHub below) and running git checkout ST3.


This plugin provides commands for listing models, controllers, views, helpers, fixtures, tests/specs, javascript files, or stylesheets in a quick panel for easy selection.

Related files are located at the top of the list so that they can be selected simply by pressing Enter. For instance, if the active view is a Rails model and you request a list of controllers, the controller corresponding to the model will be listed at the top, provided that you follow normal Rails resource conventions with the controller name containing the pluralized version of the model name (e.g. post.rb and posts_controller.rb).

The same goes for tests or specs (in the example case, the test file should be called test/unit/post_test.rb or spec/models/post_spec.rb). If the application contains a spec directory, the plugin will search for specs and ignore the test directory; otherwise the test directory will be used.

The following table shows which related files will be put at the top of the list:

Active file Listing these file types will show related files at the top of the list
model controller; fixture; model unit test/model spec
controller model; views; helper; functional test/controller spec
view controller; functional test/view spec
helper controller; helper unit test/helper spec
fixture model; model unit test/model spec; functional test/controller spec
model unit test/model spec model; fixture
functional test controller; views; fixture
controller spec controller; fixture
view spec view
helper unit test/helper spec helper
routes.rb route specs

This plugin was inspired by Luqman Amjad's Rails Related Files plugin. The plugins have complementary functionality (Amjad's plugin shows related files of all types in a single list), and they can be used together.

Installation

Package Control

The easiest way to install this is with Package Control.

  • If you just went and installed Package Control, you probably need to restart Sublime Text 2 before doing this next bit.
  • Bring up the Command Palette (Command+Shift+p on OS X, Control+Shift+p on Linux/Windows).
  • Select "Package Control: Install Package" (it'll take a few seconds)
  • Select Simple Rails Navigator when the list appears.

Package Control will automatically keep the Simple Rails Navigator up to date with the latest version.

Clone from GitHub

Alternatively, you can clone the repository directly from GitHub into your Packages directory:

git clone http://github.com/noklesta/SublimeRailsNav

Key bindings

The plugin does not install any key bindings automatically. The following is an example of how you can set up your own key bindings. To make sure they don't conflict with existing commands, first run sublime.log_commands(True) in the console, try out the key combinations and see if anything is logged.

{ "keys": ["super+ctrl+m"], "command": "list_rails_models" },
{ "keys": ["super+ctrl+c"], "command": "list_rails_controllers" },
{ "keys": ["super+ctrl+v"], "command": "list_rails_views" },
{ "keys": ["super+ctrl+h"], "command": "list_rails_helpers" },
{ "keys": ["super+ctrl+x"], "command": "list_rails_fixtures" },
{ "keys": ["super+ctrl+t"], "command": "list_rails_tests" },
{ "keys": ["super+ctrl+i"], "command": "list_rails_javascripts" },
{ "keys": ["super+ctrl+y"], "command": "list_rails_stylesheets" }

If you are using Vintage mode and want to use sequences of non-modifier keys, you can restrict the key bindings to command mode like this:

{ "keys": [" ", "m"], "command": "list_rails_models", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "c"], "command": "list_rails_controllers", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "v"], "command": "list_rails_views", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "h"], "command": "list_rails_helpers", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "x"], "command": "list_rails_fixtures", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "t"], "command": "list_rails_tests", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "i"], "command": "list_rails_javascripts", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "y"], "command": "list_rails_stylesheets", "context": [{"key": "setting.command_mode"}] }

All commands are also available from the Command Palette (search for commands beginning with "Simple Rails Navigator").

Settings

The settings in SublimeRailsNav.sublime-settings may be overridden either in Packages/User/SublimeRailsNav.sublime-settings or, for a particular project, in the project file under a top-level "settings" key. An example of the latter:

"settings":
{
  "SublimeRailsNav":
  {
    "javascript_locations": [
      ["app", "assets", "javascripts"]
    ],
    "stylesheet_locations": [
      ["app", "assets", "stylesheets"],
      ["lib", "assets", "stylesheets"]
    ]
  }
}

Credits

  • Inspiration from Luqman Amjad's Rails Related Files plugin for ST2 and from Tim Pope's rails.vim plugin for Vim (which contains sooo much more functionality than this one, of course :-)
  • Python version of the Rails inflector: https://bitbucket.org/ixmatus/inflector
  • Contains a modified version of a small code snippet from the Git package for ST2.

Licence

All of SublimeRailsNav is licensed under the MIT licence.

Copyright (c) 2012 Anders Nøklestad

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



Sublime Text 2 plugin: Simple Rails Navigator

用于导航Ruby on Rails应用程序的简单插件。


注意:主分支与Sublime Text 3不兼容,但在那里 现在是一个单独的 ST3 分支(感谢@doz!),与ST3一起使用(与ST2不兼容)。 直到ST3的包控制准备就绪,才能安装ST3版本 克隆GitHub repo(参见下面的GitHub 的克隆),并运行 git checkout ST3


此插件提供了列出模型,控制器,视图,帮助器, 快速面板中的灯具,测试/规格,JavaScript文件或样式表 轻松选择。

相关文件位于列表的顶部,以便可以选择它们 只需按Enter键即可。例如,如果活动视图是Rails模型 并且您要求一个控制器列表,控制器对应 模型将列在顶部,只要您遵循正常的Rails 资源约定与控制器名称包含复数 版本的型号名称(例如 post.rb posts_controller.rb )。

测试或规范也是如此(在示例中,测试文件应该是 称为 test / unit / post_test.rb spec / models / post_spec.rb )。如果 应用程序包含一个 spec 目录,该插件将搜索规格和 忽略 test 目录;否则将使用 test 目录。

下表显示了列表顶部的相关文件:

Active file Listing these file types will show related files at the top of the list
model controller; fixture; model unit test/model spec
controller model; views; helper; functional test/controller spec
view controller; functional test/view spec
helper controller; helper unit test/helper spec
fixture model; model unit test/model spec; functional test/controller spec
model unit test/model spec model; fixture
functional test controller; views; fixture
controller spec controller; fixture
view spec view
helper unit test/helper spec helper
routes.rb route specs

这个插件灵感来自Luqman Amjad的Rails相关文件插件。的 插件具有互补功能(Amjad的插件显示相关文件 所有类型在单个列表中),并且它们可以一起使用。

安装

软件包控制

最简单的安装方式是软件包 控制

  • 如果您刚刚安装了Package Control,则可能需要重新启动Sublime Text 2才能执行下一步。
  • 启动命令调色板(OS +上的Command + Shift + p,Linux / Windows上的Control + Shift + p)。
  • 选择软件包控制:安装软件包(需要几秒钟)
  • 当列表出现时,选择简单路径导航器。
软件包控制将自动使Simple Rails Navigator保持最新 与最新版本。

从GitHub克隆

或者,您可以将存储库直接从GitHub克隆到您的Packages目录中:

git clone http://github.com/noklesta/SublimeRailsNav

键绑定

插件不会自动安装任何键绑定。以下是 一个如何设置自己的键绑定的例子。确保他们 不要与现有命令冲突,首先运行 sublime.log_commands(True) 在控制台中,尝试组合键并查看是否记录了任何内容。

{ "keys": ["super+ctrl+m"], "command": "list_rails_models" },
{ "keys": ["super+ctrl+c"], "command": "list_rails_controllers" },
{ "keys": ["super+ctrl+v"], "command": "list_rails_views" },
{ "keys": ["super+ctrl+h"], "command": "list_rails_helpers" },
{ "keys": ["super+ctrl+x"], "command": "list_rails_fixtures" },
{ "keys": ["super+ctrl+t"], "command": "list_rails_tests" },
{ "keys": ["super+ctrl+i"], "command": "list_rails_javascripts" },
{ "keys": ["super+ctrl+y"], "command": "list_rails_stylesheets" }

如果您正在使用复古模式,并想使用非修饰键序列, 您可以将密钥绑定限制为命令模式,如下所示:

{ "keys": [" ", "m"], "command": "list_rails_models", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "c"], "command": "list_rails_controllers", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "v"], "command": "list_rails_views", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "h"], "command": "list_rails_helpers", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "x"], "command": "list_rails_fixtures", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "t"], "command": "list_rails_tests", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "i"], "command": "list_rails_javascripts", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "y"], "command": "list_rails_stylesheets", "context": [{"key": "setting.command_mode"}] }

所有命令也可以从命令调色板(搜索以简单轨道导航器开头的命令)获取。

设置

SublimeRailsNav.sublime-settings中的设置可能会被覆盖 Packages / User / SublimeRailsNav.sublime-settings或对于特定项目,在 项目文件在顶级设置键下。后者的例子:

"settings":
{
  "SublimeRailsNav":
  {
    "javascript_locations": [
      ["app", "assets", "javascripts"]
    ],
    "stylesheet_locations": [
      ["app", "assets", "stylesheets"],
      ["lib", "assets", "stylesheets"]
    ]
  }
}

信用

  • 灵感来自Luqman Amjad的Rails相关文件插件为ST2和Tim Pope的rails.vim插件为Vim (其中包含了比这个更多的功能,当然: - )
  • Python版本的Rails inflector: https://bitbucket.org/ixmatus/inflector
  • 包含来自ST2的Git包的小型代码段的修改版本。

许可证

所有SublimeRailsNav都是根据麻省理工学院的许可证进行许可的。

版权所有(c)2012 AndersNøklestad

特此授予任何获得副本的人免费许可 的这个软件和相关的文档文件(软件)来处理 软件无限制,包括但不限于权限 使用,复制,修改,合并,发布,分发,再许可和/或销售 软件的副本,并允许本软件的人员 须遵守以下条件:

上述版权声明和本许可声明应包括在内 软件的所有副本或主要部分。

该软件按原样提供,不提供任何明示或暗示的保证 暗示,包括但不限于适销性的保证, 适用于特定用途和非侵权。在任何情况下 作者或版权所有人不得对任何索赔,损害或其他责任负责 责任,无论在合同,侵权行为或其他方面的行为, 与本软件或其使用或其他交易相关或不存在 该软件。




相关问题推荐