asf_scaffold_generator 0.0.9 → 0.1.0

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.
@@ -26,7 +26,28 @@
26
26
  # Rails::Generator::Base.sources << Rails::Generator::PathSource.new(:development, "#{Dir.user_home}/dev/activesfdc/trunk/ActiveSalesforceGenerator/")
27
27
 
28
28
 
29
+ class AsfScaffoldingSandbox
30
+ include ActionView::Helpers::ActiveRecordHelper
31
+
32
+ attr_accessor :form_action, :singular_name, :suffix, :model_instance, :model_name
33
+
34
+ def initialize(singular_name, model_instance)
35
+ @singular_name = singular_name
36
+ @model_instance = model_instance
37
+ @model_name = model_instance.class.name
38
+ @scaffold_singular_name = singular_name
39
+ end
40
+
41
+ def sandbox_binding
42
+ binding
43
+ end
44
+
45
+ end
46
+
47
+
29
48
  class AsfScaffoldGenerator < ScaffoldGenerator
49
+ include ActionView::Helpers::ActiveRecordHelper
50
+
30
51
  attr_accessor :record_type
31
52
 
32
53
  def initialize(runtime_args, runtime_options = {})
@@ -37,6 +58,18 @@ class AsfScaffoldGenerator < ScaffoldGenerator
37
58
 
38
59
  def manifest
39
60
  record do |m|
61
+ # Scaffolded forms.
62
+ m.complex_template "form.rhtml",
63
+ File.join('app/views',
64
+ controller_class_path,
65
+ controller_file_name,
66
+ "_form.rhtml"),
67
+ :insert => 'asf_form_scaffolding.rhtml',
68
+ :sandbox => lambda { create_sandbox },
69
+ :begin_mark => 'form',
70
+ :end_mark => 'eoform',
71
+ :mark_id => singular_name
72
+
40
73
  # Scaffolded views.
41
74
  scaffold_views.each do |action|
42
75
  m.template "asf_view_#{action}.rhtml",
@@ -55,6 +88,14 @@ class AsfScaffoldGenerator < ScaffoldGenerator
55
88
 
56
89
  protected
57
90
 
91
+ def create_sandbox
92
+ sandbox = AsfScaffoldingSandbox.new(singular_name, model_instance)
93
+ sandbox.instance_variable_set("@#{singular_name}", sandbox.model_instance)
94
+
95
+ sandbox.suffix = suffix
96
+ sandbox
97
+ end
98
+
58
99
  # DCHASMAN TODO Remove this when the show, new and edit templates are ready
59
100
  def scaffold_views
60
101
  #%w(list show new edit)
@@ -0,0 +1,2 @@
1
+ gem build activesfdcgen.gemspec
2
+ gem install asf_scaffold_generator-*.gem
@@ -0,0 +1,56 @@
1
+ <% def safe_array(value)
2
+ if value.is_a? Array
3
+ value
4
+ else
5
+ value.nil? ? [] : [ value ]
6
+ end
7
+ end
8
+ %>
9
+ <% model = model_name.constantize
10
+ connection = model.connection
11
+ entity_name = connection.entity_name_from_table(model.table_name)
12
+ entity_def = connection.get_entity_def(entity_name)
13
+ layoutMetadata = entity_def.layouts
14
+ %>
15
+ <div class="bPageBlock secondaryPalette" id="ep"><div class="pbHeader">
16
+ <div class="pbBody"><div class="pbSubsection">
17
+ <table class="detailList">
18
+ <% safe_array(layoutMetadata[:layouts]).each do |layout|
19
+ safe_array(layout[:detailLayoutSections]).each do |section|
20
+ safe_array(section[:layoutRows]).each do | row |
21
+ %>
22
+ <tr>
23
+ <% safe_array(row[:layoutItems]).each do | item | %>
24
+ <td class="labelCol"><%= item[:label] %></td>
25
+ <td class="dataCol col02">
26
+ <% safe_array(item[:layoutComponents]).each do |component|
27
+ if component[:type] == "Field"
28
+ field = component[:value]
29
+ column = entity_def.api_name_to_column[field]
30
+
31
+ col_ref = "@#{singular_name}.#{column.name}"
32
+ if column.respond_to?(:reference_to) and column.reference_to
33
+ %>
34
+ <%%= <%= col_ref %> ? link_to(<%= col_ref %>, { :controller => '<%= column.reference_to.pluralize.underscore %>', :action=> 'show', :id => <%= col_ref %> }) : '&nbsp;' %>
35
+ <% else %>
36
+ <%%= <%= col_ref %> ? <%= col_ref %> : '&nbsp;' %>
37
+ <% end
38
+ end
39
+ end
40
+ %>
41
+ </td>
42
+ <% end %>
43
+ </tr>
44
+ <% end
45
+ end
46
+ end
47
+ %>
48
+ </table>
49
+ </div></div>
50
+ </div></div>
51
+
52
+
53
+ <%% @id_resolver = ActiveSalesforce::IdResolver.new(<%= model_name %>.connection)
54
+ @id_resolver.add(@<%= singular_name %>)
55
+ %>
56
+
@@ -6,8 +6,16 @@
6
6
  <%%= tag("link", { "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => "#{url.scheme}://#{url.host}:#{url.port}/dCSS/Theme2/default/common.css" }) %>
7
7
  <script type="text/javascript" src="http://na1.salesforce.com/js/functions.js"></script>
8
8
  <%%= javascript_include_tag "prototype", "effects" %>
9
-
10
- <script>
9
+ </head>
10
+
11
+ <body class="contact overviewPage" onload="request_id_resolve()">
12
+
13
+ <p style="color: green"><%%= flash[:notice] %></p>
14
+
15
+ <%%= @content_for_layout %>
16
+
17
+ <script>
18
+ <%% if @id_resolver %>
11
19
  function update_ids(id_map) {
12
20
  links = document.getElementsByTagName('a')
13
21
 
@@ -26,20 +34,12 @@
26
34
  }
27
35
  }
28
36
  }
37
+ <%% end %>
29
38
 
30
- </script>
31
-
32
- </head>
33
-
34
- <body class="contact overviewPage" onload="request_id_resolve()">
35
-
36
- <p style="color: green"><%%= flash[:notice] %></p>
37
-
38
- <%%= @content_for_layout %>
39
-
40
- <script>
41
39
  function request_id_resolve() {
42
- <%%= remote_function(:url => { :controller => 'asf_resolveids', :action => :resolve, :class => '<%= model_name %>', :ids => @id_resolver.serialize }, :complete => "update_ids(eval(request.responseText))") %>
40
+ <%% if @id_resolver %>
41
+ <%%= remote_function(:url => { :controller => 'asf_resolveids', :action => :resolve, :class => '<%= model_name %>', :ids => @id_resolver.serialize }, :complete => "update_ids(eval(request.responseText))") %>
42
+ <%% end %>
43
43
  }
44
44
  </script>
45
45
 
@@ -0,0 +1,7 @@
1
+ <h1>Editing <%= @scaffold_singular_name %></h1>
2
+
3
+ <%= error_messages_for(@scaffold_singular_name) %>
4
+ <%= form(@scaffold_singular_name, { :action => "update#{@scaffold_suffix}", :value => "Save" }) %>
5
+
6
+ <%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => instance_variable_get("@#{@scaffold_singular_name}") %> |
7
+ <%= link_to "Back", :action => "list#{@scaffold_suffix}" %>
@@ -83,6 +83,6 @@
83
83
 
84
84
 
85
85
  <%% @id_resolver = ActiveSalesforce::IdResolver.new(<%= model_name %>.connection)
86
- @<%= plural_name %>.each { |<%= singular_name %>| @id_resolver.add(<%= singular_name %>, columns) }
86
+ @<%= plural_name %>.each { |<%= singular_name %>| @id_resolver.add(<%= singular_name %>, columns) }
87
87
  %>
88
88
 
@@ -51,6 +51,6 @@
51
51
 
52
52
 
53
53
  <%% @id_resolver = ActiveSalesforce::IdResolver.new(<%= model_name %>.connection)
54
- @id_resolver.add(@<%= singular_name %>)
54
+ @id_resolver.add(@<%= singular_name %>)
55
55
  %>
56
56
 
@@ -0,0 +1,3 @@
1
+ <%%= error_messages_for '<%= singular_name %>' %>
2
+
3
+ <%= template_for_inclusion %>
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: asf_scaffold_generator
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.9
7
- date: 2006-03-02 00:00:00 -05:00
6
+ version: 0.1.0
7
+ date: 2006-03-05 00:00:00 -05:00
8
8
  summary: ActiveSalesforce Generator provides additional salesforce aware scaffolding support.
9
9
  require_paths:
10
10
  - lib
@@ -28,21 +28,26 @@ cert_chain:
28
28
  authors:
29
29
  - Doug Chasman
30
30
  files:
31
- - ./USAGE
32
31
  - ./asf_scaffold_generator.rb
32
+ - ./build.sh
33
33
  - ./templates
34
+ - ./USAGE
35
+ - ./templates/asf_form_scaffolding.rhtml
36
+ - ./templates/asf_layout.rhtml
34
37
  - ./templates/asf_resolveids_controller.rb
35
- - ./templates/asf_view_list.rhtml
36
- - ./templates/asf_view_show.rhtml
37
38
  - ./templates/asf_view_edit.rhtml
39
+ - ./templates/asf_view_list.rhtml
38
40
  - ./templates/asf_view_new.rhtml
39
- - ./templates/asf_layout.rhtml
41
+ - ./templates/asf_view_show.rhtml
42
+ - ./templates/form.rhtml
43
+ - templates/asf_form_scaffolding.rhtml
44
+ - templates/asf_layout.rhtml
40
45
  - templates/asf_resolveids_controller.rb
41
- - templates/asf_view_list.rhtml
42
- - templates/asf_view_show.rhtml
43
46
  - templates/asf_view_edit.rhtml
47
+ - templates/asf_view_list.rhtml
44
48
  - templates/asf_view_new.rhtml
45
- - templates/asf_layout.rhtml
49
+ - templates/asf_view_show.rhtml
50
+ - templates/form.rhtml
46
51
  - USAGE
47
52
  test_files: []
48
53