mactag 0.4.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,81 +1,49 @@
1
1
  # Mactag
2
2
 
3
3
  Mactag is a plugin for Rails developers that do their development in
4
- an editor that supports Ctags (Emacs, Vim, TextMate, jEdit, ...). With
5
- Ctags you can follow tags (of functions, variables, macros, whatever)
6
- to their definitions.
4
+ an editor that supports Ctags (Emacs, Vim, TextMate, ...). With Ctags
5
+ you can follow tags (of functions, variables, macros, whatever) to
6
+ their definitions.
7
7
 
8
8
 
9
9
  # Exuberant Ctags
10
10
  First off, you must install [Ctags](http://ctags.sourceforge.net/).
11
- Some systems comes with a ctags command already. If you have the ctags
12
- executable, but have problems creating the tags file. Then make sure
13
- that you are using **Exuberant Ctags** and not some other version.
11
+ Some systems comes with a **ctags** command already. If you have the
12
+ ctags executable, but have problems creating the tags file. Then make
13
+ sure that you are using **Exuberant Ctags** and not some other version.
14
14
 
15
15
 
16
16
  # Installation
17
17
 
18
- ## Rails 2.x
19
-
20
- ### Plugin
21
- Install the plugin:
22
- $ ./script/plugin install git://github.com/rejeep/mactag.git --revision 'tags/v0.0.5'
23
-
24
- ### Gem
25
- Install the gem:
26
- $ gem install mactag --version='0.0.5'
27
-
28
- Load the gem in **config/environments/development.rb**:
29
- config.gem 'mactag'
30
-
31
- Load the rake tasks in **Rakefile**.
32
- require 'mactag/tasks'
33
-
34
-
35
- ## Rails 3.x
36
-
37
- ### Plugin
18
+ ## Plugin
38
19
  Install the plugin:
39
20
  $ rails plugin install git://github.com/rejeep/mactag.git
40
21
 
41
- ### Gem
22
+ ## Gem
42
23
  Install the gem:
43
24
  $ gem install mactag
44
25
 
45
- Load the gem in **Gemfile**:
26
+ Add mactag to the **Gemfile**:
46
27
  group :development do
47
- gem 'mactag', '0.4.0'
28
+ gem 'mactag'
48
29
  end
49
30
 
50
31
 
51
32
  # Configuration
52
- Generate a basic configuration file:
53
33
 
54
- ## Rails 2.x
55
- $ ./script/generate mactag
56
-
57
- ## Rails 3.x
34
+ To generate a template configuration file (**config/mactag.rb**),
35
+ which contains a basic setup and some examples of how to configure
36
+ Mactag, use the **mactag** generator:
58
37
  $ rails generate mactag
59
38
 
60
- This will create the file **config/mactag.rb**, which contains some
61
- examples of how to configure Mactag.
62
-
63
- ## Options
64
-
65
- * **Mactag::Config.rvm:** If true, use RVM gems. Defaults to **true**
66
- * **Mactag::Config.gem_home:** The path where the gems are located. Defaults to **/Library/Ruby/Gems/1.8/gems**
67
- * **Mactag::Config.binary:** The command to run when creating the TAGS-file. Defaults to **ctags -o {OUTPUT} -e {INPUT}**
68
- * **Mactag::Config.tags_file:** Name of output file. Defaults to **TAGS**
69
- * **Mactag::Config.tags_dir:** Name of output directory to store tags files when using FSSM. Defaults to **.tags**
70
-
71
39
  ## Example mactag.rb file
40
+
72
41
  Mactag::Config.rvm = false
73
42
  Mactag::Config.gem_home = '/usr/lib/ruby/gems/1.8/gems'
74
43
  Mactag::Config.binary = 'etags -o {OUTPUT} {INPUT}'
75
44
  Mactag::Config.tags_file = 'TAGS'
76
- Mactag::Config.tags_dir = '.tags' # See FSSM
77
45
 
78
- Mactag do # This is "Mactag::Table.generate do" in Rails 2 applications
46
+ Mactag do
79
47
  app 'app/**/*.rb', 'lib/*.rb'
80
48
 
81
49
  plugins 'thinking-sphinx', 'whenever'
@@ -85,29 +53,32 @@ examples of how to configure Mactag.
85
53
 
86
54
  rails :except => :actionmailer, :version => '2.3.5'
87
55
  end
56
+
57
+ ## Options
58
+ The available configuration options are described below.
88
59
 
89
- # Usage
90
- To create the TAGS file. Simply run:
91
- $ rake mactag:create
92
-
60
+ ### Mactag::Config.rvm
61
+ If true, use [Rvm](http://rvm.beginrescueend.com/) when indexing gems.
62
+ Defaults to: `true`
93
63
 
94
- # FSSM
95
- A problem with tags, is that when your project's code changes, your
96
- tags file will not keep up. Mactag can solve this by using FSSM, which
97
- is a tool that notice file system modifications.
64
+ ### Mactag::Config.gem_home
65
+ Path to gems. No need to set this when using **Mactag::Config.rvm**.
66
+ Defaults to: `/Library/Ruby/Gems/1.8/gems`
67
+
68
+ ### Mactag::Config.binary
69
+ The command to run when creating the TAGS-file. **{OUTPUT}** will be
70
+ replaced with the value of **Mactag::Config.tags_file**. **{INPUT}**
71
+ will be replaced with all files to index.
72
+ Defaults to: `ctags -o {OUTPUT} -e {INPUT}`
98
73
 
99
- To enable FSSM, add the **fssm** gem to your projects Gemfile.
74
+ ### Mactag::Config.tags_file
75
+ Name of the output tags file.
76
+ Defaults to: `TAGS`
100
77
 
101
- Then start the server that keeps track of changes
102
- rake mactag:server
103
-
104
- This creates a couple of tags files in **Mactag::Config.tags_dir**
105
- (one for each source file). This means your editor must support
106
- multiple tags files.
107
78
 
108
- ## Editor support
109
-
110
- * Emacs - <http://github.com/rejeep/mactag.el>
79
+ # Usage
80
+ To create the TAGS file, simply run:
81
+ $ rake mactag
111
82
 
112
83
 
113
84
  # License
@@ -0,0 +1,12 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << 'lib'
6
+ t.libs << 'spec'
7
+ t.pattern = 'spec/**/*_spec.rb'
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :spec
12
+ task :test => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.1
@@ -1,34 +1,52 @@
1
1
  ##
2
2
  #
3
- # Use RVM gem path. Mactag will automatically find this.
4
- # Defaults to *true*.
5
- # Mactag::Config.rvm = true
3
+ # Rvm support or not. Mactag will automatically set path to gems.
4
+ #
5
+ # Defaults to: true
6
+ #
7
+ # Example:
8
+ # Mactag::Config.rvm = false
6
9
  #
7
10
 
8
11
  ##
9
12
  #
10
- # Path to gems. This options is only interesting if Mactag::Config.rvm
11
- # is false.
13
+ # Path to gems.
14
+ #
15
+ # Change to whatever your system is using, if not the default. Most
16
+ # GNU/Linux systems use: /usr/lib/ruby/gems/1.8/gems
17
+ #
18
+ # (You don't need to set this when Mactag::Config.rvm is true)
19
+ #
20
+ # Defaults to: '/Library/Ruby/Gems/1.8/gems'
12
21
  #
13
- # Default is */Library/Ruby/Gems/1.8/gems* (standard path on Mac OS).
14
- #
15
- # Change to whatever your system is using, if not the default.
16
- # Most GNU/Linux systems:
22
+ # Example:
17
23
  # Mactag::Config.gem_home = '/usr/lib/ruby/gems/1.8/gems'
18
24
  #
19
25
 
20
26
  ##
21
27
  #
22
- # Change the binary option if you are not satisfied with the standard
23
- # command (ctags -o TAGS -e) used to create the TAGS table.
24
- # Default is *ctags -o TAGS -e*
25
- # Mactag::Config.binary = 'etags -o TAGS'
28
+ # Name of tags file.
29
+ #
30
+ # Defaults to: 'TAGS'
31
+ #
32
+ # Example:
33
+ # Mactag::Config.tags_file = '.tags'
26
34
  #
27
35
 
28
36
  ##
29
37
  #
30
- # Example configuration. Change according to your application.
38
+ # This is the command used to create the TAGS table.
39
+ #
40
+ # The command must specify:
41
+ # {INPUT} - replaced by the input files to tag
42
+ # {OUTPUT} - replaced by Mactag::Config.tags_file
43
+ #
44
+ # Defaults to: 'ctags -o {OUTPUT} -e {INPUT}'
31
45
  #
46
+ # Example:
47
+ # Mactag::Config.binary = '/usr/local/Cellar/ctags/5.8/bin/ctags -e -o {OUTPUT} {INPUT}'
48
+ #
49
+
32
50
  Mactag do
33
51
  ##
34
52
  #
@@ -47,7 +65,7 @@ Mactag do
47
65
  # Index the gems paperclip and authlogic.
48
66
  # gems 'paperclip', 'authlogic'
49
67
  #
50
-
68
+
51
69
  ##
52
70
  #
53
71
  # Index the gem formtastic version 0.9.7.
@@ -59,16 +77,22 @@ Mactag do
59
77
  # Index all rails packages, except actionmailer.
60
78
  # rails :except => :actionmailer
61
79
  #
62
-
80
+
63
81
  ##
64
82
  #
65
83
  # Index only rails packages activerecord and activesupport.
66
84
  # rails :only => [:activerecord, :active_support]
67
85
  #
68
-
86
+
87
+ ##
88
+ #
89
+ # Index all rails packages, version 3.0.0.
90
+ # rails :version => '3.0.0'
91
+ #
92
+
69
93
  ##
70
94
  #
71
- # Index all rails packages, version 2.3.5.
72
- # rails :version => '2.3.5'
95
+ # Index all rails packages, same version as current application.
96
+ # rails
73
97
  #
74
98
  end
@@ -4,18 +4,12 @@ require 'mactag/builder'
4
4
  require 'mactag/dsl'
5
5
  require 'mactag/tag'
6
6
  require 'mactag/ctags'
7
- require 'mactag/server'
8
- require 'mactag/event_handler'
9
- require 'mactag/tags_file'
7
+ require 'mactag/bundler'
8
+ require 'mactag/errors'
10
9
 
11
10
  module Mactag
12
11
  autoload :Bundler, 'bundler'
13
12
  autoload :Rails, 'rails'
14
- autoload :FSSM, 'fssm'
15
-
16
- def self.warn(message)
17
- STDERR.puts(message)
18
- end
19
13
  end
20
14
 
21
15
  def Mactag(&block)
@@ -29,40 +29,42 @@ module Mactag
29
29
  end
30
30
 
31
31
  def all
32
- @all_tags ||= @tags.collect!(&:tag)
32
+ @all ||= @tags.collect!(&:tag)
33
33
  end
34
34
 
35
- def gems?
35
+ def has_gems?
36
36
  all.flatten.compact.any?
37
37
  end
38
38
 
39
- def self.create
40
- unless gem_home_exists?
41
- Mactag.warn 'Gem home path does not exist on your system'
42
- end
39
+ class << self
40
+ def create
41
+ unless gem_home_exists?
42
+ raise Mactag::MactagError.new("Specified gem home directory does not exist: #{Mactag::Config.gem_home}")
43
+ end
43
44
 
44
- if @builder.gems?
45
- Mactag::Ctags.new(@builder.files, Mactag::Config.tags_file).create
45
+ if builder.has_gems?
46
+ Mactag::Ctags.new(@builder.files, Mactag::Config.tags_file).create
46
47
 
47
- puts "Successfully generated TAGS file"
48
- else
49
- Mactag.warn 'You did not specify anything to tag'
48
+ puts 'Successfully generated TAGS file'
49
+ else
50
+ raise Mactag::MactagError.new('Nothing to tag')
51
+ end
50
52
  end
51
- end
52
53
 
53
- def self.generate(&block)
54
- @builder = Mactag::Builder.new
54
+ def generate(&block)
55
+ @builder = Mactag::Builder.new
55
56
 
56
- dsl = Mactag::Dsl.new(@builder)
57
- dsl.instance_eval(&block)
58
- end
57
+ dsl = Mactag::Dsl.new(@builder)
58
+ dsl.instance_eval(&block)
59
+ end
59
60
 
60
- def self.gem_home_exists?
61
- File.directory?(Mactag::Config.gem_home)
62
- end
61
+ def gem_home_exists?
62
+ File.directory?(Mactag::Config.gem_home)
63
+ end
63
64
 
64
- def self.builder
65
- @builder
65
+ def builder
66
+ @builder
67
+ end
66
68
  end
67
69
  end
68
70
  end
@@ -0,0 +1,36 @@
1
+ module Mactag
2
+ ##
3
+ #
4
+ # For fetching information from Bundler regarding what gems are
5
+ # used.
6
+ #
7
+ class Bundler
8
+ def gems
9
+ dependencies.map do |dependency|
10
+ Mactag::Tag::Gem.new(dependency, specs[dependency])
11
+ end
12
+ end
13
+
14
+
15
+ private
16
+
17
+ def specs
18
+ @specs ||= runtime.specs.inject({}) do |hash, spec|
19
+ hash[spec.name] = spec.version.to_s
20
+ hash
21
+ end
22
+ end
23
+
24
+ def dependencies
25
+ default = runtime.dependencies.select { |dependency|
26
+ dependency.groups.include?(:default)
27
+ }.collect(&:name)
28
+ default.delete('rails')
29
+ default
30
+ end
31
+
32
+ def runtime
33
+ @runtime ||= ::Bundler.load
34
+ end
35
+ end
36
+ end
@@ -21,10 +21,13 @@ module Mactag
21
21
 
22
22
  ##
23
23
  #
24
- # Directory to store tags in when using Mactag server and FSSM.
24
+ # If using Ruby Version Manager (RVM), setting this option to true
25
+ # will enable Mactag to find out the gem path automatically.
26
+ #
27
+ # Mactag::Config.rvm = false
25
28
  #
26
- @@tags_dir = '.tags'
27
- cattr_accessor :tags_dir
29
+ @@rvm = true
30
+ cattr_accessor :rvm
28
31
 
29
32
  ##
30
33
  #
@@ -42,15 +45,5 @@ module Mactag
42
45
  @@gem_home
43
46
  end
44
47
  end
45
-
46
- ##
47
- #
48
- # If using Ruby Version Manager (RVM), setting this option to true
49
- # will enable Mactag to find out the gem path automatically.
50
- #
51
- # Mactag::Config.rvm = false
52
- #
53
- @@rvm = true
54
- cattr_accessor :rvm
55
48
  end
56
49
  end
@@ -15,7 +15,7 @@ module Mactag
15
15
 
16
16
 
17
17
  private
18
-
18
+
19
19
  def command
20
20
  "cd #{Rails.root} && #{binary}"
21
21
  end
@@ -25,7 +25,7 @@ module Mactag
25
25
 
26
26
  binary.gsub!('{OUTPUT}', @output)
27
27
  binary.gsub!('{INPUT}', @input.join(' '))
28
-
28
+
29
29
  binary
30
30
  end
31
31
  end
@@ -13,6 +13,10 @@ module Mactag
13
13
  # @see Mactag::Tag::App
14
14
  #
15
15
  def app(*tags)
16
+ if tags.empty?
17
+ raise ArgumentError.new('App requires at least one argument')
18
+ end
19
+
16
20
  tags.each do |tag|
17
21
  @builder << Mactag::Tag::App.new(tag)
18
22
  end
@@ -31,7 +35,7 @@ module Mactag
31
35
  @builder << Mactag::Tag::Plugin.new(plugin)
32
36
  end
33
37
  end
34
- alias_method :plugins, :plugin
38
+ alias :plugins :plugin
35
39
 
36
40
  ##
37
41
  #
@@ -39,22 +43,30 @@ module Mactag
39
43
  #
40
44
  def gem(*gems)
41
45
  options = gems.extract_options!
46
+
47
+ if options[:version] && gems.size > 1
48
+ raise ArgumentError.new('The :version option is not valid when specifying more than one gem')
49
+ end
42
50
 
43
51
  if gems.empty?
44
52
  @builder << Mactag::Tag::Gem.all
45
53
  else
46
- gems.each do |name|
47
- @builder << Mactag::Tag::Gem.new(name, options[:version])
54
+ gems.each do |gem|
55
+ @builder << Mactag::Tag::Gem.new(gem, options[:version])
48
56
  end
49
57
  end
50
58
  end
51
- alias_method :gems, :gem
59
+ alias :gems :gem
52
60
 
53
61
  ##
54
62
  #
55
63
  # @see Mactag::Tag::Rails
56
64
  #
57
65
  def rails(options = {})
66
+ if options[:only] && options[:except]
67
+ raise ArgumentError.new('Can not specify options :only and :except at the same time')
68
+ end
69
+
58
70
  @builder << Mactag::Tag::Rails.new(options)
59
71
  end
60
72
  end