mactag 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,90 +1,104 @@
1
1
  # Mactag
2
2
 
3
- Mactag is a plugin for Rails developers that do their development in
3
+ Mactag is a Ruby gem for Ruby developers that do their development in
4
4
  an editor that supports Ctags (Emacs, Vim, TextMate, ...). With Ctags
5
5
  you can follow tags (of functions, variables, macros, whatever) to
6
6
  their definitions.
7
7
 
8
+ Mactag works with both Ruby projects and Rails applications.
8
9
 
9
- # Exuberant Ctags
10
10
 
11
- First off, you must install [Ctags](http://ctags.sourceforge.net/).
12
- Some systems comes with a `ctags` binary already. If you have the
13
- ctags executable, but have problems creating the tags file. Then make
14
- sure that you are using **Exuberant Ctags** and not some other version.
11
+ # Exuberant Ctags
15
12
 
13
+ Mactag requires a tool called
14
+ [Exuberant Ctags](http://ctags.sourceforge.net/), which is used to
15
+ create the tags file. Install it if you don't have it already. Some
16
+ systems includes a `ctags` exectuable. If you use that and you have
17
+ trouble creating the tags file, then install it from your package
18
+ manager instead. The package is called `ctags` in Homebrew and
19
+ `exuberant-ctags` in Ubuntu.
16
20
 
17
21
  # Installation
18
22
 
19
23
  Install the gem:
20
24
 
21
25
  $ gem install mactag
22
-
26
+
23
27
  Add `mactag` to the `Gemfile`:
24
28
 
25
- group :development do
26
- gem 'mactag'
27
- end
29
+ gem 'mactag'
30
+
31
+ Then run `bundle install`.
28
32
 
29
33
 
30
34
  # Configuration
31
35
 
32
- To generate the configuration file `config/mactag.rb`, use the
33
- `mactag` generator. The generated file contains a basic setup and some
34
- examples of how to configure Mactag.
36
+ You specify what you want to index in the configuration file (default
37
+ is `config/mactag.rb`). To generate such as file with a basic setup,
38
+ run the command:
35
39
 
36
- $ rails generate mactag
40
+ $ mactag new
37
41
 
38
- ## Example mactag.rb file
42
+ Or if you want the config file someplace else:
43
+
44
+ $ mactag new conf/mactag.rb
45
+
46
+ That will generate a configuration file looking something like this:
39
47
 
40
48
  Mactag.configure do |config|
41
- # Do not use RVM
42
- config.rvm = false
43
- config.gem_home = '/usr/lib/ruby/gems/1.8/gems'
44
-
45
- # Binary when installing ctags from Homebrew
46
- config.binary = '/usr/local/Cellar/ctags/5.8/bin/ctags -e -o {OUTPUT} {INPUT}'
47
-
48
- # Change name of output file
49
- config.tags_file = 'DA-TAGS'
49
+ # Use RVM to locate project gems.
50
+ # config.rvm = false
51
+
52
+ # Path to gems. No need to set this when RVM is used!
53
+ # config.gem_home = '/Library/Ruby/Gems/1.8/gems'
54
+
55
+ # Name of tags file to create.
56
+ # config.tags_file = '.tags'
57
+
58
+ # Command used to create the tags table. {INPUT} and {OUTPUT} are required!
59
+ # config.binary = '/usr/local/Cellar/ctags/5.8/bin/ctags -e -o {OUTPUT} {INPUT}'
50
60
  end
51
61
 
52
62
  Mactag do
53
- index 'app/models/*.rb'
54
-
55
- index 'carrerwave', 'simple_form'
56
- index 'redcarpet', :version => '1.17.2'
63
+ # Index current project.
64
+ # index :lib
57
65
 
58
- index :rails, :except => :actionmailer, :version => '3.1.3'
59
- end
60
-
61
- ## Configuration Options
62
- The available configuration options are described below.
66
+ # Index current Rails project.
67
+ # index :app
68
+
69
+ # Index all models and helpers.
70
+ # index 'app/models/*.rb', 'app/helpers/*.rb'
71
+
72
+ # Index the gems carrierwave and redcarpet.
73
+ # index 'carrierwave', 'redcarpet'
74
+
75
+ # Index the gem simple_form version 1.5.2.
76
+ # index 'simple_form', :version => '1.5.2'
63
77
 
64
- ### rvm
65
- If true, use [Rvm](http://rvm.beginrescueend.com/) when indexing gems.
66
- Defaults to: `true`
78
+ # Index rails.
79
+ # index :rails
67
80
 
68
- ### gem_home
69
- Path to gems. No need to set this when using `rvm`.
70
- Defaults to: `/Library/Ruby/Gems/1.8/gems`
71
-
72
- ### binary
73
- The command to run when creating the TAGS-file. `{OUTPUT}` will be
74
- replaced with the value of `tags_file` configuration option. `{INPUT}`
75
- will be replaced with all files to index.
76
- Defaults to: `ctags -o {OUTPUT} -e {INPUT}`
81
+ # Index rails except action mailer.
82
+ # index :rails, :except => :actionmailer
77
83
 
78
- ### tags_file
79
- Name of the output tags file.
80
- Defaults to: `TAGS`
84
+ # Index only rails packages activerecord and activesupport.
85
+ # index :rails, :only => %w(activerecord activesupport)
86
+
87
+ # Index rails, version 3.1.3.
88
+ # index :rails, :version => '3.1.3'
89
+ end
81
90
 
82
91
 
83
92
  # Usage
84
- To create the TAGS file, simply run:
85
93
 
86
- $ rake mactag
94
+ When you are done configuring, create the tags file with the command:
87
95
 
96
+ $ mactag
97
+
98
+ Or if the config file is someplace else than `config/mactag.rb`.
99
+
100
+ $ mactag conf/mactag.rb
88
101
 
89
102
  # License
103
+
90
104
  Copyright (c) 2010-2012 Johan Andersson, released under the MIT license
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+
5
+ if ARGV.include?('-h') || ARGV.include?('--help') || ARGV.include?('help')
6
+ $stderr.puts 'Usage: mactag [new] [configuration_file]'
7
+ else
8
+ default_config_file = File.join('config', 'mactag.rb')
9
+
10
+ if ARGV.first == 'new'
11
+ config_file = ARGV[1] || default_config_file
12
+
13
+ config_dir = File.dirname(config_file)
14
+ if File.exists?(config_dir)
15
+ if File.exists?(config_file)
16
+ $stderr.puts "[skip] file `#{config_file}' already exists"
17
+ else
18
+ content = <<-CONFIG
19
+ Mactag.configure do |config|
20
+ # Use RVM to locate project gems.
21
+ # config.rvm = false
22
+
23
+ # Path to gems. No need to set this when RVM is used!
24
+ # config.gem_home = '/Library/Ruby/Gems/1.8/gems'
25
+
26
+ # Name of tags file to create.
27
+ # config.tags_file = '.tags'
28
+
29
+ # Command used to create the tags table. {INPUT} and {OUTPUT} are required!
30
+ # config.binary = '/usr/local/Cellar/ctags/5.8/bin/ctags -e -o {OUTPUT} {INPUT}'
31
+ end
32
+
33
+ Mactag do
34
+ # Index current project.
35
+ # index :lib
36
+
37
+ # Index current Rails project.
38
+ # index :app
39
+
40
+ # Index all models and helpers.
41
+ # index 'app/models/*.rb', 'app/helpers/*.rb'
42
+
43
+ # Index the gems carrierwave and redcarpet.
44
+ # index 'carrierwave', 'redcarpet'
45
+
46
+ # Index the gem simple_form version 1.5.2.
47
+ # index 'simple_form', :version => '1.5.2'
48
+
49
+ # Index rails.
50
+ # index :rails
51
+
52
+ # Index rails except action mailer.
53
+ # index :rails, :except => :actionmailer
54
+
55
+ # Index only rails packages activerecord and activesupport.
56
+ # index :rails, :only => %w(activerecord activesupport)
57
+
58
+ # Index rails, version 3.1.3.
59
+ # index :rails, :version => '3.1.3'
60
+ end
61
+ CONFIG
62
+
63
+ File.open(config_file, 'w') do |f|
64
+ f.write(content)
65
+ end
66
+
67
+ puts "[done] created `#{config_file}'"
68
+ end
69
+ else
70
+ $stderr.puts "[skip] directory `#{config_dir}' does not exist"
71
+ end
72
+ else
73
+ config_file = ARGV[0] || default_config_file
74
+
75
+ if File.exists?(config_file)
76
+ require 'mactag'
77
+
78
+ environment = File.expand_path(File.join(ENV['PWD'], 'config', 'environment.rb'))
79
+ if File.exists?(environment)
80
+ require environment
81
+ end
82
+
83
+ begin
84
+ require config_file
85
+
86
+ Mactag::Builder.create
87
+ rescue Mactag::MactagError => e
88
+ $stderr.puts "[error] #{e.message}"
89
+ end
90
+
91
+ else
92
+ $stderr.puts "[skip] file `#{config_file}' does not exist"
93
+ end
94
+ end
95
+ end
@@ -1,4 +1,3 @@
1
- require 'mactag/railtie'
2
1
  require 'mactag/config'
3
2
  require 'mactag/builder'
4
3
  require 'mactag/dsl'
@@ -8,16 +7,39 @@ require 'mactag/bundler'
8
7
  require 'mactag/errors'
9
8
 
10
9
  module Mactag
11
- autoload :Bundler, 'bundler'
12
- autoload :Rails, 'rails'
13
-
14
10
  class << self
15
11
  def configure(&block)
16
12
  Mactag::Config.configure(&block)
17
13
  end
14
+
15
+ def rails_app?
16
+ defined?(::Rails)
17
+ end
18
+
19
+ def rails_version
20
+ if rails_app?
21
+ ::Rails.version
22
+ end
23
+ end
24
+
25
+ def project_root
26
+ if rails_app?
27
+ ::Rails.root
28
+ else
29
+ ENV['PWD']
30
+ end
31
+ end
32
+
33
+ def current_project
34
+ File.basename(project_root)
35
+ end
18
36
  end
19
37
  end
20
38
 
21
39
  def Mactag(&block)
22
40
  Mactag::Builder.generate(&block)
23
41
  end
42
+
43
+ if Mactag.rails_app?
44
+ require 'mactag/railtie'
45
+ end
@@ -43,7 +43,7 @@ module Mactag
43
43
  if builder.has_gems?
44
44
  Mactag::Ctags.new(@builder.files, Mactag::Config.tags_file).create
45
45
 
46
- puts "Successfully generated #{Mactag::Config.tags_file} file"
46
+ puts "[done] Successfully generated #{Mactag::Config.tags_file} file"
47
47
  else
48
48
  raise Mactag::MactagError.new('Nothing to tag')
49
49
  end
@@ -1,3 +1,5 @@
1
+ require 'bundler'
2
+
1
3
  module Mactag
2
4
  ##
3
5
  #
@@ -26,7 +28,13 @@ module Mactag
26
28
  default = runtime.dependencies.select { |dependency|
27
29
  dependency.groups.include?(:default)
28
30
  }.map(&:name)
29
- default.delete('rails')
31
+ if Mactag.rails_app?
32
+ default.delete('rails')
33
+ else
34
+ if project = Mactag.current_project
35
+ default.delete(project)
36
+ end
37
+ end
30
38
  default
31
39
  end
32
40
 
@@ -1,41 +1,25 @@
1
1
  module Mactag
2
- class Config
3
- ##
4
- #
5
- # The command to run (replacing <tt>{OUTPUT}</tt> with <tt>tags_file</tt>
6
- # and <tt>{INPUT}</tt> with the input files) when creating the tags file.
7
- #
8
- @@binary = 'ctags -o {OUTPUT} -e {INPUT}'
9
- cattr_reader :binary
10
-
11
- ##
12
- #
13
- # Name of the output tags file.
14
- #
15
- @@tags_file = 'TAGS'
16
- cattr_accessor :tags_file
17
-
18
- ##
19
- #
20
- # If using Ruby Version Manager (RVM), setting this option to true
21
- # will enable Mactag to find out the gem path automatically.
22
- #
23
- @@rvm = true
24
- cattr_accessor :rvm
25
-
26
- ##
27
- #
28
- # The system folder where the gems are located.
29
- #
30
- @@gem_home = '/Library/Ruby/Gems/1.8/gems'
31
- cattr_writer :gem_home
32
-
2
+ module Config
33
3
  class << self
34
- def binary=(binary)
35
- if binary.include?('{INPUT}') && binary.include?('{OUTPUT}')
36
- @@binary = binary
37
- else
38
- raise Mactag::MactagError.new("Binary command must include '{INPUT}' and '{OUTPUT}'")
4
+ def configure(&block)
5
+ yield self
6
+ end
7
+
8
+ def add_config(name, &block)
9
+ unless respond_to?(name)
10
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
11
+ def self.#{name}
12
+ @#{name}
13
+ end
14
+ RUBY
15
+ end
16
+
17
+ unless respond_to?("#{name}=")
18
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
19
+ def self.#{name}=(value)
20
+ @#{name} = value
21
+ end
22
+ RUBY
39
23
  end
40
24
  end
41
25
 
@@ -43,13 +27,41 @@ module Mactag
43
27
  if rvm
44
28
  File.join(ENV['GEM_HOME'], 'gems')
45
29
  else
46
- @@gem_home
30
+ @gem_home
47
31
  end
48
32
  end
49
33
 
50
- def configure(&block)
51
- yield self
34
+ def rvm=(rvm)
35
+ if rvm == true || rvm == false
36
+ @rvm = rvm
37
+ else
38
+ raise Mactag::MactagError.new("RVM must be either true or false")
39
+ end
40
+ end
41
+
42
+ def binary=(binary)
43
+ if binary.include?('{INPUT}') && binary.include?('{OUTPUT}')
44
+ @binary = binary
45
+ else
46
+ raise Mactag::MactagError.new("Binary command must include '{INPUT}' and '{OUTPUT}'")
47
+ end
48
+ end
49
+
50
+ def reset_config
51
+ configure do |config|
52
+ config.binary = 'ctags -o {OUTPUT} -e {INPUT}'
53
+ config.tags_file = 'TAGS'
54
+ config.rvm = true
55
+ config.gem_home = '/Library/Ruby/Gems/1.8/gems'
56
+ end
52
57
  end
53
58
  end
59
+
60
+ add_config :binary
61
+ add_config :tags_file
62
+ add_config :rvm
63
+ add_config :gem_home
64
+
65
+ reset_config
54
66
  end
55
67
  end
@@ -19,7 +19,7 @@ module Mactag
19
19
  private
20
20
 
21
21
  def command
22
- "cd #{Rails.root} && #{binary}"
22
+ "cd #{Mactag.project_root} && #{binary}"
23
23
  end
24
24
 
25
25
  def binary
@@ -18,18 +18,21 @@ module Mactag
18
18
  #
19
19
  # = App
20
20
  #
21
- # App indexes files in the current project.
21
+ # App indexes files in the current Rails project.
22
22
  #
23
23
  # == Examples
24
24
  #
25
25
  # Mactag do
26
- # # Index single file.
26
+ # # Index all ruby files in app and lib, recursive
27
+ # index :app
28
+ #
29
+ # # Index single file
27
30
  # index 'lib/super_duper.rb'
28
31
  #
29
- # # Index all ruby files in lib, recursive.
32
+ # # Index all ruby files in lib, recursive
30
33
  # index 'lib/**/*.rb'
31
34
  #
32
- # # Index all helper and model ruby files.
35
+ # # Index all helper and model ruby files
33
36
  # index 'app/helpers/*.rb', 'app/models/*.rb'
34
37
  #
35
38
  # # Same as above
@@ -44,16 +47,16 @@ module Mactag
44
47
  # == Examples
45
48
  #
46
49
  # Mactag do
47
- # # Index all gems specified in Gemfile.
50
+ # # Index all gems specified in Gemfile
48
51
  # index :gems
49
52
  #
50
- # # Index the gem whenever, latest version.
53
+ # # Index the gem whenever, latest version
51
54
  # index 'whenever'
52
55
  #
53
- # # Index the thinking-sphinx and carrierwave gems, latest versions.
56
+ # # Index the thinking-sphinx and carrierwave gems, latest versions
54
57
  # index 'thinking-sphinx', 'carrierwave'
55
58
  #
56
- # # Index the gem simple_form, version 1.5.2.
59
+ # # Index the gem simple_form, version 1.5.2
57
60
  # index 'simple_form', :version => '1.5.2'
58
61
  # end
59
62
  #
@@ -77,6 +80,24 @@ module Mactag
77
80
  # * activesupport
78
81
  #
79
82
  #
83
+ # = Lib
84
+ #
85
+ # Lib indexes files in the current project.
86
+ #
87
+ # == Examples
88
+ #
89
+ # Mactag do
90
+ # # Index all ruby files in lib, recursive
91
+ # index :lib
92
+ #
93
+ # # Index single file
94
+ # index 'lib/super_duper.rb'
95
+ #
96
+ # # Index all ruby files in lib, recursive
97
+ # index 'lib/**/*.rb'
98
+ # end
99
+ #
100
+ #
80
101
  # == Examples
81
102
  #
82
103
  # Mactag do
@@ -103,6 +124,8 @@ module Mactag
103
124
  def index(*args)
104
125
  if args.first == :app
105
126
  app_private
127
+ elsif args.first == :lib
128
+ lib_private
106
129
  elsif args.first == :gems
107
130
  gem_private
108
131
  elsif args.first == :rails
@@ -110,14 +133,18 @@ module Mactag
110
133
  else
111
134
  options = args.last
112
135
 
113
- if options[:version] && args.size > 2
136
+ if options.is_a?(Hash) && options[:version] && args.size > 2
114
137
  raise ArgumentError.new('The :version option is not valid when specifying more than one gem')
115
138
  end
116
139
 
117
140
  if options.is_a?(Hash) || args.all? { |arg| Mactag::Indexer::Gem.exist?(arg) }
118
- gem_private(*args)
141
+ gem_private(*args)
119
142
  else
120
- app_private(*args)
143
+ if Mactag.rails_app?
144
+ app_private(*args)
145
+ else
146
+ lib_private(*args)
147
+ end
121
148
  end
122
149
  end
123
150
  end
@@ -182,7 +209,25 @@ module Mactag
182
209
 
183
210
  private
184
211
 
212
+ def lib_private(*tags)
213
+ if Mactag.rails_app?
214
+ raise MactagError.new('Can not index :lib when in a Rails application')
215
+ end
216
+
217
+ if tags.empty?
218
+ @builder << Mactag::Indexer::Lib.all
219
+ else
220
+ tags.each do |tag|
221
+ @builder << Mactag::Indexer::Lib.new(tag)
222
+ end
223
+ end
224
+ end
225
+
185
226
  def app_private(*tags)
227
+ unless Mactag.rails_app?
228
+ raise MactagError.new('Can not index :app when not a Rails application')
229
+ end
230
+
186
231
  if tags.empty?
187
232
  @builder << Mactag::Indexer::App.all
188
233
  else
@@ -198,8 +243,8 @@ module Mactag
198
243
  else
199
244
  options = args.last
200
245
 
201
- if version = options[:version]
202
- @builder << Mactag::Indexer::Gem.new(args.first, version)
246
+ if options.is_a?(Hash) && options[:version]
247
+ @builder << Mactag::Indexer::Gem.new(args.first, options[:version])
203
248
  else
204
249
  args.each do |arg|
205
250
  @builder << Mactag::Indexer::Gem.new(arg)
@@ -209,6 +254,10 @@ module Mactag
209
254
  end
210
255
 
211
256
  def rails_private(*args)
257
+ unless Mactag.rails_app?
258
+ raise MactagError.new('You can not index :rails when not in a Rails application')
259
+ end
260
+
212
261
  args.shift
213
262
 
214
263
  if args.size.zero?
@@ -235,4 +284,3 @@ module Mactag
235
284
  end
236
285
  end
237
286
  end
238
-