opensteam 0.9.2 → 0.9.3

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 (213) hide show
  1. data/CHANGELOG +53 -0
  2. data/README.rdoc +19 -10
  3. data/generators/opensteam/opensteam_generator.rb +27 -3
  4. data/generators/opensteam/templates/app/controllers/admin/configurations_controller.rb +85 -0
  5. data/generators/opensteam/templates/app/controllers/admin/inventories_controller.rb +1 -1
  6. data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +35 -4
  7. data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +5 -4
  8. data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +6 -3
  9. data/generators/opensteam/templates/app/controllers/admin/shipping_rate_groups_controller.rb +76 -0
  10. data/generators/opensteam/templates/app/controllers/admin/tax_groups_controller.rb +124 -0
  11. data/generators/opensteam/templates/app/controllers/admin/tax_rules_controller.rb +19 -0
  12. data/generators/opensteam/templates/app/controllers/admin/tax_zones_controller.rb +118 -0
  13. data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +1 -1
  14. data/generators/opensteam/templates/app/controllers/admin_controller.rb +20 -0
  15. data/generators/opensteam/templates/app/controllers/carts_controller.rb +118 -0
  16. data/generators/opensteam/templates/app/controllers/checkout_controller.rb +119 -79
  17. data/generators/opensteam/templates/app/controllers/profile_controller.rb +2 -4
  18. data/generators/opensteam/templates/app/controllers/searches_controller.rb +1 -1
  19. data/generators/opensteam/templates/app/controllers/user_sessions_controller.rb +2 -1
  20. data/generators/opensteam/templates/app/controllers/users_controller.rb +10 -3
  21. data/generators/opensteam/templates/app/helpers/admin_helper.rb +15 -1
  22. data/generators/opensteam/templates/app/helpers/checkout_helper.rb +38 -0
  23. data/generators/opensteam/templates/app/helpers/webshop_helper.rb +6 -1
  24. data/generators/opensteam/templates/app/models/zone.rb +18 -0
  25. data/generators/opensteam/templates/app/views/admin/_menu.html.erb +18 -0
  26. data/generators/opensteam/templates/app/views/admin/catalog.html.erb +2 -3
  27. data/generators/opensteam/templates/app/views/admin/configurations/edit.html.erb +20 -0
  28. data/generators/opensteam/templates/app/views/admin/configurations/index.html.erb +22 -0
  29. data/generators/opensteam/templates/app/views/admin/configurations/new.html.erb +19 -0
  30. data/generators/opensteam/templates/app/views/admin/configurations/show.html.erb +13 -0
  31. data/generators/opensteam/templates/app/views/admin/filters/_filter.html.erb +1 -1
  32. data/generators/opensteam/templates/app/views/admin/index.html.erb +0 -19
  33. data/generators/opensteam/templates/app/views/admin/inventories/edit.html.erb +10 -6
  34. data/generators/opensteam/templates/app/views/admin/inventories/new.html.erb +5 -0
  35. data/generators/opensteam/templates/app/views/admin/inventories/show.html.erb +10 -6
  36. data/generators/opensteam/templates/app/views/admin/invoices/_invoice.html.erb +1 -0
  37. data/generators/opensteam/templates/app/views/admin/invoices/_invoice_fields.html.erb +52 -0
  38. data/generators/opensteam/templates/app/views/admin/invoices/new.html.erb +9 -37
  39. data/generators/opensteam/templates/app/views/admin/invoices/show.html.erb +10 -36
  40. data/generators/opensteam/templates/app/views/admin/invoices/show.pdf.prawn +59 -0
  41. data/generators/opensteam/templates/app/views/admin/order_config.html.erb +5 -0
  42. data/generators/opensteam/templates/app/views/admin/order_items/_item_entry.html.erb +9 -0
  43. data/generators/opensteam/templates/app/views/admin/order_items/_items_table.html.erb +16 -0
  44. data/generators/opensteam/templates/app/views/admin/orders/_order.html.erb +9 -9
  45. data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +1 -1
  46. data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +25 -9
  47. data/generators/opensteam/templates/app/views/admin/payment_types.html.erb +27 -0
  48. data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment.html.erb +26 -0
  49. data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment_info.html.erb +15 -0
  50. data/generators/opensteam/templates/app/views/admin/payments/_direct_debit_payment.html.erb +5 -0
  51. data/generators/opensteam/templates/app/views/admin/shipments/new.html.erb +45 -30
  52. data/generators/opensteam/templates/app/views/admin/shipments/show.html.erb +3 -3
  53. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_payment_addition.html.erb +12 -0
  54. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_rate.html.erb +16 -0
  55. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/edit.html.erb +63 -0
  56. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/index.html.erb +28 -0
  57. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/new.html.erb +60 -0
  58. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/show.html.erb +13 -0
  59. data/generators/opensteam/templates/app/views/admin/system.html.erb +5 -0
  60. data/generators/opensteam/templates/app/views/admin/tax_groups/_attributes.html.erb +11 -0
  61. data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups.html.erb +17 -0
  62. data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups_row.html.erb +12 -0
  63. data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_rule.html.erb +14 -0
  64. data/generators/opensteam/templates/app/views/admin/tax_groups/edit.html.erb +26 -0
  65. data/generators/opensteam/templates/app/views/admin/tax_groups/index.html.erb +8 -0
  66. data/generators/opensteam/templates/app/views/admin/tax_groups/new.html.erb +27 -0
  67. data/generators/opensteam/templates/app/views/admin/tax_groups/show.html.erb +28 -0
  68. data/generators/opensteam/templates/app/views/admin/tax_zones/_attributes.html.erb +18 -0
  69. data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zone_row.html.erb +13 -0
  70. data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zones.html.erb +11 -0
  71. data/generators/opensteam/templates/app/views/admin/tax_zones/edit.html.erb +16 -0
  72. data/generators/opensteam/templates/app/views/admin/tax_zones/index.html.erb +16 -0
  73. data/generators/opensteam/templates/app/views/admin/tax_zones/new.html.erb +14 -0
  74. data/generators/opensteam/templates/app/views/admin/tax_zones/show.html.erb +15 -0
  75. data/generators/opensteam/templates/app/views/admin/users.html.erb +0 -1
  76. data/generators/opensteam/templates/app/views/admin/users/show.html.erb +10 -0
  77. data/generators/opensteam/templates/app/views/administration_mailer/order_customer.erb +1 -1
  78. data/generators/opensteam/templates/app/views/carts/_cart.html.erb +7 -0
  79. data/generators/opensteam/templates/app/views/carts/_cart_content.html.erb +45 -0
  80. data/generators/opensteam/templates/app/views/carts/create.rjs +3 -0
  81. data/generators/opensteam/templates/app/views/{cart → carts}/index.html.erb +0 -0
  82. data/generators/opensteam/templates/app/views/carts/update.rjs +11 -0
  83. data/generators/opensteam/templates/app/views/checkout/_address.html.erb +42 -0
  84. data/generators/opensteam/templates/app/views/checkout/_customer.html.erb +31 -0
  85. data/generators/opensteam/templates/app/views/checkout/_edit_checkout.html.erb +42 -0
  86. data/generators/opensteam/templates/app/views/checkout/_new_checkout.html.erb +44 -0
  87. data/generators/opensteam/templates/app/views/checkout/_shipping_buttons.html.erb +8 -0
  88. data/generators/opensteam/templates/app/views/checkout/edit.html.erb +7 -0
  89. data/generators/opensteam/templates/app/views/checkout/new.html.erb +11 -0
  90. data/generators/opensteam/templates/app/views/checkout/outro.html.erb +1 -4
  91. data/generators/opensteam/templates/app/views/checkout/show.html.erb +63 -0
  92. data/generators/opensteam/templates/app/views/common/_header_admin.html.erb +5 -0
  93. data/generators/opensteam/templates/app/views/layouts/admin.html.erb +28 -12
  94. data/generators/opensteam/templates/app/views/layouts/profile.html.erb +2 -2
  95. data/generators/opensteam/templates/app/views/layouts/webshop.html.erb +5 -4
  96. data/generators/opensteam/templates/app/views/payment/_advance_payment_payment.html.erb +1 -0
  97. data/generators/opensteam/templates/app/views/payment/_credit_card_payment.html.erb +37 -0
  98. data/generators/opensteam/templates/app/views/payment/_credit_card_payment_confirmation.html.erb +20 -0
  99. data/generators/opensteam/templates/app/views/payment/_direct_debit_payment.html.erb +5 -0
  100. data/generators/opensteam/templates/app/views/payment/_direct_debit_payment_confirmation.html.erb +5 -0
  101. data/generators/opensteam/templates/app/views/profile/index.html.erb +1 -1
  102. data/generators/opensteam/templates/app/views/profile/infos/edit.html.erb +20 -12
  103. data/generators/opensteam/templates/app/views/profile/infos/edit_password.html.erb +16 -12
  104. data/generators/opensteam/templates/app/views/profile/orders/_order.html.erb +1 -1
  105. data/generators/opensteam/templates/app/views/profile/orders/show.html.erb +10 -7
  106. data/generators/opensteam/templates/app/views/webshop/_inventory_content.html.erb +1 -0
  107. data/generators/opensteam/templates/app/views/webshop/show.html.erb +3 -1
  108. data/generators/opensteam/templates/config/initializers/init_states.rb +13 -24
  109. data/generators/opensteam/templates/config/initializers/opensteam.rb +41 -0
  110. data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +49 -10
  111. data/generators/opensteam/templates/config/initializers/opensteam_security.rb +8 -0
  112. data/generators/opensteam/templates/config/initializers/payment_process.rb +37 -0
  113. data/generators/opensteam/templates/db/migrate/20080609095723_create_addresses.rb +8 -2
  114. data/generators/opensteam/templates/db/migrate/20080609095726_create_inventories.rb +6 -3
  115. data/generators/opensteam/templates/db/migrate/20080609095728_create_order_items.rb +12 -1
  116. data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +8 -12
  117. data/generators/opensteam/templates/db/migrate/20080609095730_create_payment_types.rb +2 -0
  118. data/generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb +2 -1
  119. data/generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb +3 -1
  120. data/generators/opensteam/templates/db/migrate/20080808075247_create_containers.rb +30 -0
  121. data/generators/opensteam/templates/db/migrate/20080808083011_create_container_items.rb +25 -0
  122. data/generators/opensteam/templates/db/migrate/20080812102727_create_tax_zones.rb +16 -0
  123. data/generators/opensteam/templates/db/migrate/20080812102858_create_tax_rules.rb +15 -0
  124. data/generators/opensteam/templates/db/migrate/20080812102956_create_tax_groups.rb +14 -0
  125. data/generators/opensteam/templates/db/migrate/20080831181436_create_configurations.rb +15 -0
  126. data/generators/opensteam/templates/db/migrate/20080903131506_create_payments.rb +22 -0
  127. data/generators/opensteam/templates/db/migrate/20080904133625_create_payment_transactions.rb +24 -0
  128. data/generators/opensteam/templates/db/migrate/20080916102341_create_zones.rb +19 -0
  129. data/generators/opensteam/templates/db/migrate/20080916134340_create_region_shipping_rates.rb +18 -0
  130. data/generators/opensteam/templates/db/migrate/20080916134523_create_shipping_rate_groups.rb +18 -0
  131. data/generators/opensteam/templates/db/migrate/20080916135226_create_shipping_payment_additions.rb +20 -0
  132. data/generators/opensteam/templates/db/migrate/20080916135228_init_opensteam_config.rb +60 -0
  133. data/generators/opensteam/templates/public/images/opensteam_black.jpg +0 -0
  134. data/generators/opensteam/templates/public/images/pdf.png +0 -0
  135. data/generators/opensteam/templates/public/images/shader.png +0 -0
  136. data/generators/opensteam/templates/public/index.html +1 -0
  137. data/generators/opensteam/templates/public/javascripts/opensteam.js +21 -21
  138. data/generators/opensteam/templates/public/stylesheets/opensteam_admin.css +291 -0
  139. data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +47 -11
  140. data/generators/opensteam/templates/tasks/opensteam.rake +2 -12
  141. data/generators/opensteam/templates/test/fixtures/addresses.yml +26 -0
  142. data/generators/opensteam/templates/test/fixtures/configurations.yml +29 -0
  143. data/generators/opensteam/templates/test/fixtures/inventories.yml +32 -15
  144. data/generators/opensteam/templates/test/fixtures/profiles.yml +21 -0
  145. data/generators/opensteam/templates/test/fixtures/region_shipping_rates.yml +33 -0
  146. data/generators/opensteam/templates/test/fixtures/shipping_payment_additions.yml +91 -0
  147. data/generators/opensteam/templates/test/fixtures/shipping_rate_groups.yml +25 -0
  148. data/generators/opensteam/templates/test/fixtures/tax_groups.yml +13 -0
  149. data/generators/opensteam/templates/test/fixtures/tax_rules.yml +29 -0
  150. data/generators/opensteam/templates/test/fixtures/tax_zones.yml +33 -0
  151. data/generators/opensteam/templates/test/fixtures/users.yml +26 -0
  152. data/generators/opensteam/templates/test/fixtures/zones.yml +2707 -0
  153. data/generators/opensteam/templates/test/functional/carts_controller_test.rb +103 -0
  154. data/generators/opensteam/templates/test/test_helper.rb +38 -0
  155. data/generators/opensteam/templates/test/unit/container_test.rb +71 -0
  156. data/generators/opensteam/templates/test/unit/order_test.rb +93 -0
  157. data/generators/opensteam/templates/test/unit/payment_test.rb +220 -0
  158. data/generators/opensteam/templates/test/unit/product_test.rb +158 -0
  159. data/generators/opensteam/templates/vendor/plugins/prawnto/.gitignore +3 -0
  160. data/generators/opensteam/templates/vendor/plugins/prawnto/MIT-LICENSE +20 -0
  161. data/generators/opensteam/templates/vendor/plugins/prawnto/README +12 -0
  162. data/generators/opensteam/templates/vendor/plugins/prawnto/Rakefile +22 -0
  163. data/generators/opensteam/templates/vendor/plugins/prawnto/init.rb +6 -0
  164. data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto.rb +13 -0
  165. data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/action_controller.rb +47 -0
  166. data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/base.rb +75 -0
  167. data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/raw.rb +54 -0
  168. data/generators/opensteam/templates/vendor/plugins/prawnto/tasks/prawnto_tasks.rake +4 -0
  169. data/generators/opensteam/templates/vendor/plugins/prawnto/test/action_controller_test.rb +36 -0
  170. data/generators/opensteam/templates/vendor/plugins/prawnto/test/base_template_handler_test.rb +58 -0
  171. data/generators/opensteam/templates/vendor/plugins/prawnto/test/raw_template_handler_test.rb +163 -0
  172. data/generators/opensteam/templates/vendor/plugins/prawnto/test/template_handler_test_mocks.rb +83 -0
  173. data/generators/opensteam_product/templates/views/admin/_attributes.html.erb +8 -3
  174. data/generators/opensteam_product/templates/views/admin/_inventories.html.erb +2 -0
  175. data/lib/opensteam.rb +0 -1
  176. data/lib/opensteam/base.rb +2 -1
  177. data/lib/opensteam/checkout.rb +3 -12
  178. data/lib/opensteam/config.rb +50 -2
  179. data/lib/opensteam/container.rb +196 -0
  180. data/lib/opensteam/extension_base.rb +19 -1
  181. data/lib/opensteam/finder.rb +1 -1
  182. data/lib/opensteam/helpers/config_table_helper.rb +18 -6
  183. data/lib/opensteam/initializer.rb +24 -4
  184. data/lib/opensteam/inventory_base.rb +6 -1
  185. data/lib/opensteam/invoice_base.rb +12 -13
  186. data/lib/opensteam/money.rb +230 -0
  187. data/lib/opensteam/order_base.rb +122 -48
  188. data/lib/opensteam/payment.rb +225 -0
  189. data/lib/opensteam/payment/advance_payment.rb +34 -0
  190. data/lib/opensteam/payment/credit_card_payment.rb +217 -0
  191. data/lib/opensteam/payment/direct_debit_payment.rb +53 -0
  192. data/lib/opensteam/product_base.rb +48 -12
  193. data/lib/opensteam/security.rb +54 -0
  194. data/lib/opensteam/shipment_base.rb +214 -6
  195. data/lib/opensteam/shopping_cart.rb +20 -300
  196. data/lib/opensteam/state_logic.rb +5 -3
  197. data/lib/opensteam/state_machine.rb +8 -3
  198. data/lib/opensteam/user_base.rb +48 -6
  199. data/lib/opensteam/version.rb +1 -1
  200. metadata +122 -16
  201. data/generators/opensteam/templates/app/controllers/cart_controller.rb +0 -94
  202. data/generators/opensteam/templates/app/views/admin/orders/_event.html.erb +0 -5
  203. data/generators/opensteam/templates/app/views/admin/orders/_order_item.html.erb +0 -10
  204. data/generators/opensteam/templates/app/views/cart/_cart.html.erb +0 -8
  205. data/generators/opensteam/templates/app/views/cart/_cart_content.html.erb +0 -20
  206. data/generators/opensteam/templates/app/views/cart/update.rjs +0 -1
  207. data/generators/opensteam/templates/app/views/checkout/payment.html.erb +0 -8
  208. data/generators/opensteam/templates/app/views/checkout/shipping.html.erb +0 -45
  209. data/generators/opensteam/templates/app/views/checkout/show_cart.html.erb +0 -13
  210. data/generators/opensteam/templates/app/views/checkout/update_cart_content.rjs +0 -2
  211. data/generators/opensteam/templates/app/views/profile/orders/_order_item.html.erb +0 -10
  212. data/generators/opensteam/templates/db/migrate/20080609095725_create_dummy_users.rb +0 -21
  213. data/lib/opensteam/cart_base.rb +0 -227
@@ -0,0 +1,158 @@
1
+ require 'test_helper'
2
+
3
+ class ProductTest < ActiveSupport::TestCase
4
+
5
+ fixtures :inventories
6
+
7
+
8
+ def test_table_prefix
9
+ assert_equal( Opensteam::Config::PRODUCT_BASE_TABLE_PREFIX.to_s, DogFood.table_prefix )
10
+ end
11
+
12
+ def test_create_product_without_properties
13
+ c = Animal.new( :type => "Dog" )
14
+ assert( c.save )
15
+ assert_equal(0, c.inventories.size)
16
+
17
+
18
+ c = Animal.new( :type => "Dog", :set_properties => [] )
19
+ assert( c.save )
20
+ assert_equal(1, c.inventories.size)
21
+ assert_equal(0, c.inventories.first.storage)
22
+ assert_equal(0, c.inventories.first.active )
23
+
24
+ end
25
+
26
+
27
+ def test_create_product_with_properties
28
+ weights = [ Weight.first.id.to_s ]
29
+ dog_kinds = [ DogKind.first.id.to_s ]
30
+ c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } )
31
+
32
+ assert( c.save )
33
+ assert_equal(1, c.inventories.size)
34
+ assert_equal(0, c.inventories.first.storage)
35
+ assert_equal(0, c.inventories.first.active )
36
+
37
+ assert_equal( 2, Array( c.properties ).size )
38
+
39
+ end
40
+
41
+
42
+ def test_create_product_with_invalid_properties
43
+ assert_raise(Opensteam::Config::Errors::NotAProperty ) {
44
+ DogFood.new( :name => "test", :set_properties => { "string" => [ 1,2 ] } )
45
+ }
46
+ end
47
+
48
+ def test_add_properties
49
+ c = DogFood.new( :name => "test" )
50
+ assert( c.save )
51
+
52
+ c.add_properties( [ Weight.first ] )
53
+ assert_equal(1, Array( c.properties ).size )
54
+ assert_equal(1, Array( c.inventories ).size )
55
+ assert_equal(c.inventories, c.inventories( [Weight.first] ) )
56
+
57
+ c.add_properties( [ Weight.first ] )
58
+ assert_equal(1, Array( c.properties ).size )
59
+ assert_equal(1, Array( c.inventories ).size )
60
+ assert_equal(c.inventories, c.inventories( [Weight.first] ) )
61
+
62
+ end
63
+
64
+ def test_edit_product_and_update_properties
65
+ weights = [ Weight.first.id.to_s, Weight.last.id.to_s ]
66
+ dog_kinds = [ DogKind.first.id.to_s, DogKind.last.id.to_s ]
67
+ assert_not_nil( c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } ) )
68
+ assert c.save
69
+ assert_equal(4, c.inventories.size)
70
+ assert_equal(4, Array( c.properties ).size )
71
+ dd = [ DogKind.last.id.to_s ]
72
+ c.set_properties = { "weight" => weights, "dog_kinds" => dd }
73
+ c.reload
74
+ assert_equal(2, c.inventories.size )
75
+ assert_equal(3, Array(c.properties).size )
76
+ assert_equal([], c.inventories( [Weight.first, DogKind.first]))
77
+ assert(!Array(c.properties).include?( DogKind.first ) )
78
+
79
+ end
80
+
81
+
82
+ def test_delete_inventory_by_properties
83
+ c = DogFood.new( :name => "test" )
84
+ assert( c.save )
85
+
86
+ c.add_properties( [ Weight.first ] )
87
+ assert_equal(1, Array( c.properties ).size )
88
+ assert_equal(1, Array( c.inventories ).size )
89
+ assert_equal(c.inventories, c.inventories( [Weight.first] ) )
90
+
91
+ c.del_properties( Weight.first )
92
+ c.reload
93
+ assert_equal(0, Array( c.properties ).size )
94
+ assert_equal(0, Array( c.inventories ).size )
95
+ end
96
+
97
+
98
+ def test_create_product_with_properties_and_perm
99
+ weights = [ Weight.first.id.to_s, Weight.last.id.to_s ]
100
+ dog_kinds = [ DogKind.first.id.to_s, DogKind.last.id.to_s ]
101
+ c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } )
102
+
103
+ assert( c.save )
104
+ assert_equal(4, c.inventories.size)
105
+ assert_equal(0, c.inventories.first.storage)
106
+ assert_equal(0, c.inventories.last.active )
107
+
108
+ assert_equal( 4, Array( c.properties ).size )
109
+ end
110
+
111
+
112
+
113
+ def test_create_product_and_verify_inventory_search
114
+ weights = [ Weight.first.id.to_s, Weight.last.id.to_s ]
115
+ dog_kinds = [ DogKind.first.id.to_s, DogKind.last.id.to_s ]
116
+
117
+ c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } )
118
+ assert c
119
+ assert c.save
120
+
121
+ assert_equal(4, c.inventories.size)
122
+ assert_equal(0, c.inventories.first.storage)
123
+ assert_equal(0, c.inventories.last.active )
124
+ assert_equal( 4, Array( c.properties ).size )
125
+
126
+ i = c.inventories.first
127
+
128
+ assert_equal([i], c.inventories( i.properties ) )
129
+
130
+
131
+ end
132
+
133
+
134
+ def test_create_product_and_test_crud_inventory
135
+ weights = [ Weight.first.id.to_s, Weight.last.id.to_s ]
136
+ dog_kinds = [ DogKind.first.id.to_s, DogKind.last.id.to_s ]
137
+
138
+ c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } )
139
+ assert c
140
+ assert c.save
141
+
142
+ assert c.inventories.first.update_attributes( :storage => 123, :active => 1 )
143
+ c.selected_inventory = c.inventories.first
144
+ assert_not_nil( c.selected_inventories )
145
+ assert c.is_available?
146
+
147
+
148
+ end
149
+
150
+
151
+
152
+
153
+
154
+ # Replace this with your real tests.
155
+ def test_truth
156
+ assert true
157
+ end
158
+ end
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ **/*.swp
3
+ reference_pdfs
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 cracklabs.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ Prawnto
2
+ =======
3
+
4
+ a rails (2.1) plugin, providing templating abilities
5
+ for generating pdf files leveraging the new kick-ass prawn library
6
+
7
+ full documentation/demos at: http://cracklabs.com/prawnto
8
+
9
+
10
+
11
+
12
+ Copyright (c) 2008 cracklabs.com, released under the MIT license
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the prawnto plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the prawnto plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Prawnto'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,6 @@
1
+ require 'prawnto'
2
+
3
+ Mime::Type.register "application/pdf", :pdf
4
+ ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandler::Base
5
+ ActionView::Template.register_template_handler 'prawnx', Prawnto::TemplateHandler::Raw # experimental
6
+
@@ -0,0 +1,13 @@
1
+ require 'prawn'
2
+ require 'prawnto/action_controller'
3
+
4
+ require 'prawnto/template_handler/base'
5
+ require 'prawnto/template_handler/raw'
6
+
7
+ # for now applying to all Controllers
8
+ # however, could reduce footprint by letting user mixin (i.e. include) only into controllers that need it
9
+ # but does it really matter performance wise to include in a controller that doesn't need it? doubtful-- depends how much of a hit the before_filter is i guess..
10
+ class ActionController::Base
11
+ include Prawnto::ActionController
12
+ end
13
+
@@ -0,0 +1,47 @@
1
+ module Prawnto
2
+ module ActionController
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ base.before_filter :reset_prawnto_options
7
+ end
8
+
9
+ module ClassMethods
10
+ def prawnto(options)
11
+ prawn_options, prawnto_options = breakdown_prawnto_options options
12
+ write_inheritable_hash(:prawn, prawn_options)
13
+ write_inheritable_hash(:prawnto, prawnto_options)
14
+ end
15
+
16
+ private
17
+
18
+ def breakdown_prawnto_options(options)
19
+ prawnto_options = options.dup
20
+ prawn_options = (prawnto_options.delete(:prawn) || {}).dup
21
+ [prawn_options, prawnto_options]
22
+ end
23
+ end
24
+
25
+ def prawnto(options)
26
+ @prawnto_options.merge! options
27
+ end
28
+
29
+
30
+ private
31
+
32
+ def reset_prawnto_options
33
+ @prawnto_options = {:inline=> true}
34
+ end
35
+
36
+ def compute_prawnto_options
37
+ @prawnto_options ||= reset_prawnto_options
38
+ @prawnto_options[:prawn] ||= {}
39
+ @prawnto_options[:prawn].merge!(self.class.read_inheritable_attribute(:prawn) || {}) {|k,o,n| o}
40
+ @prawnto_options.merge!(self.class.read_inheritable_attribute(:prawnto) || {}) {|k,o,n| o}
41
+ @prawnto_options
42
+ end
43
+
44
+ end
45
+ end
46
+
47
+
@@ -0,0 +1,75 @@
1
+ module Prawnto
2
+ module TemplateHandler
3
+ class Base < ActionView::TemplateHandler
4
+
5
+ attr_reader :prawnto_options
6
+
7
+ # TODO: kept around from railspdf-- maybe not needed anymore? should check.
8
+ def ie_request?
9
+ @view.request.env['HTTP_USER_AGENT'] =~ /msie/i
10
+ end
11
+
12
+ # TODO: kept around from railspdf-- maybe not needed anymore? should check.
13
+ def set_pragma
14
+ @view.headers['Pragma'] ||= ie_request? ? 'no-cache' : ''
15
+ end
16
+
17
+ # TODO: kept around from railspdf-- maybe not needed anymore? should check.
18
+ def set_cache_control
19
+ @view.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : ''
20
+ end
21
+
22
+ def set_content_type
23
+ @view.response.content_type = Mime::PDF
24
+ end
25
+
26
+ def set_disposition
27
+ inline = 'attachment'
28
+ # inline = @prawnto_options[:inline] ? 'inline' : 'attachment'
29
+ filename = @prawnto_options[:filename] ? "filename=#{@prawnto_options[:filename]}" : nil
30
+ @view.headers["Content-Disposition"] = [inline,filename].compact.join(';')
31
+ end
32
+
33
+ def build_headers
34
+ set_pragma
35
+ set_cache_control
36
+ set_content_type
37
+ set_disposition
38
+ end
39
+
40
+ def build_source_to_establish_locals(template)
41
+ prawnto_locals = {}
42
+ if dsl = @prawnto_options[:dsl]
43
+ if dsl.kind_of?(Array)
44
+ dsl.each {|v| v = v.to_s.gsub(/^@/,''); prawnto_locals[v]="@#{v}"}
45
+ elsif dsl.kind_of?(Hash)
46
+ prawnto_locals.merge!(dsl)
47
+ end
48
+ end
49
+ prawnto_locals.merge!(template.locals)
50
+ prawnto_locals.map {|k,v| "#{k} = #{v};"}.join("")
51
+ end
52
+
53
+ def pull_prawnto_options
54
+ @prawnto_options = @view.controller.send :compute_prawnto_options
55
+ end
56
+
57
+ def render(template)
58
+ pull_prawnto_options
59
+ build_headers
60
+
61
+ source = build_source_to_establish_locals(template)
62
+ if @prawnto_options[:dsl]
63
+ source += "pdf.instance_eval do\n#{template.source}\nend"
64
+ else
65
+ source += "\n#{template.source}"
66
+ end
67
+
68
+ pdf = Prawn::Document.new(@prawnto_options[:prawn])
69
+ @view.instance_eval source, template.filename, 1
70
+ pdf.render
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,54 @@
1
+ module Prawnto
2
+ module TemplateHandler
3
+ class Raw < Base
4
+
5
+ attr_reader :run_environment
6
+
7
+ GENERATE_REGULAR_EXPRESSION = /^\s*Prawn\:\:Document\.generate(\(?)(.*?)(\,(.*))?(\s*\)?\s+do(.*?))$/m
8
+ RENDER_FILE_REGULAR_EXPRESSION = /(\w+)\.render_file\(?(.*?)\)?\s*$/
9
+
10
+
11
+ def render(template)
12
+ setup_run_environment
13
+ pull_prawnto_options
14
+ source,filename = massage_template_source(template)
15
+ @prawnto_options[:filename] = filename if filename
16
+ build_headers
17
+ @run_environment.instance_eval(source, template.filename, 0) #run in anonymous class
18
+ end
19
+
20
+
21
+ protected
22
+
23
+ def setup_run_environment
24
+ @run_environment = Object.new
25
+ end
26
+
27
+ def massage_template_source(template)
28
+ source = template.source
29
+ variable_name = '_pdf'
30
+ filename = nil
31
+
32
+ source.gsub! /^(\s*?)(\$LOAD_PATH)/, '\1#\2'
33
+ source.gsub! /^(\s*?)(require\(?\s*['"]rubygems['"]\s*\)?\s*)$/, '\1#\2'
34
+ source.gsub! /^(\s*?)(require\(?\s*['"]prawn['"]\s*\)?\s*)$/, '\1#\2'
35
+
36
+ if (source =~ GENERATE_REGULAR_EXPRESSION)
37
+ filename = $2
38
+ source.sub! GENERATE_REGULAR_EXPRESSION, "#{variable_name} = Prawn::Document.new\\1\\4\\5"
39
+ elsif (source =~ RENDER_FILE_REGULAR_EXPRESSION)
40
+ variable_name = $1
41
+ filename = $2
42
+ source.sub! RENDER_FILE_REGULAR_EXPRESSION, '#\0'
43
+ end
44
+ source.gsub! /^(\s*)(class\s|def\s).*?\n\1end/m do |match|
45
+ eval "class <<@run_environment; #{match}; end;"
46
+ "\n" * match.count("\n")
47
+ end
48
+ source += "\n[#{variable_name}.render,#{filename}]\n"
49
+ source
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :prawnto do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'action_controller'
3
+ require 'action_view'
4
+
5
+ require 'test/unit'
6
+ require File.dirname(__FILE__) + '/../lib/prawnto'
7
+
8
+
9
+ class ActionControllerTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @controller_class = Class.new(ActionController::Base)
13
+
14
+ # for some reason using the following as a block in the preceding statement is somehow different?
15
+ @controller_class.module_eval do
16
+ prawnto :inline=>true, :prawn=>{:page_orientation=>:landscape}
17
+
18
+ def test
19
+ prawnto :inline=>false, :prawn=>{:page_size=>'A4'}
20
+ end
21
+ end
22
+ end
23
+
24
+ def test_inheritable_options
25
+ assert_equal({:page_orientation=>:landscape}, @controller_class.read_inheritable_attribute(:prawn))
26
+ assert_equal({:inline=>true}, @controller_class.read_inheritable_attribute(:prawnto))
27
+ end
28
+
29
+ def test_computed_options
30
+ controller = @controller_class.new
31
+ controller.test
32
+ assert_equal({:inline=>false, :prawn=>{:page_orientation=>:landscape, :page_size=>'A4'}}, controller.send(:compute_prawnto_options))
33
+ end
34
+
35
+ end
36
+