generator_extensions 0.1.6 → 0.1.7
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.rdoc +10 -1
- data/VERSION +1 -1
- data/generator_extensions.gemspec +1 -1
- data/lib/generator_extensions.rb +28 -75
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ template directory containing a partially duplicated Rails directory
|
|
29
29
|
structure (obviously, only include the directories you need):
|
30
30
|
|
31
31
|
your_generator.rb
|
32
|
-
templates
|
32
|
+
-templates
|
33
33
|
-mirror
|
34
34
|
-public
|
35
35
|
-stylesheets
|
@@ -47,4 +47,13 @@ do this:
|
|
47
47
|
|
48
48
|
m.mirror
|
49
49
|
|
50
|
+
One problem with mirroring a directory tree is that at the moment
|
51
|
+
there is no way to distinguish between existing directories (say, the
|
52
|
+
ones rails sets up) and any new ones you've implicitly created by
|
53
|
+
including them in the mirrored directory tree in your 'templates'
|
54
|
+
directory. So when you run the following:
|
50
55
|
|
56
|
+
script/destroy your_generator
|
57
|
+
|
58
|
+
it will delete any files you've copied over as part of an "m.mirror"
|
59
|
+
command, but none of the new directories.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/lib/generator_extensions.rb
CHANGED
@@ -1,91 +1,44 @@
|
|
1
1
|
require 'find'
|
2
2
|
|
3
|
-
module
|
4
|
-
module Generator
|
5
|
-
module Commands
|
6
|
-
|
7
|
-
|
8
|
-
class Create < Base
|
9
|
-
|
10
|
-
def mirror(origin='mirror')
|
11
|
-
directory_copy(origin, '')
|
12
|
-
end
|
3
|
+
module RailsGeneratorExtensions
|
13
4
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
path_to_delete = "#{source_root}/"
|
18
|
-
|
19
|
-
Find.find(source) do |f|
|
20
|
-
source = f.sub(path_to_delete, '')
|
21
|
-
target = File.join(relative_destination, source.sub(relative_source, ''))
|
22
|
-
case
|
23
|
-
when File.file?(f)
|
24
|
-
file source, target
|
25
|
-
when File.directory?(f)
|
26
|
-
directory target
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
5
|
+
def mirror(origin='mirror')
|
6
|
+
directory_copy(origin, '')
|
7
|
+
end
|
30
8
|
|
9
|
+
def directory_copy(relative_source, relative_destination=nil)
|
10
|
+
source = source_path(relative_source)
|
11
|
+
relative_destination ||= relative_source
|
12
|
+
path_to_delete = "#{source_root}/"
|
13
|
+
|
14
|
+
Find.find(source) do |f|
|
15
|
+
source = f.sub(path_to_delete, '')
|
16
|
+
target = File.join(relative_destination, source.sub(relative_source, ''))
|
17
|
+
case
|
18
|
+
when File.file?(f)
|
19
|
+
file source, target
|
20
|
+
when File.directory?(f)
|
21
|
+
directory target unless self.class.to_s.include? "Destroy"
|
31
22
|
end
|
23
|
+
end
|
24
|
+
end
|
32
25
|
|
26
|
+
end
|
33
27
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def mirror(origin='mirror')
|
38
|
-
directory_copy(origin, '')
|
39
|
-
end
|
40
|
-
|
41
|
-
def directory_copy(relative_source, relative_destination=nil)
|
42
|
-
source = source_path(relative_source)
|
43
|
-
relative_destination ||= relative_source
|
44
|
-
path_to_delete = "#{source_root}/"
|
28
|
+
module Rails
|
29
|
+
module Generator
|
30
|
+
module Commands
|
45
31
|
|
46
|
-
|
47
|
-
|
48
|
-
target = File.join(relative_destination, source.sub(relative_source, ''))
|
49
|
-
case
|
50
|
-
when File.file?(f)
|
51
|
-
file source, target
|
52
|
-
when File.directory?(f)
|
53
|
-
directory target
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
32
|
+
class Base
|
33
|
+
include RailsGeneratorExtensions
|
57
34
|
end
|
58
35
|
|
59
|
-
# Undo the actions performed by a generator. Rewind the action
|
60
|
-
# manifest and attempt to completely erase the results of each action.
|
61
|
-
# Note that we're punting here when it comes to directories.
|
62
36
|
class Destroy < RewindBase
|
63
|
-
|
64
|
-
directory_copy(origin, '')
|
65
|
-
end
|
66
|
-
|
67
|
-
def directory_copy(relative_source, relative_destination=nil)
|
68
|
-
source = source_path(relative_source)
|
69
|
-
relative_destination ||= relative_source
|
70
|
-
path_to_delete = "#{source_root}/"
|
71
|
-
|
72
|
-
Find.find(source) do |f|
|
73
|
-
source = f.sub(path_to_delete, '')
|
74
|
-
target = File.join(relative_destination, source.sub(relative_source, ''))
|
75
|
-
case
|
76
|
-
when File.file?(f)
|
77
|
-
file source, target
|
78
|
-
when File.directory?(f)
|
79
|
-
# Do nothing here, because the point is to use this to
|
80
|
-
# mirror directories. We don't want to risk deleting
|
81
|
-
# directories Rails needs.
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
|
37
|
+
include RailsGeneratorExtensions
|
87
38
|
end
|
88
39
|
|
89
40
|
end
|
90
41
|
end
|
91
42
|
end
|
43
|
+
|
44
|
+
|