case_form 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +1 -0
- data/MIT-LICENSE.rdoc +20 -0
- data/Manifest +86 -0
- data/README.rdoc +0 -0
- data/Rakefile +30 -0
- data/TODO.rdoc +7 -0
- data/case_form.gemspec +31 -0
- data/lib/case_form.rb +88 -0
- data/lib/case_form/associations.rb +50 -0
- data/lib/case_form/buttons.rb +175 -0
- data/lib/case_form/core_ext/form_helper.rb +54 -0
- data/lib/case_form/core_ext/layout_helper.rb +16 -0
- data/lib/case_form/core_ext/sentence_error.rb +38 -0
- data/lib/case_form/element.rb +40 -0
- data/lib/case_form/element/base.rb +95 -0
- data/lib/case_form/element/button.rb +64 -0
- data/lib/case_form/element/error.rb +54 -0
- data/lib/case_form/element/errors/complex_error.rb +107 -0
- data/lib/case_form/element/errors/simple_error.rb +76 -0
- data/lib/case_form/element/fieldset.rb +35 -0
- data/lib/case_form/element/hint.rb +54 -0
- data/lib/case_form/element/input.rb +106 -0
- data/lib/case_form/element/inputs/collection/checkbox_input.rb +36 -0
- data/lib/case_form/element/inputs/collection/radio_input.rb +27 -0
- data/lib/case_form/element/inputs/collection/select_input.rb +22 -0
- data/lib/case_form/element/inputs/collection_input.rb +89 -0
- data/lib/case_form/element/inputs/datetime/date_input.rb +45 -0
- data/lib/case_form/element/inputs/datetime/date_time_input.rb +50 -0
- data/lib/case_form/element/inputs/datetime/time_input.rb +34 -0
- data/lib/case_form/element/inputs/datetime/time_zone_input.rb +24 -0
- data/lib/case_form/element/inputs/file_input.rb +13 -0
- data/lib/case_form/element/inputs/hidden_input.rb +17 -0
- data/lib/case_form/element/inputs/number_input.rb +42 -0
- data/lib/case_form/element/inputs/search_input.rb +32 -0
- data/lib/case_form/element/inputs/string_input.rb +18 -0
- data/lib/case_form/element/inputs/text_input.rb +19 -0
- data/lib/case_form/element/label.rb +52 -0
- data/lib/case_form/element/nested_model.rb +105 -0
- data/lib/case_form/element/nested_models/handle.rb +18 -0
- data/lib/case_form/element/nested_models/handles/destructor_handle.rb +47 -0
- data/lib/case_form/element/nested_models/handles/generator_handle.rb +55 -0
- data/lib/case_form/element_ext/associationable.rb +54 -0
- data/lib/case_form/element_ext/columnable.rb +21 -0
- data/lib/case_form/element_ext/naming.rb +17 -0
- data/lib/case_form/element_ext/validationable.rb +13 -0
- data/lib/case_form/errors.rb +189 -0
- data/lib/case_form/form_builder.rb +11 -0
- data/lib/case_form/inputs.rb +1095 -0
- data/lib/case_form/labels.rb +102 -0
- data/lib/case_form/version.rb +6 -0
- data/lib/generators/case_form/install_generator.rb +33 -0
- data/lib/generators/case_form/templates/case_form.rb +63 -0
- data/lib/generators/case_form/templates/javascripts/jquery.case_form.js +10 -0
- data/lib/generators/case_form/templates/javascripts/prototype.case_form.js +0 -0
- data/lib/generators/case_form/templates/locales/en.yml +28 -0
- data/lib/generators/case_form/templates/locales/pl.yml +28 -0
- data/lib/generators/case_form/templates/stylesheets/stylesheet.css +93 -0
- data/lib/generators/case_form/templates/stylesheets/stylesheet_changes.css +1 -0
- data/lib/generators/case_form/uninstall_generator.rb +30 -0
- data/rails/init.rb +1 -0
- data/test/element/button_test.rb +85 -0
- data/test/element/errors/complex_error_test.rb +140 -0
- data/test/element/errors/simple_error_test.rb +92 -0
- data/test/element/fieldset_test.rb +28 -0
- data/test/element/hint_test.rb +81 -0
- data/test/element/input_test.rb +197 -0
- data/test/element/inputs/collection/checkbox_input_test.rb +176 -0
- data/test/element/inputs/collection/radio_input_test.rb +156 -0
- data/test/element/inputs/collection/select_input_test.rb +152 -0
- data/test/element/inputs/datetime/date_input_test.rb +160 -0
- data/test/element/inputs/datetime/datetime_input_test.rb +227 -0
- data/test/element/inputs/datetime/time_input_test.rb +72 -0
- data/test/element/inputs/datetime/time_zone_input_test.rb +42 -0
- data/test/element/inputs/file_input_test.rb +13 -0
- data/test/element/inputs/hidden_input_test.rb +13 -0
- data/test/element/inputs/number_input_test.rb +50 -0
- data/test/element/inputs/search_input_test.rb +13 -0
- data/test/element/inputs/string_input_test.rb +33 -0
- data/test/element/inputs/text_input_test.rb +13 -0
- data/test/element/label_test.rb +62 -0
- data/test/element/nested_model_test.rb +163 -0
- data/test/element/nested_models/handles/destructor_handle_test.rb +35 -0
- data/test/element/nested_models/handles/generator_handle_test.rb +27 -0
- data/test/form_builder_test.rb +25 -0
- data/test/form_helper_test.rb +15 -0
- data/test/lib/models.rb +268 -0
- data/test/test_helper.rb +74 -0
- metadata +235 -0
| @@ -0,0 +1,102 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            module CaseForm
         | 
| 3 | 
            +
              module Labels
         | 
| 4 | 
            +
                # == Label
         | 
| 5 | 
            +
                # 
         | 
| 6 | 
            +
                # Generate label for model attribute. By default it use I18n translation (see lookups).
         | 
| 7 | 
            +
                # If method is required by validation or attribute column option, should add required symbol.
         | 
| 8 | 
            +
                #
         | 
| 9 | 
            +
                # == Label config
         | 
| 10 | 
            +
                # 
         | 
| 11 | 
            +
                # * CaseForm.all_fields_required
         | 
| 12 | 
            +
                # * CaseForm.require_symbol
         | 
| 13 | 
            +
                #
         | 
| 14 | 
            +
                #
         | 
| 15 | 
            +
                # == Examples:
         | 
| 16 | 
            +
                #
         | 
| 17 | 
            +
                #   <%= case_form_for(@user) do |f| %>
         | 
| 18 | 
            +
                #     <%= f.label :firstname %>                   # Uses I18n lookup
         | 
| 19 | 
            +
                #   <% end %>
         | 
| 20 | 
            +
                #   
         | 
| 21 | 
            +
                #   # or
         | 
| 22 | 
            +
                #
         | 
| 23 | 
            +
                #   <%= case_form_for(@user) do |f| %>
         | 
| 24 | 
            +
                #     <%= f.label :firstname, :text => "Your firstname" %>            
         | 
| 25 | 
            +
                #                                                 # Overwrite I18n lookup
         | 
| 26 | 
            +
                #   <% end %>
         | 
| 27 | 
            +
                #
         | 
| 28 | 
            +
                # == Default label config
         | 
| 29 | 
            +
                # 
         | 
| 30 | 
            +
                # * CaseForm.all_fields_required
         | 
| 31 | 
            +
                # * CaseForm.require_symbol
         | 
| 32 | 
            +
                #
         | 
| 33 | 
            +
                # == Allowed options:
         | 
| 34 | 
            +
                # * +:id+ - HTML ID
         | 
| 35 | 
            +
                # * +:class+ - HTML class
         | 
| 36 | 
            +
                # * +:style+ - not recommended HTML styles (use CSS)
         | 
| 37 | 
            +
                # * +:for+ - label's target 
         | 
| 38 | 
            +
                # * +:text+ - text for label, overwrite a default value
         | 
| 39 | 
            +
                # * +:required+ - add "required" symbol to label if attribute is needed by validation or as column option "NULL" 
         | 
| 40 | 
            +
                #
         | 
| 41 | 
            +
                # == I18n lookups priority:
         | 
| 42 | 
            +
                #
         | 
| 43 | 
            +
                # * 'activerecord.attributes.{{model}}.{{method}}'
         | 
| 44 | 
            +
                # * 'activemodel.attributes.{{model}}.{{method}}'
         | 
| 45 | 
            +
                # * 'case_form.attributes.{{model}}.{{method}}'
         | 
| 46 | 
            +
                # * humanized method
         | 
| 47 | 
            +
                #
         | 
| 48 | 
            +
                def label(method, options={})
         | 
| 49 | 
            +
                  Element::Label.new(self, method, options).generate
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
                
         | 
| 52 | 
            +
                # == Form hint for input
         | 
| 53 | 
            +
                # 
         | 
| 54 | 
            +
                # Generate hint for input as simple HTML tag. Hints can be use for model attribute - it use I18n 
         | 
| 55 | 
            +
                # for translate. You can also enter just some string as argument or +:text+ option for different situation.
         | 
| 56 | 
            +
                # I18n lookup see bottom.
         | 
| 57 | 
            +
                #
         | 
| 58 | 
            +
                # == Hint config
         | 
| 59 | 
            +
                # 
         | 
| 60 | 
            +
                # * CaseForm.hint_tag
         | 
| 61 | 
            +
                #
         | 
| 62 | 
            +
                # == Examples for model attribute:
         | 
| 63 | 
            +
                #
         | 
| 64 | 
            +
                #   <%= case_form_for(@user) do |f| %>
         | 
| 65 | 
            +
                #     <%= f.hint :firstname %>                    # Uses I18n lookup  
         | 
| 66 | 
            +
                #   <% end %>
         | 
| 67 | 
            +
                #   
         | 
| 68 | 
            +
                #   # or
         | 
| 69 | 
            +
                #
         | 
| 70 | 
            +
                #   <%= case_form_for(@user) do |f| %>
         | 
| 71 | 
            +
                #     <%= f.hint :firstname, :text => "Enter your firstname" %>       
         | 
| 72 | 
            +
                #                                                 # Overwrite I18n lookup
         | 
| 73 | 
            +
                #   <% end %>
         | 
| 74 | 
            +
                #
         | 
| 75 | 
            +
                # == Examples for non model attribute:
         | 
| 76 | 
            +
                #
         | 
| 77 | 
            +
                #   <%= case_form_for(@user) do |f| %>
         | 
| 78 | 
            +
                #     <%= f.hint "Enter your firstname" %>        # Uses string argument
         | 
| 79 | 
            +
                #   <% end %>
         | 
| 80 | 
            +
                #
         | 
| 81 | 
            +
                # == Default hint config
         | 
| 82 | 
            +
                # 
         | 
| 83 | 
            +
                # * CaseForm.hint_tag
         | 
| 84 | 
            +
                #
         | 
| 85 | 
            +
                # == Allowed options:
         | 
| 86 | 
            +
                #
         | 
| 87 | 
            +
                # * +:id+ - HTML ID
         | 
| 88 | 
            +
                # * +:class+ - HTML class
         | 
| 89 | 
            +
                # * +:style+ - not recommended HTML styles (use CSS)
         | 
| 90 | 
            +
                # * +:text+ - text for hint, overwrite a I18n or string value
         | 
| 91 | 
            +
                # * +:tag+ - hint's HTML tag
         | 
| 92 | 
            +
                #
         | 
| 93 | 
            +
                # == I18n lookups priority:
         | 
| 94 | 
            +
                #
         | 
| 95 | 
            +
                # * 'case_form.hints.{{model}}.{{method}}'
         | 
| 96 | 
            +
                #
         | 
| 97 | 
            +
                def hint(method_or_string, options={})
         | 
| 98 | 
            +
                  Element::Hint.new(self, method_or_string, options).generate
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
                alias_method :comment, :hint
         | 
| 101 | 
            +
              end
         | 
| 102 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            module CaseForm
         | 
| 2 | 
            +
              module Generators
         | 
| 3 | 
            +
                class InstallGenerator < Rails::Generators::Base
         | 
| 4 | 
            +
                  desc "Copy CaseForm files..."
         | 
| 5 | 
            +
                  source_root File.expand_path('../templates', __FILE__)
         | 
| 6 | 
            +
                  class_option :config, :type => :boolean, :default => true, :desc => "Include CaseForm config file..."
         | 
| 7 | 
            +
                  class_option :stylesheets, :type => :boolean, :default => true, :desc => "Include stylesheet files..."
         | 
| 8 | 
            +
                  class_option :javascripts, :type => :string, :default => :jquery, :desc => "Include javascript files..."
         | 
| 9 | 
            +
                  class_option :locales, :type => :array, :default => [:pl, :en], :desc => "Include locale files..."
         | 
| 10 | 
            +
                  
         | 
| 11 | 
            +
                  def copy_config
         | 
| 12 | 
            +
                    copy_file "case_form.rb", "config/initializers/case_form.rb"
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
                  
         | 
| 15 | 
            +
                  def copy_stylesheets
         | 
| 16 | 
            +
                    if options.stylesheets?
         | 
| 17 | 
            +
                      copy_file "stylesheets/stylesheet.css", "public/stylesheets/case_form.css"
         | 
| 18 | 
            +
                      copy_file "stylesheets/stylesheet_changes.css", "public/stylesheets/case_form_changes.css"
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                  
         | 
| 22 | 
            +
                  def copy_javascripts
         | 
| 23 | 
            +
                    copy_file "javascripts/#{options.javascripts}.case_form.js", "public/javascripts/case_form.js"
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                  
         | 
| 26 | 
            +
                  def copy_locales
         | 
| 27 | 
            +
                    options.locales.each do |l|
         | 
| 28 | 
            +
                      copy_file "locales/#{l}.yml", "config/locales/case_form/#{l}.yml"
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            CaseForm.config do |c|
         | 
| 2 | 
            +
              # Default input elements for each form field
         | 
| 3 | 
            +
              # To remove for example inline errors for single field delete symbol from this array
         | 
| 4 | 
            +
              c.input_elements = [:label, :input, :error, :hint]
         | 
| 5 | 
            +
              
         | 
| 6 | 
            +
              # Default form buttons
         | 
| 7 | 
            +
              c.form_buttons = [:commit, :reset]
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              # Collection of locked columns for dynamic attribute finder (in "attributes" method)
         | 
| 10 | 
            +
              c.locked_columns = [:id, :type, :lock_version, :version,
         | 
| 11 | 
            +
                                  :created_at, :updated_at, :created_on, :updated_on]
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              # All fields required in every form by default
         | 
| 14 | 
            +
              c.all_fields_required = false
         | 
| 15 | 
            +
              
         | 
| 16 | 
            +
              # Required symbol in form label
         | 
| 17 | 
            +
              c.require_symbol = "*"
         | 
| 18 | 
            +
              
         | 
| 19 | 
            +
              # Default input size
         | 
| 20 | 
            +
              c.input_size = 50
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              # Default count of textarea cols
         | 
| 23 | 
            +
              c.textarea_cols = 20
         | 
| 24 | 
            +
              
         | 
| 25 | 
            +
              # Default count of textarea rows
         | 
| 26 | 
            +
              c.textarea_rows = 10
         | 
| 27 | 
            +
              
         | 
| 28 | 
            +
              # Default step for number input
         | 
| 29 | 
            +
              c.number_step = 1
         | 
| 30 | 
            +
              
         | 
| 31 | 
            +
              # Default wrapper tag for each form field
         | 
| 32 | 
            +
              c.wrapper_tag = :div
         | 
| 33 | 
            +
              
         | 
| 34 | 
            +
              # Default hint tag
         | 
| 35 | 
            +
              c.hint_tag = :span
         | 
| 36 | 
            +
              
         | 
| 37 | 
            +
              # Default error tag (same for complex and simple errors)
         | 
| 38 | 
            +
              c.error_tag = :div
         | 
| 39 | 
            +
              
         | 
| 40 | 
            +
              # Default error type (available options are :list and :sentence)
         | 
| 41 | 
            +
              # Differences between types search in CaseForm documentation (:error_messages and :error_message methods)
         | 
| 42 | 
            +
              c.error_type = :sentence
         | 
| 43 | 
            +
              
         | 
| 44 | 
            +
              # Default connector for sentence errors type
         | 
| 45 | 
            +
              # Example: some error, another error, just error
         | 
| 46 | 
            +
              c.error_connector = ", "
         | 
| 47 | 
            +
              
         | 
| 48 | 
            +
              # Default last connector for sentence errors type
         | 
| 49 | 
            +
              # Example: some error, another error, just error and last error
         | 
| 50 | 
            +
              c.last_error_connector = " and "
         | 
| 51 | 
            +
              
         | 
| 52 | 
            +
              # Default header tag for complex errors
         | 
| 53 | 
            +
              c.complex_error_header_tag = :h2
         | 
| 54 | 
            +
              
         | 
| 55 | 
            +
              # Default message tag for complex errors
         | 
| 56 | 
            +
              c.complex_error_message_tag = :p
         | 
| 57 | 
            +
              
         | 
| 58 | 
            +
              # Collection of methods for label in associated model (first found is taken)
         | 
| 59 | 
            +
              c.collection_label_methods = [:to_label, :full_name, :fullname, :name, :title, :login, :email, :value, :to_s]
         | 
| 60 | 
            +
              
         | 
| 61 | 
            +
              # Collection of methods for value in associated model (first found is taken)
         | 
| 62 | 
            +
              c.collection_value_methods = [:id]
         | 
| 63 | 
            +
            end
         | 
| 
            File without changes
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            en:
         | 
| 2 | 
            +
              case_form:
         | 
| 3 | 
            +
                yes: "Yes"
         | 
| 4 | 
            +
                no: "No"
         | 
| 5 | 
            +
                nested_attributes:
         | 
| 6 | 
            +
                  destroy: "Remove {{model}}"
         | 
| 7 | 
            +
                  create: "Add {{model}}"
         | 
| 8 | 
            +
                buttons:
         | 
| 9 | 
            +
                  # user:
         | 
| 10 | 
            +
                    # new: "New account"
         | 
| 11 | 
            +
                    # edit: "Update account"
         | 
| 12 | 
            +
                    # reset: "Reset"
         | 
| 13 | 
            +
                  new: "Create"
         | 
| 14 | 
            +
                  edit: "Update"
         | 
| 15 | 
            +
                  reset: "Reset"
         | 
| 16 | 
            +
                errors:
         | 
| 17 | 
            +
                  template:
         | 
| 18 | 
            +
                    header_message: "Some errors prohibited this object from being saved"
         | 
| 19 | 
            +
                    message: "There were problems with the following fields:"
         | 
| 20 | 
            +
                hints:
         | 
| 21 | 
            +
                  # user:
         | 
| 22 | 
            +
                    # name: "Enter your firstname and lastname"
         | 
| 23 | 
            +
                    # email: "Please enter valid email"
         | 
| 24 | 
            +
                attributes:
         | 
| 25 | 
            +
                  # user:
         | 
| 26 | 
            +
                    # name: "Name"
         | 
| 27 | 
            +
                    # email: "E-mail"
         | 
| 28 | 
            +
                    # password: "Password"
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            pl:
         | 
| 2 | 
            +
              case_form:
         | 
| 3 | 
            +
                yes: "Tak"
         | 
| 4 | 
            +
                no: "Nie"
         | 
| 5 | 
            +
                nested_attributes:
         | 
| 6 | 
            +
                  destroy: "Usuń {{model}}"
         | 
| 7 | 
            +
                  create: "Utwórz {{model}}"
         | 
| 8 | 
            +
                buttons:
         | 
| 9 | 
            +
                  # user:
         | 
| 10 | 
            +
                    # new: "Nowe konto"
         | 
| 11 | 
            +
                    # edit: "Uaktualnij"
         | 
| 12 | 
            +
                    # reset: "Resetuj dane"
         | 
| 13 | 
            +
                  new: "Utwórz"
         | 
| 14 | 
            +
                  edit: "Uaktualnij"
         | 
| 15 | 
            +
                  reset: "Resetuj"
         | 
| 16 | 
            +
                errors:
         | 
| 17 | 
            +
                  template:
         | 
| 18 | 
            +
                    header_message: "Pewne błędy nie pozwalają na zapisanie obiektu"
         | 
| 19 | 
            +
                    message: "Błędy występują w następujących sytuacjach:"
         | 
| 20 | 
            +
                hints:
         | 
| 21 | 
            +
                  # user:
         | 
| 22 | 
            +
                    # name: "Podaj imię i nazwisko"
         | 
| 23 | 
            +
                    # email: "Podaj poprawny email"
         | 
| 24 | 
            +
                attributes:
         | 
| 25 | 
            +
                  # user:
         | 
| 26 | 
            +
                    # name: "Imię i nazwisko"
         | 
| 27 | 
            +
                    # email: "E-mail"
         | 
| 28 | 
            +
                    # password: "Hasło"
         | 
| @@ -0,0 +1,93 @@ | |
| 1 | 
            +
            /* Default styles for CaseForm */
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            .case_form, .case_form fieldset {
         | 
| 4 | 
            +
            	font-family: "Lucida Grande", "Trebuchet MS", Verdana, sans-serif;
         | 
| 5 | 
            +
            	margin: 0;
         | 
| 6 | 
            +
            	padding: 0;
         | 
| 7 | 
            +
            }
         | 
| 8 | 
            +
            .case_form fieldset {
         | 
| 9 | 
            +
            	border: none;
         | 
| 10 | 
            +
            }
         | 
| 11 | 
            +
            .case_form fieldset legend {
         | 
| 12 | 
            +
            	margin:0;
         | 
| 13 | 
            +
            	padding:0;
         | 
| 14 | 
            +
            	font-size: 18px;
         | 
| 15 | 
            +
            }
         | 
| 16 | 
            +
            .case_form fieldset.inputs {
         | 
| 17 | 
            +
            	display: block;
         | 
| 18 | 
            +
            }
         | 
| 19 | 
            +
            .case_form .element {
         | 
| 20 | 
            +
            	display: block;
         | 
| 21 | 
            +
            }
         | 
| 22 | 
            +
            .case_form .label {
         | 
| 23 | 
            +
            	display: block;
         | 
| 24 | 
            +
            	float: left;
         | 
| 25 | 
            +
            	padding-top: 0.2em;
         | 
| 26 | 
            +
            	width: 25%;
         | 
| 27 | 
            +
            	position: absolute;
         | 
| 28 | 
            +
            }
         | 
| 29 | 
            +
            .case_form .inline_label {
         | 
| 30 | 
            +
            	display: inline-block;
         | 
| 31 | 
            +
            	width: 70%;
         | 
| 32 | 
            +
            	padding-left: 1%;
         | 
| 33 | 
            +
            }
         | 
| 34 | 
            +
            .case_form .input {
         | 
| 35 | 
            +
            	margin: 0 0 0.5em 25%;
         | 
| 36 | 
            +
            	display: inline-block;
         | 
| 37 | 
            +
            }
         | 
| 38 | 
            +
            .case_form input, select, textarea {
         | 
| 39 | 
            +
            	min-width: 275px;
         | 
| 40 | 
            +
            }
         | 
| 41 | 
            +
            .case_form input[type=checkbox], input[type=radio] {
         | 
| 42 | 
            +
            	width: auto;
         | 
| 43 | 
            +
            	min-width: 0;
         | 
| 44 | 
            +
            }
         | 
| 45 | 
            +
            .case_form .error {
         | 
| 46 | 
            +
            	display: block;
         | 
| 47 | 
            +
            	margin-left: 25%;
         | 
| 48 | 
            +
            	color: #E41B17;
         | 
| 49 | 
            +
            	font-weight: bold;
         | 
| 50 | 
            +
            }
         | 
| 51 | 
            +
            .case_form .hint {
         | 
| 52 | 
            +
            	display: block;
         | 
| 53 | 
            +
            	margin-left: 25%;
         | 
| 54 | 
            +
            	font-style: italic;
         | 
| 55 | 
            +
            }
         | 
| 56 | 
            +
            .case_form .errors {
         | 
| 57 | 
            +
            	max-width: 75%;
         | 
| 58 | 
            +
            	padding: 0px;
         | 
| 59 | 
            +
            	border: 1px solid #E41B17;
         | 
| 60 | 
            +
            	-webkit-border-radius: 5px;
         | 
| 61 | 
            +
            	-moz-border-radius: 5px;
         | 
| 62 | 
            +
            	border-radius: 5px;
         | 
| 63 | 
            +
            	margin-bottom: 10px;
         | 
| 64 | 
            +
            	background: -webkit-gradient(linear, 0% 0%, 0% 100%, to(#FF6666), from(#FFB0B0));
         | 
| 65 | 
            +
            	background: -moz-linear-gradient(15% 85% 90deg,#FFB0B0, #FF6666);
         | 
| 66 | 
            +
            }
         | 
| 67 | 
            +
            .case_form .errors h2 {
         | 
| 68 | 
            +
            	margin: 0;
         | 
| 69 | 
            +
            	background: #E41B17;
         | 
| 70 | 
            +
            	padding: 10px;
         | 
| 71 | 
            +
            	color: white;
         | 
| 72 | 
            +
            }
         | 
| 73 | 
            +
            .case_form .errors p {
         | 
| 74 | 
            +
            	margin: 5px;
         | 
| 75 | 
            +
            }
         | 
| 76 | 
            +
            .case_form .errors ul {
         | 
| 77 | 
            +
            	list-style: none;
         | 
| 78 | 
            +
            	margin: 5px 15px;
         | 
| 79 | 
            +
            	padding: 0;
         | 
| 80 | 
            +
            }
         | 
| 81 | 
            +
            .case_form fieldset.buttons {
         | 
| 82 | 
            +
            	margin: 10px 0;
         | 
| 83 | 
            +
            	display: block;
         | 
| 84 | 
            +
            	padding-left:25%;
         | 
| 85 | 
            +
            }
         | 
| 86 | 
            +
            .case_form .button {
         | 
| 87 | 
            +
            	float: left;
         | 
| 88 | 
            +
            	width: 120px;
         | 
| 89 | 
            +
            	margin-right: 10px;
         | 
| 90 | 
            +
            }
         | 
| 91 | 
            +
            a[data-action=remove] {
         | 
| 92 | 
            +
            	margin: -5px 0 15px 25%;
         | 
| 93 | 
            +
            }
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            /* All changes for default CaseForm CSS */
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            module CaseForm
         | 
| 2 | 
            +
              module Generators
         | 
| 3 | 
            +
                class UninstallGenerator < Rails::Generators::Base
         | 
| 4 | 
            +
                  desc "Delete all CaseForm files..."
         | 
| 5 | 
            +
                  class_option :config,      :type => :boolean, :default => true, :desc => "Delete CaseForm config file..."
         | 
| 6 | 
            +
                  class_option :stylesheets, :type => :boolean, :default => true, :desc => "Delete stylesheet files..."
         | 
| 7 | 
            +
                  class_option :javascripts, :type => :boolean, :default => true, :desc => "Delete javascript files..."
         | 
| 8 | 
            +
                  class_option :locales,     :type => :boolean, :default => true, :desc => "Delete locale files..."
         | 
| 9 | 
            +
                  
         | 
| 10 | 
            +
                  def delete_config
         | 
| 11 | 
            +
                    remove_file "config/initializers/case_form.rb" if options.config?
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                  
         | 
| 14 | 
            +
                  def delete_stylesheets
         | 
| 15 | 
            +
                    if options.stylesheets?
         | 
| 16 | 
            +
                      remove_file "public/stylesheets/case_form.css"
         | 
| 17 | 
            +
                      remove_file "public/stylesheets/case_form_changes.css"
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  
         | 
| 21 | 
            +
                  def delete_javascripts
         | 
| 22 | 
            +
                    remove_file "public/javascripts/case_form.js" if options.javascripts?
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                  
         | 
| 25 | 
            +
                  def delete_locales
         | 
| 26 | 
            +
                    remove_file "config/locales/case_form" if options.locales?
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
    
        data/rails/init.rb
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "case_form"
         | 
| @@ -0,0 +1,85 @@ | |
| 1 | 
            +
            require 'test_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class ButtonTest < ActionView::TestCase
         | 
| 4 | 
            +
              def buttons_case_form_for(*args)
         | 
| 5 | 
            +
                concat(case_form_for(@user) { |f| f.buttons(*args) })
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              test "should generate all buttons" do
         | 
| 9 | 
            +
                buttons_case_form_for
         | 
| 10 | 
            +
                assert_select "fieldset", 1
         | 
| 11 | 
            +
                assert_select "input[type=submit]", 1
         | 
| 12 | 
            +
                assert_select "input[type=reset]", 1
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
              test "should generate buttons from args" do
         | 
| 16 | 
            +
                buttons_case_form_for(:commit, :reset)
         | 
| 17 | 
            +
                assert_select "fieldset", 1
         | 
| 18 | 
            +
                assert_select "input[type=submit]", 1
         | 
| 19 | 
            +
                assert_select "input[type=reset]", 1
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              test "should generate buttons from default config" do
         | 
| 23 | 
            +
                CaseForm.form_buttons = [:commit]
         | 
| 24 | 
            +
                buttons_case_form_for
         | 
| 25 | 
            +
                assert_select "fieldset", 1
         | 
| 26 | 
            +
                assert_select "input[type=submit]", 1
         | 
| 27 | 
            +
                assert_select "input[type=reset]", 0
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
              
         | 
| 30 | 
            +
              def button_case_form_for(object, button_type, options={})
         | 
| 31 | 
            +
                concat(case_form_for(object) { |f| f.send(button_type, options) })
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
              
         | 
| 34 | 
            +
              test "should generate button" do
         | 
| 35 | 
            +
                button_case_form_for(@user, :commit)
         | 
| 36 | 
            +
                assert_select "input[type=submit]", 1
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
              
         | 
| 39 | 
            +
              test "should generate reset button" do
         | 
| 40 | 
            +
                button_case_form_for(@user, :reset)
         | 
| 41 | 
            +
                assert_select "input[type=reset]", 1
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
              
         | 
| 44 | 
            +
              test "should generate button with text" do
         | 
| 45 | 
            +
                text = "Save"
         | 
| 46 | 
            +
                button_case_form_for(@user, :commit, :text => text)
         | 
| 47 | 
            +
                assert_select "input[value=#{text}]", 1
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
              
         | 
| 50 | 
            +
              test "should generate button with default HTML class" do
         | 
| 51 | 
            +
                button_case_form_for(@user, :commit)
         | 
| 52 | 
            +
                assert_select "input.button", 1
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
              
         | 
| 55 | 
            +
              test "should generate button with specific HTML class" do
         | 
| 56 | 
            +
                specific_class = :some_button_class
         | 
| 57 | 
            +
                button_case_form_for(@user, :commit, :class => specific_class)
         | 
| 58 | 
            +
                assert_select "input.#{specific_class}", 1
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
              
         | 
| 61 | 
            +
              test "should generate button with default HTML id" do
         | 
| 62 | 
            +
                button_case_form_for(@user, :commit)
         | 
| 63 | 
            +
                assert_select "input#user_submit", 1
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
              
         | 
| 66 | 
            +
              test "should generate button with specific HTML id" do
         | 
| 67 | 
            +
                specific_id = :some_button_id
         | 
| 68 | 
            +
                button_case_form_for(@user, :commit, :id => specific_id)
         | 
| 69 | 
            +
                assert_select "input##{specific_id}", 1
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
              
         | 
| 72 | 
            +
              test "should generate button with non disabled options on default" do
         | 
| 73 | 
            +
                button_case_form_for(@user, :commit)
         | 
| 74 | 
            +
                assert_select "input[type=submit][disabled=disabled]", 0
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
              
         | 
| 77 | 
            +
              test "should generate button with disabled options" do
         | 
| 78 | 
            +
                button_case_form_for(@user, :commit, :disabled => true)
         | 
| 79 | 
            +
                assert_select "input[type=submit][disabled=disabled]", 1
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
              
         | 
| 82 | 
            +
              test "should generate button with wrong options" do
         | 
| 83 | 
            +
                assert_raise(ArgumentError) { button_case_form_for(@user, :commit, :foo => :bar) }
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
            end
         |