opensteam 0.9.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.
Files changed (134) hide show
  1. data/History.txt +0 -0
  2. data/License.txt +4 -0
  3. data/Manifest.txt +131 -0
  4. data/Manifest.txt.bak +132 -0
  5. data/README.txt +92 -0
  6. data/generators/opensteam/opensteam_generator.rb +295 -0
  7. data/generators/opensteam/templates/controllers/administration/customers_controller.rb +23 -0
  8. data/generators/opensteam/templates/controllers/administration/inventories_controller.rb +88 -0
  9. data/generators/opensteam/templates/controllers/administration/orders_controller.rb +61 -0
  10. data/generators/opensteam/templates/controllers/administration_controller.rb +80 -0
  11. data/generators/opensteam/templates/controllers/checkout_controller.rb +142 -0
  12. data/generators/opensteam/templates/controllers/webshop_controller.rb +68 -0
  13. data/generators/opensteam/templates/fixtures/inventories.yml +221 -0
  14. data/generators/opensteam/templates/fixtures/inventories_properties.yml +127 -0
  15. data/generators/opensteam/templates/fixtures/product_animals.yml +73 -0
  16. data/generators/opensteam/templates/fixtures/product_dog_foods.yml +7 -0
  17. data/generators/opensteam/templates/fixtures/properties.yml +42 -0
  18. data/generators/opensteam/templates/helpers/webshop_helper.rb +29 -0
  19. data/generators/opensteam/templates/init/opensteam.rb +30 -0
  20. data/generators/opensteam/templates/migrations/create_addresses.rb +17 -0
  21. data/generators/opensteam/templates/migrations/create_customers.rb +16 -0
  22. data/generators/opensteam/templates/migrations/create_dummy_users.rb +16 -0
  23. data/generators/opensteam/templates/migrations/create_inventories.rb +20 -0
  24. data/generators/opensteam/templates/migrations/create_inventories_properties.rb +14 -0
  25. data/generators/opensteam/templates/migrations/create_order_items.rb +16 -0
  26. data/generators/opensteam/templates/migrations/create_orders.rb +18 -0
  27. data/generators/opensteam/templates/migrations/create_payment_types.rb +13 -0
  28. data/generators/opensteam/templates/migrations/create_properties.rb +12 -0
  29. data/generators/opensteam/templates/migrations/create_sessions.rb +16 -0
  30. data/generators/opensteam/templates/migrations/create_users.rb +19 -0
  31. data/generators/opensteam/templates/models/administration_mailer.rb +18 -0
  32. data/generators/opensteam/templates/models/inventories_property.rb +10 -0
  33. data/generators/opensteam/templates/models/inventory.rb +57 -0
  34. data/generators/opensteam/templates/public/images/bullet_arrow_down.png +0 -0
  35. data/generators/opensteam/templates/public/images/bullet_arrow_up.png +0 -0
  36. data/generators/opensteam/templates/public/images/cancel.png +0 -0
  37. data/generators/opensteam/templates/public/images/folder_database.png +0 -0
  38. data/generators/opensteam/templates/public/images/indicator.gif +0 -0
  39. data/generators/opensteam/templates/public/images/indicator_big.gif +0 -0
  40. data/generators/opensteam/templates/public/images/minus.png +0 -0
  41. data/generators/opensteam/templates/public/images/opensteam_logo_small.jpg +0 -0
  42. data/generators/opensteam/templates/public/images/opensteam_logo_web.jpg +0 -0
  43. data/generators/opensteam/templates/public/images/palette.png +0 -0
  44. data/generators/opensteam/templates/public/images/plus.png +0 -0
  45. data/generators/opensteam/templates/public/images/rails.png +0 -0
  46. data/generators/opensteam/templates/public/index.html +297 -0
  47. data/generators/opensteam/templates/public/stylesheets/webshop.css +262 -0
  48. data/generators/opensteam/templates/tasks/opensteam.rake +114 -0
  49. data/generators/opensteam/templates/views/administration/_address.html.erb +4 -0
  50. data/generators/opensteam/templates/views/administration/_nav.html.erb +11 -0
  51. data/generators/opensteam/templates/views/administration/_update_tree.html.erb +18 -0
  52. data/generators/opensteam/templates/views/administration/admin_info.html.erb +12 -0
  53. data/generators/opensteam/templates/views/administration/customers.html.erb +44 -0
  54. data/generators/opensteam/templates/views/administration/customers/index.html.erb +27 -0
  55. data/generators/opensteam/templates/views/administration/customers/show.html.erb +27 -0
  56. data/generators/opensteam/templates/views/administration/index.html.erb +9 -0
  57. data/generators/opensteam/templates/views/administration/inventories/edit.html.erb +48 -0
  58. data/generators/opensteam/templates/views/administration/inventories/index.html.erb +27 -0
  59. data/generators/opensteam/templates/views/administration/inventories/new.html.erb +41 -0
  60. data/generators/opensteam/templates/views/administration/inventories/show.html.erb +45 -0
  61. data/generators/opensteam/templates/views/administration/login.html.erb +16 -0
  62. data/generators/opensteam/templates/views/administration/order.html.erb +22 -0
  63. data/generators/opensteam/templates/views/administration/orders.html.erb +32 -0
  64. data/generators/opensteam/templates/views/administration/orders/_order_item.html.erb +22 -0
  65. data/generators/opensteam/templates/views/administration/orders/index.html.erb +32 -0
  66. data/generators/opensteam/templates/views/administration/orders/show.html.erb +25 -0
  67. data/generators/opensteam/templates/views/administration/products.html.erb +7 -0
  68. data/generators/opensteam/templates/views/administration/properties.html.erb +7 -0
  69. data/generators/opensteam/templates/views/administration/show_order_item.html.erb +5 -0
  70. data/generators/opensteam/templates/views/administration/signup.html.erb +65 -0
  71. data/generators/opensteam/templates/views/administration/tree.html.erb +15 -0
  72. data/generators/opensteam/templates/views/administration/update_products.html.erb +5 -0
  73. data/generators/opensteam/templates/views/administration/update_properties.html.erb +5 -0
  74. data/generators/opensteam/templates/views/administration/update_tree.rjs +3 -0
  75. data/generators/opensteam/templates/views/administration_mailer/order_admin.erb +27 -0
  76. data/generators/opensteam/templates/views/administration_mailer/order_customer.erb +24 -0
  77. data/generators/opensteam/templates/views/checkout/intro.html.erb +5 -0
  78. data/generators/opensteam/templates/views/checkout/outro.html.erb +6 -0
  79. data/generators/opensteam/templates/views/checkout/payment.html.erb +8 -0
  80. data/generators/opensteam/templates/views/checkout/shipping.html.erb +39 -0
  81. data/generators/opensteam/templates/views/checkout/show_cart.html.erb +13 -0
  82. data/generators/opensteam/templates/views/checkout/update_cart_content.rjs +2 -0
  83. data/generators/opensteam/templates/views/common/_cart.html.erb +11 -0
  84. data/generators/opensteam/templates/views/common/_cart_content.html.erb +19 -0
  85. data/generators/opensteam/templates/views/common/_header.html.erb +15 -0
  86. data/generators/opensteam/templates/views/layouts/administration.html.erb +29 -0
  87. data/generators/opensteam/templates/views/layouts/webshop.html.erb +36 -0
  88. data/generators/opensteam/templates/views/webshop/_cart.html.erb +11 -0
  89. data/generators/opensteam/templates/views/webshop/_cart_content.html.erb +23 -0
  90. data/generators/opensteam/templates/views/webshop/_header.html.erb +15 -0
  91. data/generators/opensteam/templates/views/webshop/_inventory_content.html.erb +12 -0
  92. data/generators/opensteam/templates/views/webshop/add_inventory_to_cart.rjs +2 -0
  93. data/generators/opensteam/templates/views/webshop/add_to_cart_with_parameters.rjs +2 -0
  94. data/generators/opensteam/templates/views/webshop/del_item.rjs +1 -0
  95. data/generators/opensteam/templates/views/webshop/index.html.erb +12 -0
  96. data/generators/opensteam/templates/views/webshop/inventory.rjs +2 -0
  97. data/generators/opensteam/templates/views/webshop/show.html.erb +40 -0
  98. data/generators/opensteam_product/opensteam_product_generator.rb +115 -0
  99. data/generators/opensteam_product/templates/controllers/product_controller.rb +104 -0
  100. data/generators/opensteam_product/templates/migration.rb +16 -0
  101. data/generators/opensteam_product/templates/models/product.rb +3 -0
  102. data/generators/opensteam_product/templates/views/_attr_product.html.erb +8 -0
  103. data/generators/opensteam_product/templates/views/_attr_property.html.erb +9 -0
  104. data/generators/opensteam_product/templates/views/_details.html.erb +29 -0
  105. data/generators/opensteam_product/templates/views/administration/_attributes.html.erb +21 -0
  106. data/generators/opensteam_product/templates/views/administration/_get_products.html.erb +8 -0
  107. data/generators/opensteam_product/templates/views/administration/_inventories.html.erb +27 -0
  108. data/generators/opensteam_product/templates/views/administration/edit.html.erb +13 -0
  109. data/generators/opensteam_product/templates/views/administration/index.html.erb +36 -0
  110. data/generators/opensteam_product/templates/views/administration/new.html.erb +16 -0
  111. data/generators/opensteam_product/templates/views/administration/show.html.erb +15 -0
  112. data/generators/opensteam_property/opensteam_property_generator.rb +126 -0
  113. data/generators/opensteam_property/templates/controllers/property_controller.rb +86 -0
  114. data/generators/opensteam_property/templates/migration.rb +14 -0
  115. data/generators/opensteam_property/templates/models/property.rb +3 -0
  116. data/generators/opensteam_property/templates/views/administration/edit.html.erb +19 -0
  117. data/generators/opensteam_property/templates/views/administration/index.html.erb +24 -0
  118. data/generators/opensteam_property/templates/views/administration/new.html.erb +18 -0
  119. data/generators/opensteam_property/templates/views/administration/show.html.erb +10 -0
  120. data/lib/opensteam.rb +49 -0
  121. data/lib/opensteam/base.rb +121 -0
  122. data/lib/opensteam/checkout.rb +89 -0
  123. data/lib/opensteam/config.rb +31 -0
  124. data/lib/opensteam/finder.rb +145 -0
  125. data/lib/opensteam/inventory_base.rb +79 -0
  126. data/lib/opensteam/order_base.rb +58 -0
  127. data/lib/opensteam/product_base.rb +222 -0
  128. data/lib/opensteam/property_base.rb +63 -0
  129. data/lib/opensteam/shopping_cart.rb +343 -0
  130. data/lib/opensteam/user_base.rb +165 -0
  131. data/lib/opensteam/version.rb +9 -0
  132. data/test/test_helper.rb +2 -0
  133. data/test/test_opensteam.rb +11 -0
  134. metadata +189 -0
@@ -0,0 +1,104 @@
1
+ class Administration::<%= class_name.pluralize %>Controller < AdministrationController
2
+ include Opensteam::Finder
3
+
4
+ # GET /<%= table_name %>
5
+ # GET /<%= table_name %>.xml
6
+ def index
7
+ @<%= table_name %> = <%= class_name %>.find(:all)
8
+
9
+ respond_to do |format|
10
+ format.html # index.html.erb
11
+ format.xml { render :xml => @<%= table_name %> }
12
+ end
13
+ end
14
+
15
+ # GET /<%= table_name %>/1
16
+ # GET /<%= table_name %>/1.xml
17
+ def show
18
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
19
+
20
+ @inventories = @<%= file_name %>.inventories
21
+ respond_to do |format|
22
+ format.html # show.html.erb
23
+ format.xml { render :xml => @<%= file_name %> }
24
+ end
25
+ end
26
+
27
+ # GET /<%= table_name %>/new
28
+ # GET /<%= table_name %>/new.xml
29
+ def new
30
+ @<%= file_name %> = <%= class_name %>.new
31
+
32
+ @properties = <%= class_name %>.get_has_property
33
+ @products = <%= class_name %>.get_has_products
34
+
35
+ respond_to do |format|
36
+ format.html # new.html.erb
37
+ format.xml { render :xml => @<%= file_name %> }
38
+ end
39
+ end
40
+
41
+
42
+
43
+ # GET /<%= table_name %>/1/edit
44
+ def edit
45
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
46
+
47
+ @properties = <%= class_name %>.get_has_property
48
+ @products = <%= class_name %>.get_has_products
49
+
50
+
51
+ end
52
+
53
+ # POST /<%= table_name %>
54
+ # POST /<%= table_name %>.xml
55
+ def create
56
+ params[:<%= file_name %>][:set_properties] = {} unless params[:<%= file_name %>][:set_properties]
57
+
58
+ @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
59
+
60
+
61
+ respond_to do |format|
62
+ if @<%= file_name %>.save
63
+ flash[:notice] = '<%= class_name %> was successfully created.'
64
+ format.html { redirect_to( [:administration, @<%= file_name %> ]) }
65
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
66
+ else
67
+ format.html { render :action => "new" }
68
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
69
+ end
70
+ end
71
+ end
72
+
73
+ # PUT /<%= table_name %>/1
74
+ # PUT /<%= table_name %>/1.xml
75
+ def update
76
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
77
+ unless @<%= file_name %>.properties.empty?
78
+ params[:<%= file_name %>][:set_properties] = {} unless params[:<%= file_name %>][:set_properties]
79
+ end
80
+
81
+ respond_to do |format|
82
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
83
+ flash[:notice] = '<%= class_name %> was successfully updated.'
84
+ format.html { redirect_to( [:administration, @<%= file_name %> ] ) }
85
+ format.xml { head :ok }
86
+ else
87
+ format.html { render :action => "edit" }
88
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
89
+ end
90
+ end
91
+ end
92
+
93
+ # DELETE /<%= table_name %>/1
94
+ # DELETE /<%= table_name %>/1.xml
95
+ def destroy
96
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
97
+ @<%= file_name %>.destroy
98
+
99
+ respond_to do |format|
100
+ format.html { redirect_to(administration_<%= table_name %>_url) }
101
+ format.xml { head :ok }
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,16 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :product_<%= table_name %> do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+ <% unless options[:skip_timestamps] %>
8
+ t.timestamps
9
+ <% end -%>
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :product_<%= table_name %>
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ opensteam :product
3
+ end
@@ -0,0 +1,8 @@
1
+ <%% if attr_product_counter.modulo(2) == 0 %></tr><tr> <%% end %>
2
+ <td class="prodtd<%%= attr_product_counter.modulo 4%>">
3
+ <%% f.fields_for "products#{attr_product_counter}", attr_product do |prop| %>
4
+ <%%= render :partial => "#{attr_product.class.to_s.demodulize.tableize}/details",
5
+ :locals => { "#{attr_product.class.to_s.demodulize.downcase}" => attr_product,
6
+ :f => prop } %>
7
+ <%% end %>
8
+ </td>
@@ -0,0 +1,9 @@
1
+ <%% f.fields_for :properties do |prop| %>
2
+ <%% @properties.each_pair do |k,v| %>
3
+ <%%= prop.label k.humanize %>: <%%= prop.select "#{k}", v.collect { |i| [i.name, i.id] },
4
+ @cart_details ? { } : { :include_blank => "please select a #{k}" }, @cart_details ? { :disabled => true } : {} %>
5
+
6
+ <br /><br />
7
+ <%% end %>
8
+ <%% end %>
9
+ <br />
@@ -0,0 +1,29 @@
1
+ <b>Class:</b> <%%=h details.class %><br />
2
+ <% for attribute in attributes -%>
3
+ <%- if attribute.name == "picture" -%>
4
+ <%%= image_tag details.picture || "" %><br />
5
+ <%- else -%>
6
+ <b><%= attribute.column.human_name %>:</b> <%%=h details.<%= attribute.name %> %><br />
7
+ <%- end -%>
8
+ <%- end -%>
9
+ <br /><br />
10
+
11
+ <%%= f.hidden_field :id %>
12
+ <%%= f.hidden_field :class %>
13
+ <br />
14
+ <br />
15
+ <%% unless details.properties.empty? -%>
16
+ <u>Properties</u><br /><br />
17
+ <%%= render :partial => "<%= table_name %>/attr_property",
18
+ :locals => { :f => f, :<%=file_name %> => details } %>
19
+ <%% end %>
20
+ <br />
21
+ <br />
22
+ <%% unless details.products.empty? -%>
23
+ <u>Products</u><br /><br />
24
+ <%%= render :partial => "<%= table_name %>/attr_product", :collection => cart_details ? details.selected_products : details.products ,
25
+ :locals => { :f => f, :dog_food => details } %>
26
+ <%% end %>
27
+
28
+ <br />
29
+
@@ -0,0 +1,21 @@
1
+ <% for attribute in attributes -%>
2
+ <p>
3
+ <b><%= attribute.column.human_name %></b><br />
4
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
5
+ </p>
6
+
7
+ <% end -%>
8
+ <%% @properties.each_pair do |prop_name,prop_array| %>
9
+ <u><%%=h prop_name %></u><br />
10
+ <%% for property in prop_array %>
11
+ <%%=h property.name %> <%%= check_box_tag "<%= file_name %>[set_properties][#{prop_name}][#{property.id}]", 1,
12
+ @<%= file_name %>.properties.include?(property) %> |
13
+ <%% end %>
14
+ <br /><br />
15
+ <%% end %>
16
+ <br />
17
+ <br />Products:<br />
18
+ <%%= render :partial => "administration/<%= table_name %>/get_products" %>
19
+ <p>
20
+ <%%= f.submit button_name %>
21
+ </p>
@@ -0,0 +1,8 @@
1
+ <%% @products.each_pair do |k,v| %>
2
+ <u><%%= k %></u><br />
3
+ <%% for product in v %>
4
+ <%%= product.name %> :
5
+ <%%= check_box_tag "<%= file_name %>[set_products][#{product.class.to_s}][#{product.id}]",1,
6
+ @<%= file_name %>.products.include?( product ) %><br />
7
+ <%% end %>
8
+ <%% end %>
@@ -0,0 +1,27 @@
1
+ <table>
2
+ <tr>
3
+ <th>#</th>
4
+ <th>Configuration</th>
5
+ <th>Active</th>
6
+ <th>Price</th>
7
+ <th>Storage</th>
8
+ <th>BackOrdered</th>
9
+ </tr>
10
+ <% for inventory in @inventories %>
11
+ <tr>
12
+ <td><%=h inventory.id %></td>
13
+ <td><%=h inventory.properties.sort.collect(&:name) %></td>
14
+ <td><%=h inventory.active == 0 ? "false" : "true" %></td>
15
+ <td><%=h inventory.price %></td>
16
+ <td><%=h inventory.storage %></td>
17
+ <td><%=h inventory.back_ordered == 0 ? "false" : "true" %></td>
18
+
19
+ <td><%= link_to "show inventory", administration_inventory_path( inventory) %></td>
20
+ <td><%= link_to "edit inventory", edit_administration_inventory_path( inventory ) %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+ <br />
25
+ <br />
26
+
27
+
@@ -0,0 +1,13 @@
1
+ <%% content_for :sub_nav do %>
2
+ <%%= link_to "<%= class_name %> Index", administration_<%= table_name %>_path %> ||
3
+ <%%= link_to "Show Current", [:administration, @<%= file_name %>] %>
4
+ <%% end %>
5
+
6
+ <h1>Editing <%= class_name %></h1>
7
+
8
+ <%%= error_messages_for :<%= file_name %> %>
9
+
10
+ <%% form_for :<%= file_name %>, @<%= file_name %>, :url => { :action => :update }, :html => { :method => "put" } do |f| %>
11
+ <%%= render :partial => "administration/<%= table_name %>/attributes", :locals => { :button_name => "Update", :f => f }%>
12
+ <%% end %>
13
+
@@ -0,0 +1,36 @@
1
+ <%% content_for :sub_nav do %>
2
+ <%%= link_to "<%= class_name.pluralize %> Index", administration_<%= table_name %>_path %>
3
+ <%% end %>
4
+
5
+
6
+
7
+ <h1>Listing <%= table_name.capitalize %></h1>
8
+ <table>
9
+ <tr>
10
+ <% for attribute in attributes -%>
11
+ <th><%= attribute.column.human_name %></th>
12
+ <% end -%>
13
+ </tr>
14
+
15
+ <%% for <%= file_name %> in @<%= table_name %> %>
16
+ <tr>
17
+ <% for attribute in attributes -%>
18
+ <% if attribute.type.to_s == "references" -%>
19
+ <td><%% if <%= file_name %>.<%= attribute.name %> -%>
20
+ <%%=h <%= file_name %>.<%= attribute.name %>.name %>
21
+ <%% else -%>-<%% end -%>
22
+ </td>
23
+ <% else -%>
24
+ <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
25
+ <% end -%>
26
+ <% end -%>
27
+ <td><%%= link_to 'Show', [:administration, <%= file_name %>] %></td>
28
+ <td><%%= link_to 'Edit', edit_administration_<%= file_name %>_path( <%= file_name %> ) %></td>
29
+ <td><%%= link_to 'Destroy', [:administration, <%= file_name %>], :confirm => 'Are you sure?', :method => :delete %></td>
30
+ </tr>
31
+ <%% end %>
32
+ </table>
33
+
34
+ <br />
35
+
36
+ <%%= link_to 'New <%= class_name %>', new_administration_<%= file_name %>_path %>
@@ -0,0 +1,16 @@
1
+ <%% content_for :sub_nav do %>
2
+ <%%= link_to "<%= class_name.pluralize %> Index", administration_<%= table_name %>_path %>
3
+ <%% end %>
4
+
5
+
6
+ <h1>New <%= class_name %></h1>
7
+
8
+ <%%= error_messages_for :<%= file_name %> %>
9
+
10
+
11
+
12
+ <%% form_for :<%= file_name %>, @<%= file_name %>, :url => { :action => :create }, :html => { :method => "post" } do |f| %>
13
+ <%%= render :partial => "administration/<%= table_name %>/attributes", :locals => { :button_name => "Create", :f => f }%>
14
+ <%% end %>
15
+
16
+ <%%= link_to 'Back', administration_<%= table_name %>_path %>
@@ -0,0 +1,15 @@
1
+
2
+ <%% content_for :sub_nav do %>
3
+ <%%= link_to "<%= class_name.pluralize %> Index", administration_<%= table_name %>_path %> ||
4
+ <%%= link_to "Edit Current", edit_administration_<%= file_name %>_path( @<%= file_name %> ) %>
5
+ <%% end %>
6
+ <% for attribute in attributes -%>
7
+ <p>
8
+ <b><%= attribute.column.human_name %>:</b>
9
+ <%%=h @<%= singular_name %>.<%= attribute.name %> %>
10
+ </p>
11
+
12
+ <% end -%>
13
+
14
+ <%%= render :partial => "inventories" %>
15
+
@@ -0,0 +1,126 @@
1
+ class OpensteamPropertyGenerator < Rails::Generator::NamedBase
2
+
3
+ def initialize(runtime_args, runtime_options = {})
4
+ super
5
+ end
6
+
7
+
8
+ # check if the attribute.names (columns) already exists in the "properties" model (-> STI)
9
+ # - ask Property-Model (columns)
10
+ # - check previous migration-files
11
+ #
12
+ def migration_attributes
13
+ properties_migrations = Dir.glob("db/migrate/*_create_properties_*.rb")
14
+ a = attributes
15
+ if Opensteam::Find.properties_table_exists?
16
+ a.delete_if { |x| "Opensteam::Base::PropertyBase".constantize.columns.collect(&:name).include?( x ) }
17
+ end
18
+ a.delete_if { |x|
19
+ properties_migrations.inject(false) { |r,v| r ? true : File.read("#{v}").include?( "add_column :properties, :#{x.name}" ) }
20
+ }
21
+ a
22
+ end
23
+
24
+
25
+ def manifest
26
+
27
+ record do |m|
28
+
29
+ m.class_collisions class_path, class_name, "#{class_name}Test"
30
+
31
+
32
+
33
+ ### Controllers
34
+ m.directory( File.join('app/controllers', 'administration') )
35
+
36
+ # app/controllers/administration/* #
37
+ m.template("controllers/property_controller.rb", "app/controllers/administration/#{table_name}_controller.rb")
38
+
39
+
40
+
41
+ ### Models ###
42
+ # app/models/* #
43
+ m.template("models/property.rb", "app/models/#{file_name}.rb")
44
+
45
+
46
+
47
+ ### Views ###
48
+ # app/views/administratino/<property>/* #
49
+ m.directory( File.join('app/views', 'administration', table_name ) )
50
+ %w( edit show index new ).each { |f|
51
+ m.template("views/administration/#{f}.html.erb", "app/views/administration/#{table_name}/#{f}.html.erb")
52
+ }
53
+
54
+
55
+ ### Migrations ###
56
+ unless options[:skip_migration]
57
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => {
58
+ :migration_name => "CreateProperties#{class_name.pluralize.gsub(/::/, '')}"
59
+ }, :migration_file_name => "create_properties_#{file_path.gsub(/\//, '_').pluralize}"
60
+ end
61
+
62
+
63
+ end
64
+ end
65
+
66
+ protected
67
+
68
+ def gsub_file(relative_destination, regexp, *args, &block)
69
+ path = destination_path(relative_destination)
70
+ content = File.read(path).gsub(regexp, *args, &block)
71
+ File.open(path, 'wb') { |file| file.write(content) }
72
+ end
73
+
74
+
75
+ def map_add_namespace(str)
76
+ logger.route "add administration namepsace for #{file_name}"
77
+ sentinel = ' map.namespace :administration do |administration|'
78
+
79
+ unless options[:pretend]
80
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
81
+ "#{match}\n administration.resources :#{str}\n"
82
+ end
83
+ end
84
+ end
85
+
86
+
87
+ def map_namedroutes(name, path, *r)
88
+ route_list = r.inspect.gsub(/[\[\]{}]/, " ")
89
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
90
+
91
+ logger.route "map.#{name} \"#{path}\", #{route_list}"
92
+ unless options[:pretend]
93
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
94
+ "#{match}\n map.#{name} \"#{path}\", #{route_list}\n"
95
+ end
96
+ end
97
+ end
98
+
99
+ def map_customroutes
100
+ end
101
+
102
+
103
+
104
+
105
+ # Override with your own usage banner.
106
+ def banner
107
+ "Usage: #{$0} opensteam_property PropertyName [column:type]"
108
+ end
109
+
110
+ def add_options!(opt)
111
+ opt.separator ''
112
+ opt.separator 'Options:'
113
+ opt.on("--skip-timestamps",
114
+ "Don't add timestamps to the migration file for this property") { |v| options[:skip_timestamps] = v }
115
+ opt.on("--skip-migration",
116
+ "Don't generate a migration file for this property") { |v| options[:skip_migration] = v }
117
+ end
118
+
119
+ def scaffold_views
120
+ %w[ index show new edit ]
121
+ end
122
+
123
+ def model_name
124
+ class_name.demodulize
125
+ end
126
+ end