scaffoldhub 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +28 -28
- data/lib/generators/erb/scaffoldhub_generator.rb +1 -15
- data/lib/generators/scaffoldhub/scaffoldhub_generator.rb +2 -2
- data/lib/scaffoldhub.rb +1 -1
- data/lib/scaffoldhub/helper.rb +4 -0
- data/lib/scaffoldhub/scaffold_spec.rb +2 -2
- data/lib/scaffoldhub/specification.rb +3 -2
- data/lib/scaffoldhub/template_file.rb +7 -2
- data/spec/fixtures/test_scaffold.rb +5 -3
- data/spec/helper_spec.rb +6 -6
- data/spec/scaffold_spec_spec.rb +10 -1
- data/spec/template_file_spec.rb +11 -2
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
scaffoldhub (0.0.
|
4
|
+
scaffoldhub (0.0.8)
|
5
5
|
rails
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
abstract (1.0.0)
|
11
|
-
actionmailer (3.0.
|
12
|
-
actionpack (= 3.0.
|
11
|
+
actionmailer (3.0.7)
|
12
|
+
actionpack (= 3.0.7)
|
13
13
|
mail (~> 2.2.15)
|
14
|
-
actionpack (3.0.
|
15
|
-
activemodel (= 3.0.
|
16
|
-
activesupport (= 3.0.
|
14
|
+
actionpack (3.0.7)
|
15
|
+
activemodel (= 3.0.7)
|
16
|
+
activesupport (= 3.0.7)
|
17
17
|
builder (~> 2.1.2)
|
18
18
|
erubis (~> 2.6.6)
|
19
|
-
i18n (~> 0.
|
19
|
+
i18n (~> 0.5.0)
|
20
20
|
rack (~> 1.2.1)
|
21
|
-
rack-mount (~> 0.6.
|
21
|
+
rack-mount (~> 0.6.14)
|
22
22
|
rack-test (~> 0.5.7)
|
23
23
|
tzinfo (~> 0.3.23)
|
24
|
-
activemodel (3.0.
|
25
|
-
activesupport (= 3.0.
|
24
|
+
activemodel (3.0.7)
|
25
|
+
activesupport (= 3.0.7)
|
26
26
|
builder (~> 2.1.2)
|
27
|
-
i18n (~> 0.
|
28
|
-
activerecord (3.0.
|
29
|
-
activemodel (= 3.0.
|
30
|
-
activesupport (= 3.0.
|
27
|
+
i18n (~> 0.5.0)
|
28
|
+
activerecord (3.0.7)
|
29
|
+
activemodel (= 3.0.7)
|
30
|
+
activesupport (= 3.0.7)
|
31
31
|
arel (~> 2.0.2)
|
32
32
|
tzinfo (~> 0.3.23)
|
33
|
-
activeresource (3.0.
|
34
|
-
activemodel (= 3.0.
|
35
|
-
activesupport (= 3.0.
|
36
|
-
activesupport (3.0.
|
33
|
+
activeresource (3.0.7)
|
34
|
+
activemodel (= 3.0.7)
|
35
|
+
activesupport (= 3.0.7)
|
36
|
+
activesupport (3.0.7)
|
37
37
|
arel (2.0.9)
|
38
38
|
builder (2.1.2)
|
39
39
|
diff-lcs (1.1.2)
|
@@ -53,17 +53,17 @@ GEM
|
|
53
53
|
rack (>= 1.0.0)
|
54
54
|
rack-test (0.5.7)
|
55
55
|
rack (>= 1.0)
|
56
|
-
rails (3.0.
|
57
|
-
actionmailer (= 3.0.
|
58
|
-
actionpack (= 3.0.
|
59
|
-
activerecord (= 3.0.
|
60
|
-
activeresource (= 3.0.
|
61
|
-
activesupport (= 3.0.
|
56
|
+
rails (3.0.7)
|
57
|
+
actionmailer (= 3.0.7)
|
58
|
+
actionpack (= 3.0.7)
|
59
|
+
activerecord (= 3.0.7)
|
60
|
+
activeresource (= 3.0.7)
|
61
|
+
activesupport (= 3.0.7)
|
62
62
|
bundler (~> 1.0)
|
63
|
-
railties (= 3.0.
|
64
|
-
railties (3.0.
|
65
|
-
actionpack (= 3.0.
|
66
|
-
activesupport (= 3.0.
|
63
|
+
railties (= 3.0.7)
|
64
|
+
railties (3.0.7)
|
65
|
+
actionpack (= 3.0.7)
|
66
|
+
activesupport (= 3.0.7)
|
67
67
|
rake (>= 0.8.7)
|
68
68
|
thor (~> 0.14.4)
|
69
69
|
rake (0.8.7)
|
@@ -10,22 +10,8 @@ module Erb
|
|
10
10
|
|
11
11
|
def copy_view_files
|
12
12
|
each_template_file(:view) do |erb_template_file|
|
13
|
-
|
14
|
-
copy_layout_file(erb_template_file)
|
15
|
-
else
|
16
|
-
template erb_template_file.src, File.join("app/views", controller_file_path, erb_template_file.dest)
|
17
|
-
end
|
13
|
+
template erb_template_file.src, File.join("app/views", controller_file_path, erb_template_file.dest)
|
18
14
|
end
|
19
15
|
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def copy_layout_file(layout_template)
|
24
|
-
template layout_template.src, File.join('app/views/layouts', "#{controller_file_name}.html.erb")
|
25
|
-
end
|
26
|
-
|
27
|
-
def is_layout_erb?(template_file)
|
28
|
-
template_file.dest == 'app/views/layouts/layout.erb'
|
29
|
-
end
|
30
16
|
end
|
31
17
|
end
|
@@ -15,10 +15,10 @@ class ScaffoldhubGenerator < Rails::Generators::ScaffoldGenerator
|
|
15
15
|
|
16
16
|
def download_and_copy_other_files
|
17
17
|
each_template_file(:template) do |template_file|
|
18
|
-
template
|
18
|
+
template template_file.src, replace_name_tokens(template_file.dest)
|
19
19
|
end
|
20
20
|
each_template_file(:file) do |template_file|
|
21
|
-
copy_file template_file.src, template_file.dest
|
21
|
+
copy_file template_file.src, replace_name_tokens(template_file.dest)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/scaffoldhub.rb
CHANGED
data/lib/scaffoldhub/helper.rb
CHANGED
@@ -59,6 +59,10 @@ module Scaffoldhub
|
|
59
59
|
parse_scaffold_option(1)
|
60
60
|
end
|
61
61
|
|
62
|
+
def replace_name_tokens(dest)
|
63
|
+
dest.gsub(/PLURAL_NAME/, file_name.pluralize).gsub(/NAME/, file_name)
|
64
|
+
end
|
65
|
+
|
62
66
|
def status_proc
|
63
67
|
@status_proc ||= lambda { |url| say_status :download, url }
|
64
68
|
end
|
@@ -18,14 +18,14 @@ module Scaffoldhub
|
|
18
18
|
|
19
19
|
def select_files(type)
|
20
20
|
template_file_specs.select { |file_spec| file_spec[:type].to_sym == type }.collect do |file_spec|
|
21
|
-
TemplateFile.new file_spec[:src], file_spec[:dest], @local, base_url, @status_proc
|
21
|
+
TemplateFile.new file_spec[:src], file_spec[:dest], file_spec[:rename], @local, base_url, @status_proc
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def find_file(type)
|
26
26
|
file_spec = template_file_specs.detect { |file_spec| file_spec[:type].to_sym == type }
|
27
27
|
unless file_spec.nil?
|
28
|
-
TemplateFile.new file_spec[:src], file_spec[:dest], @local, base_url, @status_proc
|
28
|
+
TemplateFile.new file_spec[:src], file_spec[:dest], file_spec[:rename], @local, base_url, @status_proc
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -51,8 +51,8 @@ module Scaffoldhub
|
|
51
51
|
|
52
52
|
class << self
|
53
53
|
|
54
|
-
def add_file(src, dest, type)
|
55
|
-
@@files << { :type => type, :src => src, :dest => dest }
|
54
|
+
def add_file(src, dest, rename, type)
|
55
|
+
@@files << { :type => type, :src => src, :rename => rename, :dest => dest }
|
56
56
|
end
|
57
57
|
|
58
58
|
def add_tag(keyword)
|
@@ -141,6 +141,7 @@ module Scaffoldhub
|
|
141
141
|
self.class.add_file(
|
142
142
|
join_with_parent(@context_options[:src], src),
|
143
143
|
join_with_parent(@context_options[:dest], options[:dest]),
|
144
|
+
options[:rename],
|
144
145
|
type
|
145
146
|
)
|
146
147
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Scaffoldhub
|
2
2
|
class TemplateFile < RemoteFile
|
3
3
|
|
4
|
-
def initialize(src, dest, local, base_url, status_proc)
|
4
|
+
def initialize(src, dest, rename, local, base_url, status_proc)
|
5
5
|
@src = src
|
6
6
|
@dest = dest || ''
|
7
|
+
@rename = rename
|
7
8
|
@local = local
|
8
9
|
@base_url = base_url
|
9
10
|
super(url, status_proc)
|
@@ -18,7 +19,11 @@ module Scaffoldhub
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def dest
|
21
|
-
|
22
|
+
if @rename
|
23
|
+
File.join(@dest, @rename)
|
24
|
+
else
|
25
|
+
File.join(@dest, File.basename(@src))
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
def download!
|
@@ -39,7 +39,7 @@ Scaffoldhub::Specification.new do
|
|
39
39
|
view 'templates/_form.html.erb'
|
40
40
|
|
41
41
|
# Define a view layout template - this ERB file will be used to generate a new
|
42
|
-
# view layout file with this path & filename: app/views/layouts/PLURAL_NAME.
|
42
|
+
# view layout file with this path & filename: app/views/layouts/PLURAL_NAME.html.erb
|
43
43
|
layout 'templates/layout.erb'
|
44
44
|
|
45
45
|
# You can use "with_options" to specify the same source folder for a series of templates:
|
@@ -48,6 +48,7 @@ Scaffoldhub::Specification.new do
|
|
48
48
|
view 'edit.html.erb'
|
49
49
|
view 'index.html.erb'
|
50
50
|
view 'show.html.erb'
|
51
|
+
view 'partial.erb', :rename => '_NAME.html.erb'
|
51
52
|
end
|
52
53
|
|
53
54
|
# Specify some other code file that should be generated from an ERB template; use
|
@@ -58,10 +59,11 @@ Scaffoldhub::Specification.new do
|
|
58
59
|
# the :dest option is required to indicate where the generated file should go
|
59
60
|
file 'templates/jquery/jquery-1.4.4.min.js', :dest => 'public/javascripts'
|
60
61
|
|
61
|
-
# You can use with_options recursively - both the :src and :dest options values
|
62
|
-
# will be constructed relative to the parent with_option values.
|
63
62
|
with_options :src => 'templates/jquery', :dest => 'public/javascripts' do
|
64
63
|
file 'jquery-ui-1.8.10.custom.min.js'
|
64
|
+
|
65
|
+
# You can use with_options recursively - both the :src and :dest options values
|
66
|
+
# will be constructed relative to the parent with_option values.
|
65
67
|
with_options :src => 'ui-lightness', :dest => 'ui-lightness' do
|
66
68
|
file 'jquery-ui-1.8.10.custom.css'
|
67
69
|
with_options :src => 'images', :dest => 'images' do
|
data/spec/helper_spec.rb
CHANGED
@@ -34,9 +34,9 @@ describe Scaffoldhub::Helper do
|
|
34
34
|
Scaffoldhub::ScaffoldSpec.stubs(:new).with('some_scaffold', true, status_proc).returns(mock_spec)
|
35
35
|
mock_spec.stubs(:download_and_parse!)
|
36
36
|
mock_template_file_array = [
|
37
|
-
Scaffoldhub::TemplateFile.new('src1', 'dest1', true, '/some/path', status_proc),
|
38
|
-
Scaffoldhub::TemplateFile.new('src2', 'dest2', true, '/some/path', status_proc),
|
39
|
-
Scaffoldhub::TemplateFile.new('src3', 'dest3', true, '/some/path', status_proc)
|
37
|
+
Scaffoldhub::TemplateFile.new('src1', 'dest1', nil, true, '/some/path', status_proc),
|
38
|
+
Scaffoldhub::TemplateFile.new('src2', 'dest2', nil, true, '/some/path', status_proc),
|
39
|
+
Scaffoldhub::TemplateFile.new('src3', 'dest3', nil, true, '/some/path', status_proc)
|
40
40
|
]
|
41
41
|
mock_spec.stubs(:select_files).with(:sometype).returns(mock_template_file_array)
|
42
42
|
@gen = FakeGenerator.new(true)
|
@@ -69,13 +69,13 @@ describe Scaffoldhub::Helper do
|
|
69
69
|
mock_spec = mock
|
70
70
|
Scaffoldhub::ScaffoldSpec.stubs(:new).with('some_scaffold', false, status_proc).returns(mock_spec)
|
71
71
|
mock_spec.stubs(:download_and_parse!)
|
72
|
-
template1 = Scaffoldhub::TemplateFile.new('src1', 'dest1', false, 'http://some.server/some/path', status_proc)
|
72
|
+
template1 = Scaffoldhub::TemplateFile.new('src1', 'dest1', nil, false, 'http://some.server/some/path', status_proc)
|
73
73
|
template1.expects(:download!).returns(template1)
|
74
74
|
template1.stubs(:src).returns('src1')
|
75
|
-
template2 = Scaffoldhub::TemplateFile.new('src2', 'dest2', false, 'http://some.server/some/path', status_proc)
|
75
|
+
template2 = Scaffoldhub::TemplateFile.new('src2', 'dest2', nil, false, 'http://some.server/some/path', status_proc)
|
76
76
|
template2.expects(:download!).returns(template2)
|
77
77
|
template2.stubs(:src).returns('src2')
|
78
|
-
template3 = Scaffoldhub::TemplateFile.new('src3', 'dest3', false, 'http://some.server/some/path', status_proc)
|
78
|
+
template3 = Scaffoldhub::TemplateFile.new('src3', 'dest3', nil, false, 'http://some.server/some/path', status_proc)
|
79
79
|
template3.expects(:download!).returns(template3)
|
80
80
|
template3.stubs(:src).returns('src3')
|
81
81
|
mock_template_file_array = [ template1, template2, template3 ]
|
data/spec/scaffold_spec_spec.rb
CHANGED
@@ -58,6 +58,12 @@ describe Scaffoldhub::ScaffoldSpec do
|
|
58
58
|
find_spec(subject, :view, 'templates/show.html.erb').should_not be_nil
|
59
59
|
end
|
60
60
|
|
61
|
+
it 'should parse the :rename option' do
|
62
|
+
partial_spec = find_spec(subject, :view, 'templates/partial.erb')
|
63
|
+
partial_spec.should_not be_nil
|
64
|
+
partial_spec[:rename].should == '_NAME.html.erb'
|
65
|
+
end
|
66
|
+
|
61
67
|
it 'should parse a vanilla template file with a dest attribute' do
|
62
68
|
template_spec = find_spec(subject, :template, 'templates/other_code_file.erb')
|
63
69
|
template_spec.should_not be_nil
|
@@ -153,6 +159,9 @@ YAML
|
|
153
159
|
model_spec.should_not be_nil
|
154
160
|
some_file_spec = find_spec_in_array(parsed_yaml[:files], :file, 'templates/jquery/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png')
|
155
161
|
some_file_spec.should_not be_nil
|
162
|
+
partial_view_spec = find_spec_in_array(parsed_yaml[:files], :view, 'templates/partial.erb')
|
163
|
+
partial_view_spec.should_not be_nil
|
164
|
+
partial_view_spec[:rename].should == '_NAME.html.erb'
|
156
165
|
end
|
157
166
|
|
158
167
|
describe '#adjusted_base_url' do
|
@@ -221,7 +230,7 @@ YAML
|
|
221
230
|
end
|
222
231
|
|
223
232
|
it 'should find the file with the given type and src' do
|
224
|
-
Scaffoldhub::TemplateFile.expects(:new).with('some_src', 'some_dest', true, 'base', @status_proc).returns(mock1 = mock)
|
233
|
+
Scaffoldhub::TemplateFile.expects(:new).with('some_src', 'some_dest', nil, true, 'base', @status_proc).returns(mock1 = mock)
|
225
234
|
subject.find_file(:type1).should == mock1
|
226
235
|
end
|
227
236
|
|
data/spec/template_file_spec.rb
CHANGED
@@ -10,18 +10,27 @@ describe Scaffoldhub::TemplateFile do
|
|
10
10
|
|
11
11
|
describe 'local template file' do
|
12
12
|
|
13
|
-
subject { Scaffoldhub::TemplateFile.new('templates/index.html', 'public', true, File.expand_path(File.dirname(__FILE__)), @status_proc) }
|
13
|
+
subject { Scaffoldhub::TemplateFile.new('templates/index.html', 'public', nil, true, File.expand_path(File.dirname(__FILE__)), @status_proc) }
|
14
14
|
|
15
15
|
its(:src) { should == File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'index.html')) }
|
16
16
|
its(:url) { should == File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'index.html')) }
|
17
17
|
its(:dest) { should == File.join('public', 'index.html') }
|
18
18
|
end
|
19
19
|
|
20
|
+
describe 'local template file with rename option' do
|
21
|
+
|
22
|
+
subject { Scaffoldhub::TemplateFile.new('templates/index.html', 'public', 'other_file_name.html', true, File.expand_path(File.dirname(__FILE__)), @status_proc) }
|
23
|
+
|
24
|
+
its(:src) { should == File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'index.html')) }
|
25
|
+
its(:url) { should == File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'index.html')) }
|
26
|
+
its(:dest) { should == File.join('public', 'other_file_name.html') }
|
27
|
+
end
|
28
|
+
|
20
29
|
describe 'remote template file' do
|
21
30
|
|
22
31
|
FAKE_TEMPLATE_FILE_URL = 'http://github.com/patshaughnessy/scaffolds/default'
|
23
32
|
|
24
|
-
subject { Scaffoldhub::TemplateFile.new('templates/index.html', 'public', false, FAKE_TEMPLATE_FILE_URL, @status_proc) }
|
33
|
+
subject { Scaffoldhub::TemplateFile.new('templates/index.html', 'public', nil, false, FAKE_TEMPLATE_FILE_URL, @status_proc) }
|
25
34
|
|
26
35
|
its(:url) { should == FAKE_TEMPLATE_FILE_URL + '/templates/index.html' }
|
27
36
|
its(:dest) { should == File.join('public', 'index.html') }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffoldhub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pat Shaughnessy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-08 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|