=====
A gem for maintaining consistent user experiences between unit systems.
Make your apps all unit-y!
- Makes constructing unit-aware form elements easy.
- Fixes the biggest problem in switching between units---intelligently choosing the most appropriate value in the new unit system.
- Adds a new collection object to your projects, UnityCollection.
- Supports construction of form elements with standard Rails FormHelpers and FormOptionsHelpers.
- Provides an instance method of UnityCollection, closest_to(), for selecting the most appropriate value in the new unit system.
Add unity
to your Gemfile and run the bundle
command to install it.
gem "unity", :git => "git://github.com/afinetooth/unity.git"
Construct form elements as normal with FormHelpers and FormOptionsHelpers, but use UnityCollection as the source for your FormOptionsHelper.
Example:
<%= select_tag("length", options_from_collection_for_select(@lengths, :with_units, :without_units, @lengths.closest_to("29 cm"))) %>
Where @lengths is a UnityCollection, which might be constructed as follows:
@lengths = UnityCollection.new(:units => "in", :range => 4..16, :increment => 0.5)
Follow the steps here to get unity working in your project.
Questions or problems? Please post them on the issue tracker.
You can contribute changes by forking the project and submitting a pull request.
This gem is created by James Kessler and is under the MIT License.