Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add z3c inspector interface for inspecting utilities and adapters.
  • Loading branch information
jone committed Oct 16, 2012
1 parent e3c7ee6 commit 06cc90b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bundles/ergonomic/bundle.el
Expand Up @@ -182,7 +182,11 @@
(cabbage-global-set-key (kbd "C-c f r") 'cabbage-plone-reload-code)
(cabbage-global-set-key (kbd "C-c f f") 'cabbage-plone-run)
(cabbage-global-set-key (kbd "C-c f t") 'cabbage-plone-tests)
(cabbage-global-set-key (kbd "C-c f p") 'cabbage-plone--pep8-package))
(cabbage-global-set-key (kbd "C-c f p") 'cabbage-plone--pep8-package)
(cabbage-global-set-key (kbd "C-c f a") 'cabbage-plone-find-adapter-by-name)
(cabbage-global-set-key (kbd "C-c f A") 'cabbage-plone-find-adapter-by-providing-interface)
(cabbage-global-set-key (kbd "C-c f u") 'cabbage-plone-find-utility-by-name)
(cabbage-global-set-key (kbd "C-c f U") 'cabbage-plone-find-utility-by-providing-interface))

;; cabbage-developer bundle bindings
(when (cabbage-bundle-active-p 'cabbage-developer)
Expand Down
2 changes: 1 addition & 1 deletion bundles/plone/bundle.el
Expand Up @@ -46,7 +46,7 @@ optional parameters."

;; dependencies
(cabbage-vendor 'textmate)
(cabbage-load-bundle-dependencies "plone" '("lookup" "buildout"))
(cabbage-load-bundle-dependencies "plone" '("lookup" "buildout" "z3cinspect"))

;; add additional files / directories to execlude from textmate-goto-file
(when (not (string-match "eggs" *textmate-gf-exclude*))
Expand Down
85 changes: 85 additions & 0 deletions bundles/plone/z3cinspect.el
@@ -0,0 +1,85 @@
;; Finds components in the zope 3 component registry of the current instance
;; using collective.z3cinspector (http://github.com/collective/collective.z3cinspector)


(require 'url-http)
(cabbage-vendor 'json)


(defun cabbage-plone-find-adapter-by-name ()
"Find a adapter by its name by searching the component registry of the current
zope instance."
(interactive)
(cabbage-plone--z3c-lookup "adapter_name"))

(defun cabbage-plone-find-adapter-by-providing-interface ()
"Find a adapter by the interface it provides by searching the component
registry of the current zope instance."
(interactive)
(cabbage-plone--z3c-lookup "adapter_provided_name"))

(defun cabbage-plone-find-utility-by-name ()
"Find a utility by its name by searching the component registry of the current
zope instance."
(interactive)
(cabbage-plone--z3c-lookup "utility_name"))

(defun cabbage-plone-find-utility-by-providing-interface ()
"Find a utility by the interface it provides by searching the component
registry of the current zope instance."
(interactive)
(cabbage-plone--z3c-lookup "utility_provided_name"))



(defun cabbage-plone--z3c-lookup (type)
"Search the component registry for adapters and utilities."
(cabbage-plone--make-request
(concat "@@inspector-ajax/" type "s")

(lambda (status type)
(let ((value (ido-completing-read
(concat type ": ")
(coerce (cabbage-plone--read-json-from-request) 'list))))

(when value
(cabbage-plone--make-request
(concat "@@inspector-ajax/list_components?" type "=" value "&format=as_text")

(lambda (status)
(switch-to-buffer (current-buffer))
(goto-char (point-min))
(delete-region (point-min) (search-forward "\n\n"))
(cabbage-plone--buttonize-buffer)
(call-interactively 'beginning-of-buffer))))))

(list type)))


(define-button-type 'cabbage-plone--find-file-button
'follow-link t
'action #'cabbage-plone--find-file-button)


(defun cabbage-plone--find-file-button (button)
(let* ((location (buffer-substring (button-start button) (button-end button)))
(path location)
(line "0"))

(when (string-match ":" location)
(let ((parts (split-string location ":")))
(setq path (car parts))
(setq line (car (cdr parts)))))

(find-file path)
(goto-line (string-to-number line))))


(defun cabbage-plone--buttonize-buffer ()
"turn all file paths into buttons"
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "/[^ \t\r\n]*" nil t)
(make-button (match-beginning 0) (match-end 0) :type
'cabbage-plone--find-file-button))))

0 comments on commit 06cc90b

Please sign in to comment.