mactag 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,7 +44,7 @@ Install the gem:
44
44
 
45
45
  Load the gem in **Gemfile**:
46
46
  group :development do
47
- gem 'mactag', '0.3.3'
47
+ gem 'mactag', '0.4.0'
48
48
  end
49
49
 
50
50
 
@@ -64,12 +64,16 @@ examples of how to configure Mactag.
64
64
 
65
65
  * **Mactag::Config.rvm:** If true, use RVM gems. Defaults to **true**
66
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 TAGS -e**
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**
68
70
 
69
71
  ## Example mactag.rb file
70
72
  Mactag::Config.rvm = false
71
73
  Mactag::Config.gem_home = '/usr/lib/ruby/gems/1.8/gems'
72
- Mactag::Config.binary = 'etags -o TAGS'
74
+ Mactag::Config.binary = 'etags -o {OUTPUT} {INPUT}'
75
+ Mactag::Config.tags_file = 'TAGS'
76
+ Mactag::Config.tags_dir = '.tags' # See FSSM
73
77
 
74
78
  Mactag do # This is "Mactag::Table.generate do" in Rails 2 applications
75
79
  app 'app/**/*.rb', 'lib/*.rb'
@@ -82,10 +86,28 @@ examples of how to configure Mactag.
82
86
  rails :except => :actionmailer, :version => '2.3.5'
83
87
  end
84
88
 
85
-
86
89
  # Usage
87
90
  To create the TAGS file. Simply run:
88
- $ rake mactag
91
+ $ rake mactag:create
92
+
93
+
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.
98
+
99
+ To enable FSSM, add the **fssm** gem to your projects Gemfile.
100
+
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
+
108
+ ## Editor support
109
+
110
+ * Emacs - <http://github.com/rejeep/mactag.el>
89
111
 
90
112
 
91
113
  # License
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.4.0
@@ -1,15 +1,20 @@
1
- require 'rails'
2
-
3
1
  require 'mactag/railtie'
4
2
  require 'mactag/config'
5
3
  require 'mactag/builder'
6
4
  require 'mactag/dsl'
7
- require 'mactag/ctags'
8
5
  require 'mactag/tag'
6
+ require 'mactag/ctags'
7
+ require 'mactag/server'
8
+ require 'mactag/event_handler'
9
+ require 'mactag/tags_file'
9
10
 
10
11
  module Mactag
12
+ autoload :Bundler, 'bundler'
13
+ autoload :Rails, 'rails'
14
+ autoload :FSSM, 'fssm'
15
+
11
16
  def self.warn(message)
12
- $stderr.puts "Mactag Warning: #{message}"
17
+ STDERR.puts(message)
13
18
  end
14
19
  end
15
20
 
@@ -8,27 +8,24 @@ module Mactag
8
8
  @tags = []
9
9
  end
10
10
 
11
- ##
12
- #
13
- # Add +tag+ to list of tags.
14
- #
15
11
  def <<(tags)
16
12
  @tags += Array(tags)
17
13
  end
18
14
 
19
- ##
20
- #
21
- # Returns a string with all files that should be tagged. The
22
- # files are separated with a whitespace.
23
- #
24
- def tags
15
+ def files
25
16
  tags = all
26
17
  tags.flatten!
27
18
  tags.compact!
28
19
  tags.collect! { |file| File.expand_path(file) }
29
20
  tags.collect! { |file| Dir.glob(file) }
21
+ tags.flatten!
30
22
  tags.uniq!
31
- tags.join(' ')
23
+ tags.reject! { |file| File.directory?(file) }
24
+ tags
25
+ end
26
+
27
+ def directories
28
+ files.collect { |file| File.dirname(file) }.uniq
32
29
  end
33
30
 
34
31
  def all
@@ -39,42 +36,20 @@ module Mactag
39
36
  all.flatten.compact.any?
40
37
  end
41
38
 
42
- ##
43
- #
44
- # Create the TAGS file.
45
- #
46
39
  def self.create
47
40
  unless gem_home_exists?
48
41
  Mactag.warn 'Gem home path does not exist on your system'
49
42
  end
50
43
 
51
- tags = Mactag::Ctags.new(@builder)
52
- if tags.build
44
+ if @builder.gems?
45
+ Mactag::Ctags.new(@builder.files, Mactag::Config.tags_file).create
46
+
53
47
  puts "Successfully generated TAGS file"
54
48
  else
55
49
  Mactag.warn 'You did not specify anything to tag'
56
50
  end
57
51
  end
58
52
 
59
- ##
60
- #
61
- # Generates the TAGS-table.
62
- #
63
- # ==== Example
64
- # Mactag::Builder.generate do
65
- # app 'app/**/*.rb', 'lib/*.rb'
66
- #
67
- # plugins 'thinking-sphinx', 'whenever'
68
- #
69
- # gems 'paperclip', 'authlogic'
70
- # gem 'formtastic', :version => '0.9.7'
71
- #
72
- # rails :except => :actionmailer, :version => '2.3.5'
73
- # end
74
- #
75
- # See documentation for the methods *app*, *plugins*, *gems* and
76
- # *rails* in respective tag class.
77
- #
78
53
  def self.generate(&block)
79
54
  @builder = Mactag::Builder.new
80
55
 
@@ -82,13 +57,12 @@ module Mactag
82
57
  dsl.instance_eval(&block)
83
58
  end
84
59
 
85
- ##
86
- #
87
- # Returns true if the specified gem home path exists on the
88
- # system, false otherwise.
89
- #
90
60
  def self.gem_home_exists?
91
61
  File.directory?(Mactag::Config.gem_home)
92
62
  end
63
+
64
+ def self.builder
65
+ @builder
66
+ end
93
67
  end
94
68
  end
@@ -2,15 +2,34 @@ module Mactag
2
2
  class Config
3
3
  ##
4
4
  #
5
- # The command to run when creating the TAGS-file.
6
- # Mactag::Config.binary = 'etags -o TAGS'
5
+ # The command to run (replacing {OUTPUT} with Mactag::Config.tags_file
6
+ # and {INPUT} with the input files) when creating the TAGS-file.
7
7
  #
8
- @@binary = 'ctags -o TAGS -e'
8
+ # Mactag::Config.binary = 'etags -o {OUTPUT} {INPUT}'
9
+ #
10
+ @@binary = 'ctags -o {OUTPUT} -e {INPUT}'
9
11
  cattr_accessor :binary
10
12
 
13
+ ##
14
+ #
15
+ # Name of the output tags file.
16
+ #
17
+ # Mactag::Config.binary = 'TAGS_FILE'
18
+ #
19
+ @@tags_file = 'TAGS'
20
+ cattr_accessor :tags_file
21
+
22
+ ##
23
+ #
24
+ # Directory to store tags in when using Mactag server and FSSM.
25
+ #
26
+ @@tags_dir = '.tags'
27
+ cattr_accessor :tags_dir
28
+
11
29
  ##
12
30
  #
13
31
  # The system folder where the gems are located.
32
+ #
14
33
  # Mactag::Config.gem_home = '/Library/Ruby/Gems/1.8/gems'
15
34
  #
16
35
  @@gem_home = '/Library/Ruby/Gems/1.8/gems'
@@ -28,6 +47,7 @@ module Mactag
28
47
  #
29
48
  # If using Ruby Version Manager (RVM), setting this option to true
30
49
  # will enable Mactag to find out the gem path automatically.
50
+ #
31
51
  # Mactag::Config.rvm = false
32
52
  #
33
53
  @@rvm = true
@@ -1,23 +1,32 @@
1
- require 'rails'
2
-
3
1
  module Mactag
4
2
  ##
5
3
  #
6
- # Helper class for creating CTags files.
4
+ # Wrapper around Ctags command.
7
5
  #
8
6
  class Ctags
9
- def initialize(builder)
10
- @builder = builder
7
+ def initialize(input, output)
8
+ @input = Array(input)
9
+ @output = output
10
+ end
11
+
12
+ def create
13
+ system(command)
11
14
  end
12
15
 
13
- ##
14
- #
15
- # Creates the tags file. Returns true if anything was tagged,
16
- # false otherwise.
17
- #
18
- def build
19
- system "cd #{Rails.root} && #{Mactag::Config.binary} #{@builder.tags}"
20
- @builder.gems?
16
+
17
+ private
18
+
19
+ def command
20
+ "cd #{Rails.root} && #{binary}"
21
+ end
22
+
23
+ def binary
24
+ binary = Mactag::Config.binary
25
+
26
+ binary.gsub!('{OUTPUT}', @output)
27
+ binary.gsub!('{INPUT}', @input.join(' '))
28
+
29
+ binary
21
30
  end
22
31
  end
23
32
  end
@@ -0,0 +1,22 @@
1
+ module Mactag
2
+ class EventHandler
3
+ def update(file)
4
+ tags_file = Mactag::TagsFile.new(file)
5
+ if tags_file.exist?
6
+ tags_file.delete
7
+ tags_file.create
8
+ end
9
+ end
10
+
11
+ def delete(file)
12
+ tags_file = Mactag::TagsFile.new(file)
13
+ if tags_file.exist?
14
+ tags_file.delete
15
+ end
16
+ end
17
+
18
+ def create(file)
19
+ Mactag::TagsFile.new(file).create
20
+ end
21
+ end
22
+ end
@@ -1,7 +1,7 @@
1
1
  module Mactag
2
2
  class Railtie < Rails::Railtie
3
3
  rake_tasks do
4
- load "tasks/mactag.rake"
4
+ load 'tasks/mactag.rake'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,48 @@
1
+ module Mactag
2
+ class Server
3
+ class << self
4
+ def start
5
+ create_tags_dir
6
+ clear_tags
7
+ init_tags
8
+ init_monitor
9
+ end
10
+
11
+
12
+ private
13
+
14
+ def create_tags_dir
15
+ tags_dir = File.join(Rails.root, Mactag::Config.tags_dir)
16
+ unless File.directory?(tags_dir)
17
+ Dir.mkdir(tags_dir)
18
+ end
19
+ end
20
+
21
+ def clear_tags
22
+ tags_files = File.join(Rails.root, Mactag::Config.tags_dir, '*')
23
+ Dir.glob(tags_files).each do |file|
24
+ File.delete(file)
25
+ end
26
+ end
27
+
28
+ def init_tags
29
+ Mactag::Builder.builder.files.each do |file|
30
+ Mactag::TagsFile.new(file).create
31
+ end
32
+ end
33
+
34
+ def init_monitor
35
+ event_handler = Mactag::EventHandler.new
36
+ FSSM.monitor do
37
+ Mactag::Builder.builder.directories.each do |directory|
38
+ path(directory) do
39
+ update { |base, relative| event_handler.update(File.join(base, relative)) }
40
+ delete { |base, relative| event_handler.delete(File.join(base, relative)) }
41
+ create { |base, relative| event_handler.create(File.join(base, relative)) }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -6,7 +6,7 @@ module Mactag
6
6
  #
7
7
  # ==== Examples
8
8
  # Mactag do
9
- # # Tag all gems given by *...*
9
+ # # Tags all gems specified in Gemfile.
10
10
  # gems
11
11
  #
12
12
  # # Tag the whenever gem, latest version
@@ -20,8 +20,6 @@ module Mactag
20
20
  # do
21
21
  #
22
22
  class Gem
23
- autoload :Bundler, 'bundler'
24
-
25
23
  def initialize(name, version = nil)
26
24
  @name = name
27
25
  @version = version
@@ -40,10 +38,6 @@ module Mactag
40
38
  end
41
39
  end
42
40
 
43
- ##
44
- #
45
- # Returns all application gems in Bundler default group.
46
- #
47
41
  def self.all
48
42
  gems = {}
49
43
  Bundler.load.specs.each do |spec|
@@ -55,10 +49,6 @@ module Mactag
55
49
  default.collect { |tmp| Gem.new(tmp, gems[tmp]) }
56
50
  end
57
51
 
58
- ##
59
- #
60
- # Returns the most recent gem with +name+.
61
- #
62
52
  def self.most_recent(name)
63
53
  versions = Dir.glob(File.join(Mactag::Config.gem_home, name) + "-*")
64
54
  unless versions.empty?
@@ -74,10 +64,6 @@ module Mactag
74
64
 
75
65
  private
76
66
 
77
- ##
78
- #
79
- # Returns true if +gem+ exists, false otherwise.
80
- #
81
67
  def exists?
82
68
  if @version
83
69
  File.directory?(File.join(Mactag::Config.gem_home, splash))
@@ -86,10 +72,6 @@ module Mactag
86
72
  end
87
73
  end
88
74
 
89
- ##
90
- #
91
- # Returns the gem name, dash, version.
92
- #
93
75
  def splash
94
76
  "#{@name}-#{@version}"
95
77
  end
@@ -41,15 +41,7 @@ module Mactag
41
41
  # do
42
42
  #
43
43
  class Rails
44
- PACKAGES = [
45
- :actionmailer,
46
- :actionpack,
47
- :activemodel,
48
- :activerecord,
49
- :activeresource,
50
- :railties,
51
- :activesupport
52
- ]
44
+ PACKAGES = [:actionmailer, :actionpack, :activemodel, :activerecord, :activeresource, :railties, :activesupport]
53
45
 
54
46
  def initialize(options)
55
47
  @options = options
@@ -70,11 +62,7 @@ module Mactag
70
62
 
71
63
 
72
64
  private
73
-
74
- ##
75
- #
76
- # Returns a list of all packages that should be included.
77
- #
65
+
78
66
  def packages
79
67
  result = []
80
68
  unless @only || @except
@@ -88,11 +76,7 @@ module Mactag
88
76
  end
89
77
  result
90
78
  end
91
-
92
- ##
93
- #
94
- # Packagizes all +pkgs+.
95
- #
79
+
96
80
  def packagize!(pkgs)
97
81
  return nil if pkgs.blank?
98
82
 
@@ -100,11 +84,7 @@ module Mactag
100
84
  "#{pkg}".gsub(/[^a-z]/, '').to_sym
101
85
  end
102
86
  end
103
-
104
- ##
105
- #
106
- # Returns what Rails version to use.
107
- #
87
+
108
88
  def version
109
89
  @options[:version] || ::Rails.version
110
90
  end