mactag 0.0.1
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.
- data/README.markdown +68 -0
- data/VERSION +1 -0
- data/features/app.feature +35 -0
- data/features/gem.feature +59 -0
- data/features/plugin.feature +41 -0
- data/features/rails/actionmailer/lib/action_mailer/base.rb +9 -0
- data/features/rails/actionpack/lib/action_controller/caching/actions.rb +11 -0
- data/features/rails/actionpack/lib/action_view/action_view/helpers/form_tag_helper.rb +9 -0
- data/features/rails/activerecord/lib/active_record/associations.rb +9 -0
- data/features/rails/activeresource/lib/active_resource/connection.rb +7 -0
- data/features/rails/activesupport/lib/active_support/core_ext/hash/diff.rb +5 -0
- data/features/rails_gem.feature +69 -0
- data/features/rails_vendor.feature +46 -0
- data/features/step_definitions/app_steps.rb +11 -0
- data/features/step_definitions/gem_steps.rb +40 -0
- data/features/step_definitions/mactab_steps.rb +53 -0
- data/features/step_definitions/plugin_steps.rb +34 -0
- data/features/step_definitions/rails_steps.rb +62 -0
- data/features/support/core_ext.rb +5 -0
- data/features/support/env.rb +10 -0
- data/features/support/rails_app.rb +74 -0
- data/features/support/tags_file.rb +21 -0
- data/generators/mactag/mactag_generator.rb +10 -0
- data/generators/mactag/templates/mactag.rb +11 -0
- data/lib/mactag.rb +6 -0
- data/lib/mactag/config.rb +20 -0
- data/lib/mactag/table.rb +45 -0
- data/lib/mactag/tag.rb +8 -0
- data/lib/mactag/tag/app.rb +30 -0
- data/lib/mactag/tag/gem.rb +46 -0
- data/lib/mactag/tag/parser.rb +33 -0
- data/lib/mactag/tag/plugin.rb +32 -0
- data/lib/mactag/tag/rails.rb +138 -0
- data/lib/mactag/tasks.rb +10 -0
- data/tasks/mactag_tasks.rake +1 -0
- data/test/mactag/config_test.rb +10 -0
- data/test/mactag/tag/app_test.rb +16 -0
- data/test/mactag/tag/gem_test.rb +42 -0
- data/test/mactag/tag/plugin_test.rb +40 -0
- data/test/mactag/tag/rails_test.rb +182 -0
- data/test/mactag_test.rb +4 -0
- metadata +94 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
Given /^the plugin "([^\"]*)" is installed$/ do |plugin|
|
2
|
+
@app.install_plugin(plugin)
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^an acts as method for the "([^\"]*)" plugin$/ do |plugin|
|
6
|
+
file = File.join("vendor", "plugins", plugin, "lib", "#{plugin}.rb")
|
7
|
+
@app.puts file do
|
8
|
+
<<-eos
|
9
|
+
module #{plugin.camelize}
|
10
|
+
def self.included(base)
|
11
|
+
base.send :extend, ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def acts_as_#{plugin}
|
16
|
+
# ...
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
eos
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Given /^a plugin mactag config with the following tags$/ do |table|
|
25
|
+
tags = table.rows.flatten.collect(&:quote).join(", ")
|
26
|
+
|
27
|
+
@app.puts "config/mactag.rb" do
|
28
|
+
<<-eos
|
29
|
+
Mactag::Table.generate do
|
30
|
+
plugins #{tags}
|
31
|
+
end
|
32
|
+
eos
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
Given /^rails lives in vendor$/ do
|
2
|
+
@app.install_rails_vendor
|
3
|
+
|
4
|
+
# Replaces the path to vendor rails. We can not use "rails" here
|
5
|
+
# since when running the rake task rails will try to start by using
|
6
|
+
# rails in vendor. But by renaming it to "rails-temp", this will not happen.
|
7
|
+
mactag = File.join(@app.rails_root, "vendor", "plugins", "mactag")
|
8
|
+
vendor = File.join(mactag, "lib", "mactag", "tag", "rails.rb")
|
9
|
+
from = 'VENDOR = File.join("vendor", "rails")'
|
10
|
+
to = 'VENDOR = File.join("vendor", "rails-temp")'
|
11
|
+
@app.gsub(vendor, from, to)
|
12
|
+
end
|
13
|
+
|
14
|
+
Given /^a rails mactag config with the following tags$/ do |table|
|
15
|
+
options = {
|
16
|
+
"only" => [],
|
17
|
+
"except" => [],
|
18
|
+
"version" => []
|
19
|
+
}
|
20
|
+
|
21
|
+
table.hashes.each do |hash|
|
22
|
+
hash.each do |option, value|
|
23
|
+
options[option] << value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if options.values.flatten.empty?
|
28
|
+
tags = ""
|
29
|
+
else
|
30
|
+
tags = []
|
31
|
+
options.each do |option, value|
|
32
|
+
unless value.empty?
|
33
|
+
if value.size == 1
|
34
|
+
tags << ":#{option} => #{value.first.quote}"
|
35
|
+
else
|
36
|
+
values = value.collect(&:quote).join(", ")
|
37
|
+
tags << ":#{option} => [#{values}]"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
tags = tags.join(", ")
|
43
|
+
end
|
44
|
+
|
45
|
+
@app.puts "config/mactag.rb" do
|
46
|
+
<<-eos
|
47
|
+
Mactag::Config.gem_home = File.join("vendor", "rails-temp")
|
48
|
+
|
49
|
+
Mactag::Table.generate do
|
50
|
+
rails #{tags}
|
51
|
+
end
|
52
|
+
eos
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Given /^rails is installed as a gem$/ do
|
57
|
+
@app.install_rails_gem
|
58
|
+
end
|
59
|
+
|
60
|
+
Given /^rails version "([^\"]*)" is installed as a gem$/ do |version|
|
61
|
+
@app.install_rails_gem(version)
|
62
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class RailsApp
|
2
|
+
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name = "rails_app")
|
6
|
+
@name = name
|
7
|
+
|
8
|
+
create
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy
|
12
|
+
FileUtils.rm_rf(rails_root)
|
13
|
+
end
|
14
|
+
|
15
|
+
def puts(file, &block)
|
16
|
+
file = File.join(rails_root, file)
|
17
|
+
contents = block_given? ? instance_eval(&block) : ""
|
18
|
+
File.open(file, "a") { |f| f.write(contents) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def install_plugin(plugin)
|
22
|
+
system "cd #{rails_root} && ./script/generate plugin #{plugin} &> /dev/null"
|
23
|
+
end
|
24
|
+
|
25
|
+
def install_gem(gem, version)
|
26
|
+
install_plugin(gem)
|
27
|
+
|
28
|
+
plugins = File.join(rails_root, "vendor", "plugins")
|
29
|
+
gems = File.join(rails_root, "vendor", "gems")
|
30
|
+
|
31
|
+
FileUtils.mkdir_p(gems)
|
32
|
+
FileUtils.mv(File.join(plugins, gem), File.join(gems, "#{gem}-#{version}"))
|
33
|
+
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
|
+
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def create
|
72
|
+
system "rails #{rails_root} -q"
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class TagsFile
|
2
|
+
def initialize(app)
|
3
|
+
@app = app
|
4
|
+
@tags_file = File.join(@app.rails_root, "TAGS")
|
5
|
+
|
6
|
+
create
|
7
|
+
end
|
8
|
+
|
9
|
+
def contain?(tag)
|
10
|
+
File.open(@tags_file) do |file|
|
11
|
+
return file.read =~ /#{tag}/
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def create
|
19
|
+
system "cd #{@app.rails_root} && rake mactag --trace"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Mactag::Table.generate do
|
2
|
+
app "app/**/*.rb", "lib/*.rb"
|
3
|
+
|
4
|
+
plugins "thinking-sphinx", "formtastic"
|
5
|
+
|
6
|
+
gems "paperclip", "authlogic"
|
7
|
+
gem "formtastic", :version => "0.9.7"
|
8
|
+
|
9
|
+
rails :except => :actionmailer
|
10
|
+
rails :only => [:activerecord, :active_support]
|
11
|
+
end
|
data/lib/mactag.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mactag
|
2
|
+
# Configuration options.
|
3
|
+
#
|
4
|
+
# ==== Binary
|
5
|
+
# The command to run when creating the TAGS-file.
|
6
|
+
# Mactag::Config.binary = "etags -o TAGS"
|
7
|
+
#
|
8
|
+
# ==== Gem Home
|
9
|
+
# The folder where the gems are stored.
|
10
|
+
# Mactag::Config.gem_home = "/usr/lib/ruby/gems/1.9/gems"
|
11
|
+
class Config
|
12
|
+
|
13
|
+
@@binary = "ctags -o TAGS -e"
|
14
|
+
cattr_accessor :binary
|
15
|
+
|
16
|
+
@@gem_home = "/usr/lib/ruby/gems/1.8/gems"
|
17
|
+
cattr_accessor :gem_home
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/mactag/table.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Mactag
|
2
|
+
class Table
|
3
|
+
|
4
|
+
@@tags = []
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# Generates the TAGS-table.
|
8
|
+
#
|
9
|
+
# ==== Example
|
10
|
+
# Mactag::Table.generate do
|
11
|
+
# app "app/**/*.rb", "lib/*.rb"
|
12
|
+
#
|
13
|
+
# plugins "thinking-sphinx", "whenever"
|
14
|
+
#
|
15
|
+
# gems "paperclip", "authlogic"
|
16
|
+
# gem "formtastic", :version => "0.9.7"
|
17
|
+
#
|
18
|
+
# rails :except => :actionmailer, :version => "2.3.5"
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# See documentation for the methods *app*, *plugins*, *gems* and
|
22
|
+
# *rails* in respective tag class.
|
23
|
+
def generate(&block)
|
24
|
+
parser = Mactag::Tag::Parser.new(self)
|
25
|
+
parser.instance_eval(&block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def <<(tag)
|
29
|
+
@@tags << tag
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns a string with all files that should be tagged. The
|
33
|
+
# files are separated with a whitespace.
|
34
|
+
def tags
|
35
|
+
@@tags.collect!(&:files)
|
36
|
+
@@tags.flatten!
|
37
|
+
@@tags.collect! { |file| File.expand_path(file) }
|
38
|
+
@@tags.collect! { |file| Dir.glob(file) }
|
39
|
+
@@tags.uniq!
|
40
|
+
@@tags.join(' ')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/lib/mactag/tag.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mactag
|
2
|
+
module Tag
|
3
|
+
|
4
|
+
# Tag for files in the current application.
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
# Mactag::Table.generate do
|
8
|
+
# # Tag only one file
|
9
|
+
# app "lib/super_duper.rb"
|
10
|
+
#
|
11
|
+
# # Tag all files in lib, recursive
|
12
|
+
# app "lib/**/*.rb"
|
13
|
+
#
|
14
|
+
# # Tag all helpers and models
|
15
|
+
# app "app/helpers/*.rb", "app/models/*.rb"
|
16
|
+
#
|
17
|
+
# # Same as above
|
18
|
+
# app "app/{models,helpers}/*.rb"
|
19
|
+
# do
|
20
|
+
class App
|
21
|
+
|
22
|
+
attr_reader :files
|
23
|
+
|
24
|
+
def initialize(*files)
|
25
|
+
@files = files
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Mactag
|
2
|
+
module Tag
|
3
|
+
|
4
|
+
# Tag for gems.
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
# Mactag::Table.generate do
|
8
|
+
# # Tag all gems given by *Rails.configuration.gems*
|
9
|
+
# gems
|
10
|
+
#
|
11
|
+
# # Tag the whenever gem, latest version
|
12
|
+
# gem "whenever"
|
13
|
+
#
|
14
|
+
# # Tag the thinking-sphinx and formtastic gems, latest versions
|
15
|
+
# gems "thinking-sphinx", "formtastic"
|
16
|
+
#
|
17
|
+
# # Tag the formtastic gem version 0.8.2
|
18
|
+
# gem "formtastic", :version => "0.8.2"
|
19
|
+
# do
|
20
|
+
class Gem
|
21
|
+
|
22
|
+
def initialize(*gems)
|
23
|
+
@options = gems.extract_options!
|
24
|
+
@gems = gems.blank? ? ::Rails.configuration.gems.collect(&:name) : gems
|
25
|
+
end
|
26
|
+
|
27
|
+
def files
|
28
|
+
@gems.collect do |gem|
|
29
|
+
if version = @options[:version]
|
30
|
+
gem = File.join(Mactag::Config.gem_home, "#{gem}-#{version}")
|
31
|
+
else
|
32
|
+
versions = Dir.glob(File.join(Mactag::Config.gem_home, "#{gem}*"))
|
33
|
+
if versions.size == 1
|
34
|
+
gem = versions.first
|
35
|
+
else
|
36
|
+
gem = versions.sort.last
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
File.join(gem, "lib", "**", "*.rb")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Mactag
|
2
|
+
module Tag
|
3
|
+
class Parser
|
4
|
+
|
5
|
+
def initialize(table)
|
6
|
+
@table = table
|
7
|
+
end
|
8
|
+
|
9
|
+
# @see Mactag::Tag::App
|
10
|
+
def app(*files)
|
11
|
+
@table << Mactag::Tag::App.new(*files)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @see Mactag::Tag::Plugin
|
15
|
+
def plugin(*plugins)
|
16
|
+
@table << Mactag::Tag::Plugin.new(*plugins)
|
17
|
+
end
|
18
|
+
alias_method :plugins, :plugin
|
19
|
+
|
20
|
+
# @see Mactag::Tag::Gem
|
21
|
+
def gem(*gems)
|
22
|
+
@table << Mactag::Tag::Gem.new(*gems)
|
23
|
+
end
|
24
|
+
alias_method :gems, :gem
|
25
|
+
|
26
|
+
# @see Mactag::Tag::Rails
|
27
|
+
def rails(options = {})
|
28
|
+
@table << Mactag::Tag::Rails.new(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Mactag
|
2
|
+
module Tag
|
3
|
+
|
4
|
+
# Tag for the current project plugins.
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
# Mactag::Table.generate do
|
8
|
+
# # Tag the whenever plugin
|
9
|
+
# plugin "whenever"
|
10
|
+
#
|
11
|
+
# # Tag the thinking-sphinx and formtastic plugins
|
12
|
+
# plugins "thinking-sphinx", "formtastic"
|
13
|
+
# do
|
14
|
+
class Plugin
|
15
|
+
|
16
|
+
PLUGIN_PATH = File.join("vendor", "plugins")
|
17
|
+
|
18
|
+
def initialize(*plugins)
|
19
|
+
@plugins = plugins
|
20
|
+
end
|
21
|
+
|
22
|
+
def files
|
23
|
+
return File.join(PLUGIN_PATH, "*", "lib", "**", "*.rb") if @plugins.empty?
|
24
|
+
|
25
|
+
@plugins.collect do |plugin|
|
26
|
+
File.join(PLUGIN_PATH, plugin, "lib", "**", "*.rb")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|