Projectile Hanami

May 6, 2016 ยท View on GitHub

Summary

Projectile Hanami is an Emacs minor mode, based on Projectile, for navigating Hanami projects. With Projectile Hanami, you can:

  • navigate through entities, repositories, actions, views and templates are different apps in your project;
  • quickly jump to some important standard files;
  • run hanami server
  • run hanami console
  • run hanami generate
  • run Rake tasks

Projectile Hanami is based on Projectile Rails, but is not a complete port of all its functionality.

Installation

This guide assumes you have Projectile already set up.

MELPA

If you have MELPA set up, you can use package-install to install the projectile-hanami package.

Manual installation

You can manually install Projectile hanami by cloning the repository and adding it to your load-path:

(add-to-list 'load-path "/path/to/repo")
(require 'projectile-hanami)

Setup

To have Projectile Hanami loaded whenever Projectile is loaded, you can add it as a hook:

(add-hook 'projectile-mode-hook 'projectile-hanami-on)

...but, this will most likely conflict with Projectile Rails. If you use both Ruby on Rails and Hanami, you will probably want something slightly more sophisticated. I use the following snippet:

(defun projectile-rails-or-hanami-on ()
  "Activate either `projectile-rails-mode` or `projectile-hanami-mode`."
  (if (projectile-hanami-applicable-p)
    (projectile-hanami-mode +1)
    (projectile-rails-on)))

(add-hook 'projectile-mode-hook 'projectile-rails-or-hanami-on)

Since Projectile Rails cannot distinguish between Rails and Hanami projects, and Hanami can, we use Projectile Hanami's detection mechanism and fall back to Projectile Rails in case of no match.

Usage

Customization

You can define the Projectile Hanami keybinding prefix:

;; Defaults to C-c ;
(setq projectile-hanami-keymap-prefix (kbd "C-c p C-q"))

To override how Hanami commands are invoked:

;; Defaults to `bundle exec hanami`
(setq projectile-hanami-cmd "/path/to/hanami")

Commands

CommandKeybindingDescription
projectile-hanami-find-initializerC-c ; iUse projectile-completion-system to find initializers across apps.
projectile-hanami-find-libC-c ; lUse projectile-completion-system to find project lib files.
projectile-hanami-find-controllerC-c ; cUse projectile-completion-system to find controller actions across apps.
projectile-hanami-find-viewC-c ; vUse projectile-completion-system to find views across apps.
projectile-hanami-find-templateC-c ; tUse projectile-completion-system to find templates across apps.
projectile-hanami-find-presenterC-c ; pUse projectile-completion-system to find presenters across apps.
projectile-hanami-find-stylesheetC-c ; sUse projectile-completion-system to find stylesheets across apps.
projectile-hanami-find-javascriptC-c ; jUse projectile-completion-system to find javascripts across apps.
projectile-hanami-find-configC-c ; gUse projectile-completion-system to find config files across apps.
projectile-hanami-find-routesC-c ; uUse projectile-completion-system to find routes files across apps.
projectile-hanami-find-entityC-c ; eUse projectile-completion-system to find entities.
projectile-hanami-find-repositoryC-c ; rUse projectile-completion-system to find repositories.
projectile-hanami-find-mailerC-c ; mUse projectile-completion-system to find mailers.
projectile-hanami-find-mailer-templateC-c ; TUse projectile-completion-system to find mailer templates.
projectile-hanami-find-applicationC-c ; aUse projectile-completion-system to find main application files.
projectile-hanami-goto-related-controllerC-c ; CFind the controller action related to the current view or template.
projectile-hanami-goto-related-templateC-c ; TFind the template related to the current view or controller action.
projectile-hanami-goto-related-viewC-c ; VFind the view related to the current template or controller action.
projectile-hanami-goto-entityC-c ; EFind the entity for the current repository.
projectile-hanami-goto-repositoryC-c ; RFind the repository for the current entity.
projectile-hanami-goto-mappingC-c ; g mFind the project's lib/config/mapping.rb file
projectile-hanami-goto-rakefileC-c ; g rFind the project's Rakefile.
projectile-hanami-goto-gemfileC-c ; g gFind the project's Gemfile.
projectile-hanami-rakeC-c ; ! rRun a project Rake task.
projectile-hanami-consoleC-c ; ! cRun hanami console
projectile-hanami-serverC-c ; ! sRun hanami server
projectile-hanami-generateC-c ; ! gRun hanami generate