view_mapper 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -2
- data/VERSION +1 -1
- data/generators/scaffold_for_view/scaffold_for_view_generator.rb +2 -6
- data/generators/view_for/view_for_generator.rb +1 -5
- data/lib/view_mapper/{has_many_view.rb → has_many_child_models.rb} +33 -37
- data/lib/view_mapper/model_info.rb +8 -0
- data/lib/view_mapper/view_mapper.rb +15 -2
- data/lib/view_mapper/views/auto_complete/auto_complete_view.rb +77 -0
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/controller.rb +3 -1
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/layout.html.erb +0 -0
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_edit.html.erb +1 -1
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_new.html.erb +1 -1
- data/lib/view_mapper/views/has_many/has_many_view.rb +28 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/helper.rb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/layout.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/model.rb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/nested_attributes.js +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/style.css +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_child_form.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_edit.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_form.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_new.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_show.html.erb +0 -0
- data/lib/view_mapper/{paperclip_view.rb → views/paperclip/paperclip_view.rb} +6 -2
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/migration.rb +1 -1
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/model.rb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_edit.html.erb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_new.html.erb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_show.html.erb +0 -0
- data/lib/view_mapper.rb +4 -3
- data/test/{fake → generators/fake}/fake_generator.rb +0 -0
- data/test/generators/fake/templates/fake_template1.html.erb +1 -0
- data/test/generators/fake/templates/fake_template2.html.erb +1 -0
- data/test/{scaffold_for_view_generator_test.rb → generators/scaffold_for_view/scaffold_for_view_generator_test.rb} +2 -2
- data/test/{view_for_generator_test.rb → generators/view_for/view_for_generator_test.rb} +0 -0
- data/test/model_info_test.rb +12 -3
- data/test/test_helper.rb +12 -8
- data/test/view_mapper_test.rb +13 -2
- data/test/{auto_complete_test.rb → views/auto_complete/auto_complete_test.rb} +63 -40
- data/test/{expected_templates/auto_complete/index.html.erb → views/auto_complete/expected_templates/actual_index} +2 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/edit.html.erb +7 -3
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/expected_routes.rb +0 -0
- data/test/{expected_templates/paperclip → views/auto_complete/expected_templates}/index.html.erb +3 -1
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/new.html.erb +7 -3
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/show.html.erb +6 -1
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/standard_routes.rb +0 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/testies.html.erb +0 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/testies_controller.rb +2 -1
- data/test/views/fake/fake_view.rb +7 -0
- data/test/views/fake/templates/fake_template1.html.erb +1 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/_form.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/_person.html.erb +4 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/create_parents.rb +4 -3
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/edit.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/index.html.erb +1 -1
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/new.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/parent.rb +2 -1
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/show.html.erb +4 -0
- data/test/{has_many_view_test.rb → views/has_many/has_many_view_test.rb} +17 -17
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/create_testies.rb +4 -3
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/edit.html.erb +4 -0
- data/test/views/paperclip/expected_templates/index.html.erb +26 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/new.html.erb +4 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/show.html.erb +5 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/testy.rb +0 -0
- data/test/{paperclip_view_test.rb → views/paperclip/paperclip_view_test.rb} +17 -9
- data/view_mapper.gemspec +77 -124
- metadata +72 -120
- data/lib/view_mapper/auto_complete_templates/functional_test.rb +0 -45
- data/lib/view_mapper/auto_complete_templates/helper.rb +0 -2
- data/lib/view_mapper/auto_complete_templates/helper_test.rb +0 -4
- data/lib/view_mapper/auto_complete_templates/style.css +0 -54
- data/lib/view_mapper/auto_complete_templates/view_index.html.erb +0 -24
- data/lib/view_mapper/auto_complete_templates/view_show.html.erb +0 -10
- data/lib/view_mapper/auto_complete_view.rb +0 -44
- data/lib/view_mapper/has_many_templates/controller.rb +0 -85
- data/lib/view_mapper/has_many_templates/fixtures.yml +0 -19
- data/lib/view_mapper/has_many_templates/functional_test.rb +0 -45
- data/lib/view_mapper/has_many_templates/helper_test.rb +0 -4
- data/lib/view_mapper/has_many_templates/migration.rb +0 -16
- data/lib/view_mapper/has_many_templates/unit_test.rb +0 -8
- data/lib/view_mapper/has_many_templates/view_index.html.erb +0 -24
- data/lib/view_mapper/paperclip_templates/controller.rb +0 -85
- data/lib/view_mapper/paperclip_templates/fixtures.yml +0 -19
- data/lib/view_mapper/paperclip_templates/functional_test.rb +0 -45
- data/lib/view_mapper/paperclip_templates/helper.rb +0 -2
- data/lib/view_mapper/paperclip_templates/helper_test.rb +0 -4
- data/lib/view_mapper/paperclip_templates/layout.html.erb +0 -17
- data/lib/view_mapper/paperclip_templates/style.css +0 -54
- data/lib/view_mapper/paperclip_templates/unit_test.rb +0 -8
- data/lib/view_mapper/paperclip_templates/view_index.html.erb +0 -24
- data/test/database.yml +0 -3
- data/test/fake_view.rb +0 -7
- data/test/rails_generator/base.rb +0 -266
- data/test/rails_generator/commands.rb +0 -621
- data/test/rails_generator/generated_attribute.rb +0 -46
- data/test/rails_generator/generators/components/model/model_generator.rb +0 -45
- data/test/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -102
- data/test/rails_generator/lookup.rb +0 -249
- data/test/rails_generator/manifest.rb +0 -53
- data/test/rails_generator/options.rb +0 -150
- data/test/rails_generator/scripts/destroy.rb +0 -29
- data/test/rails_generator/scripts/generate.rb +0 -7
- data/test/rails_generator/scripts/update.rb +0 -12
- data/test/rails_generator/scripts.rb +0 -89
- data/test/rails_generator/secret_key_generator.rb +0 -24
- data/test/rails_generator/simple_logger.rb +0 -46
- data/test/rails_generator/spec.rb +0 -44
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
=View Mapper
|
2
2
|
|
3
|
-
|
3
|
+
View_mapper will generate scaffolding for new or existing models, customized for the plugins or Rails features you use in your application.
|
4
4
|
|
5
5
|
When you run the "view_for" generator, View Mapper will generate the view scaffolding code for your model, enhanced to use the specified plugin or feature with your model's attributes. For example:
|
6
6
|
|
@@ -12,7 +12,7 @@ When you run the "view_for" generator, View Mapper will generate the view scaffo
|
|
12
12
|
|
13
13
|
...will generate a "paperclip view" for your existing song model. This is scaffolding that will support viewing and editing your song model and its Paperclip attachments. It's a good way to learn how to use Paperclip if you aren't familiar with it yet.
|
14
14
|
|
15
|
-
Currently View Mapper supports views for the auto_complete and paperclip plugins. If you don't specify any view then View Mapper by default will generate standard Rails scaffolding.
|
15
|
+
Currently View Mapper supports views for the auto_complete and paperclip plugins, and views that contain complex forms for editing multiple associated models. If you don't specify any view then View Mapper by default will generate standard Rails scaffolding.
|
16
16
|
|
17
17
|
If you also want to create a new model at the same time, then use a second View Mapper generator called "scaffold_for_view" and provide the model's attributes in the usual way:
|
18
18
|
|
@@ -39,6 +39,8 @@ This is the same as view_for, but will also generate a new model at the same tim
|
|
39
39
|
|
40
40
|
{paperclip}[http://patshaughnessy.net/2009/10/16/paperclip-scaffolding]: Generates scaffolding that uses Paperclip to upload and download files.
|
41
41
|
|
42
|
+
{has_many}[http://patshaughnessy.net/2009/11/9/scaffolding-for-complex-forms-using-nested-attributes]: Generates scaffolding for a complex form to edit two or more associated models.
|
43
|
+
|
42
44
|
== Examples
|
43
45
|
|
44
46
|
For detailed examples and more information see: http://patshaughnessy.net/view_mapper
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -8,14 +8,10 @@ class ScaffoldForViewGenerator < ScaffoldGenerator
|
|
8
8
|
|
9
9
|
def initialize(runtime_args, runtime_options = {})
|
10
10
|
super
|
11
|
-
@source_root =
|
11
|
+
@source_root = self.class.lookup('scaffold').path + '/templates'
|
12
12
|
validate
|
13
13
|
end
|
14
|
-
|
15
|
-
def source_root_for_view
|
16
|
-
self.class.lookup('scaffold').path + "/templates"
|
17
|
-
end
|
18
|
-
|
14
|
+
|
19
15
|
def validate
|
20
16
|
@valid = true
|
21
17
|
end
|
@@ -9,15 +9,11 @@ class ViewForGenerator < ScaffoldGenerator
|
|
9
9
|
|
10
10
|
def initialize(runtime_args, runtime_options = {})
|
11
11
|
super
|
12
|
-
@source_root =
|
12
|
+
@source_root = self.class.lookup('scaffold').path + "/templates"
|
13
13
|
@model = ModelInfo.new(@name)
|
14
14
|
validate
|
15
15
|
end
|
16
16
|
|
17
|
-
def source_root_for_view
|
18
|
-
self.class.lookup('scaffold').path + "/templates"
|
19
|
-
end
|
20
|
-
|
21
17
|
def record
|
22
18
|
EditableManifest.new(self) { |m| yield m }
|
23
19
|
end
|
@@ -1,38 +1,10 @@
|
|
1
1
|
module ViewMapper
|
2
|
-
module
|
2
|
+
module HasManyChildModels
|
3
3
|
|
4
4
|
attr_reader :child_models
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def manifest
|
11
|
-
m = super.edit do |action|
|
12
|
-
action unless is_model_dependency_action(action) || is_view_show(action) || !valid
|
13
|
-
end
|
14
|
-
add_model_actions(m) if valid && !view_only?
|
15
|
-
if valid
|
16
|
-
m.template(
|
17
|
-
"view_show.html.erb",
|
18
|
-
File.join('app/views', controller_class_path, controller_file_name, "show.html.erb"),
|
19
|
-
{ :assigns => { :child_models => child_models } }
|
20
|
-
)
|
21
|
-
m.template(
|
22
|
-
"view_form.html.erb",
|
23
|
-
File.join('app/views', controller_class_path, controller_file_name, "_form.html.erb")
|
24
|
-
)
|
25
|
-
child_models.each do |child_model|
|
26
|
-
m.template(
|
27
|
-
"view_child_form.html.erb",
|
28
|
-
File.join('app/views', controller_class_path, controller_file_name, "_#{child_model.name.underscore}.html.erb"),
|
29
|
-
{ :assigns => { :child_model => child_model } }
|
30
|
-
|
31
|
-
)
|
32
|
-
end
|
33
|
-
m.file('nested_attributes.js', 'public/javascripts/nested_attributes.js')
|
34
|
-
end
|
35
|
-
m
|
6
|
+
def is_child_model_action?(action)
|
7
|
+
is_model_dependency_action(action) || is_view_show(action)
|
36
8
|
end
|
37
9
|
|
38
10
|
def is_model_dependency_action(action)
|
@@ -43,7 +15,35 @@ module ViewMapper
|
|
43
15
|
action[0] == :template && action[1].include?('view_show.html.erb')
|
44
16
|
end
|
45
17
|
|
46
|
-
def
|
18
|
+
def add_child_models_manifest(m)
|
19
|
+
add_child_model_actions(m) if valid && !view_only?
|
20
|
+
add_child_model_forms(m) if valid
|
21
|
+
m
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_child_model_forms(m)
|
25
|
+
m.template(
|
26
|
+
"view_show.html.erb",
|
27
|
+
File.join('app/views', controller_class_path, controller_file_name, "show.html.erb"),
|
28
|
+
{ :assigns => { :child_models => child_models } }
|
29
|
+
)
|
30
|
+
m.template(
|
31
|
+
"view_form.html.erb",
|
32
|
+
File.join('app/views', controller_class_path, controller_file_name, "_form.html.erb")
|
33
|
+
)
|
34
|
+
child_models.each do |child_model|
|
35
|
+
m.template(
|
36
|
+
"view_child_form.html.erb",
|
37
|
+
File.join('app/views', controller_class_path, controller_file_name, "_#{child_model.name.underscore}.html.erb"),
|
38
|
+
{ :assigns => { :child_model => child_model } }
|
39
|
+
|
40
|
+
)
|
41
|
+
end
|
42
|
+
m.file('nested_attributes.js', 'public/javascripts/nested_attributes.js')
|
43
|
+
m
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_child_model_actions(m)
|
47
47
|
m.directory(File.join('test/fixtures', class_path))
|
48
48
|
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
49
49
|
m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
|
@@ -72,11 +72,6 @@ module ViewMapper
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
def validate
|
76
|
-
super
|
77
|
-
@valid &&= validate_child_models
|
78
|
-
end
|
79
|
-
|
80
75
|
def validate_child_models
|
81
76
|
cms = child_models
|
82
77
|
if cms.empty?
|
@@ -122,3 +117,4 @@ module ViewMapper
|
|
122
117
|
end
|
123
118
|
end
|
124
119
|
end
|
120
|
+
|
@@ -23,6 +23,14 @@ module ViewMapper
|
|
23
23
|
@attributes ||= active_record_columns.collect { |col| Rails::Generator::GeneratedAttribute.new col.name, col.type }
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.is_text_field_attrib_type?(type)
|
27
|
+
[:integer, :float, :decimal, :string].include? type
|
28
|
+
end
|
29
|
+
|
30
|
+
def text_fields
|
31
|
+
attributes.reject { |attrib| !ModelInfo.is_text_field_attrib_type? attrib.type }.collect { |attrib| attrib.name }
|
32
|
+
end
|
33
|
+
|
26
34
|
def attachments
|
27
35
|
@attachments = find_attachments
|
28
36
|
end
|
@@ -5,12 +5,25 @@ module ViewMapper
|
|
5
5
|
Rails::Generator::Commands::Create.class_eval { include RouteAction::Create }
|
6
6
|
Rails::Generator::Commands::Destroy.class_eval { include RouteAction::Destroy }
|
7
7
|
super
|
8
|
+
self.extend(view_module) if options[:view]
|
9
|
+
end
|
10
|
+
|
11
|
+
def source_path(relative_source)
|
8
12
|
if options[:view]
|
9
|
-
|
10
|
-
|
13
|
+
source_roots_for_view.map do |source_root|
|
14
|
+
File.join(File.expand_path(source_root), relative_source)
|
15
|
+
end.detect do |path|
|
16
|
+
File.exists? path
|
17
|
+
end
|
18
|
+
else
|
19
|
+
super
|
11
20
|
end
|
12
21
|
end
|
13
22
|
|
23
|
+
def source_roots_for_view
|
24
|
+
[ view_module.source_root, File.expand_path(source_root) ]
|
25
|
+
end
|
26
|
+
|
14
27
|
def view_module
|
15
28
|
"ViewMapper::#{view_name.camelize}View".constantize
|
16
29
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module ViewMapper
|
2
|
+
module AutoCompleteView
|
3
|
+
|
4
|
+
def self.source_root
|
5
|
+
File.expand_path(File.dirname(__FILE__) + "/templates")
|
6
|
+
end
|
7
|
+
|
8
|
+
def manifest
|
9
|
+
manifest = super
|
10
|
+
if @valid
|
11
|
+
auto_complete_attributes.each do |attrib|
|
12
|
+
manifest.route :name => 'connect',
|
13
|
+
:path => auto_complete_for_method(attrib),
|
14
|
+
:controller => controller_file_name,
|
15
|
+
:action => auto_complete_for_method(attrib)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
manifest
|
19
|
+
end
|
20
|
+
|
21
|
+
def auto_complete_for_method(attrib)
|
22
|
+
"auto_complete_for_#{singular_name}_#{attrib}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def auto_complete_attributes
|
26
|
+
if view_param
|
27
|
+
parse_auto_complete_attributes_from_param
|
28
|
+
elsif view_only?
|
29
|
+
model.text_fields
|
30
|
+
else
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_auto_complete_attributes_from_param
|
36
|
+
view_param.split(',')
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate
|
40
|
+
super
|
41
|
+
@valid &&= validate_auto_complete_attributes
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_auto_complete_attributes
|
45
|
+
if !auto_complete_installed
|
46
|
+
logger.error "The auto_complete plugin does not appear to be installed."
|
47
|
+
return false
|
48
|
+
elsif auto_complete_attributes.empty?
|
49
|
+
if view_only?
|
50
|
+
logger.error "No text fields exist in the specified class."
|
51
|
+
else
|
52
|
+
logger.error "No auto_complete attribute specified."
|
53
|
+
end
|
54
|
+
return false
|
55
|
+
else
|
56
|
+
!auto_complete_attributes.detect { |a| !validate_auto_complete_attribute(a) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_auto_complete_attribute(attrib_name)
|
61
|
+
attrib = attributes.find { |a| a.name == attrib_name }
|
62
|
+
if attrib.nil?
|
63
|
+
logger.error "Field '#{attrib_name}' does not exist."
|
64
|
+
return false
|
65
|
+
elsif !ModelInfo.is_text_field_attrib_type? attrib.type
|
66
|
+
logger.error "Field '#{attrib_name}' is not a text field."
|
67
|
+
return false
|
68
|
+
end
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
def auto_complete_installed
|
73
|
+
ActionController::Base.methods.include? 'auto_complete_for'
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/controller.rb
RENAMED
@@ -1,6 +1,8 @@
|
|
1
1
|
class <%= controller_class_name %>Controller < ApplicationController
|
2
2
|
|
3
|
-
|
3
|
+
<% auto_complete_attributes.each do |attrib| -%>
|
4
|
+
auto_complete_for :<%= controller_singular_name %>, :<%= attrib %>
|
5
|
+
<% end -%>
|
4
6
|
|
5
7
|
# GET /<%= table_name %>
|
6
8
|
# GET /<%= table_name %>.xml
|
data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/layout.html.erb
RENAMED
File without changes
|
data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_edit.html.erb
RENAMED
@@ -5,7 +5,7 @@
|
|
5
5
|
<% for attribute in attributes -%>
|
6
6
|
<p>
|
7
7
|
<%%= f.label :<%= attribute.name %> %><br />
|
8
|
-
<%- if
|
8
|
+
<%- if auto_complete_attributes.include? attribute.name -%>
|
9
9
|
<%%= text_field_with_auto_complete :<%= singular_name %>, :<%= attribute.name %>, {}, { :method => :get } %>
|
10
10
|
<%- else -%>
|
11
11
|
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_new.html.erb
RENAMED
@@ -5,7 +5,7 @@
|
|
5
5
|
<%- for attribute in attributes -%>
|
6
6
|
<p>
|
7
7
|
<%%= f.label :<%= attribute.name %> %><br />
|
8
|
-
<%- if
|
8
|
+
<%- if auto_complete_attributes.include? attribute.name -%>
|
9
9
|
<%%= text_field_with_auto_complete :<%= singular_name %>, :<%= attribute.name %>, {}, { :method => :get } %>
|
10
10
|
<%- else -%>
|
11
11
|
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ViewMapper
|
2
|
+
module HasManyView
|
3
|
+
|
4
|
+
include HasManyChildModels
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
File.expand_path(File.dirname(__FILE__) + "/templates")
|
8
|
+
end
|
9
|
+
|
10
|
+
def source_roots_for_view
|
11
|
+
[ HasManyView.source_root, File.expand_path(source_root), File.join(self.class.lookup('model').path, 'templates') ]
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
m = super.edit do |action|
|
16
|
+
action unless is_child_model_action?(action)
|
17
|
+
end
|
18
|
+
add_child_models_manifest(m)
|
19
|
+
m
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate
|
23
|
+
super
|
24
|
+
@valid &&= validate_child_models
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_child_form.html.erb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,8 +1,12 @@
|
|
1
1
|
module ViewMapper
|
2
2
|
module PaperclipView
|
3
3
|
|
4
|
-
def
|
5
|
-
File.dirname(__FILE__) + "/
|
4
|
+
def self.source_root
|
5
|
+
File.expand_path(File.dirname(__FILE__) + "/templates")
|
6
|
+
end
|
7
|
+
|
8
|
+
def source_roots_for_view
|
9
|
+
[ PaperclipView.source_root, File.expand_path(source_root), File.join(self.class.lookup('model').path, 'templates') ]
|
6
10
|
end
|
7
11
|
|
8
12
|
def manifest
|
@@ -2,7 +2,7 @@ class <%= migration_name %> < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :<%= table_name %> do |t|
|
4
4
|
<% for attribute in attributes -%>
|
5
|
-
t.<%= attribute.type %>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
6
|
<% end -%>
|
7
7
|
<% for attachment in attachments -%>
|
8
8
|
t.string :<%= attachment %>_file_name
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/view_mapper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require 'view_mapper/auto_complete_view'
|
2
|
-
require 'view_mapper/paperclip_view'
|
3
|
-
require 'view_mapper/has_many_view'
|
4
1
|
require 'view_mapper/route_action'
|
5
2
|
require 'view_mapper/editable_manifest'
|
6
3
|
require 'view_mapper/model_info'
|
4
|
+
require 'view_mapper/has_many_child_models'
|
7
5
|
require 'view_mapper/view_mapper'
|
6
|
+
require 'view_mapper/views/auto_complete/auto_complete_view'
|
7
|
+
require 'view_mapper/views/paperclip/paperclip_view'
|
8
|
+
require 'view_mapper/views/has_many/has_many_view'
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
This is fake.
|
@@ -0,0 +1 @@
|
|
1
|
+
This is fake.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
|
3
3
|
class ScaffoldForViewGeneratorTest < Test::Unit::TestCase
|
4
4
|
|
@@ -69,7 +69,7 @@ class ScaffoldForViewGeneratorTest < Test::Unit::TestCase
|
|
69
69
|
end
|
70
70
|
|
71
71
|
should "return the source root folder for the Rails scaffold generator" do
|
72
|
-
assert_equal '
|
72
|
+
assert_equal @scaffold_for_view_gen.class.lookup('scaffold').path + '/templates', @scaffold_for_view_gen.source_root
|
73
73
|
end
|
74
74
|
|
75
75
|
end
|
File without changes
|
data/test/model_info_test.rb
CHANGED
@@ -17,11 +17,12 @@ class ModelInfoTest < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
should "return the model's columns and not the primary key or time stamp columns" do
|
20
|
-
assert_equal [ 'first_name', 'last_name', 'address' ], @model_info.columns
|
20
|
+
assert_equal [ 'first_name', 'last_name', 'address', 'some_flag' ], @model_info.columns
|
21
21
|
end
|
22
22
|
|
23
23
|
should "return the model's Rails Generator attributes" do
|
24
24
|
attribs = @model_info.attributes
|
25
|
+
assert_equal 4, attribs.size
|
25
26
|
assert_kind_of Rails::Generator::GeneratedAttribute, attribs[0]
|
26
27
|
assert_kind_of Rails::Generator::GeneratedAttribute, attribs[1]
|
27
28
|
assert_kind_of Rails::Generator::GeneratedAttribute, attribs[2]
|
@@ -29,6 +30,14 @@ class ModelInfoTest < Test::Unit::TestCase
|
|
29
30
|
assert_equal 'last_name', attribs[1].name
|
30
31
|
assert_equal 'address', attribs[2].name
|
31
32
|
end
|
33
|
+
|
34
|
+
should "return the model's text fields" do
|
35
|
+
text_fields = @model_info.text_fields
|
36
|
+
assert_equal 3, text_fields.size
|
37
|
+
assert_equal 'first_name', text_fields[0]
|
38
|
+
assert_equal 'last_name', text_fields[1]
|
39
|
+
assert_equal 'address', text_fields[2]
|
40
|
+
end
|
32
41
|
end
|
33
42
|
|
34
43
|
context "Child and parent model info objects" do
|
@@ -40,7 +49,7 @@ class ModelInfoTest < Test::Unit::TestCase
|
|
40
49
|
end
|
41
50
|
|
42
51
|
should "not include the parent foreign key column in the child model's columns" do
|
43
|
-
assert_equal [ 'first_name', 'last_name', 'address' ], @child_model.columns
|
52
|
+
assert_equal [ 'first_name', 'last_name', 'address', 'some_flag' ], @child_model.columns
|
44
53
|
end
|
45
54
|
|
46
55
|
should "determine that the child model belongs to the parent model" do
|
@@ -75,7 +84,7 @@ class ModelInfoTest < Test::Unit::TestCase
|
|
75
84
|
end
|
76
85
|
|
77
86
|
should "not include the Paperclip columns in the model's columns" do
|
78
|
-
assert_equal [ 'first_name', 'last_name', 'address' ], @model_info.columns
|
87
|
+
assert_equal [ 'first_name', 'last_name', 'address', 'some_flag' ], @model_info.columns
|
79
88
|
end
|
80
89
|
end
|
81
90
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,32 +5,29 @@ require 'shoulda'
|
|
5
5
|
require 'mocha'
|
6
6
|
require 'activerecord'
|
7
7
|
|
8
|
-
|
9
|
-
ActiveRecord::Base.establish_connection(config['test'])
|
8
|
+
ActiveRecord::Base.establish_connection({ :adapter => 'sqlite3', :database => ':memory:' })
|
10
9
|
|
11
10
|
require 'rails_generator'
|
12
11
|
require 'rails_generator/scripts'
|
13
12
|
require 'rails_generator/scripts/generate'
|
14
13
|
|
15
|
-
Rails::Generator::Base.reset_sources
|
16
14
|
def add_source(path)
|
17
15
|
Rails::Generator::Base.append_sources(Rails::Generator::PathSource.new(:builtin, path))
|
18
16
|
end
|
19
|
-
|
20
17
|
add_source(File.dirname(__FILE__) + '/../generators')
|
21
|
-
add_source(File.dirname(__FILE__) + '/
|
22
|
-
add_source(File.dirname(__FILE__))
|
18
|
+
add_source(File.dirname(__FILE__) + '/generators')
|
23
19
|
|
24
20
|
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
25
21
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
26
22
|
require 'view_mapper'
|
27
|
-
require 'fake_view'
|
23
|
+
require 'views/fake/fake_view'
|
28
24
|
|
29
25
|
def setup_test_table(paperclip_columns = false)
|
30
26
|
ActiveRecord::Base.connection.create_table :testies, :force => true do |table|
|
31
27
|
table.column :first_name, :string
|
32
28
|
table.column :last_name, :string
|
33
29
|
table.column :address, :string
|
30
|
+
table.column :some_flag, :boolean
|
34
31
|
if paperclip_columns
|
35
32
|
table.column :avatar_file_name, :string
|
36
33
|
table.column :avatar_content_type, :string
|
@@ -116,11 +113,18 @@ class Rails::Generator::NamedBase
|
|
116
113
|
public :attributes
|
117
114
|
end
|
118
115
|
|
116
|
+
module ActionController
|
117
|
+
class Base
|
118
|
+
def self.auto_complete_for
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
119
123
|
def generator_cmd_line(gen, args, model)
|
120
124
|
if gen == 'view_for'
|
121
125
|
cmd_line = [model]
|
122
126
|
else
|
123
|
-
cmd_line = [model, 'first_name:string', 'last_name:string', 'address:string']
|
127
|
+
cmd_line = [model, 'first_name:string', 'last_name:string', 'address:string', 'some_flag:boolean']
|
124
128
|
end
|
125
129
|
(cmd_line << args).flatten
|
126
130
|
end
|
data/test/view_mapper_test.rb
CHANGED
@@ -11,8 +11,19 @@ class ViewMapperTest < Test::Unit::TestCase
|
|
11
11
|
assert_equal 'fake', @gen.view_name
|
12
12
|
end
|
13
13
|
|
14
|
-
should "
|
15
|
-
assert_equal
|
14
|
+
should "have the proper default value for source_roots_for_view" do
|
15
|
+
assert_equal [
|
16
|
+
'/Users/pat/rails-apps/view_mapper/test/views/fake/templates',
|
17
|
+
'/Users/pat/rails-apps/view_mapper/test/generators/fake/templates'
|
18
|
+
], @gen.source_roots_for_view
|
19
|
+
end
|
20
|
+
|
21
|
+
should "use the correct source path for a template file that is overridden in the view" do
|
22
|
+
assert_equal '/Users/pat/rails-apps/view_mapper/test/views/fake/templates/fake_template1.html.erb', @gen.source_path('fake_template1.html.erb')
|
23
|
+
end
|
24
|
+
|
25
|
+
should "use the correct source path for a template file that is not overridden in the view" do
|
26
|
+
assert_equal '/Users/pat/rails-apps/view_mapper/test/generators/fake/templates/fake_template2.html.erb', @gen.source_path('fake_template2.html.erb')
|
16
27
|
end
|
17
28
|
end
|
18
29
|
|