mactag 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +19 -16
- data/VERSION +1 -1
- data/features/app.feature +82 -16
- data/features/gem.feature +116 -36
- data/features/plugin.feature +86 -21
- data/features/rails.feature +6 -0
- data/features/step_definitions/mactag_steps.rb +43 -0
- data/features/support/env.rb +4 -0
- data/features/support/rails_app.rb +20 -48
- data/features/support/tags_file.rb +8 -5
- data/lib/generators/mactag/templates/mactag.rb +50 -9
- data/lib/mactag.rb +1 -1
- data/lib/mactag/config.rb +28 -7
- data/lib/mactag/table.rb +22 -9
- data/lib/mactag/tag/app.rb +10 -10
- data/lib/mactag/tag/gem.rb +51 -17
- data/lib/mactag/tag/parser.rb +12 -2
- data/lib/mactag/tag/plugin.rb +15 -12
- data/lib/mactag/tag/rails.rb +43 -67
- data/test/mactag/config_test.rb +33 -3
- data/test/mactag/tag/app_test.rb +3 -5
- data/test/mactag/tag/gem_test.rb +47 -20
- data/test/mactag/tag/plugin_test.rb +23 -25
- data/test/mactag/tag/rails_test.rb +18 -123
- metadata +105 -27
- data/TODO +0 -8
- data/features/rails/actionmailer/lib/action_mailer/base.rb +0 -9
- data/features/rails/actionpack/lib/action_controller/caching/actions.rb +0 -11
- data/features/rails/actionpack/lib/action_view/action_view/helpers/form_tag_helper.rb +0 -9
- data/features/rails/activerecord/lib/active_record/associations.rb +0 -9
- data/features/rails/activeresource/lib/active_resource/connection.rb +0 -7
- data/features/rails/activesupport/lib/active_support/core_ext/hash/diff.rb +0 -5
- data/features/rails_gem.feature +0 -89
- data/features/rails_vendor.feature +0 -57
- data/features/step_definitions/gem_steps.rb +0 -22
- data/features/step_definitions/mactab_steps.rb +0 -57
- data/features/step_definitions/plugin_steps.rb +0 -22
- data/features/step_definitions/rails_steps.rb +0 -20
- data/lib/mactag/tag/versioned.rb +0 -22
@@ -0,0 +1,43 @@
|
|
1
|
+
Given /^a Rails application$/ do
|
2
|
+
@app = RailsApp.new
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^mactag is installed$/ do
|
6
|
+
mactag = File.join(@app.root, "vendor", "plugins", "mactag")
|
7
|
+
|
8
|
+
FileUtils.mkdir_p(mactag)
|
9
|
+
|
10
|
+
[ "lib", "Rakefile", "init.rb" ].each do |file|
|
11
|
+
file = File.join(File.dirname(__FILE__), "..", "..", file)
|
12
|
+
|
13
|
+
FileUtils.cp_r(file, mactag)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Given /^this mactag config file:$/ do |config|
|
18
|
+
@app.inject "config/mactag.rb", config
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^I create the tags file$/ do
|
22
|
+
@tags = TagsFile.new(@app)
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^"([^"]*)" should be tagged$/ do |definition|
|
26
|
+
assert @tags.include?(definition)
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^"([^"]*)" should not be tagged$/ do |definition|
|
30
|
+
assert !@tags.include?(definition)
|
31
|
+
end
|
32
|
+
|
33
|
+
Given /^the plugin "([^"]*)" is installed$/ do |plugin|
|
34
|
+
@app.install_plugin(plugin)
|
35
|
+
end
|
36
|
+
|
37
|
+
Given /^the gem "([^"]*)" version "([^"]*)" is installed$/ do |gem, version|
|
38
|
+
@app.install_gem(gem, version)
|
39
|
+
end
|
40
|
+
|
41
|
+
Given /^file "([^"]*)" with contents:$/ do |file, contents|
|
42
|
+
@app.inject file, contents
|
43
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -1,74 +1,46 @@
|
|
1
1
|
class RailsApp
|
2
|
+
NAME = 'rails_app'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(name = "rails_app")
|
6
|
-
@name = name
|
7
|
-
|
4
|
+
def initialize
|
8
5
|
create
|
9
6
|
end
|
10
7
|
|
8
|
+
def root
|
9
|
+
@root ||= File.join(File.dirname(__FILE__), '..', '..', NAME)
|
10
|
+
end
|
11
|
+
|
11
12
|
def destroy
|
12
|
-
FileUtils.rm_rf(
|
13
|
+
FileUtils.rm_rf(root)
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
File.open(file, "a") { |f| f.write(text) }
|
16
|
+
def inject(file, contents)
|
17
|
+
to = File.join(root, file)
|
18
|
+
File.open(to, 'a') { |f| f.write("#{contents}\n") }
|
19
19
|
end
|
20
20
|
|
21
21
|
def install_plugin(plugin)
|
22
|
-
|
22
|
+
cmd = "cd #{root}"
|
23
|
+
cmd << " && rails generate plugin #{plugin}"
|
24
|
+
cmd << ' -q' unless ENV['DEBUG'] == 'true'
|
25
|
+
system cmd
|
23
26
|
end
|
24
27
|
|
25
28
|
def install_gem(gem, version)
|
26
29
|
install_plugin(gem)
|
27
30
|
|
28
|
-
plugins = File.join(
|
29
|
-
gems = File.join(
|
31
|
+
plugins = File.join(root, 'vendor', 'plugins')
|
32
|
+
gems = File.join(root, 'vendor', 'gems')
|
30
33
|
|
31
34
|
FileUtils.mkdir_p(gems)
|
32
35
|
FileUtils.mv(File.join(plugins, gem), File.join(gems, "#{gem}-#{version}"))
|
33
36
|
end
|
34
|
-
|
35
|
-
def install_rails_vendor
|
36
|
-
from = File.join("features", "rails")
|
37
|
-
to = File.join(rails_root, "vendor", "rails-temp")
|
38
|
-
|
39
|
-
FileUtils.cp_r(from, to)
|
40
|
-
end
|
41
|
-
|
42
|
-
def install_rails_gem(version = "3.0.0")
|
43
|
-
from = File.join("features", "rails", "*")
|
44
|
-
to = File.join(rails_root, "vendor", "rails-temp")
|
45
|
-
|
46
|
-
FileUtils.mkdir_p(to)
|
47
|
-
|
48
|
-
Dir.glob(from).each do |file|
|
49
|
-
FileUtils.cp_r(file, to)
|
50
|
-
end
|
51
|
-
|
52
|
-
Dir.glob(File.join(to, "*[a-z]")).each do |file|
|
53
|
-
FileUtils.mv(file, "#{file}-#{version}")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def gsub(file, from, to)
|
58
|
-
text = File.read(file)
|
59
|
-
File.open(file, 'w+') do |f|
|
60
|
-
f << text.gsub(from, to)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def rails_root
|
65
|
-
@rails_root ||= File.join(File.dirname(__FILE__), "..", "..", @name)
|
66
|
-
end
|
67
|
-
|
37
|
+
|
68
38
|
|
69
39
|
private
|
70
40
|
|
71
41
|
def create
|
72
|
-
|
42
|
+
cmd = "rails new #{NAME}"
|
43
|
+
cmd << ' -q' unless ENV['DEBUG'] == 'true'
|
44
|
+
system cmd
|
73
45
|
end
|
74
46
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
class TagsFile
|
2
2
|
def initialize(app)
|
3
3
|
@app = app
|
4
|
-
@
|
4
|
+
@file = File.join(@app.root, "TAGS")
|
5
5
|
|
6
6
|
create
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
File.open(@
|
11
|
-
return file.read =~ /#{
|
9
|
+
def include?(definition)
|
10
|
+
File.open(@file) do |file|
|
11
|
+
return file.read =~ /#{definition}/
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -16,6 +16,9 @@ class TagsFile
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def create
|
19
|
-
|
19
|
+
cmd = "cd #{@app.root}"
|
20
|
+
cmd << " && rake mactag"
|
21
|
+
cmd << " --trace" if ENV['DEBUG'] == 'true'
|
22
|
+
system cmd
|
20
23
|
end
|
21
24
|
end
|
@@ -1,33 +1,74 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
##
|
2
|
+
#
|
3
|
+
# Use RVM gem path. Mactag will automatically find this.
|
4
|
+
# Defaults to *true*.
|
5
|
+
# Mactag::Config.rvm = true
|
6
|
+
#
|
7
|
+
|
8
|
+
##
|
9
|
+
#
|
10
|
+
# Path to gems. This options is only interesting if Mactag::Config.rvm
|
11
|
+
# is false.
|
3
12
|
#
|
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.
|
4
16
|
# Most GNU/Linux systems:
|
5
|
-
# Mactag::Config.gem_home =
|
17
|
+
# Mactag::Config.gem_home = '/usr/lib/ruby/gems/1.8/gems'
|
18
|
+
#
|
6
19
|
|
20
|
+
##
|
21
|
+
#
|
7
22
|
# Change the binary option if you are not satisfied with the standard
|
8
23
|
# command (ctags -o TAGS -e) used to create the TAGS table.
|
9
|
-
#
|
24
|
+
# Default is *ctags -o TAGS -e*
|
25
|
+
# Mactag::Config.binary = 'etags -o TAGS'
|
26
|
+
#
|
10
27
|
|
28
|
+
##
|
29
|
+
#
|
11
30
|
# Example configuration. Change according to your application.
|
31
|
+
#
|
12
32
|
Mactag::Table.generate do
|
33
|
+
##
|
34
|
+
#
|
13
35
|
# Index all ruby files in app recursive and all ruby files directly under lib.
|
14
|
-
# app
|
36
|
+
# app 'app/**/*.rb', 'lib/*.rb'
|
37
|
+
#
|
15
38
|
|
39
|
+
##
|
40
|
+
#
|
16
41
|
# Index the plugins thinking-sphinx and formtastic.
|
17
|
-
# plugins
|
42
|
+
# plugins 'thinking-sphinx', 'formtastic'
|
43
|
+
#
|
18
44
|
|
45
|
+
##
|
46
|
+
#
|
19
47
|
# Index the gems paperclip and authlogic.
|
20
|
-
# gems
|
48
|
+
# gems 'paperclip', 'authlogic'
|
49
|
+
#
|
21
50
|
|
51
|
+
##
|
52
|
+
#
|
22
53
|
# Index the gem formtastic version 0.9.7.
|
23
|
-
# gem
|
54
|
+
# gem 'formtastic', :version => '0.9.7'
|
55
|
+
#
|
24
56
|
|
57
|
+
##
|
58
|
+
#
|
25
59
|
# Index all rails packages, except actionmailer.
|
26
60
|
# rails :except => :actionmailer
|
61
|
+
#
|
27
62
|
|
63
|
+
##
|
64
|
+
#
|
28
65
|
# Index only rails packages activerecord and activesupport.
|
29
66
|
# rails :only => [:activerecord, :active_support]
|
67
|
+
#
|
30
68
|
|
69
|
+
##
|
70
|
+
#
|
31
71
|
# Index all rails packages, version 2.3.5.
|
32
|
-
# rails :version =>
|
72
|
+
# rails :version => '2.3.5'
|
73
|
+
#
|
33
74
|
end
|
data/lib/mactag.rb
CHANGED
data/lib/mactag/config.rb
CHANGED
@@ -1,15 +1,36 @@
|
|
1
1
|
module Mactag
|
2
2
|
class Config
|
3
|
-
|
3
|
+
##
|
4
|
+
#
|
4
5
|
# The command to run when creating the TAGS-file.
|
5
|
-
# Mactag::Config.binary =
|
6
|
-
|
6
|
+
# Mactag::Config.binary = 'etags -o TAGS'
|
7
|
+
#
|
8
|
+
@@binary = 'ctags -o TAGS -e'
|
7
9
|
cattr_accessor :binary
|
8
10
|
|
9
|
-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
11
|
+
##
|
12
|
+
#
|
13
|
+
# The system folder where the gems are located.
|
14
|
+
# Mactag::Config.gem_home = '/Library/Ruby/Gems/1.8/gems'
|
15
|
+
#
|
16
|
+
@@gem_home = '/Library/Ruby/Gems/1.8/gems'
|
17
|
+
cattr_writer :gem_home
|
18
|
+
|
19
|
+
def self.gem_home
|
20
|
+
if rvm
|
21
|
+
File.join(ENV['GEM_HOME'], 'gems')
|
22
|
+
else
|
23
|
+
@@gem_home
|
24
|
+
end
|
25
|
+
end
|
13
26
|
|
27
|
+
##
|
28
|
+
#
|
29
|
+
# If using Ruby Version Manager (RVM), setting this option to true
|
30
|
+
# will enable Mactag to find out the gem path automatically.
|
31
|
+
# Mactag::Config.rvm = false
|
32
|
+
#
|
33
|
+
@@rvm = true
|
34
|
+
cattr_accessor :rvm
|
14
35
|
end
|
15
36
|
end
|
data/lib/mactag/table.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
module Mactag
|
2
2
|
class Table
|
3
|
-
|
4
3
|
@@tags = []
|
5
4
|
|
6
5
|
class << self
|
6
|
+
##
|
7
|
+
#
|
7
8
|
# Generates the TAGS-table.
|
8
9
|
#
|
9
10
|
# ==== Example
|
10
11
|
# Mactag::Table.generate do
|
11
|
-
# app
|
12
|
+
# app 'app/**/*.rb', 'lib/*.rb'
|
12
13
|
#
|
13
|
-
# plugins
|
14
|
+
# plugins 'thinking-sphinx', 'whenever'
|
14
15
|
#
|
15
|
-
# gems
|
16
|
-
# gem
|
16
|
+
# gems 'paperclip', 'authlogic'
|
17
|
+
# gem 'formtastic', :version => '0.9.7'
|
17
18
|
#
|
18
|
-
# rails :except => :actionmailer, :version =>
|
19
|
+
# rails :except => :actionmailer, :version => '2.3.5'
|
19
20
|
# end
|
20
21
|
#
|
21
22
|
# See documentation for the methods *app*, *plugins*, *gems* and
|
22
23
|
# *rails* in respective tag class.
|
24
|
+
#
|
23
25
|
def generate(&block)
|
24
26
|
parser = Mactag::Tag::Parser.new(self)
|
25
27
|
parser.instance_eval(&block)
|
@@ -29,8 +31,11 @@ module Mactag
|
|
29
31
|
@@tags << tag
|
30
32
|
end
|
31
33
|
|
34
|
+
##
|
35
|
+
#
|
32
36
|
# Returns a string with all files that should be tagged. The
|
33
37
|
# files are separated with a whitespace.
|
38
|
+
#
|
34
39
|
def tags
|
35
40
|
@@tags.collect!(&:files)
|
36
41
|
@@tags.flatten!
|
@@ -40,14 +45,22 @@ module Mactag
|
|
40
45
|
@@tags.join(' ')
|
41
46
|
end
|
42
47
|
|
48
|
+
##
|
49
|
+
#
|
50
|
+
# Create the TAGS file.
|
51
|
+
#
|
43
52
|
def create
|
44
53
|
unless File.directory?(Mactag::Config.gem_home)
|
45
|
-
Mactag.warn
|
54
|
+
Mactag.warn 'Gem home path does not exist on your system'
|
46
55
|
end
|
47
56
|
|
48
|
-
|
57
|
+
if @@tags.collect(&:files).flatten.empty?
|
58
|
+
Mactag.warn 'You did not specify anything to tag'
|
59
|
+
else
|
60
|
+
system "cd #{Rails.root} && #{Mactag::Config.binary} #{Mactag::Table.tags}"
|
61
|
+
puts "Successfully generated TAGS file"
|
62
|
+
end
|
49
63
|
end
|
50
64
|
end
|
51
|
-
|
52
65
|
end
|
53
66
|
end
|
data/lib/mactag/tag/app.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
module Mactag
|
2
2
|
module Tag
|
3
|
-
|
4
|
-
#
|
3
|
+
##
|
4
|
+
#
|
5
|
+
# Tags files in current Rails application.
|
5
6
|
#
|
6
7
|
# ==== Examples
|
7
8
|
# Mactag::Table.generate do
|
8
|
-
# # Tag
|
9
|
-
# app
|
9
|
+
# # Tag single file
|
10
|
+
# app 'lib/super_duper.rb'
|
10
11
|
#
|
11
12
|
# # Tag all files in lib, recursive
|
12
|
-
# app
|
13
|
+
# app 'lib/**/*.rb'
|
13
14
|
#
|
14
15
|
# # Tag all helpers and models
|
15
|
-
# app
|
16
|
+
# app 'app/helpers/*.rb', 'app/models/*.rb'
|
16
17
|
#
|
17
18
|
# # Same as above
|
18
|
-
# app
|
19
|
+
# app 'app/{models,helpers}/*.rb'
|
19
20
|
# do
|
21
|
+
#
|
20
22
|
class App
|
21
|
-
|
22
23
|
attr_reader :files
|
23
|
-
|
24
|
+
|
24
25
|
def initialize(*files)
|
25
26
|
@files = files
|
26
27
|
end
|
27
|
-
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/lib/mactag/tag/gem.rb
CHANGED
@@ -1,32 +1,33 @@
|
|
1
|
-
require 'mactag/tag/versioned'
|
2
|
-
|
3
|
-
|
4
1
|
module Mactag
|
5
2
|
module Tag
|
6
|
-
|
7
|
-
#
|
3
|
+
##
|
4
|
+
#
|
5
|
+
# Tags ruby gems.
|
8
6
|
#
|
9
7
|
# ==== Examples
|
10
8
|
# Mactag::Table.generate do
|
11
|
-
# # Tag all gems given by
|
9
|
+
# # Tag all gems given by *...*
|
12
10
|
# gems
|
13
11
|
#
|
14
12
|
# # Tag the whenever gem, latest version
|
15
|
-
# gem
|
13
|
+
# gem 'whenever'
|
16
14
|
#
|
17
15
|
# # Tag the thinking-sphinx and formtastic gems, latest versions
|
18
|
-
# gems
|
16
|
+
# gems 'thinking-sphinx', 'formtastic'
|
19
17
|
#
|
20
|
-
# # Tag the formtastic gem version 0.8.2
|
21
|
-
# gem
|
18
|
+
# # Tag the formtastic gem, version 0.8.2
|
19
|
+
# gem 'formtastic', :version => '0.8.2'
|
22
20
|
# do
|
21
|
+
#
|
23
22
|
class Gem
|
24
|
-
|
25
|
-
include Versioned
|
26
|
-
|
27
23
|
def initialize(*gems)
|
28
|
-
|
29
|
-
|
24
|
+
if gems.blank?
|
25
|
+
@gems = all
|
26
|
+
@options = {}
|
27
|
+
else
|
28
|
+
@gems = gems
|
29
|
+
@options = gems.extract_options!
|
30
|
+
end
|
30
31
|
end
|
31
32
|
|
32
33
|
def files
|
@@ -38,15 +39,48 @@ module Mactag
|
|
38
39
|
gem = latest(gem_name)
|
39
40
|
end
|
40
41
|
|
41
|
-
if gem
|
42
|
+
if exists?(gem)
|
42
43
|
result << File.join(gem, "lib", "**", "*.rb")
|
43
44
|
else
|
44
|
-
|
45
|
+
Mactag.warn "Gem #{gem_name} not found"
|
45
46
|
end
|
46
47
|
end
|
47
48
|
result
|
48
49
|
end
|
49
50
|
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
##
|
55
|
+
#
|
56
|
+
# Returns the latest version of +gem+. If only one gem, that gem
|
57
|
+
# is returned.
|
58
|
+
#
|
59
|
+
def latest(gem)
|
60
|
+
versions = Dir.glob(File.join(Mactag::Config.gem_home, gem) + "-*")
|
61
|
+
if versions.size == 1
|
62
|
+
gem = versions.first
|
63
|
+
else
|
64
|
+
gem = versions.sort.last
|
65
|
+
end
|
66
|
+
gem
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
#
|
71
|
+
# Returns true if +gem+ exists, false otherwise.
|
72
|
+
#
|
73
|
+
def exists?(gem)
|
74
|
+
gem && File.directory?(gem)
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
#
|
79
|
+
# Returns all gems in this application.
|
80
|
+
#
|
81
|
+
def all
|
82
|
+
Bundler.environment.dependencies.select { |d| d.groups.include?(:default) }.collect(&:name)
|
83
|
+
end
|
50
84
|
end
|
51
85
|
end
|
52
86
|
end
|