rb_nav 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ .DS_Store
2
+ *.swp
3
+ *~.nib
4
+ build/
5
+ *.pbxuser
6
+ *.perspective
7
+ *.perspectivev3
8
+ *.mode1v3
9
+ *.mode2v3
10
+ xcuserdata
11
+ src/
12
+ pkg/
13
+ rdoc-3.6.1/
14
+ other/
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011 Daniel Choi, http://danielchoi.com/software/
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/NOTES ADDED
@@ -0,0 +1,10 @@
1
+
2
+
3
+
4
+ nav/methods.sh app/models/delivery.rb
5
+ nav/nav.sh
6
+
7
+ TODO
8
+ - function to show everywhere a class or method is called in the code
9
+ - autocomplete
10
+ - look for constants too ^\s*[A-Z]\w+\s*=\s*\S
data/README.markdown ADDED
@@ -0,0 +1,91 @@
1
+ # RbNav
2
+
3
+ RbNav is a lightweight Vim pluging that helps you navigate the classes,
4
+ modules, and methods in your Ruby project
5
+
6
+ [screenshots]
7
+
8
+ Benefits
9
+
10
+ * navigate the classes and modules in your Ruby projects with less typing
11
+ * jump to methods on current page more quickly
12
+ * symbol-centric approach to navigation might suit you better than the file-centric approach
13
+
14
+
15
+ ## Prerequisites
16
+
17
+ * Ruby 1.8.6 (tested on 1.9.2)
18
+ * Vim 7.2 or higher
19
+
20
+ ## Install
21
+
22
+ gem install rb_nav
23
+
24
+ Then
25
+
26
+ rb_nav_install
27
+
28
+ This installs the rb_nav.vim plugin into your ~/.vim/plugin directory.
29
+
30
+ To upgrade RbNav to a newer version, just repeat the installation procedure.
31
+ Don't forget to run `rb_nav_install` again after you download the new gem.
32
+
33
+
34
+ ## Commands
35
+
36
+ For the all the commands below, the mapleader is assumed to be `,`. If it is
37
+ `\` or something else for your setup, use that instead.
38
+
39
+ ### Invoking the plugin
40
+
41
+ * `,N` navigate the classes and modules in your project
42
+ * `,n` navigating the methods in the current file
43
+
44
+
45
+ Press `TAB` to start autocompletion.
46
+
47
+ Use the standard Vim autocompletion commands to move up and down the match
48
+ list.
49
+
50
+ * `CTRL-p` and `CTRL-n` let you navigate the drop-down matches. Press `ENTER` to select
51
+ one.
52
+ * `CTRL-e` closes the match list and lets you continue typing
53
+ * `CTRL-u`: when the match list is active, cycles forward through the match
54
+ list and what you've typed so far; when the match list is inactive, erases
55
+ what you've typed.
56
+ * both `TAB` and `CTRL-x CTRL-u` reactivates autocompletion if it's gone away
57
+ * `CTRL-y` selects the highlighted match without triggering ENTER
58
+
59
+
60
+ ### The search path
61
+
62
+ By default RbNav looks for `app`, `lib`, and `test` directories in your working
63
+ directory and adds what it finds to the search path.
64
+
65
+ You can customize the search path by putting something like this in a `.vimrc`
66
+ files at the root of your project's directory.
67
+
68
+ let g:RbNavPaths = "application lib spec"
69
+
70
+ The directories should be separated by spaces.
71
+
72
+
73
+ ## Bug reports and feature requests
74
+
75
+ Please submit them here:
76
+
77
+ * <https://github.com/danchoi/rb_nav/issues>
78
+
79
+
80
+ ## About the developer
81
+
82
+ My name is Daniel Choi. I specialize in Ruby, Rails, MySQL, PostgreSQL, and iOS
83
+ development. I am based in Cambridge, Massachusetts, USA.
84
+
85
+ * Twitter: [@danchoi][twitter]
86
+ * Personal Email: dhchoi@gmail.com
87
+ * My Homepage: <http://danielchoi.com/software>
88
+
89
+ [twitter]:http://twitter.com/#!/danchoi
90
+
91
+
data/Rakefile ADDED
@@ -0,0 +1,70 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
7
+
8
+ desc "release and build and push new website"
9
+ task :push => [:release, :web]
10
+
11
+ desc "Bumps version number up one and git commits"
12
+ task :bump do
13
+ basefile = "lib/rb_nav/version.rb"
14
+ file = File.read(basefile)
15
+ oldver = file[/VERSION = '(\d.\d.\d)'/, 1]
16
+ newver_i = oldver.gsub(".", '').to_i + 1
17
+ newver = ("%.3d" % newver_i).split(//).join('.')
18
+ puts oldver
19
+ puts newver
20
+ puts "Bumping version: #{oldver} => #{newver}"
21
+ newfile = file.gsub("VERSION = '#{oldver}'", "VERSION = '#{newver}'")
22
+ File.open(basefile, 'w') {|f| f.write newfile}
23
+ `git commit -am 'Bump'`
24
+ end
25
+
26
+ desc "build and push website"
27
+ task :web => :build_webpage do
28
+ puts "Building and pushing website"
29
+ Dir.chdir "../project-webpages" do
30
+ `scp out/rb_nav.html zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
31
+ `rsync -avz out/images-rb_nav zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
32
+ `rsync -avz out/stylesheets zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
33
+ `rsync -avz out/lightbox2 zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
34
+ end
35
+ #`open http://danielchoi.com/software/rb_nav.html`
36
+ end
37
+
38
+ desc "build webpage"
39
+ task :build_webpage do
40
+ `cp README.markdown ../project-webpages/src/rb_nav.README.markdown`
41
+ `cp coverage.markdown ../project-webpages/src/rb_nav.coverage.markdown`
42
+ Dir.chdir "../project-webpages" do
43
+ puts `ruby gen.rb rb_nav #{RIVim::VERSION}`
44
+ `open out/rb_nav.html`
45
+ end
46
+ end
47
+
48
+
49
+ desc "git push and rake release bumped version"
50
+ task :bumped do
51
+ puts `git push && rake release`
52
+ Rake::Task["web"].execute
53
+ end
54
+
55
+ desc "Run tests"
56
+ task :test do
57
+ $:.unshift File.expand_path("test")
58
+ require 'test_helper'
59
+ Dir.chdir("test") do
60
+ Dir['*_test.rb'].each do |x|
61
+ puts "requiring #{x}"
62
+ require x
63
+ end
64
+ end
65
+
66
+ MiniTest::Unit.autorun
67
+ end
68
+
69
+ task :default => :test
70
+
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Use this pipe
4
+ # grep -rn '^\s*\(class\|module\) ' app lib | ruby nav/nav.rb
5
+
6
+ begin
7
+ xs = STDIN.readlines.
8
+ map {|x|
9
+ parts = x.strip.split(/:/,3)
10
+ path, line, klass = *parts
11
+ klass = klass ? klass.strip.sub(/^\w+\s/,'') : "no class"
12
+ if klass =~ /<<\s*self/
13
+ nil
14
+ else
15
+ [klass, [path, line].join(':')]
16
+ end
17
+ }.compact
18
+
19
+ max_width = xs.reduce(0) { |max, x| [x[0].length, max].max }
20
+
21
+ xs.each do |x|
22
+ klass, path = *x
23
+ puts "%-#{max_width}s %s" % [klass, path]
24
+ end
25
+ rescue
26
+ puts $!
27
+ end
28
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'install'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'install'
7
+ end
8
+
9
+ `mkdir -p #{ENV['HOME']}/.vim/plugin`
10
+ vimscript_file = File.join(File.dirname(__FILE__), '..', 'lib/rb_nav.vim')
11
+
12
+ path = "#{ENV['HOME']}/.vim/plugin/"
13
+ `cp #{vimscript_file} #{path}`
14
+ puts "rb_nav.vim installed at #{path}"
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Use this pipe
4
+ #grep -rn '^\s*\def ' $1 | ruby nav/methods.rb
5
+
6
+ xs = STDIN.readlines.
7
+ map {|x|
8
+ line, method = *x.strip.split(/:/)
9
+ method = method.strip
10
+ [method, line]
11
+ }
12
+
13
+ max_width = xs.reduce(0) { |max, x| [x[0].length, max].max }
14
+
15
+ xs.each do |x|
16
+ method, line = *x
17
+ puts "%-#{max_width}s %s" % [method, line]
18
+ end
19
+
@@ -0,0 +1,4 @@
1
+ module RbNav
2
+
3
+ VERSION = '0.0.1'
4
+ end
data/lib/rb_nav.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'rb_nav/version'
2
+
3
+ module RbNav
4
+ end
data/lib/rb_nav.vim ADDED
@@ -0,0 +1,150 @@
1
+ " Vim script that add ability to search and play iTunes tracks from Vim
2
+ " Maintainer: Daniel Choi <dhchoi@gmail.com>
3
+ " License: MIT License (c) 2011 Daniel Choi
4
+
5
+ " This can be set in .vimrc
6
+ if !exists("g:RbNavPaths")
7
+ let g:RbNavPaths = ""
8
+ for x in ['app', 'lib', 'test']
9
+ if isdirectory(x)
10
+ let g:RbNavPaths .= x.' '
11
+ endif
12
+ endfor
13
+ endif
14
+
15
+ let s:last_class_search = ""
16
+
17
+ func! RbNavClasses()
18
+ endfunc
19
+
20
+ func! RbNavMethods()
21
+ endfunc
22
+
23
+ func! s:trimString(string)
24
+ let string = substitute(a:string, '\s\+$', '', '')
25
+ return substitute(string, '^\s\+', '', '')
26
+ endfunc
27
+
28
+ func! s:prepare_autocomplete()
29
+ let s:current_file = bufname('')
30
+ leftabove split rb_nav_prompt
31
+ setlocal textwidth=0
32
+ setlocal buftype=nofile
33
+ setlocal noswapfile
34
+ setlocal modifiable
35
+ setlocal nowrap
36
+ resize 2
37
+ noremap <buffer> <Esc> :close<cr>
38
+ inoremap <buffer> <Tab> <C-x><C-u>
39
+ endfunc
40
+
41
+ " Classes
42
+
43
+ function! s:autocomplete_classes()
44
+ call s:prepare_autocomplete()
45
+ inoremap <buffer> <cr> <Esc>:call <SID>open_class_file()<cr>
46
+ noremap <buffer> <cr> <Esc>:call <SID>open_class_file()<cr>
47
+ setlocal completefunc=AutocompleteRbNavClasses
48
+ call setline(1, "Select a class or module: ")
49
+ call setline(2, "") " s:last_class_search)
50
+ normal G$
51
+ call feedkeys("a\<c-x>\<c-u>\<c-p>", 't')
52
+ endfunction
53
+
54
+ function! AutocompleteRbNavClasses(findstart, base)
55
+ if a:findstart
56
+ let start = 0
57
+ return start
58
+ else
59
+ let res = []
60
+ for m in RbNavClasses()
61
+ " why doesn't case insensitive flag work?
62
+ if m =~ substitute(a:base, '\*', '\\*', '')
63
+ call add(res, m)
64
+ endif
65
+ endfor
66
+ return res
67
+ endif
68
+ endfun
69
+
70
+ func! RbNavClasses()
71
+ let command = "grep -rn ".g:RbNavPaths." --include='*.rb' -e '^\\s*\\(class\\|module\\) \\+[A-Z]' | rb_nav_classes | sort"
72
+ let res = system(command)
73
+ return split(res, "\n")
74
+ endfunc
75
+
76
+ " Methods
77
+
78
+ function! s:autocomplete_methods()
79
+ call s:prepare_autocomplete()
80
+ inoremap <buffer> <cr> <Esc>:call <SID>jump_to_method()<cr>
81
+ noremap <buffer> <cr> <Esc>:call <SID>jump_to_method()<cr>
82
+ setlocal completefunc=AutocompleteRbNavMethods
83
+ call setline(1, "Select a method: ")
84
+ call setline(2, "")
85
+ normal G$
86
+ call feedkeys("a\<c-x>\<c-u>\<c-p>", 't')
87
+ endfunction
88
+
89
+ function! AutocompleteRbNavMethods(findstart, base)
90
+ if a:findstart
91
+ let start = 0
92
+ return start
93
+ else
94
+ let res = []
95
+ for m in RbNavMethods()
96
+ " why doesn't case insensitive flag work?
97
+ if m =~ '^\c.\?' . substitute(a:base, '\*', '\\*', '')
98
+ call add(res, m)
99
+ endif
100
+ endfor
101
+ return res
102
+ endif
103
+ endfun
104
+
105
+ func! RbNavMethods()
106
+ let command = "grep -rn '^\\s*\\def ' ".s:current_file." | rb_nav_methods "
107
+ echom command
108
+ let res = system(command)
109
+ return split(res, "\n")
110
+ endfunc
111
+
112
+ func! s:open_class_file()
113
+ if (getline(2) =~ '^\s*$')
114
+ close
115
+ return
116
+ endif
117
+ let selection = s:trimString(getline(2))
118
+ close
119
+ let query = get(split(selection, '\s\+'), 0)
120
+ let location = get(split(selection, '\s\+'), -1)
121
+ let path = get(split(location, ':'), 0)
122
+ let line = get(split(location, ':'), 1)
123
+ if filereadable(path)
124
+ let s:last_class_search = query
125
+ exec 'edit '.path
126
+ exec "normal ".line."G"
127
+ call feedkeys("z\<cr>", "t")
128
+ else
129
+ echo "File ".path." not found"
130
+ endif
131
+ endfunc
132
+
133
+ func! s:jump_to_method()
134
+ if (getline(2) =~ '^\s*$')
135
+ close
136
+ return
137
+ endif
138
+ let selection = s:trimString(getline(2))
139
+ close
140
+ let line = get(split(selection, '\s\+'), -1)
141
+ exec 'normal '.line.'G'
142
+ call feedkeys("z\<cr>", "t")
143
+ endfunc
144
+
145
+
146
+ au BufRead,BufNewFile *.rb nnoremap <Leader>N :call <SID>autocomplete_classes()<cr>
147
+ au BufRead,BufNewFile *.rb nnoremap <Leader>n :call <SID>autocomplete_methods()<cr>
148
+
149
+
150
+
data/rb_nav.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rb_nav/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rb_nav"
7
+ s.version = RbNav::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.required_ruby_version = '>= 1.8.6'
10
+
11
+ s.authors = ["Daniel Choi"]
12
+ s.email = ["dhchoi@gmail.com"]
13
+ s.homepage = "http://danielchoi.com/software/rb_nav.html"
14
+ s.summary = %q{Browse Ruby documentation in Vim}
15
+ s.description = %q{Browse Ruby documentation in Vim}
16
+
17
+ s.rubyforge_project = "rb_nav"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ message = "* Now please run rb_nav_install to install the Vim plugin *"
25
+ divider = "*" * message.length
26
+ s.post_install_message = [divider, message, divider].join("\n")
27
+
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb_nav
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Choi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-08 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Browse Ruby documentation in Vim
18
+ email:
19
+ - dhchoi@gmail.com
20
+ executables:
21
+ - rb_nav_classes
22
+ - rb_nav_install
23
+ - rb_nav_methods
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - .gitignore
30
+ - MIT-LICENSE.txt
31
+ - NOTES
32
+ - README.markdown
33
+ - Rakefile
34
+ - bin/rb_nav_classes
35
+ - bin/rb_nav_install
36
+ - bin/rb_nav_methods
37
+ - lib/rb_nav.rb
38
+ - lib/rb_nav.vim
39
+ - lib/rb_nav/version.rb
40
+ - rb_nav.gemspec
41
+ has_rdoc: true
42
+ homepage: http://danielchoi.com/software/rb_nav.html
43
+ licenses: []
44
+
45
+ post_install_message: |-
46
+ ***********************************************************
47
+ * Now please run rb_nav_install to install the Vim plugin *
48
+ ***********************************************************
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.8.6
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: rb_nav
68
+ rubygems_version: 1.6.1
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Browse Ruby documentation in Vim
72
+ test_files: []
73
+