nimbleshop_core 0.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/Rakefile +15 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/american_express.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/authorize_net_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/authorizedotnet_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/discover.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/mastercard.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/visa.png +0 -0
- data/app/assets/images/engines/nimbleshop_cod/cod_small.png +0 -0
- data/app/assets/images/engines/nimbleshop_paypalwp/paypal_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_paypalwp/paypal_small.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable_small.png +0 -0
- data/app/assets/javascripts/admin/products/edit.js.coffee +19 -0
- data/app/assets/javascripts/admin/shipping_methods/edit.js.coffee +6 -0
- data/app/assets/javascripts/admin.js +25 -0
- data/app/assets/javascripts/fadeout_success.js.coffee +2 -0
- data/app/assets/javascripts/payment_method.js.coffee +19 -0
- data/app/assets/javascripts/product-group-condition.js.coffee +33 -0
- data/app/assets/javascripts/remove_deletion_of_product_pictures.js.coffee +5 -0
- data/app/assets/javascripts/shipit.js.coffee +10 -0
- data/app/assets/javascripts/twitter_bootstrap.js.coffee +4 -0
- data/app/assets/stylesheets/admin.css +9 -0
- data/app/assets/stylesheets/admin_bootstrap_and_overrides.css.less +38 -0
- data/app/assets/stylesheets/admin_custom.css +104 -0
- data/app/assets/twitter/bootstrap/glyphicons-halflings-white.png +0 -0
- data/app/assets/twitter/bootstrap/glyphicons-halflings.png +0 -0
- data/app/controllers/admin/custom_fields_controller.rb +56 -0
- data/app/controllers/admin/link_groups_controller.rb +76 -0
- data/app/controllers/admin/main_controller.rb +9 -0
- data/app/controllers/admin/navigations_controller.rb +49 -0
- data/app/controllers/admin/orders_controller.rb +47 -0
- data/app/controllers/admin/payment_methods_controller.rb +26 -0
- data/app/controllers/admin/product_groups_controller.rb +70 -0
- data/app/controllers/admin/products_controller.rb +71 -0
- data/app/controllers/admin/shipments_controller.rb +19 -0
- data/app/controllers/admin/shipping_methods_controller.rb +93 -0
- data/app/controllers/admin/shipping_zones_controller.rb +62 -0
- data/app/controllers/admin/shops_controller.rb +33 -0
- data/app/controllers/admin_controller.rb +38 -0
- data/app/helpers/admin_helper.rb +83 -0
- data/app/helpers/nimbleshop_helper.rb +43 -0
- data/app/helpers/payment_method_helper.rb +52 -0
- data/app/mailers/admin_mailer.rb +22 -0
- data/app/mailers/mailer.rb +31 -0
- data/app/models/address.rb +69 -0
- data/app/models/country_shipping_zone.rb +36 -0
- data/app/models/creditcard.rb +95 -0
- data/app/models/custom_field.rb +8 -0
- data/app/models/custom_field_answer/field.rb +101 -0
- data/app/models/custom_field_answer.rb +17 -0
- data/app/models/line_item.rb +48 -0
- data/app/models/link.rb +3 -0
- data/app/models/link_group.rb +8 -0
- data/app/models/navigation.rb +7 -0
- data/app/models/order.rb +158 -0
- data/app/models/payment_method.rb +20 -0
- data/app/models/payment_transaction.rb +11 -0
- data/app/models/picture.rb +30 -0
- data/app/models/product.rb +76 -0
- data/app/models/product_group.rb +65 -0
- data/app/models/product_group_condition.rb +8 -0
- data/app/models/regional_shipping_zone.rb +25 -0
- data/app/models/shipment.rb +19 -0
- data/app/models/shipment_carrier.rb +3 -0
- data/app/models/shipping_cost_calculator.rb +9 -0
- data/app/models/shipping_method.rb +103 -0
- data/app/models/shipping_zone.rb +9 -0
- data/app/models/shop.rb +26 -0
- data/app/models/tax_calculator.rb +18 -0
- data/app/observers/order_observer.rb +53 -0
- data/app/uploaders/picture_uploader.rb +65 -0
- data/app/views/admin/custom_fields/_form.html.erb +45 -0
- data/app/views/admin/custom_fields/edit.html.erb +7 -0
- data/app/views/admin/custom_fields/index.html.erb +31 -0
- data/app/views/admin/custom_fields/new.html.erb +7 -0
- data/app/views/admin/link_groups/_form.html.erb +31 -0
- data/app/views/admin/link_groups/_link_group.html.erb +50 -0
- data/app/views/admin/link_groups/_link_group_title.html.erb +5 -0
- data/app/views/admin/link_groups/edit.html.erb +8 -0
- data/app/views/admin/link_groups/index.html.erb +29 -0
- data/app/views/admin/link_groups/new.html.erb +9 -0
- data/app/views/admin/mailer/new_order_notification.text.erb +31 -0
- data/app/views/admin/main/index.html.erb +5 -0
- data/app/views/admin/navigations/new.html.erb +29 -0
- data/app/views/admin/orders/_line_item.html.erb +11 -0
- data/app/views/admin/orders/_line_items.html.erb +39 -0
- data/app/views/admin/orders/_payment_info.html.erb +20 -0
- data/app/views/admin/orders/_shipping_info.html.erb +40 -0
- data/app/views/admin/orders/index.html.erb +33 -0
- data/app/views/admin/orders/show.html.erb +40 -0
- data/app/views/admin/payment_methods/index.html.erb +6 -0
- data/app/views/admin/product_groups/_condition.html.mustache +20 -0
- data/app/views/admin/product_groups/_form.html.erb +72 -0
- data/app/views/admin/product_groups/edit.html.erb +7 -0
- data/app/views/admin/product_groups/index.html.erb +30 -0
- data/app/views/admin/product_groups/new.html.erb +7 -0
- data/app/views/admin/product_groups/show.html.erb +9 -0
- data/app/views/admin/products/_custom_field_answer.html.erb +9 -0
- data/app/views/admin/products/_form.html.erb +69 -0
- data/app/views/admin/products/_handle_pictures.html.erb +32 -0
- data/app/views/admin/products/_pictures.html.erb +33 -0
- data/app/views/admin/products/edit.html.erb +26 -0
- data/app/views/admin/products/index.html.erb +34 -0
- data/app/views/admin/products/new.html.erb +9 -0
- data/app/views/admin/shipping_methods/_form.html.erb +58 -0
- data/app/views/admin/shipping_methods/_shipping_method.html.erb +31 -0
- data/app/views/admin/shipping_methods/edit.html.erb +18 -0
- data/app/views/admin/shipping_methods/new.html.erb +7 -0
- data/app/views/admin/shipping_zones/_form.html.erb +31 -0
- data/app/views/admin/shipping_zones/_shipping_method.html.erb +13 -0
- data/app/views/admin/shipping_zones/_shipping_zone.html.erb +47 -0
- data/app/views/admin/shipping_zones/edit.html.erb +8 -0
- data/app/views/admin/shipping_zones/index.html.erb +16 -0
- data/app/views/admin/shipping_zones/new.html.erb +8 -0
- data/app/views/admin/shops/edit.html.erb +119 -0
- data/app/views/layouts/_admin_footer.html.erb +23 -0
- data/app/views/layouts/_admin_sidebar.html.erb +0 -0
- data/app/views/layouts/_container.html.erb +33 -0
- data/app/views/layouts/_top_nav_bar.html.erb +30 -0
- data/app/views/layouts/admin.html.erb +35 -0
- data/app/views/layouts/payment_method.html.erb +12 -0
- data/app/views/mailer/order_notification_to_buyer.text.erb +31 -0
- data/app/views/mailer/shipment_notification_to_buyer.text.erb +34 -0
- data/config/initializers/001_settings_application.rb +10 -0
- data/config/initializers/002_load_core_extensions.rb +8 -0
- data/config/initializers/field_with_error.rb +2 -0
- data/config/initializers/strip_and_nullify.rb +13 -0
- data/config/initializers/time_formats.rb +1 -0
- data/config/locales/en.yml +61 -0
- data/config/routes.rb +56 -0
- data/db/development.sqlite3 +0 -0
- data/db/migrate/20111022144421_create_product_groups.rb +12 -0
- data/db/migrate/20111022144426_create_products.rb +16 -0
- data/db/migrate/20111022144653_create_orders.rb +21 -0
- data/db/migrate/20111022144725_create_line_items.rb +15 -0
- data/db/migrate/20111022234951_create_shops.rb +20 -0
- data/db/migrate/20111026193227_create_link_groups.rb +12 -0
- data/db/migrate/20111026193435_create_navigations.rb +10 -0
- data/db/migrate/20111031135810_create_links.rb +10 -0
- data/db/migrate/20111106193938_create_custom_fields.rb +10 -0
- data/db/migrate/20111106195112_create_custom_field_answers.rb +14 -0
- data/db/migrate/20111106201548_create_product_group_conditions.rb +12 -0
- data/db/migrate/20111107035350_create_creditcard_transactions.rb +15 -0
- data/db/migrate/20111109190754_create_addresses.rb +24 -0
- data/db/migrate/20111125173344_create_pictures.rb +16 -0
- data/db/migrate/20111201024408_create_shipping_methods.rb +16 -0
- data/db/migrate/20111202143154_create_shipping_zones.rb +17 -0
- data/db/migrate/20111203034020_create_payment_methods.rb +14 -0
- data/db/migrate/20111221190000_create_preferences.rb +14 -0
- data/db/migrate/20120105234047_create_shipments.rb +11 -0
- data/db/migrate/20120105234553_create_shipment_carriers.rb +11 -0
- data/db/migrate/20120606165355_create_delayed_jobs.rb +22 -0
- data/db/production.sqlite3 +0 -0
- data/db/schema.rb +265 -0
- data/db/seeds.rb +1 -0
- data/db/test.sqlite3 +0 -0
- data/lib/assets/javascripts/loading_state_for_buttons.js.coffee +3 -0
- data/lib/assets/javascripts/show_help_on_hover.js.coffee +2 -0
- data/lib/assets/javascripts/utils/autoresize.js.coffee +3 -0
- data/lib/assets/javascripts/utils/focus.js.coffee +3 -0
- data/lib/assets/javascripts/utils/formatNumber.js.coffee +25 -0
- data/lib/assets/javascripts/utils/formatPrice.js.coffee +24 -0
- data/lib/generators/nimbleshop/app/app_generator.rb +84 -0
- data/lib/generators/nimbleshop/app/templates/config/application.yml +61 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/airbrake.rb +3 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/cache_images.rb +4 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/carrierwave.rb +36 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/delayed_job.rb +15 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/setup_email.rb +24 -0
- data/lib/nimbleshop/core_ext/activerecord_base.rb +18 -0
- data/lib/nimbleshop/core_ext/filelessio.rb +4 -0
- data/lib/nimbleshop/core_ext/force_ssl.rb +26 -0
- data/lib/nimbleshop/core_ext/mustache_templater_handler.rb +10 -0
- data/lib/nimbleshop/engine.rb +23 -0
- data/lib/nimbleshop/permalink/builder.rb +46 -0
- data/lib/nimbleshop/processor/base.rb +51 -0
- data/lib/nimbleshop/processor.rb +3 -0
- data/lib/nimbleshop/product_group_search/base_field.rb +19 -0
- data/lib/nimbleshop/product_group_search/core_field_strategy.rb +31 -0
- data/lib/nimbleshop/product_group_search/custom_field_strategy.rb +39 -0
- data/lib/nimbleshop/product_group_search/date_field.rb +16 -0
- data/lib/nimbleshop/product_group_search/extension.rb +46 -0
- data/lib/nimbleshop/product_group_search/number_field.rb +17 -0
- data/lib/nimbleshop/product_group_search/text_field.rb +33 -0
- data/lib/nimbleshop/product_group_search.rb +74 -0
- data/lib/nimbleshop/sampledata/data.rb +246 -0
- data/lib/nimbleshop/sampledata/pictures/product1/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product2/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product2/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product4/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product4/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product5/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product5/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic10.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic11.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic12.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic13.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic14.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic15.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic16.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic17.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic6.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic7.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic8.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic9.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic6.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic7.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic8.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product9/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product9/pic2.jpg +0 -0
- data/lib/nimbleshop/util.rb +60 -0
- data/lib/nimbleshop/version.rb +18 -0
- data/lib/nimbleshop_core.rb +23 -0
- data/lib/tasks/localhost2public.rake +8 -0
- data/lib/tasks/setup.rake +26 -0
- data/test/factories/address_factory.rb +31 -0
- data/test/factories/creditcard_factory.rb +30 -0
- data/test/factories/custom_field_answer_factory.rb +6 -0
- data/test/factories/custom_field_factory.rb +21 -0
- data/test/factories/line_item_factory.rb +7 -0
- data/test/factories/link_factory.rb +6 -0
- data/test/factories/link_group_factory.rb +5 -0
- data/test/factories/navigation_factory.rb +6 -0
- data/test/factories/order_factory.rb +49 -0
- data/test/factories/payment_method_factory.rb +6 -0
- data/test/factories/payment_transaction_factory.rb +42 -0
- data/test/factories/picture_factory.rb +11 -0
- data/test/factories/product_group_condition_factory.rb +40 -0
- data/test/factories/product_group_factory.rb +5 -0
- data/test/factories/products_factory.rb +11 -0
- data/test/factories/shipment_carrier_factory.rb +6 -0
- data/test/factories/shipment_factory.rb +6 -0
- data/test/factories/shipping_method_factory.rb +15 -0
- data/test/factories/shipping_zone_factory.rb +5 -0
- data/test/factories/shop_factory.rb +8 -0
- data/test/fixtures/files/avatar.png +0 -0
- data/test/fixtures/link_groups.yml +13 -0
- data/test/fixtures/payment_methods.yml +39 -0
- data/test/fixtures/shops.yml +15 -0
- data/test/helpers/admin_helper_test.rb +37 -0
- data/test/helpers/nimbleshop_helper_test.rb +17 -0
- data/test/integration/admin/link_groups_acceptance_test.rb +39 -0
- data/test/integration/admin/orders_acceptance_test.rb +63 -0
- data/test/integration/admin/payment_methods_acceptance_test.rb +13 -0
- data/test/integration/admin/product_groups_acceptance_test.rb +89 -0
- data/test/integration/admin/products_acceptance_test.rb +105 -0
- data/test/integration/admin/shipping_methods_acceptance_test.rb +63 -0
- data/test/integration/admin/shipping_zones_acceptance_test.rb +16 -0
- data/test/integration/admin/shops_acceptance_test.rb +44 -0
- data/test/integration/checkout/cart_acceptance_test.rb +113 -0
- data/test/integration/checkout/payment_confirmation_acceptance_test.rb +24 -0
- data/test/integration/checkout/paypal_acceptance_test.rb +34 -0
- data/test/integration/checkout/shipping_address_acceptance_test.rb +91 -0
- data/test/integration/checkout/shipping_method_acceptance_test.rb +51 -0
- data/test/integration/homepage_acceptance_test.rb +24 -0
- data/test/integration/products_acceptance_test.rb +12 -0
- data/test/integration/static_pages_acceptance_test.rb +13 -0
- data/test/mailers/mailer_test.rb +25 -0
- data/test/rails_app/Gemfile +27 -0
- data/test/rails_app/Gemfile.lock +218 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/controllers/application_controller.rb +6 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/views/layouts/application.html.erb +10 -0
- data/test/rails_app/config/application.rb +25 -0
- data/test/rails_app/config/application.yml +61 -0
- data/test/rails_app/config/boot.rb +5 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +18 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +10 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/development.sqlite3 +0 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +74 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/log/development.log +94 -0
- data/test/rails_app/log/test.log +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/support/address_test_helper.rb +24 -0
- data/test/support/checkout_test_helper.rb +40 -0
- data/test/support/dbify_sql_helper.rb +12 -0
- data/test/support/images/cookware.jpg +0 -0
- data/test/support/must_be_like.rb +24 -0
- data/test/support/shipping_method_test_helper.rb +5 -0
- data/test/support/wait_for_ajax.rb +4 -0
- data/test/test_helper.rb +65 -0
- data/test/unit/address_test.rb +33 -0
- data/test/unit/country_shipping_zone_test.rb +17 -0
- data/test/unit/creditcard_test.rb +33 -0
- data/test/unit/custom_field_answer/field_test.rb +93 -0
- data/test/unit/order_test.rb +70 -0
- data/test/unit/payment_method/authorizedotnet_test.rb +21 -0
- data/test/unit/payment_method/paypalwp_test.rb +17 -0
- data/test/unit/payment_method/splitable_test.rb +18 -0
- data/test/unit/picture_test.rb +24 -0
- data/test/unit/processor/authorize_net_test.rb +236 -0
- data/test/unit/processor/paypal_test.rb +40 -0
- data/test/unit/processor/splitable_test.rb +123 -0
- data/test/unit/product_group_condition_test.rb +188 -0
- data/test/unit/product_group_test.rb +109 -0
- data/test/unit/product_test.rb +60 -0
- data/test/unit/shipping_cost_calculator_test.rb +19 -0
- data/test/unit/shipping_method_test.rb +197 -0
- data/test/unit/shop_test.rb +11 -0
- data/test/unit/tax_calculator_test.rb +13 -0
- data/test/vcr_cassettes/authorize_net/authorize-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/authorize-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/capture-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/capture-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/purchase-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/purchase-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/refund-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/refund-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-authorize.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-success.yml +38 -0
- data/test/vcr_cassettes/splitable/split-create-failure.yml +48 -0
- data/test/vcr_cassettes/splitable/split-create-success.yml +50 -0
- data/test/vcr_cassettes/splitable/split-draft-create-failure.yml +50 -0
- data/test/vcr_cassettes/splitable/split-draft-create-success.yml +50 -0
- data/vendor/assets/javascripts/accounting.js +406 -0
- data/vendor/assets/javascripts/autoresize.js +275 -0
- data/vendor/assets/javascripts/jquery-1.7.1.js +9267 -0
- data/vendor/assets/javascripts/jquery-form.js +980 -0
- data/vendor/assets/javascripts/jquery-json.js +193 -0
- data/vendor/assets/javascripts/jquery-ui-1.8.16.js +11768 -0
- data/vendor/assets/javascripts/jquery-ujs.js +374 -0
- data/vendor/assets/javascripts/mustache.js +436 -0
- data/vendor/assets/javascripts/nested_form.js +51 -0
- metadata +740 -0
@@ -0,0 +1,436 @@
|
|
1
|
+
/*
|
2
|
+
mustache.js — Logic-less templates in JavaScript
|
3
|
+
|
4
|
+
See http://mustache.github.com/ for more info.
|
5
|
+
*/
|
6
|
+
|
7
|
+
var Mustache = function () {
|
8
|
+
var _toString = Object.prototype.toString;
|
9
|
+
|
10
|
+
Array.isArray = Array.isArray || function (obj) {
|
11
|
+
return _toString.call(obj) == "[object Array]";
|
12
|
+
}
|
13
|
+
|
14
|
+
var _trim = String.prototype.trim, trim;
|
15
|
+
|
16
|
+
if (_trim) {
|
17
|
+
trim = function (text) {
|
18
|
+
return text == null ? "" : _trim.call(text);
|
19
|
+
}
|
20
|
+
} else {
|
21
|
+
var trimLeft, trimRight;
|
22
|
+
|
23
|
+
// IE doesn't match non-breaking spaces with \s.
|
24
|
+
if ((/\S/).test("\xA0")) {
|
25
|
+
trimLeft = /^[\s\xA0]+/;
|
26
|
+
trimRight = /[\s\xA0]+$/;
|
27
|
+
} else {
|
28
|
+
trimLeft = /^\s+/;
|
29
|
+
trimRight = /\s+$/;
|
30
|
+
}
|
31
|
+
|
32
|
+
trim = function (text) {
|
33
|
+
return text == null ? "" :
|
34
|
+
text.toString().replace(trimLeft, "").replace(trimRight, "");
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
var escapeMap = {
|
39
|
+
"&": "&",
|
40
|
+
"<": "<",
|
41
|
+
">": ">",
|
42
|
+
'"': '"',
|
43
|
+
"'": '''
|
44
|
+
};
|
45
|
+
|
46
|
+
function escapeHTML(string) {
|
47
|
+
return String(string).replace(/&(?!\w+;)|[<>"']/g, function (s) {
|
48
|
+
return escapeMap[s] || s;
|
49
|
+
});
|
50
|
+
}
|
51
|
+
|
52
|
+
var regexCache = {};
|
53
|
+
var Renderer = function () {};
|
54
|
+
|
55
|
+
Renderer.prototype = {
|
56
|
+
otag: "{{",
|
57
|
+
ctag: "}}",
|
58
|
+
pragmas: {},
|
59
|
+
buffer: [],
|
60
|
+
pragmas_implemented: {
|
61
|
+
"IMPLICIT-ITERATOR": true
|
62
|
+
},
|
63
|
+
context: {},
|
64
|
+
|
65
|
+
render: function (template, context, partials, in_recursion) {
|
66
|
+
// reset buffer & set context
|
67
|
+
if (!in_recursion) {
|
68
|
+
this.context = context;
|
69
|
+
this.buffer = []; // TODO: make this non-lazy
|
70
|
+
}
|
71
|
+
|
72
|
+
// fail fast
|
73
|
+
if (!this.includes("", template)) {
|
74
|
+
if (in_recursion) {
|
75
|
+
return template;
|
76
|
+
} else {
|
77
|
+
this.send(template);
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
// get the pragmas together
|
83
|
+
template = this.render_pragmas(template);
|
84
|
+
|
85
|
+
// render the template
|
86
|
+
var html = this.render_section(template, context, partials);
|
87
|
+
|
88
|
+
// render_section did not find any sections, we still need to render the tags
|
89
|
+
if (html === false) {
|
90
|
+
html = this.render_tags(template, context, partials, in_recursion);
|
91
|
+
}
|
92
|
+
|
93
|
+
if (in_recursion) {
|
94
|
+
return html;
|
95
|
+
} else {
|
96
|
+
this.sendLines(html);
|
97
|
+
}
|
98
|
+
},
|
99
|
+
|
100
|
+
/*
|
101
|
+
Sends parsed lines
|
102
|
+
*/
|
103
|
+
send: function (line) {
|
104
|
+
if (line !== "") {
|
105
|
+
this.buffer.push(line);
|
106
|
+
}
|
107
|
+
},
|
108
|
+
|
109
|
+
sendLines: function (text) {
|
110
|
+
if (text) {
|
111
|
+
var lines = text.split("\n");
|
112
|
+
for (var i = 0; i < lines.length; i++) {
|
113
|
+
this.send(lines[i]);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
},
|
117
|
+
|
118
|
+
/*
|
119
|
+
Looks for %PRAGMAS
|
120
|
+
*/
|
121
|
+
render_pragmas: function (template) {
|
122
|
+
// no pragmas
|
123
|
+
if (!this.includes("%", template)) {
|
124
|
+
return template;
|
125
|
+
}
|
126
|
+
|
127
|
+
var that = this;
|
128
|
+
var regex = this.getCachedRegex("render_pragmas", function (otag, ctag) {
|
129
|
+
return new RegExp(otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + ctag, "g");
|
130
|
+
});
|
131
|
+
|
132
|
+
return template.replace(regex, function (match, pragma, options) {
|
133
|
+
if (!that.pragmas_implemented[pragma]) {
|
134
|
+
throw({message:
|
135
|
+
"This implementation of mustache doesn't understand the '" +
|
136
|
+
pragma + "' pragma"});
|
137
|
+
}
|
138
|
+
that.pragmas[pragma] = {};
|
139
|
+
if (options) {
|
140
|
+
var opts = options.split("=");
|
141
|
+
that.pragmas[pragma][opts[0]] = opts[1];
|
142
|
+
}
|
143
|
+
return "";
|
144
|
+
// ignore unknown pragmas silently
|
145
|
+
});
|
146
|
+
},
|
147
|
+
|
148
|
+
/*
|
149
|
+
Tries to find a partial in the curent scope and render it
|
150
|
+
*/
|
151
|
+
render_partial: function (name, context, partials) {
|
152
|
+
name = trim(name);
|
153
|
+
if (!partials || partials[name] === undefined) {
|
154
|
+
throw({message: "unknown_partial '" + name + "'"});
|
155
|
+
}
|
156
|
+
if (!context || typeof context[name] != "object") {
|
157
|
+
return this.render(partials[name], context, partials, true);
|
158
|
+
}
|
159
|
+
return this.render(partials[name], context[name], partials, true);
|
160
|
+
},
|
161
|
+
|
162
|
+
/*
|
163
|
+
Renders inverted (^) and normal (#) sections
|
164
|
+
*/
|
165
|
+
render_section: function (template, context, partials) {
|
166
|
+
if (!this.includes("#", template) && !this.includes("^", template)) {
|
167
|
+
// did not render anything, there were no sections
|
168
|
+
return false;
|
169
|
+
}
|
170
|
+
|
171
|
+
var that = this;
|
172
|
+
|
173
|
+
var regex = this.getCachedRegex("render_section", function (otag, ctag) {
|
174
|
+
// This regex matches _the first_ section ({{#foo}}{{/foo}}), and captures the remainder
|
175
|
+
return new RegExp(
|
176
|
+
"^([\\s\\S]*?)" + // all the crap at the beginning that is not {{*}} ($1)
|
177
|
+
|
178
|
+
otag + // {{
|
179
|
+
"(\\^|\\#)\\s*(.+)\\s*" + // #foo (# == $2, foo == $3)
|
180
|
+
ctag + // }}
|
181
|
+
|
182
|
+
"\n*([\\s\\S]*?)" + // between the tag ($2). leading newlines are dropped
|
183
|
+
|
184
|
+
otag + // {{
|
185
|
+
"\\/\\s*\\3\\s*" + // /foo (backreference to the opening tag).
|
186
|
+
ctag + // }}
|
187
|
+
|
188
|
+
"\\s*([\\s\\S]*)$", // everything else in the string ($4). leading whitespace is dropped.
|
189
|
+
|
190
|
+
"g");
|
191
|
+
});
|
192
|
+
|
193
|
+
|
194
|
+
// for each {{#foo}}{{/foo}} section do...
|
195
|
+
return template.replace(regex, function (match, before, type, name, content, after) {
|
196
|
+
// before contains only tags, no sections
|
197
|
+
var renderedBefore = before ? that.render_tags(before, context, partials, true) : "",
|
198
|
+
|
199
|
+
// after may contain both sections and tags, so use full rendering function
|
200
|
+
renderedAfter = after ? that.render(after, context, partials, true) : "",
|
201
|
+
|
202
|
+
// will be computed below
|
203
|
+
renderedContent,
|
204
|
+
|
205
|
+
value = that.find(name, context);
|
206
|
+
|
207
|
+
if (type === "^") { // inverted section
|
208
|
+
if (!value || Array.isArray(value) && value.length === 0) {
|
209
|
+
// false or empty list, render it
|
210
|
+
renderedContent = that.render(content, context, partials, true);
|
211
|
+
} else {
|
212
|
+
renderedContent = "";
|
213
|
+
}
|
214
|
+
} else if (type === "#") { // normal section
|
215
|
+
if (Array.isArray(value)) { // Enumerable, Let's loop!
|
216
|
+
renderedContent = that.map(value, function (row) {
|
217
|
+
return that.render(content, that.create_context(row), partials, true);
|
218
|
+
}).join("");
|
219
|
+
} else if (that.is_object(value)) { // Object, Use it as subcontext!
|
220
|
+
renderedContent = that.render(content, that.create_context(value),
|
221
|
+
partials, true);
|
222
|
+
} else if (typeof value == "function") {
|
223
|
+
// higher order section
|
224
|
+
renderedContent = value.call(context, content, function (text) {
|
225
|
+
return that.render(text, context, partials, true);
|
226
|
+
});
|
227
|
+
} else if (value) { // boolean section
|
228
|
+
renderedContent = that.render(content, context, partials, true);
|
229
|
+
} else {
|
230
|
+
renderedContent = "";
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
return renderedBefore + renderedContent + renderedAfter;
|
235
|
+
});
|
236
|
+
},
|
237
|
+
|
238
|
+
/*
|
239
|
+
Replace {{foo}} and friends with values from our view
|
240
|
+
*/
|
241
|
+
render_tags: function (template, context, partials, in_recursion) {
|
242
|
+
// tit for tat
|
243
|
+
var that = this;
|
244
|
+
|
245
|
+
var new_regex = function () {
|
246
|
+
return that.getCachedRegex("render_tags", function (otag, ctag) {
|
247
|
+
return new RegExp(otag + "(=|!|>|&|\\{|%)?([^#\\^]+?)\\1?" + ctag + "+", "g");
|
248
|
+
});
|
249
|
+
};
|
250
|
+
|
251
|
+
var regex = new_regex();
|
252
|
+
var tag_replace_callback = function (match, operator, name) {
|
253
|
+
switch(operator) {
|
254
|
+
case "!": // ignore comments
|
255
|
+
return "";
|
256
|
+
case "=": // set new delimiters, rebuild the replace regexp
|
257
|
+
that.set_delimiters(name);
|
258
|
+
regex = new_regex();
|
259
|
+
return "";
|
260
|
+
case ">": // render partial
|
261
|
+
return that.render_partial(name, context, partials);
|
262
|
+
case "{": // the triple mustache is unescaped
|
263
|
+
case "&": // & operator is an alternative unescape method
|
264
|
+
return that.find(name, context);
|
265
|
+
default: // escape the value
|
266
|
+
return escapeHTML(that.find(name, context));
|
267
|
+
}
|
268
|
+
};
|
269
|
+
var lines = template.split("\n");
|
270
|
+
for(var i = 0; i < lines.length; i++) {
|
271
|
+
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
|
272
|
+
if (!in_recursion) {
|
273
|
+
this.send(lines[i]);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
if (in_recursion) {
|
278
|
+
return lines.join("\n");
|
279
|
+
}
|
280
|
+
},
|
281
|
+
|
282
|
+
set_delimiters: function (delimiters) {
|
283
|
+
var dels = delimiters.split(" ");
|
284
|
+
this.otag = this.escape_regex(dels[0]);
|
285
|
+
this.ctag = this.escape_regex(dels[1]);
|
286
|
+
},
|
287
|
+
|
288
|
+
escape_regex: function (text) {
|
289
|
+
// thank you Simon Willison
|
290
|
+
if (!arguments.callee.sRE) {
|
291
|
+
var specials = [
|
292
|
+
'/', '.', '*', '+', '?', '|',
|
293
|
+
'(', ')', '[', ']', '{', '}', '\\'
|
294
|
+
];
|
295
|
+
arguments.callee.sRE = new RegExp(
|
296
|
+
'(\\' + specials.join('|\\') + ')', 'g'
|
297
|
+
);
|
298
|
+
}
|
299
|
+
return text.replace(arguments.callee.sRE, '\\$1');
|
300
|
+
},
|
301
|
+
|
302
|
+
/*
|
303
|
+
find `name` in current `context`. That is find me a value
|
304
|
+
from the view object
|
305
|
+
*/
|
306
|
+
find: function (name, context) {
|
307
|
+
name = trim(name);
|
308
|
+
|
309
|
+
// Checks whether a value is thruthy or false or 0
|
310
|
+
function is_kinda_truthy(bool) {
|
311
|
+
return bool === false || bool === 0 || bool;
|
312
|
+
}
|
313
|
+
|
314
|
+
var value;
|
315
|
+
|
316
|
+
// check for dot notation eg. foo.bar
|
317
|
+
if (name.match(/([a-z_]+)\./ig)) {
|
318
|
+
var childValue = this.walk_context(name, context);
|
319
|
+
if (is_kinda_truthy(childValue)) {
|
320
|
+
value = childValue;
|
321
|
+
}
|
322
|
+
} else {
|
323
|
+
if (is_kinda_truthy(context[name])) {
|
324
|
+
value = context[name];
|
325
|
+
} else if (is_kinda_truthy(this.context[name])) {
|
326
|
+
value = this.context[name];
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
if (typeof value == "function") {
|
331
|
+
return value.apply(context);
|
332
|
+
}
|
333
|
+
if (value !== undefined) {
|
334
|
+
return value;
|
335
|
+
}
|
336
|
+
// silently ignore unkown variables
|
337
|
+
return "";
|
338
|
+
},
|
339
|
+
|
340
|
+
walk_context: function (name, context) {
|
341
|
+
var path = name.split('.');
|
342
|
+
// if the var doesn't exist in current context, check the top level context
|
343
|
+
var value_context = (context[path[0]] != undefined) ? context : this.context;
|
344
|
+
var value = value_context[path.shift()];
|
345
|
+
while (value != undefined && path.length > 0) {
|
346
|
+
value_context = value;
|
347
|
+
value = value[path.shift()];
|
348
|
+
}
|
349
|
+
// if the value is a function, call it, binding the correct context
|
350
|
+
if (typeof value == "function") {
|
351
|
+
return value.apply(value_context);
|
352
|
+
}
|
353
|
+
return value;
|
354
|
+
},
|
355
|
+
|
356
|
+
// Utility methods
|
357
|
+
|
358
|
+
/* includes tag */
|
359
|
+
includes: function (needle, haystack) {
|
360
|
+
return haystack.indexOf(this.otag + needle) != -1;
|
361
|
+
},
|
362
|
+
|
363
|
+
// by @langalex, support for arrays of strings
|
364
|
+
create_context: function (_context) {
|
365
|
+
if (this.is_object(_context)) {
|
366
|
+
return _context;
|
367
|
+
} else {
|
368
|
+
var iterator = ".";
|
369
|
+
if (this.pragmas["IMPLICIT-ITERATOR"]) {
|
370
|
+
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
|
371
|
+
}
|
372
|
+
var ctx = {};
|
373
|
+
ctx[iterator] = _context;
|
374
|
+
return ctx;
|
375
|
+
}
|
376
|
+
},
|
377
|
+
|
378
|
+
is_object: function (a) {
|
379
|
+
return a && typeof a == "object";
|
380
|
+
},
|
381
|
+
|
382
|
+
/*
|
383
|
+
Why, why, why? Because IE. Cry, cry cry.
|
384
|
+
*/
|
385
|
+
map: function (array, fn) {
|
386
|
+
if (typeof array.map == "function") {
|
387
|
+
return array.map(fn);
|
388
|
+
} else {
|
389
|
+
var r = [];
|
390
|
+
var l = array.length;
|
391
|
+
for(var i = 0; i < l; i++) {
|
392
|
+
r.push(fn(array[i]));
|
393
|
+
}
|
394
|
+
return r;
|
395
|
+
}
|
396
|
+
},
|
397
|
+
|
398
|
+
getCachedRegex: function (name, generator) {
|
399
|
+
var byOtag = regexCache[this.otag];
|
400
|
+
if (!byOtag) {
|
401
|
+
byOtag = regexCache[this.otag] = {};
|
402
|
+
}
|
403
|
+
|
404
|
+
var byCtag = byOtag[this.ctag];
|
405
|
+
if (!byCtag) {
|
406
|
+
byCtag = byOtag[this.ctag] = {};
|
407
|
+
}
|
408
|
+
|
409
|
+
var regex = byCtag[name];
|
410
|
+
if (!regex) {
|
411
|
+
regex = byCtag[name] = generator(this.otag, this.ctag);
|
412
|
+
}
|
413
|
+
|
414
|
+
return regex;
|
415
|
+
}
|
416
|
+
};
|
417
|
+
|
418
|
+
return({
|
419
|
+
name: "mustache.js",
|
420
|
+
version: "0.5.0-dev",
|
421
|
+
|
422
|
+
/*
|
423
|
+
Turns a template and view into HTML
|
424
|
+
*/
|
425
|
+
to_html: function (template, view, partials, send_fun) {
|
426
|
+
var renderer = new Renderer();
|
427
|
+
if (send_fun) {
|
428
|
+
renderer.send = send_fun;
|
429
|
+
}
|
430
|
+
renderer.render(template, view || {}, partials);
|
431
|
+
if (!send_fun) {
|
432
|
+
return renderer.buffer.join("\n");
|
433
|
+
}
|
434
|
+
}
|
435
|
+
});
|
436
|
+
}();
|
@@ -0,0 +1,51 @@
|
|
1
|
+
jQuery(function($) {
|
2
|
+
$('form a.add_nested_fields').live('click', function() {
|
3
|
+
// Setup
|
4
|
+
var assoc = $(this).attr('data-association'); // Name of child
|
5
|
+
var content = $('#' + assoc + '_fields_blueprint').html(); // Fields template
|
6
|
+
|
7
|
+
// Make the context correct by replacing new_<parents> with the generated ID
|
8
|
+
// of each of the parent objects
|
9
|
+
var context = ($(this).closest('.fields').find('input:first').attr('name') || '').replace(new RegExp('\[[a-z]+\]$'), '');
|
10
|
+
|
11
|
+
// context will be something like this for a brand new form:
|
12
|
+
// project[tasks_attributes][new_1255929127459][assignments_attributes][new_1255929128105]
|
13
|
+
// or for an edit form:
|
14
|
+
// project[tasks_attributes][0][assignments_attributes][1]
|
15
|
+
if(context) {
|
16
|
+
var parent_names = context.match(/[a-z_]+_attributes/g) || [];
|
17
|
+
var parent_ids = context.match(/(new_)?[0-9]+/g) || [];
|
18
|
+
|
19
|
+
for(var i = 0; i < parent_names.length; i++) {
|
20
|
+
if(parent_ids[i]) {
|
21
|
+
content = content.replace(
|
22
|
+
new RegExp('(_' + parent_names[i] + ')_.+?_', 'g'),
|
23
|
+
'$1_' + parent_ids[i] + '_');
|
24
|
+
|
25
|
+
content = content.replace(
|
26
|
+
new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'),
|
27
|
+
'$1[' + parent_ids[i] + ']');
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
// Make a unique ID for the new child
|
33
|
+
var regexp = new RegExp('new_' + assoc, 'g');
|
34
|
+
var new_id = new Date().getTime();
|
35
|
+
content = content.replace(regexp, "new_" + new_id);
|
36
|
+
|
37
|
+
var field = $(content).insertBefore(this);
|
38
|
+
$(this).closest("form").trigger({type: 'nested:fieldAdded', field: field});
|
39
|
+
return false;
|
40
|
+
});
|
41
|
+
|
42
|
+
$('form a.remove_nested_fields').live('click', function() {
|
43
|
+
var hidden_field = $(this).prev('input[type=hidden]')[0];
|
44
|
+
if(hidden_field) {
|
45
|
+
hidden_field.value = '1';
|
46
|
+
}
|
47
|
+
$(this).closest('.fields').hide();
|
48
|
+
$(this).closest("form").trigger('nested:fieldRemoved');
|
49
|
+
return false;
|
50
|
+
});
|
51
|
+
});
|