<commit_before>h2. Creating Extensions

This guide covers the technical details of extensions and is oriented towards developers. See the "customization guide":customization.html for a more basic treatment on how to customize Spree.

After this guide you should understand:

* The important role extensions play in Spree
* How to install a third party extension
* How to write your own custom extensions
* How to share your extensions with others

endprologue.

h3. Extension Basics

There are a few basic steps to know when it comes to creating your own extension.  We'll walk you through how to create, maintain and test your extensions in the next few sections.

h4. Integrated vs. Standalone

Extensions can be createe in their own standalone directory (like the ones shared on Github) or they can be created within your Rails application.  We refer to the extensions that sit in an existing Rails application as "integrated" extensions.

Integrated extensions are usesful during the active development phase of your store.  Instead of switching projects all of the time you can just make little tweaks to your extension inside of your store repo.  Generally you would only do this if you intended to one day share the extension with someone else (or reuse it elsewhere in a private project.)

INFO: The distinction between standlone and integrated extensions is not very important.  The instructions for this guide can be assumed to apply to both cases (unless stated otherwise.)

NOTE: You may want to consider the integrated approach if the extension is potentially useful on another project but you don't want to make the extension publicly available for others to use.

h4. Creating

You can create a new extension using the +spree+ command.  This requires that you have a gem version of Spree installed that is version 0.70.0 or greater.  Once you've navigated the directory in which you wish to create the extension, you can create a new extension by typing the following in your console:

<shell>
$ spree extension foofah
</shell>

If you're inside of a Rails application that uses Spree, you may have to prefix this command with +bundle exec+ so that the correct version of Spree is used:

<shell>
$ bundle exec spree extension foofah
</shell>

This approach relies on an executable script inside the installed gem.  You can always build and install the edge gem using the source if you want to work with the latest and greatest version of the extension generator.

NOTE: See the "Source Code":source_code.html#building-the-gem-from-the-source guide which explains how to build the gem from the source.

You probably also need to create a test application which is necessary for using the Rails generators or running the tests.

<shell>
$ cd foofah
$ bundle exec rake test_app
</shell>

NOTE: The test app is not necessary when you have an integrated extension.  The Rails app that you are integrated with will suffice.

h4. Resources

Once you've created your extension you can now create resources in the typical Rails way.  For example, to create a new resource SomeBar you would use the standard Rails generator.<commit_msg>Clarify that test applications go inside the extensions<commit_after>h2. Creating Extensions

This guide covers the technical details of extensions and is oriented towards developers. See the "customization guide":customization.html for a more basic treatment on how to customize Spree.

After this guide you should understand:

* The important role extensions play in Spree
* How to install a third party extension
* How to write your own custom extensions
* How to share your extensions with others

endprologue.

h3. Extension Basics

There are a few basic steps to know when it comes to creating your own extension.  We'll walk you through how to create, maintain and test your extensions in the next few sections.

h4. Integrated vs. Standalone

Extensions can be createe in their own standalone directory (like the ones shared on Github) or they can be created within your Rails application.  We refer to the extensions that sit in an existing Rails application as "integrated" extensions.

Integrated extensions are usesful during the active development phase of your store.  Instead of switching projects all of the time you can just make little tweaks to your extension inside of your store repo.  Generally you would only do this if you intended to one day share the extension with someone else (or reuse it elsewhere in a private project.)

INFO: The distinction between standlone and integrated extensions is not very important.  The instructions for this guide can be assumed to apply to both cases (unless stated otherwise.)

NOTE: You may want to consider the integrated approach if the extension is potentially useful on another project but you don't want to make the extension publicly available for others to use.

h4. Creating

You can create a new extension using the +spree+ command.  This requires that you have a gem version of Spree installed that is version 0.70.0 or greater.  Once you've navigated the directory in which you wish to create the extension, you can create a new extension by typing the following in your console:

<shell>
$ spree extension foofah
</shell>

If you're inside of a Rails application that uses Spree, you may have to prefix this command with +bundle exec+ so that the correct version of Spree is used:

<shell>
$ bundle exec spree extension foofah
</shell>

This approach relies on an executable script inside the installed gem.  You can always build and install the edge gem using the source if you want to work with the latest and greatest version of the extension generator.

NOTE: See the "Source Code":source_code.html#building-the-gem-from-the-source guide which explains how to build the gem from the source.

You probably also need to create a test application (inside the extension) which is necessary for using the Rails generators or running the tests.

<shell>
$ cd foofah
$ bundle exec rake test_app
</shell>

NOTE: The test app is not necessary when you have an integrated extension.  The Rails app that you are integrated with will suffice.

h4. Resources

Once you've created your extension you can now create resources in the typical Rails way.  For example, to create a new resource SomeBar you would use the standard Rails generator.
{'fraction_non_alphanumeric': 0.03151095005514416, 'fraction_numerical': 0.0028359855049629747, 'mean_word_length': 4.430282292557742, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5551414', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1441, 'n_words': 1005}