rango 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/CONTRIBUTORS +1 -0
- data/README.textile +4 -1
- data/bin/rango +1 -1
- data/lib/rango.rb +78 -12
- data/lib/rango/contrib/pagination.rb +2 -0
- data/lib/rango/controller.rb +58 -12
- data/lib/rango/environments.rb +26 -0
- data/lib/rango/exceptions.rb +2 -14
- data/lib/rango/gv.rb +7 -90
- data/lib/rango/gv/static.rb +22 -0
- data/lib/rango/helpers.rb +0 -1
- data/lib/rango/helpers/assets.rb +2 -0
- data/lib/rango/helpers/general.rb +1 -0
- data/lib/rango/helpers/syntax.rb +2 -0
- data/lib/rango/mini.rb +30 -0
- data/lib/rango/mixins/application.rb +5 -3
- data/lib/rango/mixins/configurable.rb +1 -0
- data/lib/rango/mixins/render.rb +13 -84
- data/lib/rango/orm/tasks/datamapper.rake +2 -2
- data/lib/rango/project.rb +2 -2
- data/lib/rango/rack/middlewares/basic.rb +15 -11
- data/lib/rango/rack/request.rb +5 -3
- data/lib/rango/router.rb +20 -2
- data/lib/rango/router/adapters/rack_mount.rb +0 -1
- data/lib/rango/router/adapters/rack_router.rb +0 -1
- data/lib/rango/router/adapters/urlmap.rb +0 -1
- data/lib/rango/router/adapters/usher.rb +0 -1
- data/lib/rango/settings/framework.rb +2 -43
- data/lib/rango/templates/{erubis.rb → exts/erubis.rb} +0 -19
- data/lib/rango/templates/exts/tilt.rb +16 -0
- data/lib/rango/templates/helpers.rb +107 -0
- data/lib/rango/templates/template.rb +44 -115
- data/lib/rango/utils.rb +9 -4
- data/spec/rango/controller_spec.rb +3 -1
- data/spec/rango/environments_spec.rb +68 -0
- data/spec/rango/gv_spec.rb +10 -0
- data/spec/rango/mini_spec.rb +58 -0
- data/spec/rango/project_spec.rb +1 -1
- data/spec/rango/templates/template_spec.rb +81 -0
- data/spec/rango/utils_spec.rb +33 -0
- data/spec/rango_spec.rb +3 -17
- data/spec/spec_helper.rb +5 -3
- data/spec/stubs/config.ru +5 -0
- data/spec/stubs/templates/capture.html.erb +1 -1
- data/spec/stubs/templates/erubis.html.erubis +2 -0
- data/spec/stubs/templates/inheritance/basic/base.html.haml +2 -0
- data/spec/stubs/templates/inheritance/basic/index.html.haml +2 -0
- data/spec/stubs/templates/inheritance/capture/erb/base.html.erb +3 -0
- data/spec/stubs/templates/inheritance/capture/erb/index.html.erb +4 -0
- data/spec/stubs/templates/inheritance/capture/erubis/base.html.erubis +3 -0
- data/spec/stubs/templates/inheritance/capture/erubis/index.html.erubis +4 -0
- data/spec/stubs/templates/inheritance/capture/haml/base.html.haml +2 -0
- data/spec/stubs/templates/inheritance/capture/haml/index.html.haml +3 -0
- data/spec/stubs/templates/test.html.haml +1 -0
- data/spec/stubs/templates/variables.html.haml +1 -0
- data/stubs/app/content/init.rb.rbt +2 -1
- data/stubs/app/content/views.rb.rbt +2 -0
- data/stubs/bigapp/content/views/%controller%.rb.rbt +2 -0
- data/stubs/project/content/config.ru.rbt +3 -0
- data/stubs/project/content/init.rb.rbt +11 -5
- data/stubs/project/content/settings.rb +0 -2
- data/stubs/project/content/settings_local.rb.rbt +1 -1
- data/stubs/project/content/templates/base.html.haml.rbt +1 -0
- metadata +42 -329
- data/examples/README.textile +0 -12
- data/examples/blog/Gemfile +0 -80
- data/examples/blog/Rakefile +0 -12
- data/examples/blog/TODO.txt +0 -0
- data/examples/blog/bin/autospec +0 -3
- data/examples/blog/bin/css2sass +0 -3
- data/examples/blog/bin/cucumber +0 -3
- data/examples/blog/bin/haml +0 -3
- data/examples/blog/bin/html2haml +0 -3
- data/examples/blog/bin/htmldiff +0 -3
- data/examples/blog/bin/launchy +0 -3
- data/examples/blog/bin/ldiff +0 -3
- data/examples/blog/bin/nokogiri +0 -3
- data/examples/blog/bin/racksh +0 -3
- data/examples/blog/bin/rackup +0 -3
- data/examples/blog/bin/rake +0 -3
- data/examples/blog/bin/rango +0 -3
- data/examples/blog/bin/sass +0 -3
- data/examples/blog/bin/shotgun +0 -3
- data/examples/blog/bin/simple-templater +0 -3
- data/examples/blog/bin/spec +0 -3
- data/examples/blog/bin/tt +0 -3
- data/examples/blog/blog/init.rb +0 -9
- data/examples/blog/blog/models.rb +0 -21
- data/examples/blog/blog/views.rb +0 -16
- data/examples/blog/config.ru +0 -19
- data/examples/blog/gems/cache/addressable-2.1.1.gem +0 -0
- data/examples/blog/gems/cache/builder-2.1.2.gem +0 -0
- data/examples/blog/gems/cache/bundler-0.7.0.gem +0 -0
- data/examples/blog/gems/cache/cli-0.0.1.gem +0 -0
- data/examples/blog/gems/cache/configuration-1.1.0.gem +0 -0
- data/examples/blog/gems/cache/cucumber-0.4.4.gem +0 -0
- data/examples/blog/gems/cache/data_objects-0.10.0.gem +0 -0
- data/examples/blog/gems/cache/diff-lcs-1.1.2.gem +0 -0
- data/examples/blog/gems/cache/dm-core-0.10.1.gem +0 -0
- data/examples/blog/gems/cache/dm-timestamps-0.10.1.gem +0 -0
- data/examples/blog/gems/cache/do_mysql-0.10.0.gem +0 -0
- data/examples/blog/gems/cache/do_sqlite3-0.10.0.gem +0 -0
- data/examples/blog/gems/cache/extlib-0.9.13.gem +0 -0
- data/examples/blog/gems/cache/fuzzyhash-0.0.9.gem +0 -0
- data/examples/blog/gems/cache/haml-2.2.14.gem +0 -0
- data/examples/blog/gems/cache/launchy-0.3.3.gem +0 -0
- data/examples/blog/gems/cache/media-path-0.1.gem +0 -0
- data/examples/blog/gems/cache/nokogiri-1.4.0.gem +0 -0
- data/examples/blog/gems/cache/polyglot-0.2.9.gem +0 -0
- data/examples/blog/gems/cache/rack-1.0.1.gem +0 -0
- data/examples/blog/gems/cache/rack-test-0.5.2.gem +0 -0
- data/examples/blog/gems/cache/racksh-0.9.4.2.gem +0 -0
- data/examples/blog/gems/cache/rake-0.8.7.gem +0 -0
- data/examples/blog/gems/cache/rango-0.1.0.gem +0 -0
- data/examples/blog/gems/cache/rspec-1.2.9.gem +0 -0
- data/examples/blog/gems/cache/rubyexts-0.0.1.gem +0 -0
- data/examples/blog/gems/cache/shotgun-0.4.gem +0 -0
- data/examples/blog/gems/cache/simple-templater-0.0.1.gem +0 -0
- data/examples/blog/gems/cache/term-ansicolor-1.0.4.gem +0 -0
- data/examples/blog/gems/cache/treetop-1.4.2.gem +0 -0
- data/examples/blog/gems/cache/usher-0.5.11.gem +0 -0
- data/examples/blog/gems/cache/webrat-0.5.3.gem +0 -0
- data/examples/blog/init.rb +0 -49
- data/examples/blog/settings.rb +0 -15
- data/examples/blog/settings_local.rb +0 -6
- data/examples/blog/spec/blog/init_spec.rb +0 -7
- data/examples/blog/spec/blog/models_spec.rb +0 -28
- data/examples/blog/spec/blog/views_spec.rb +0 -22
- data/examples/blog/spec/spec.opts +0 -5
- data/examples/blog/spec/spec_helper.rb +0 -27
- data/examples/blog/templates/base.html.haml +0 -16
- data/examples/blog/templates/index.html.haml +0 -12
- data/lib/rango/boot.rb +0 -55
- data/lib/rango/helpers/README +0 -179
- data/lib/rango/helpers/merb-helpers.rb +0 -3
- data/lib/rango/helpers/merb-helpers/core_ext.rb +0 -58
- data/lib/rango/helpers/merb-helpers/core_ext/numeric.rb +0 -389
- data/lib/rango/helpers/merb-helpers/date_time_formatting.rb +0 -146
- data/lib/rango/helpers/merb-helpers/date_time_helpers.rb +0 -191
- data/lib/rango/helpers/merb-helpers/form/builder.rb +0 -450
- data/lib/rango/helpers/merb-helpers/form/helpers.rb +0 -453
- data/lib/rango/helpers/merb-helpers/form_helpers.rb +0 -21
- data/lib/rango/helpers/merb-helpers/tag_helpers.rb +0 -63
- data/lib/rango/helpers/merb-helpers/text_helpers.rb +0 -73
- data/lib/rango/loggers/logger.rb +0 -100
- data/lib/rango/mixins/chainable.rb +0 -68
- data/lib/rango/mixins/hookable.rb +0 -32
- data/lib/rango/mixins/import.rb +0 -89
- data/lib/rango/mixins/mini.rb +0 -29
- data/lib/rango/mixins/strategy.rb +0 -28
- data/lib/rango/rango.rb +0 -93
- data/lib/rango/router/specification.txt +0 -11
- data/lib/rango/templates/adapter.rb +0 -19
- data/lib/rango/templates/adapters/erb.rb +0 -63
- data/lib/rango/templates/adapters/erubis.rb +0 -65
- data/lib/rango/templates/adapters/haml.rb +0 -26
- data/lib/rango/templates/templates.txt +0 -39
- data/spec/factories.rb +0 -22
- data/spec/rango/boot_spec.rb +0 -15
- data/spec/rango/helpers/merb-helpers/core_ext/numeric_spec.rb +0 -0
- data/spec/rango/helpers/merb-helpers/core_ext_spec.rb +0 -21
- data/spec/rango/helpers/merb-helpers/date_time_formatting_spec.rb +0 -0
- data/spec/rango/helpers/merb-helpers/date_time_helpers_spec.rb +0 -0
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/application.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_check_box.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_file_field.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_hidden_field.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_option_tag.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_password_field.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_radio_button.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_radio_group.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_select.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_text_area.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_text_field.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/button.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/check_box.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/custom_builder.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/delete_button.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/exceptions.rb +0 -25
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/field_set.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/fields_for.rb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/file_field.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/foo.rb +0 -23
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/form.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/form_for.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/hacker.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/hidden_field.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/label.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/numeric_ext.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/option_tag.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/password_field.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/radio_button.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/radio_group.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/relative_date.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/relative_date_span.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/select.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/specs_controller.rb +0 -13
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/submit.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/tag_helper.rb +0 -23
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/text_area.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/controllers/text_field.rb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/helpers/global_helpers.rb +0 -7
- data/spec/rango/helpers/merb-helpers/fixture/app/models/fake_dm_model.rb +0 -27
- data/spec/rango/helpers/merb-helpers/fixture/app/models/first_generic_fake_model.rb +0 -59
- data/spec/rango/helpers/merb-helpers/fixture/app/models/hacker_generic_model.rb +0 -7
- data/spec/rango/helpers/merb-helpers/fixture/app/models/second_generic_fake_model.rb +0 -20
- data/spec/rango/helpers/merb-helpers/fixture/app/models/third_generic_fake_model.rb +0 -5
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/basic.html.erb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/basic_unchecked.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/checked.html.erb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/errors.html.erb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/label.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/on_and_off.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/raise_value_error.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/additional_attributes.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/takes_string.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/with_label.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/errors.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/hidden_error.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/label.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/grouped.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/nested.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/text_and_value.html.erb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/attributes.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/label.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_button_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/hashes.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/mixed.html.erb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/override_id.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/blank.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/label.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/multiple.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/prompt.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/with_options.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/with_options_with_blank.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_area_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_area_specs/label.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_field_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/button_with_label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/button_with_values.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/disabled_button.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/boolean.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/disabled.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/on_off_is_boolean.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raise_unless_both_on_and_off.html.erb +0 -2
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raises_error_if_not_boolean.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raises_error_if_on_off_and_boolean_false.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/simple.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/to_string.html.erb +0 -8
- data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/unchecked.html.erb +0 -2
- data/spec/rango/helpers/merb-helpers/fixture/app/views/custom_builder_specs/everything.html.erb +0 -10
- data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_explicit_url.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_extra_params.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/simple_delete.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/client_error.html.erb +0 -37
- data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/internal_server_error.html.erb +0 -216
- data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/not_acceptable.html.erb +0 -38
- data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/not_found.html.erb +0 -40
- data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/midstream.html.erb +0 -7
- data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/nil.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/fieldset_specs/legend.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/disabled.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/makes_multipart.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/with_label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/with_values.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/rango/helpers/merb-helpers/fixture/app/views/form_for_specs/basic.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/create_a_form.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/create_a_multipart_form.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/fake_delete_if_set.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/fake_put_if_set.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/get_if_set.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/post_by_default.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/resourceful_form.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/file_field.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/hidden_field.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/option_tag.html.erb +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/password_field.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/radio_button.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/radio_group.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/text_area.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/text_field.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/disabled.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic_with_attributes.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic_with_class.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/layout/application.html.erb +0 -11
- data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/minutes_to_hours.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/to_concurrency_default.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/two_digits.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/array.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/clean.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/collection.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/multiple_selects.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/no_extra_attributes.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/optgroups.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/selected.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/with_blank.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/with_prompt.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/password_field_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/password_field_specs/disabled.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/checked.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/disabled.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/unchecked.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/attributes.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/checked.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/hash.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/specific_attributes.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_span_specs/date_span_on_same_day.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_span_specs/date_span_on_same_day_on_different_year.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_date_with_year.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_date_without_year.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_today.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_tomorrow.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_yesterday.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/blank.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/multiple.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/selected.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/disabled_submit.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/submit_with_label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/submit_with_values.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/nested_tags.html.erb +0 -5
- data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_attributes.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_content.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_content_in_the_block.html.erb +0 -3
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/disabled.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/nil.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/basic.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/class.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/disabled.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/label.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/symbolized_name.html.erb +0 -1
- data/spec/rango/helpers/merb-helpers/fixture/config/environments/development.rb +0 -8
- data/spec/rango/helpers/merb-helpers/fixture/config/environments/production.rb +0 -7
- data/spec/rango/helpers/merb-helpers/fixture/config/environments/test.rb +0 -8
- data/spec/rango/helpers/merb-helpers/fixture/config/init.rb +0 -48
- data/spec/rango/helpers/merb-helpers/fixture/config/rack.rb +0 -13
- data/spec/rango/helpers/merb-helpers/fixture/config/router.rb +0 -40
- data/spec/rango/helpers/merb-helpers/fixture/public/images/merb.jpg +0 -0
- data/spec/rango/helpers/merb-helpers/fixture/public/merb.fcgi +0 -4
- data/spec/rango/helpers/merb-helpers/fixture/public/stylesheets/master.css +0 -119
- data/spec/rango/helpers/merb-helpers/form/builder_spec.rb +0 -0
- data/spec/rango/helpers/merb-helpers/form/helpers_spec.rb +0 -0
- data/spec/rango/helpers/merb-helpers/form_helpers_spec.rb +0 -0
- data/spec/rango/helpers/merb-helpers/merb_helpers_config_spec.rb +0 -85
- data/spec/rango/helpers/merb-helpers/merb_helpers_date_time_spec.rb +0 -270
- data/spec/rango/helpers/merb-helpers/merb_helpers_form_spec.rb +0 -1372
- data/spec/rango/helpers/merb-helpers/merb_helpers_tag_helper_spec.rb +0 -46
- data/spec/rango/helpers/merb-helpers/merb_helpers_text_spec.rb +0 -71
- data/spec/rango/helpers/merb-helpers/numeric_extlib_spec.rb +0 -138
- data/spec/rango/helpers/merb-helpers/ordinalize_spec.rb +0 -55
- data/spec/rango/helpers/merb-helpers/tag_helpers_spec.rb +0 -0
- data/spec/rango/helpers/merb-helpers/text_helpers_spec.rb +0 -0
- data/spec/rango/helpers/merb-helpers_spec.rb +0 -0
- data/spec/rango/mixins/chainable_spec.rb +0 -0
- data/spec/rango/mixins/hookable_spec.rb +0 -0
- data/spec/rango/mixins/import_spec.rb +0 -0
- data/spec/rango/mixins/mini_spec.rb +0 -0
- data/spec/rango/mixins/strategy_spec.rb +0 -0
- data/spec/rango/rango_spec.rb +0 -0
- data/spec/rango/templates/adapter_spec.rb +0 -0
- data/spec/rango/templates/adapters/erb_spec.rb +0 -0
- data/spec/rango/templates/adapters/erubis_spec.rb +0 -117
- data/spec/rango/templates/adapters/haml_spec.rb +0 -0
- data/spec/rango/templates/adapters/template_helpers.rb +0 -38
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require_relative "../spec_helper.rb"
|
4
|
-
|
5
|
-
describe "URL /" do
|
6
|
-
include Blog
|
7
|
-
before(:each) do
|
8
|
-
@response = get("/")
|
9
|
-
DataMapper.auto_migrate!
|
10
|
-
Post.create!(slug: "hello-world", title: "Hello World!")
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should returns HTTP 200 OK" do
|
14
|
-
@response.should be_successful
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should have an articles" do
|
18
|
-
@response.should have_selector(".container .post") do |element|
|
19
|
-
element.should contain("Hello World!")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# NOTE: we don't have to require spec, webrat,
|
4
|
-
# rack/test or whatever, it's bundler job to do it
|
5
|
-
|
6
|
-
# load test environment include dependencies
|
7
|
-
RANGO_ENV = "test"
|
8
|
-
require_relative "../init.rb"
|
9
|
-
|
10
|
-
# load config.ru
|
11
|
-
Rango::Utils.load_rackup
|
12
|
-
|
13
|
-
# webrat
|
14
|
-
Webrat.configure do |config|
|
15
|
-
config.mode = :rack
|
16
|
-
end
|
17
|
-
|
18
|
-
# rspec
|
19
|
-
Spec::Runner.configure do |config|
|
20
|
-
config.include Rack::Test::Methods
|
21
|
-
config.include Webrat::Matchers
|
22
|
-
|
23
|
-
# for rack-test
|
24
|
-
def app
|
25
|
-
Project.router
|
26
|
-
end
|
27
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
!!! 1.0 Strict
|
2
|
-
%html{html_attrs("en")}
|
3
|
-
%head
|
4
|
-
%title= block(:title)
|
5
|
-
%meta{"http-equiv" => "content-type", content: "text/html; charset=utf-8"}
|
6
|
-
%meta{"http-equiv" => "content-language", content: "en-us"}
|
7
|
-
%meta{name: "description", content: block(:description, "")}
|
8
|
-
%meta{name: "keywords", content: block(:keywords, "")}
|
9
|
-
%meta{name: "author", content: "botanicus"}
|
10
|
-
= javascripts *block(:javascripts, Array.new)
|
11
|
-
= stylesheets *block(:stylesheets, Array.new)
|
12
|
-
= block(:head)
|
13
|
-
%body
|
14
|
-
.container
|
15
|
-
%h1!= block(:title)
|
16
|
-
!= block(:content)
|
@@ -1,12 +0,0 @@
|
|
1
|
-
/ render into layout or render just content block if request is AJAX
|
2
|
-
- extends "base.html" unless request.ajax?
|
3
|
-
|
4
|
-
/ head
|
5
|
-
- block(:title, "Rango Blog")
|
6
|
-
- block(:description, "Example blog application in Rango")
|
7
|
-
- block(:keywords, "rango,example")
|
8
|
-
|
9
|
-
/ body
|
10
|
-
!= block(:content) do
|
11
|
-
- @posts.each do |post|
|
12
|
-
.post!= link_to(post.title, url(:post, post.slug))
|
data/lib/rango/boot.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# dependencies
|
4
|
-
require "rack"
|
5
|
-
|
6
|
-
# imports
|
7
|
-
require "rango/project"
|
8
|
-
require "rango/rack/request"
|
9
|
-
require "rango/router"
|
10
|
-
|
11
|
-
# === Boot sequence:
|
12
|
-
# 1) logger
|
13
|
-
# 2) Project
|
14
|
-
# 3) init & dependencies (we must load the plugins before they will be configured)
|
15
|
-
# 4) settings
|
16
|
-
|
17
|
-
# project
|
18
|
-
module Rango
|
19
|
-
class << self
|
20
|
-
# @since 0.0.1
|
21
|
-
# @return [String] Returns current environment name. Possibilities are +development+ or +production+.
|
22
|
-
attribute :environment, "development"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# The only file which Rango really requires is init.rb,
|
27
|
-
# where is expected that you setup database connection,
|
28
|
-
# require gems etc. However if you really want to, you
|
29
|
-
# can bypass loading of init.rb and ORM setup.
|
30
|
-
# This is useful mostly for one file applications
|
31
|
-
|
32
|
-
module Rango
|
33
|
-
class BootLoader
|
34
|
-
def load_settings
|
35
|
-
begin
|
36
|
-
Project.logger.info("Reading settings")
|
37
|
-
Project.import_first(["settings", "config/settings"], soft: true)
|
38
|
-
rescue LoadError
|
39
|
-
Rango.logger.fatal("settings.rb wasn't found or it cause another LoadError.")
|
40
|
-
exit 1
|
41
|
-
end
|
42
|
-
|
43
|
-
# settings_local.rb
|
44
|
-
Project.import_first(["settings_local", "config/settings_local"], soft: true, verbose: false)
|
45
|
-
end
|
46
|
-
|
47
|
-
def setup_orm
|
48
|
-
if orm = Project.settings.orm
|
49
|
-
unless Rango.import("orm/adapters/#{orm}/setup", soft: true, verbose: false)
|
50
|
-
Project.logger.error("ORM #{orm} isn't supported. You will need to setup your database connection manually.")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/lib/rango/helpers/README
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
merb-helpers
|
2
|
-
=================
|
3
|
-
|
4
|
-
A plugin for the Rango Web framework that provides different view helpers.
|
5
|
-
|
6
|
-
To use this plugin in merb in your app
|
7
|
-
|
8
|
-
config/dependencies.rb
|
9
|
-
|
10
|
-
#...
|
11
|
-
|
12
|
-
dependency "merb-helpers"
|
13
|
-
|
14
|
-
#...
|
15
|
-
|
16
|
-
# TODO: describe date_time_helpers, form_helpers, tag_helpers
|
17
|
-
|
18
|
-
|
19
|
-
form_helpers
|
20
|
-
------------
|
21
|
-
|
22
|
-
* +delete_button+. If you want to delete an object, you should call the delete method on the object's controller.
|
23
|
-
You should not use a simple link to your action, instead you should make a DELETE request.
|
24
|
-
To help you doing that, you can use the delete_button method as follows:
|
25
|
-
|
26
|
-
<%= delete_button(@comment) %>
|
27
|
-
|
28
|
-
The delete_button helper has many options, first thing, you can pass an object or an url:
|
29
|
-
|
30
|
-
<%= delete_button(url(:comment, @comment)) %>
|
31
|
-
|
32
|
-
This helper creates a form with a submit button.
|
33
|
-
You can pass many arguments to the delete_button helper. The first thing you might want to do is to change the
|
34
|
-
default button text.
|
35
|
-
|
36
|
-
<%= delete_button(@comment), "Remove this comment by #{@comment.author.name}" %>
|
37
|
-
|
38
|
-
You can also pass the usual helper params to specify a class to use for instance:
|
39
|
-
|
40
|
-
<%= delete_button(@comment, nil, :class => 'custom-class') %>
|
41
|
-
|
42
|
-
See usage in specs: spec/fixture/app/views/delete_button_specs
|
43
|
-
|
44
|
-
numeric helpers
|
45
|
-
---------------
|
46
|
-
|
47
|
-
Numeric helpers extend numeric instances, in lay terms: numbers.
|
48
|
-
|
49
|
-
* +minutes_to_hours+ converts a +numeric+ value representing minutes into a string representing an hour value
|
50
|
-
|
51
|
-
315.minutes_to_hours # => "05:15"
|
52
|
-
|
53
|
-
* +two_digits+ formats a +number+ into a two digit string. Basically it prepends an integer to a 2 digits string.
|
54
|
-
|
55
|
-
3.two_digits # => "03"
|
56
|
-
|
57
|
-
* +with_delimiter+, this method formats a number with grouped thousands
|
58
|
-
|
59
|
-
12345678.with_delimiter # => "12,345,678"
|
60
|
-
|
61
|
-
|
62
|
-
* +with_precison+, this method formats a number with a level of precision
|
63
|
-
|
64
|
-
111.2345.with_precision # => "111.235"
|
65
|
-
|
66
|
-
* +to_currency, this method formats a number into a currency value using a delimited and a set precision
|
67
|
-
|
68
|
-
1234567890.506.to_currency # => "$1,234,567,890.51"
|
69
|
-
|
70
|
-
(For usage example look at spec/numeric_exlib.rb)
|
71
|
-
|
72
|
-
|
73
|
-
Overwriting the default formating options:
|
74
|
-
|
75
|
-
One can overwrite the default settings by passing the name or of the format used and a hash representing the settings to overwrite.
|
76
|
-
|
77
|
-
Each method mentioned above has some format settings you can overwrite:
|
78
|
-
|
79
|
-
* +with_delimiter+
|
80
|
-
* :delimiter - Overwrites the thousands delimiter.
|
81
|
-
* :separator - Overwrites the separator between the units.
|
82
|
-
|
83
|
-
* +with_precision+
|
84
|
-
* :precision - Overwrites the level of precision
|
85
|
-
* :separator - Overwrites the separator between the units
|
86
|
-
* :delimiter - Overwrites the thousands delimiter
|
87
|
-
|
88
|
-
* +with_currency+
|
89
|
-
* :precision - Sets the level of precision
|
90
|
-
* :unit - Sets the denomination of the currency
|
91
|
-
* :format - Sets the format of the output string (defaults to "%u%n"). The field types are:
|
92
|
-
* %u The currency unit
|
93
|
-
* %n The number
|
94
|
-
|
95
|
-
Usage example:
|
96
|
-
|
97
|
-
1234567890.506.to_currency(:default, :unit => '£') # => "£1,234,567,890.51"
|
98
|
-
|
99
|
-
merb_helpers comes with a very limited set of formats you can use, here is an example:
|
100
|
-
|
101
|
-
1234567890.50.to_currency(:uk) # => "£1,234,567,890.50"
|
102
|
-
|
103
|
-
Formats are just a hash of settings used by the plugin, here is the default format:
|
104
|
-
|
105
|
-
:us => {
|
106
|
-
:number => {
|
107
|
-
:precision => 3,
|
108
|
-
:delimiter => ',',
|
109
|
-
:separator => '.'
|
110
|
-
},
|
111
|
-
:currency => {
|
112
|
-
:unit => '$',
|
113
|
-
:format => '%u%n',
|
114
|
-
:precision => 2
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
If you wish to add a new format you can easily do that as follows:
|
119
|
-
|
120
|
-
custom_format_to_add = { :custom_name => {
|
121
|
-
:number => {
|
122
|
-
:precision => 3,
|
123
|
-
:delimiter => ',',
|
124
|
-
:separator => '.'
|
125
|
-
},
|
126
|
-
:currency => {
|
127
|
-
:unit => 'Rangoollars',
|
128
|
-
:format => '%n %u',
|
129
|
-
:precision => 2
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
|
134
|
-
Numeric::Transformer.add_format(custom_format_to_add)
|
135
|
-
|
136
|
-
You can then call the format like that:
|
137
|
-
|
138
|
-
1234567890.to_currency(:custom_name) # => "1,234,567,890.00 Rangoollars"
|
139
|
-
|
140
|
-
After adding a custom format, you can set it as the default format:
|
141
|
-
|
142
|
-
Numeric::Transformer.change_default_format(:custom_name)
|
143
|
-
|
144
|
-
You can set this things up in your before/after app load block in the config/init.rb file.
|
145
|
-
|
146
|
-
|
147
|
-
Formating a Date or Time instance
|
148
|
-
---------------
|
149
|
-
|
150
|
-
Usage examples: spec/merb_helpers_date_time_spec.rb
|
151
|
-
|
152
|
-
Time.now.formatted(:db) # => "2008-09-21 02:07:31"
|
153
|
-
Time.now.formatted(:long) # => "September 21, 2008 02:08"
|
154
|
-
|
155
|
-
You can also add your own format:
|
156
|
-
|
157
|
-
Date.add_format(:matt, "%H:%M:%S %Y-%m-%d")
|
158
|
-
|
159
|
-
And use is as a default format:
|
160
|
-
|
161
|
-
Time.now.formatted(:matt) # => "02:09:18 2008-09-21"
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
Representation of time difference
|
166
|
-
-------------------
|
167
|
-
|
168
|
-
Usage examples: spec/merb_helpers_date_time_spec.rb
|
169
|
-
|
170
|
-
* Relative time:
|
171
|
-
|
172
|
-
Let's imagine that we are the June 1st 2007 at 11am UTC
|
173
|
-
|
174
|
-
|
175
|
-
relative_date(Time.now.utc) # => "today"
|
176
|
-
relative_date(1.day.ago.utc) # => 'yesterday'
|
177
|
-
relative_date(1.day.from_now.utc) # => 'tomorrow'
|
178
|
-
relative_date(Time.utc(2005, 11, 15)) # => 'Nov 15th, 2005' (date with the year since it's not this year)
|
179
|
-
relative_date(Time.utc(2007, 11, 15)) # => 'Nov 15th' (date without the year this the passed date is this year)
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "date"
|
4
|
-
require File.dirname(__FILE__) + '/date_time_formatting'
|
5
|
-
class Date
|
6
|
-
include DateAndTimeFormatting
|
7
|
-
|
8
|
-
# Converts a Date instance to a Time, where the time is set to the beginning of the day.
|
9
|
-
# The timezone can be either :local or :utc (default :utc).
|
10
|
-
#
|
11
|
-
# ==== Examples:
|
12
|
-
# date = Date.new(2007, 11, 10)
|
13
|
-
# date.to_s # => 2007-11-10
|
14
|
-
#
|
15
|
-
# date.to_time # => Sat Nov 10 00:00:00 UTC 2007
|
16
|
-
# date.to_time(:utc) # => Sat Nov 10 00:00:00 UTC 2007
|
17
|
-
# date.to_time(:local) # => Sat Nov 10 00:00:00 -0800 2007
|
18
|
-
#
|
19
|
-
def to_time(form = :utc)
|
20
|
-
::Time.send("#{form}", year, month, day)
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_date; self; end
|
24
|
-
|
25
|
-
def formatted(format=:default)
|
26
|
-
format = Date.formats[format]
|
27
|
-
if format.nil?
|
28
|
-
self.to_s
|
29
|
-
else
|
30
|
-
self.strftime(format)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
class Time
|
37
|
-
include DateAndTimeFormatting
|
38
|
-
|
39
|
-
# Ruby 1.8-cvs and 1.9 define private Time#to_date
|
40
|
-
%w(to_date to_datetime).each do |method|
|
41
|
-
public method if private_instance_methods.include?(method)
|
42
|
-
end
|
43
|
-
|
44
|
-
def to_time; self; end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Truncates a string to the given length and appends the given suffix if the string is, in fact, truncated.
|
48
|
-
#
|
49
|
-
# ==== Examples:
|
50
|
-
# "This is a long string right here".truncate(10, "...") #=> "This is..."
|
51
|
-
|
52
|
-
class String
|
53
|
-
def truncate(length = 30, truncate_string = "...")
|
54
|
-
return self unless self.length > length
|
55
|
-
length = length - truncate_string.split(//).length
|
56
|
-
self[0...length] + truncate_string
|
57
|
-
end
|
58
|
-
end
|
@@ -1,389 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# TODO: rewrite default_format-related functionality, it should simply write to Hash#default
|
4
|
-
class Numeric
|
5
|
-
module Transformer
|
6
|
-
|
7
|
-
# known formats to use with the app
|
8
|
-
# users can add their own formats by using Numeric::Transformer.add_format(:format_name => {})
|
9
|
-
|
10
|
-
@formats ={
|
11
|
-
:us => {
|
12
|
-
:number => {
|
13
|
-
:precision => 3,
|
14
|
-
:delimiter => ',',
|
15
|
-
:separator => '.'
|
16
|
-
},
|
17
|
-
:currency => {
|
18
|
-
:unit => '$',
|
19
|
-
:format => '%u%n',
|
20
|
-
:precision => 2
|
21
|
-
}
|
22
|
-
},
|
23
|
-
:uk => {
|
24
|
-
:number => {
|
25
|
-
:precision => 3,
|
26
|
-
:delimiter => ',',
|
27
|
-
:separator => '.'
|
28
|
-
},
|
29
|
-
:currency => {
|
30
|
-
:unit => '£',
|
31
|
-
:format => '%u%n',
|
32
|
-
:precision => 2
|
33
|
-
}
|
34
|
-
},
|
35
|
-
:au => {
|
36
|
-
:number => {
|
37
|
-
:precision => 3,
|
38
|
-
:delimiter => ',',
|
39
|
-
:separator => '.'
|
40
|
-
},
|
41
|
-
:currency => {
|
42
|
-
:unit => '$;',
|
43
|
-
:format => '%u%n',
|
44
|
-
:precision => 2
|
45
|
-
}
|
46
|
-
},
|
47
|
-
:fr => {
|
48
|
-
:number => {
|
49
|
-
:precision => 3,
|
50
|
-
:delimiter => ' ',
|
51
|
-
:separator => ','
|
52
|
-
},
|
53
|
-
:currency => {
|
54
|
-
:unit => '€',
|
55
|
-
:format => '%n%u',
|
56
|
-
:precision => 2
|
57
|
-
}
|
58
|
-
},
|
59
|
-
:ru => {
|
60
|
-
:number => {
|
61
|
-
:precision => 2,
|
62
|
-
:delimiter => ' ',
|
63
|
-
:separator => ','
|
64
|
-
},
|
65
|
-
:currency => {
|
66
|
-
:unit => 'р.',
|
67
|
-
:format => '%n %u',
|
68
|
-
:precision => 2
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
# accessor for @formats
|
74
|
-
#---
|
75
|
-
# @private
|
76
|
-
def self.formats
|
77
|
-
@formats
|
78
|
-
end
|
79
|
-
|
80
|
-
@default_format = @formats[:us]
|
81
|
-
|
82
|
-
|
83
|
-
# Accessor for the default format in use
|
84
|
-
#
|
85
|
-
#---
|
86
|
-
# @public
|
87
|
-
def self.default_format
|
88
|
-
@default_format
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
# Changes the default format to use when transforming a +Numeric+ instance
|
93
|
-
#
|
94
|
-
# ==== Parameters
|
95
|
-
# format_code <Symbol>:: format name to use as the new default format
|
96
|
-
#
|
97
|
-
# ==== Returns
|
98
|
-
# Hash:: a hash representing the default format
|
99
|
-
#
|
100
|
-
#---
|
101
|
-
# @public
|
102
|
-
def self.change_default_format(format_code)
|
103
|
-
@default_format = (formats[format_code] || default_format)
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
# Adds a new format to the existing transforming formats
|
108
|
-
#
|
109
|
-
# ==== Parameters
|
110
|
-
# format <Hash>:: format defining how to transform numeric values
|
111
|
-
#
|
112
|
-
# ==== Examples
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#---
|
116
|
-
# @public
|
117
|
-
def self.add_format(format)
|
118
|
-
formats.merge!(format)
|
119
|
-
formats[format]
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
# Formats a +number+ with grouped thousands using +delimiter+ (e.g., 12,324). You can
|
124
|
-
# pass another format to format the number differently.
|
125
|
-
#
|
126
|
-
#
|
127
|
-
# ==== Parameters
|
128
|
-
# format_name<Symbol>:: name of the format to use
|
129
|
-
# options<Hash>:: options which will overwrite the used format
|
130
|
-
#
|
131
|
-
# ==== Returns
|
132
|
-
# String:: a string representing the delimited number
|
133
|
-
#
|
134
|
-
# ==== Options
|
135
|
-
# :delimiter - Overwrites the thousands delimiter.
|
136
|
-
# :separator - Overwrites the separator between the units.
|
137
|
-
#
|
138
|
-
# ==== Examples
|
139
|
-
# with_delimiter(12345678) # => 12,345,678
|
140
|
-
# with_delimiter(12345678.05) # => 12,345,678.05
|
141
|
-
# with_delimiter(12345678, :FR) # => 12.345.678
|
142
|
-
# with_delimiter(12345678, :US) # => 12,345,678
|
143
|
-
#
|
144
|
-
#---
|
145
|
-
# @private
|
146
|
-
def self.with_delimiter(number, format_name = nil, options = {})
|
147
|
-
|
148
|
-
format = (formats[format_name] || default_format)[:number].merge(options)
|
149
|
-
|
150
|
-
begin
|
151
|
-
parts = number.to_s.split('.')
|
152
|
-
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{format[:delimiter]}")
|
153
|
-
parts.join(format[:separator])
|
154
|
-
rescue
|
155
|
-
number
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# Formats a +number+ with a level of <tt>:precision</tt> (e.g., 112.32 has a precision of 2).
|
160
|
-
# You can pass another format to use and even overwrite the format's options.
|
161
|
-
#
|
162
|
-
#
|
163
|
-
# ==== Parameters
|
164
|
-
# format_name<Symbol>:: name of the format to use
|
165
|
-
# options<Hash>:: options which will overwrite the used format
|
166
|
-
#
|
167
|
-
# ==== Returns
|
168
|
-
# String:: a string representing the delimited number
|
169
|
-
#
|
170
|
-
# ==== Options
|
171
|
-
# :precision - Overwrites the level of precision
|
172
|
-
# :separator - Overwrites the separator between the units
|
173
|
-
# :delimiter - Overwrites the thousands delimiter
|
174
|
-
#
|
175
|
-
# ==== Examples
|
176
|
-
# with_precision(111.2345) # => 111.235
|
177
|
-
# with_precision(111.2345, :UK, :precision => 1) # => "111.2"
|
178
|
-
# with_precision(1234.567, :US, :precision => 1, :separator => ',', :delimiter => '-') # => "1-234,6"
|
179
|
-
#
|
180
|
-
#---
|
181
|
-
# @private
|
182
|
-
def self.with_precision(number, format_name = nil, options={})
|
183
|
-
|
184
|
-
format = (formats[format_name] || default_format)[:number].merge(options)
|
185
|
-
|
186
|
-
begin
|
187
|
-
rounded_number = (Float(number) * (10 ** format[:precision])).round.to_f / 10 ** format[:precision]
|
188
|
-
with_delimiter("%01.#{format[:precision]}f" % rounded_number, format_name, :delimiter => format[:delimiter], :separator => format[:separator])
|
189
|
-
rescue
|
190
|
-
number
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
|
195
|
-
# Formats a +number+ into a currency string (e.g., $13.65). You can specify a format to use
|
196
|
-
# and even overwrite some of the format options.
|
197
|
-
#
|
198
|
-
# ==== Parameters
|
199
|
-
# number<Numeric>:: Numeric value to convert
|
200
|
-
# format_name<Symbol>:: name of the format to use
|
201
|
-
# options<Hash>:: options which will overwrite the used format
|
202
|
-
#
|
203
|
-
# ==== Returns
|
204
|
-
# String:: a string representing the number converted in currency
|
205
|
-
#
|
206
|
-
# ==== Options
|
207
|
-
# :precision - Sets the level of precision
|
208
|
-
# :unit - Sets the denomination of the currency
|
209
|
-
# :format - Sets the format of the output string (defaults to "%u%n"). The field types are:
|
210
|
-
#
|
211
|
-
# %u The currency unit
|
212
|
-
# %n The number
|
213
|
-
#
|
214
|
-
# ==== Examples
|
215
|
-
# to_currency(1234567890.506, :US, :precision => 1) # => "$1,234,567,890.5"
|
216
|
-
# to_currency(1234567890.516, :FR) # =>"1 234 567 890,52€"
|
217
|
-
# to_currency(1234567890.516, :US, :unit => "€") # =>"€1,234,567,890.52"
|
218
|
-
# to_currency(1234567890.506, :US, :precision => 3, :unit => "€") # => "€1,234,567,890.506"
|
219
|
-
# to_currency(1234567890.506, :AU, :unit => "$AUD", :format => '%n %u') # => "1,234,567,890.51 $AUD"
|
220
|
-
#
|
221
|
-
#---
|
222
|
-
# @private
|
223
|
-
def self.to_currency(number, format_name = nil, options = {})
|
224
|
-
|
225
|
-
format = (formats[format_name] || default_format)[:currency].merge(options)
|
226
|
-
|
227
|
-
begin
|
228
|
-
format[:format].gsub(/%n/, with_precision(number,
|
229
|
-
format_name, :precision => format[:precision]) ).gsub(/%u/, format[:unit])
|
230
|
-
rescue
|
231
|
-
number
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
|
236
|
-
# Formats a +number+ into a two digit string. Basically it prepends an integer to a 2 digits string.
|
237
|
-
#
|
238
|
-
# ==== Parameters
|
239
|
-
# number<Numeric>:: Numeric value to convert
|
240
|
-
#
|
241
|
-
# ==== Returns
|
242
|
-
# String:: a string representing the number converted into a 2 digits string.
|
243
|
-
#
|
244
|
-
# ==== Examples
|
245
|
-
# two_digits(5-3) # => "02"
|
246
|
-
#
|
247
|
-
#---
|
248
|
-
# @private
|
249
|
-
def self.two_digits(number)
|
250
|
-
(0..9).include?(number) ? "0#{number}" : number.to_s
|
251
|
-
end
|
252
|
-
|
253
|
-
# Converts a +numeric+ value representing minutes into a string representing an hour value
|
254
|
-
#
|
255
|
-
# ==== Parameters
|
256
|
-
# number<Numeric>:: Numeric value representing minutes to convert in hours
|
257
|
-
#
|
258
|
-
# ==== Returns
|
259
|
-
# String:: a string representing the numeric value converted in hours
|
260
|
-
#
|
261
|
-
# ==== Examples
|
262
|
-
# minutes_to_hours(315) => "05:15"
|
263
|
-
#
|
264
|
-
#---
|
265
|
-
# @private
|
266
|
-
def self.minutes_to_hours(minutes)
|
267
|
-
hours = (minutes/60).ceil
|
268
|
-
minutes = (minutes - (hours * 60)).to_i
|
269
|
-
"#{two_digits(hours)}:#{two_digits(minutes)}"
|
270
|
-
end
|
271
|
-
|
272
|
-
end #of Numeric::Transformer
|
273
|
-
|
274
|
-
# Formats with with grouped thousands using +delimiter+ (e.g., 12,324). You can
|
275
|
-
# pass another format to format the number differently.
|
276
|
-
#
|
277
|
-
#
|
278
|
-
# ==== Parameters
|
279
|
-
# format_name<Symbol>:: name of the format to use
|
280
|
-
# options<Hash>:: options which will overwrite the used format
|
281
|
-
#
|
282
|
-
# ==== Returns
|
283
|
-
# String:: a string representing the delimited number
|
284
|
-
#
|
285
|
-
# ==== Options
|
286
|
-
# :delimiter - Overwrites the thousands delimiter.
|
287
|
-
# :separator - Overwrites the separator between the units.
|
288
|
-
#
|
289
|
-
# ==== Examples
|
290
|
-
# 12345678.with_delimiter # => 12,345,678
|
291
|
-
# 12345678.05.with_delimiter # => 12,345,678.05
|
292
|
-
# 12345678.with_delimiter(:FR) # => 12.345.678
|
293
|
-
# 12345678.with_delimiter(:US) # => 12,345,678
|
294
|
-
#
|
295
|
-
#---
|
296
|
-
# @public
|
297
|
-
def with_delimiter(format_name = nil, options = {})
|
298
|
-
Transformer.with_delimiter(self, format_name, options)
|
299
|
-
end
|
300
|
-
|
301
|
-
# Formats with a level of <tt>:precision</tt> (e.g., 112.32 has a precision of 2).
|
302
|
-
# You can pass another format to use and even overwrite the format's options.
|
303
|
-
#
|
304
|
-
#
|
305
|
-
# ==== Parameters
|
306
|
-
# format_name<Symbol>:: name of the format to use
|
307
|
-
# options<Hash>:: options which will overwrite the used format
|
308
|
-
#
|
309
|
-
# ==== Returns
|
310
|
-
# String:: a string representing the delimited number
|
311
|
-
#
|
312
|
-
# ==== Options
|
313
|
-
# :precision - Overwrites the level of precision
|
314
|
-
# :separator - Overwrites the separator between the units
|
315
|
-
# :delimiter - Overwrites the thousands delimiter
|
316
|
-
#
|
317
|
-
# ==== Examples
|
318
|
-
# 111.2345.with_precision # => 111.235
|
319
|
-
# 111.2345.with_precision(:UK, :precision => 1) # => "111.2"
|
320
|
-
# 1234.567.with_precision(:US, :precision => 1, :separator => ',', :delimiter => '-') # => "1-234,6"
|
321
|
-
#
|
322
|
-
#---
|
323
|
-
# @public
|
324
|
-
def with_precision(format_name = nil, options = {})
|
325
|
-
Transformer.with_precision(self, format_name, options)
|
326
|
-
end
|
327
|
-
|
328
|
-
# Formats into a currency string (e.g., $13.65). You can specify a format to use
|
329
|
-
# and even overwrite some of the format options.
|
330
|
-
#
|
331
|
-
# ==== Parameters
|
332
|
-
# format_name<Symbol>:: name of the format to use
|
333
|
-
# options<Hash>:: options which will overwrite the used format
|
334
|
-
#
|
335
|
-
# ==== Returns
|
336
|
-
# String:: a string representing the number converted in currency
|
337
|
-
#
|
338
|
-
# ==== Options
|
339
|
-
# :precision - Sets the level of precision
|
340
|
-
# :unit - Sets the denomination of the currency
|
341
|
-
# :format - Sets the format of the output string (defaults to "%u%n"). The field types are:
|
342
|
-
#
|
343
|
-
# %u The currency unit
|
344
|
-
# %n The number
|
345
|
-
#
|
346
|
-
# ==== Examples
|
347
|
-
# 1234567890.506.to_currency(:US) # => "$1,234,567,890.51"
|
348
|
-
# 1234567890.506.to_currency(:US, :precision => 1) # => "$1,234,567,890.5"
|
349
|
-
# 1234567890.516.to_currency(:FR) # =>"1 234 567 890,52€"
|
350
|
-
# 1234567890.516.to_currency(:US, :unit => "€") # =>"€1,234,567,890.52"
|
351
|
-
# 1234567890.506.to_currency(:US, :precision => 3, :unit => "€") # => "€1,234,567,890.506"
|
352
|
-
# 1234567890.506.to_currency(:AU, :unit => "$AUD", :format => '%n %u') # => "1,234,567,890.51 $AUD"
|
353
|
-
#---
|
354
|
-
# @public
|
355
|
-
def to_currency(format_name = nil, options = {})
|
356
|
-
Transformer.to_currency(self, format_name, options)
|
357
|
-
end
|
358
|
-
|
359
|
-
# Formats a +number+ into a two digit string. Basically it prepends an integer to a 2 digits string.
|
360
|
-
#
|
361
|
-
# ==== Returns
|
362
|
-
# String:: a string representing the number converted into a 2 digits string.
|
363
|
-
#
|
364
|
-
# ==== Examples
|
365
|
-
# (5-3).two_digits # => "02"
|
366
|
-
#
|
367
|
-
#---
|
368
|
-
# @public
|
369
|
-
def two_digits
|
370
|
-
Transformer.two_digits(self)
|
371
|
-
end
|
372
|
-
|
373
|
-
# Converts a +numeric+ value representing minutes into a string representing an hour value
|
374
|
-
#
|
375
|
-
# ==== Parameters
|
376
|
-
# number<Numeric>:: Numeric value representing minutes to convert in hours
|
377
|
-
#
|
378
|
-
# ==== Returns
|
379
|
-
# String:: a string representing the numeric value converted in hours
|
380
|
-
#
|
381
|
-
# ==== Examples
|
382
|
-
# 315.minutes_to_hours => "05:15"
|
383
|
-
#
|
384
|
-
#---
|
385
|
-
# @public
|
386
|
-
def minutes_to_hours
|
387
|
-
Transformer.minutes_to_hours(self)
|
388
|
-
end
|
389
|
-
end
|