nil, "body"=>nil, "id"=>"1"}>
114 | >> f.
115 | Display all 152 possibilities? (y or n)
116 |
117 | Finally, when you're ready to resume execution, you can enter "cont".
118 |
119 |
120 | == Console
121 |
122 | The console is a Ruby shell, which allows you to interact with your
123 | application's domain model. Here you'll have all parts of the application
124 | configured, just like it is when the application is running. You can inspect
125 | domain models, change values, and save to the database. Starting the script
126 | without arguments will launch it in the development environment.
127 |
128 | To start the console, run rails console from the application
129 | directory.
130 |
131 | Options:
132 |
133 | * Passing the -s, --sandbox argument will rollback any modifications
134 | made to the database.
135 | * Passing an environment name as an argument will load the corresponding
136 | environment. Example: rails console production.
137 |
138 | To reload your controllers and models after launching the console run
139 | reload!
140 |
141 | More information about irb can be found at:
142 | link:http://www.rubycentral.org/pickaxe/irb.html
143 |
144 |
145 | == dbconsole
146 |
147 | You can go to the command line of your database directly through rails
148 | dbconsole. You would be connected to the database with the credentials
149 | defined in database.yml. Starting the script without arguments will connect you
150 | to the development database. Passing an argument will connect you to a different
151 | database, like rails dbconsole production. Currently works for MySQL,
152 | PostgreSQL and SQLite 3.
153 |
154 | == Description of Contents
155 |
156 | The default directory structure of a generated Ruby on Rails application:
157 |
158 | |-- app
159 | | |-- assets
160 | | | |-- images
161 | | | |-- javascripts
162 | | | `-- stylesheets
163 | | |-- controllers
164 | | |-- helpers
165 | | |-- mailers
166 | | |-- models
167 | | `-- views
168 | | `-- layouts
169 | |-- config
170 | | |-- environments
171 | | |-- initializers
172 | | `-- locales
173 | |-- db
174 | |-- doc
175 | |-- lib
176 | | |-- assets
177 | | `-- tasks
178 | |-- log
179 | |-- public
180 | |-- script
181 | |-- test
182 | | |-- fixtures
183 | | |-- functional
184 | | |-- integration
185 | | |-- performance
186 | | `-- unit
187 | |-- tmp
188 | | `-- cache
189 | | `-- assets
190 | `-- vendor
191 | |-- assets
192 | | |-- javascripts
193 | | `-- stylesheets
194 | `-- plugins
195 |
196 | app
197 | Holds all the code that's specific to this particular application.
198 |
199 | app/assets
200 | Contains subdirectories for images, stylesheets, and JavaScript files.
201 |
202 | app/controllers
203 | Holds controllers that should be named like weblogs_controller.rb for
204 | automated URL mapping. All controllers should descend from
205 | ApplicationController which itself descends from ActionController::Base.
206 |
207 | app/models
208 | Holds models that should be named like post.rb. Models descend from
209 | ActiveRecord::Base by default.
210 |
211 | app/views
212 | Holds the template files for the view that should be named like
213 | weblogs/index.html.erb for the WeblogsController#index action. All views use
214 | eRuby syntax by default.
215 |
216 | app/views/layouts
217 | Holds the template files for layouts to be used with views. This models the
218 | common header/footer method of wrapping views. In your views, define a layout
219 | using the layout :default and create a file named default.html.erb.
220 | Inside default.html.erb, call <% yield %> to render the view using this
221 | layout.
222 |
223 | app/helpers
224 | Holds view helpers that should be named like weblogs_helper.rb. These are
225 | generated for you automatically when using generators for controllers.
226 | Helpers can be used to wrap functionality for your views into methods.
227 |
228 | config
229 | Configuration files for the Rails environment, the routing map, the database,
230 | and other dependencies.
231 |
232 | db
233 | Contains the database schema in schema.rb. db/migrate contains all the
234 | sequence of Migrations for your schema.
235 |
236 | doc
237 | This directory is where your application documentation will be stored when
238 | generated using rake doc:app
239 |
240 | lib
241 | Application specific libraries. Basically, any kind of custom code that
242 | doesn't belong under controllers, models, or helpers. This directory is in
243 | the load path.
244 |
245 | public
246 | The directory available for the web server. Also contains the dispatchers and the
247 | default HTML files. This should be set as the DOCUMENT_ROOT of your web
248 | server.
249 |
250 | script
251 | Helper scripts for automation and generation.
252 |
253 | test
254 | Unit and functional tests along with fixtures. When using the rails generate
255 | command, template test files will be generated for you and placed in this
256 | directory.
257 |
258 | vendor
259 | External libraries that the application depends on. Also includes the plugins
260 | subdirectory. If the app has frozen rails, those gems also go here, under
261 | vendor/rails/. This directory is in the load path.
262 |
--------------------------------------------------------------------------------
/spec/dummy/Rakefile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env rake
2 | # Add your own tasks in files placed in lib/tasks ending in .rake,
3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4 |
5 | require File.expand_path('../config/application', __FILE__)
6 |
7 | Dummy::Application.load_tasks
8 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // the compiled file.
9 | //
10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11 | // GO AFTER THE REQUIRES BELOW.
12 | //
13 | //= require jquery
14 | //= require jquery_ujs
15 | //= require_tree .
16 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the top of the
9 | * compiled file, but it's generally better to create a new file per style scope.
10 | *
11 | *= require_self
12 | *= require_tree .
13 | */
14 |
--------------------------------------------------------------------------------
/spec/dummy/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | protect_from_forgery
3 | end
4 |
--------------------------------------------------------------------------------
/spec/dummy/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/spec/dummy/app/mailers/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/spec/dummy/app/mailers/.gitkeep
--------------------------------------------------------------------------------
/spec/dummy/app/models/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/spec/dummy/app/models/.gitkeep
--------------------------------------------------------------------------------
/spec/dummy/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Dummy
5 | <%= stylesheet_link_tag "application", :media => "all" %>
6 | <%= javascript_include_tag "application" %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spec/dummy/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Dummy::Application
5 |
--------------------------------------------------------------------------------
/spec/dummy/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require 'action_controller/railtie'
4 | require 'active_model/railtie'
5 |
6 | Bundler.require(*Rails.groups)
7 | require 'simple_form'
8 |
9 | module Dummy
10 | class Application < Rails::Application
11 | # Settings in config/environments/* take precedence over those specified here.
12 | # Application configuration should go into files in config/initializers
13 | # -- all .rb files in that directory are automatically loaded.
14 |
15 | # Custom directories with classes and modules you want to be autoloadable.
16 | # config.autoload_paths += %W(#{config.root}/extras)
17 |
18 | # Only load the plugins named here, in the order given (default is alphabetical).
19 | # :all can be used as a placeholder for all plugins not explicitly named.
20 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21 |
22 | # Activate observers that should always be running.
23 |
24 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26 | # config.time_zone = 'Central Time (US & Canada)'
27 |
28 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30 | # config.i18n.default_locale = :de
31 |
32 | # Configure the default encoding used in templates for Ruby 1.9.
33 | config.encoding = "utf-8"
34 |
35 | # Configure sensitive parameters which will be filtered from the log file.
36 | config.filter_parameters += [:password]
37 |
38 | # Enable escaping HTML in JSON.
39 | config.active_support.escape_html_entities_in_json = true
40 |
41 | # Use SQL instead of Active Record's schema dumper when creating the database.
42 | # This is necessary if your schema can't be completely dumped by the schema dumper,
43 | # like if you have constraints or database-specific column types
44 |
45 | # Enforce whitelist mode for mass assignment.
46 | # This will create an empty whitelist of attributes available for mass-assignment for all models
47 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
48 | # parameters by using an attr_accessible or attr_protected declaration.
49 |
50 | config.secret_key_base = 'spam'
51 |
52 | config.active_support.test_order = :sorted
53 | end
54 | end
55 |
56 |
--------------------------------------------------------------------------------
/spec/dummy/config/boot.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3 |
4 | if File.exist?(gemfile)
5 | ENV['BUNDLE_GEMFILE'] = gemfile
6 | require 'bundler'
7 | Bundler.setup
8 | end
9 |
10 | $:.unshift File.expand_path('../../../../lib', __FILE__)
--------------------------------------------------------------------------------
/spec/dummy/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | development:
7 | adapter: sqlite3
8 | database: db/development.sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | # Warning: The database defined as "test" will be erased and
13 | # re-generated from your development database when you run "rake".
14 | # Do not set this db to the same as development or production.
15 | test:
16 | adapter: sqlite3
17 | database: db/test.sqlite3
18 | pool: 5
19 | timeout: 5000
20 |
21 | production:
22 | adapter: sqlite3
23 | database: db/production.sqlite3
24 | pool: 5
25 | timeout: 5000
26 |
--------------------------------------------------------------------------------
/spec/dummy/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the rails application
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the rails application
5 | Dummy::Application.initialize!
6 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Log error messages when you accidentally call methods on nil.
10 | config.whiny_nils = true
11 |
12 | # Show full error reports and disable caching
13 | config.consider_all_requests_local = true
14 | config.action_controller.perform_caching = false
15 |
16 | # Print deprecation notices to the Rails logger
17 | config.active_support.deprecation = :log
18 |
19 | # Only use best-standards-support built into browsers
20 | config.action_dispatch.best_standards_support = :builtin
21 |
22 | config.eager_load = false
23 | end
24 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # Code is not reloaded between requests
5 | config.cache_classes = true
6 |
7 | # Full error reports are disabled and caching is turned on
8 | config.consider_all_requests_local = false
9 | config.action_controller.perform_caching = true
10 |
11 | # Specifies the header that your server uses for sending files
12 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
13 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
14 |
15 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
16 | # config.force_ssl = true
17 |
18 | # See everything in the log (default is :info)
19 | # config.log_level = :debug
20 |
21 | # Prepend all log lines with the following tags
22 | # config.log_tags = [ :subdomain, :uuid ]
23 |
24 | # Use a different logger for distributed setups
25 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
26 |
27 | # Use a different cache store in production
28 | # config.cache_store = :mem_cache_store
29 |
30 | # Enable serving of images, stylesheets, and JavaScripts from an asset server
31 | # config.action_controller.asset_host = "http://assets.example.com"
32 |
33 | # Enable threaded mode
34 | # config.threadsafe!
35 |
36 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
37 | # the I18n.default_locale when a translation can not be found)
38 | config.i18n.fallbacks = true
39 |
40 | # Send deprecation notices to registered listeners
41 | config.active_support.deprecation = :notify
42 |
43 | # Log the query plan for queries taking more than this (works
44 | # with SQLite, MySQL, and PostgreSQL)
45 | # config.active_record.auto_explain_threshold_in_seconds = 0.5
46 | #
47 | config.eager_load = true
48 | end
49 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Log error messages when you accidentally call methods on nil
11 | config.whiny_nils = true
12 |
13 | # Show full error reports and disable caching
14 | config.consider_all_requests_local = true
15 | config.action_controller.perform_caching = false
16 |
17 | # Raise exceptions instead of rendering exception templates
18 | config.action_dispatch.show_exceptions = false
19 |
20 | # Disable request forgery protection in test environment
21 | config.action_controller.allow_forgery_protection = false
22 |
23 | # Print deprecation notices to the stderr
24 | config.active_support.deprecation = :stderr
25 |
26 | config.eager_load = false
27 | end
28 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format
4 | # (all these examples are active by default):
5 | # ActiveSupport::Inflector.inflections do |inflect|
6 | # inflect.plural /^(ox)$/i, '\1en'
7 | # inflect.singular /^(ox)en/i, '\1'
8 | # inflect.irregular 'person', 'people'
9 | # inflect.uncountable %w( fish sheep )
10 | # end
11 | #
12 | # These inflection rules are supported but not enabled by default:
13 | # ActiveSupport::Inflector.inflections do |inflect|
14 | # inflect.acronym 'RESTful'
15 | # end
16 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 | # Mime::Type.register_alias "text/html", :iphone
6 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/secret_token.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 | # Make sure the secret is at least 30 characters and all random,
6 | # no regular words or you'll be exposed to dictionary attacks.
7 | Dummy::Application.config.secret_token = '6f676f37b8c42a7842dbbbc6076c1c3cb1d315c2a50f5bf16ca276c22f5f55f44aefc93bfe15afdbaa9878cb8e654d494414d55af9fab4ab2a921e43c48806c4'
8 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4 |
5 | # Use the database for sessions instead of the cookie-based default,
6 | # which shouldn't be used to store highly confidential information
7 | # (create the session table with "rails generate session_migration")
8 | # Dummy::Application.config.session_store :active_record_store
9 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/simple_form.rb:
--------------------------------------------------------------------------------
1 | # Use this setup block to configure all options available in SimpleForm.
2 | SimpleForm.setup do |config|
3 | # Wrappers are used by the form builder to generate a
4 | # complete input. You can remove any component from the
5 | # wrapper, change the order or even add your own to the
6 | # stack. The options given below are used to wrap the
7 | # whole input.
8 | config.wrappers :default, class: :input,
9 | hint_class: :field_with_hint, error_class: :field_with_errors do |b|
10 | ## Extensions enabled by default
11 | # Any of these extensions can be disabled for a
12 | # given input by passing: `f.input EXTENSION_NAME => false`.
13 | # You can make any of these extensions optional by
14 | # renaming `b.use` to `b.optional`.
15 |
16 | # Determines whether to use HTML5 (:email, :url, ...)
17 | # and required attributes
18 | b.use :html5
19 |
20 | # Calculates placeholders automatically from I18n
21 | # You can also pass a string as f.input placeholder: "Placeholder"
22 | b.use :placeholder
23 |
24 | ## Optional extensions
25 | # They are disabled unless you pass `f.input EXTENSION_NAME => true`
26 | # to the input. If so, they will retrieve the values from the model
27 | # if any exists. If you want to enable any of those
28 | # extensions by default, you can change `b.optional` to `b.use`.
29 |
30 | # Calculates maxlength from length validations for string inputs
31 | b.optional :maxlength
32 |
33 | # Calculates pattern from format validations for string inputs
34 | b.optional :pattern
35 |
36 | # Calculates min and max from length validations for numeric inputs
37 | b.optional :min_max
38 |
39 | # Calculates readonly automatically from readonly attributes
40 | b.optional :readonly
41 |
42 | ## Inputs
43 | b.use :label_input
44 | b.use :hint, wrap_with: { tag: :span, class: :hint }
45 | b.use :error, wrap_with: { tag: :span, class: :error }
46 |
47 | ## full_messages_for
48 | # If you want to display the full error message for the attribute, you can
49 | # use the component :full_error, like:
50 | #
51 | # b.use :full_error, wrap_with: { tag: :span, class: :error }
52 | end
53 |
54 | # The default wrapper to be used by the FormBuilder.
55 | config.default_wrapper = :default
56 |
57 | # Define the way to render check boxes / radio buttons with labels.
58 | # Defaults to :nested for bootstrap config.
59 | # inline: input + label
60 | # nested: label > input
61 | config.boolean_style = :nested
62 |
63 | # Default class for buttons
64 | config.button_class = 'btn'
65 |
66 | # Method used to tidy up errors. Specify any Rails Array method.
67 | # :first lists the first message for each field.
68 | # Use :to_sentence to list all errors for each field.
69 | # config.error_method = :first
70 |
71 | # Default tag used for error notification helper.
72 | config.error_notification_tag = :div
73 |
74 | # CSS class to add for error notification helper.
75 | config.error_notification_class = 'error_notification'
76 |
77 | # ID to add for error notification helper.
78 | # config.error_notification_id = nil
79 |
80 | # Series of attempts to detect a default label method for collection.
81 | # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
82 |
83 | # Series of attempts to detect a default value method for collection.
84 | # config.collection_value_methods = [ :id, :to_s ]
85 |
86 | # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
87 | # config.collection_wrapper_tag = nil
88 |
89 | # You can define the class to use on all collection wrappers. Defaulting to none.
90 | # config.collection_wrapper_class = nil
91 |
92 | # You can wrap each item in a collection of radio/check boxes with a tag,
93 | # defaulting to :span. Please note that when using :boolean_style = :nested,
94 | # SimpleForm will force this option to be a label.
95 | # config.item_wrapper_tag = :span
96 |
97 | # You can define a class to use in all item wrappers. Defaulting to none.
98 | # config.item_wrapper_class = nil
99 |
100 | # How the label text should be generated altogether with the required text.
101 | # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
102 |
103 | # You can define the class to use on all labels. Default is nil.
104 | # config.label_class = nil
105 |
106 | # You can define the default class to be used on forms. Can be overriden
107 | # with `html: { :class }`. Defaulting to none.
108 | # config.default_form_class = nil
109 |
110 | # You can define which elements should obtain additional classes
111 | # config.generate_additional_classes_for = [:wrapper, :label, :input]
112 |
113 | # Whether attributes are required by default (or not). Default is true.
114 | # config.required_by_default = true
115 |
116 | # Tell browsers whether to use the native HTML5 validations (novalidate form option).
117 | # These validations are enabled in SimpleForm's internal config but disabled by default
118 | # in this configuration, which is recommended due to some quirks from different browsers.
119 | # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
120 | # change this configuration to true.
121 | config.browser_validations = false
122 |
123 | # Collection of methods to detect if a file type was given.
124 | # config.file_methods = [ :mounted_as, :file?, :public_filename ]
125 |
126 | # Custom mappings for input types. This should be a hash containing a regexp
127 | # to match as key, and the input type that will be used when the field name
128 | # matches the regexp as value.
129 | # config.input_mappings = { /count/ => :integer }
130 |
131 | # Custom wrappers for input types. This should be a hash containing an input
132 | # type as key and the wrapper that will be used for all inputs with specified type.
133 | # config.wrapper_mappings = { string: :prepend }
134 |
135 | # Namespaces where SimpleForm should look for custom input classes that
136 | # override default inputs.
137 | # config.custom_inputs_namespaces << "CustomInputs"
138 |
139 | # Default priority for time_zone inputs.
140 | # config.time_zone_priority = nil
141 |
142 | # Default priority for country inputs.
143 | # config.country_priority = nil
144 |
145 | # When false, do not use translations for labels.
146 | # config.translate_labels = true
147 |
148 | # Automatically discover new inputs in Rails' autoload path.
149 | # config.inputs_discovery = true
150 |
151 | # Cache SimpleForm inputs discovery
152 | # config.cache_discovery = !Rails.env.development?
153 |
154 | # Default class for inputs
155 | # config.input_class = nil
156 |
157 | # Define the default class of the input wrapper of the boolean input.
158 | config.boolean_label_class = 'checkbox'
159 |
160 | # Defines if the default input wrapper class should be included in radio
161 | # collection wrappers.
162 | # config.include_default_input_wrapper_class = true
163 |
164 | # Defines which i18n scope will be used in Simple Form.
165 | # config.i18n_scope = 'simple_form'
166 | end
167 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 | #
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
--------------------------------------------------------------------------------
/spec/dummy/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Sample localization file for English. Add more files in this directory for other locales.
2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3 |
4 | en:
5 | hello: "Hello world"
6 |
--------------------------------------------------------------------------------
/spec/dummy/config/locales/simple_form.en.yml:
--------------------------------------------------------------------------------
1 | en:
2 | simple_form:
3 | "yes": 'Yes'
4 | "no": 'No'
5 | required:
6 | text: 'required'
7 | mark: '*'
8 | # You can uncomment the line below if you need to overwrite the whole required html.
9 | # When using html, text and mark won't be used.
10 | # html: '*'
11 | error_notification:
12 | default_message: "Please review the problems below:"
13 | # Examples
14 | # labels:
15 | # defaults:
16 | # password: 'Password'
17 | # user:
18 | # new:
19 | # email: 'E-mail to sign in.'
20 | # edit:
21 | # email: 'E-mail.'
22 | # hints:
23 | # defaults:
24 | # username: 'User name to sign in.'
25 | # password: 'No special characters, please.'
26 | # include_blanks:
27 | # defaults:
28 | # age: 'Rather not say'
29 | # prompts:
30 | # defaults:
31 | # age: 'Select your age'
32 |
--------------------------------------------------------------------------------
/spec/dummy/config/routes.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.routes.draw do
2 | # The priority is based upon order of creation:
3 | # first created -> highest priority.
4 |
5 | # Sample of regular route:
6 | # match 'products/:id' => 'catalog#view'
7 | # Keep in mind you can assign values other than :controller and :action
8 |
9 | # Sample of named route:
10 | # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11 | # This route can be invoked with purchase_url(:id => product.id)
12 |
13 | # Sample resource route (maps HTTP verbs to controller actions automatically):
14 | # resources :products
15 |
16 | # Sample resource route with options:
17 | # resources :products do
18 | # member do
19 | # get 'short'
20 | # post 'toggle'
21 | # end
22 | #
23 | # collection do
24 | # get 'sold'
25 | # end
26 | # end
27 |
28 | # Sample resource route with sub-resources:
29 | # resources :products do
30 | # resources :comments, :sales
31 | # resource :seller
32 | # end
33 |
34 | # Sample resource route with more complex sub-resources
35 | # resources :products do
36 | # resources :comments
37 | # resources :sales do
38 | # get 'recent', :on => :collection
39 | # end
40 | # end
41 |
42 | # Sample resource route within a namespace:
43 | # namespace :admin do
44 | # # Directs /admin/products/* to Admin::ProductsController
45 | # # (app/controllers/admin/products_controller.rb)
46 | # resources :products
47 | # end
48 |
49 | # You can have the root of your site routed with "root"
50 | # just remember to delete public/index.html.
51 | # root :to => 'welcome#index'
52 |
53 | # See how all your routes lay out with "rake routes"
54 |
55 | # This is a legacy wild controller route that's not recommended for RESTful applications.
56 | # Note: This route will make all actions in every controller accessible via GET requests.
57 | # match ':controller(/:action(/:id))(.:format)'
58 | end
59 |
--------------------------------------------------------------------------------
/spec/dummy/lib/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/spec/dummy/lib/assets/.gitkeep
--------------------------------------------------------------------------------
/spec/dummy/lib/templates/erb/scaffold/_form.html.erb:
--------------------------------------------------------------------------------
1 | <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2 | <%%= f.error_notification %>
3 |
4 |
5 | <%- attributes.each do |attribute| -%>
6 | <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7 | <%- end -%>
8 |
9 |
10 |
11 | <%%= f.button :submit %>
12 |
13 | <%% end %>
14 |
--------------------------------------------------------------------------------
/spec/dummy/log/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/spec/dummy/log/.gitkeep
--------------------------------------------------------------------------------
/spec/dummy/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The page you were looking for doesn't exist.
23 |
You may have mistyped the address or the page may have moved.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spec/dummy/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The change you wanted was rejected.
23 |
Maybe you tried to change something you didn't have access to.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spec/dummy/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
We're sorry, but something went wrong.
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/spec/dummy/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/spec/dummy/public/favicon.ico
--------------------------------------------------------------------------------
/spec/dummy/script/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3 |
4 | APP_PATH = File.expand_path('../../config/application', __FILE__)
5 | require File.expand_path('../../config/boot', __FILE__)
6 | require 'rails/commands'
7 |
--------------------------------------------------------------------------------
/spec/inputs/minicolors_input_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'minicolors input' do
4 | it 'passes minicolors settings' do
5 | markup = helper.simple_form_for :foo, url: '' do |f|
6 | f.input :minicolors, as: :minicolors, input_html: {data: {minicolors: {theme: :bootstrap}}}
7 | end
8 | doc = Nokogiri::HTML(markup)
9 | expect(MultiJson.decode(doc.css('#foo_minicolors').attr('data-minicolors').text)).
10 | to eq('theme' => 'bootstrap')
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | ENV['RAILS_ENV'] = 'test'
2 |
3 | require File.expand_path('../dummy/config/environment.rb', __FILE__)
4 | require 'rails/test_help'
5 | require 'rspec/rails'
6 | require 'multi_json'
7 | require 'webrat'
8 |
9 | Rails.backtrace_cleaner.remove_silencers!
10 |
11 | RSpec.configure do |config|
12 | config.include RSpec::Rails::HelperExampleGroup
13 | config.include Webrat::Matchers
14 | end
15 |
--------------------------------------------------------------------------------
/test_app/.gitignore:
--------------------------------------------------------------------------------
1 | .bundle/
2 | Gemfile.lock
3 | bin
4 | log/*.log
5 | tmp
6 | public/assets
7 |
--------------------------------------------------------------------------------
/test_app/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'rails', '6.0.0'
4 | gem 'jquery-minicolors-rails', path: '../'
5 |
6 | gem 'bootstrap-sass', '~> 3.3.6'
7 | gem 'jbuilder', '~> 2.0'
8 | gem 'jquery-rails'
9 | gem 'sass-rails', '~> 5.0'
10 | gem 'sdoc', '~> 0.4.0', group: :doc
11 | gem 'simple_form'
12 | gem 'turbolinks'
13 | gem 'uglifier', '>= 1.3.0'
14 |
15 | group :development, :test do
16 | gem 'byebug'
17 | end
18 |
19 | group :development do
20 | gem 'spring'
21 | gem 'web-console'
22 | end
23 |
24 |
--------------------------------------------------------------------------------
/test_app/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require File.expand_path('../config/application', __FILE__)
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/test_app/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/app/assets/images/.keep
--------------------------------------------------------------------------------
/test_app/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | //= require jquery
2 | //= require jquery_ujs
3 | //= require turbolinks
4 | //= require bootstrap-sprockets
5 |
6 | //= require jquery.minicolors
7 | //= require jquery.minicolors.simple_form
8 |
9 | //= require_self
10 |
11 | $(function() { $('input[type=text]').minicolors(); });
12 |
--------------------------------------------------------------------------------
/test_app/app/assets/stylesheets/application.scss:
--------------------------------------------------------------------------------
1 | @import "bootstrap-sprockets";
2 | @import "bootstrap";
3 | @import "jquery.minicolors";
4 |
--------------------------------------------------------------------------------
/test_app/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | # Prevent CSRF attacks by raising an exception.
3 | # For APIs, you may want to use :null_session instead.
4 | protect_from_forgery with: :exception
5 | end
6 |
--------------------------------------------------------------------------------
/test_app/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/test_app/app/controllers/test_controller.rb:
--------------------------------------------------------------------------------
1 | class TestController < ApplicationController
2 | def index
3 | @balloon = OpenStruct.new(color: '#3a8a2f')
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/test_app/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/test_app/app/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/app/mailers/.keep
--------------------------------------------------------------------------------
/test_app/app/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/app/models/.keep
--------------------------------------------------------------------------------
/test_app/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/app/models/concerns/.keep
--------------------------------------------------------------------------------
/test_app/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TestApp
5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test_app/app/views/test/index.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%= simple_form_for :balloon, url: :root, html: {class: 'form-horizontal'} do |f| %>
4 | <%= f.input :color, as: :minicolors, input_html: {data: {
5 | minicolors: {theme: :bootstrap, position: :right}}} %>
6 | <% end %>
7 |
8 |
9 |
--------------------------------------------------------------------------------
/test_app/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Rails.application
5 |
--------------------------------------------------------------------------------
/test_app/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require "rails"
4 | # Pick the frameworks you want:
5 | require "active_model/railtie"
6 | require "active_job/railtie"
7 | # require "active_record/railtie"
8 | require "action_controller/railtie"
9 | require "action_mailer/railtie"
10 | require "action_view/railtie"
11 | require "sprockets/railtie"
12 | require "rails/test_unit/railtie"
13 |
14 | # Require the gems listed in Gemfile, including any gems
15 | # you've limited to :test, :development, or :production.
16 | Bundler.require(*Rails.groups)
17 |
18 | module TestApp
19 | class Application < Rails::Application
20 | # Settings in config/environments/* take precedence over those specified here.
21 | # Application configuration should go into files in config/initializers
22 | # -- all .rb files in that directory are automatically loaded.
23 |
24 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26 | # config.time_zone = 'Central Time (US & Canada)'
27 |
28 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30 | # config.i18n.default_locale = :de
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/test_app/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/test_app/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/test_app/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports and disable caching.
13 | config.consider_all_requests_local = true
14 | config.action_controller.perform_caching = false
15 |
16 | # Don't care if the mailer can't send.
17 | config.action_mailer.raise_delivery_errors = false
18 |
19 | # Print deprecation notices to the Rails logger.
20 | config.active_support.deprecation = :log
21 |
22 | # Debug mode disables concatenation and preprocessing of assets.
23 | # This option may cause significant delays in view rendering with a large
24 | # number of complex assets.
25 | config.assets.debug = true
26 |
27 | # Asset digests allow you to set far-future HTTP expiration dates on all assets,
28 | # yet still be able to expire them through the digest params.
29 | config.assets.digest = true
30 |
31 | # Adds additional error checking when serving assets at runtime.
32 | # Checks for improperly declared sprockets dependencies.
33 | # Raises helpful error messages.
34 | config.assets.raise_runtime_errors = true
35 |
36 | # Raises error for missing translations
37 | # config.action_view.raise_on_missing_translations = true
38 | end
39 |
--------------------------------------------------------------------------------
/test_app/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both threaded web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application
18 | # Add `rack-cache` to your Gemfile before enabling this.
19 | # For large-scale production use, consider using a caching reverse proxy like
20 | # NGINX, varnish or squid.
21 | # config.action_dispatch.rack_cache = true
22 |
23 | # Disable serving static files from the `/public` folder by default since
24 | # Apache or NGINX already handles this.
25 | config.serve_static_files = true
26 |
27 | # Compress JavaScripts and CSS.
28 | config.assets.js_compressor = :uglifier
29 | # config.assets.css_compressor = :sass
30 |
31 | # Do not fallback to assets pipeline if a precompiled asset is missed.
32 | config.assets.compile = false
33 |
34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35 | # yet still be able to expire them through the digest params.
36 | config.assets.digest = true
37 |
38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
39 |
40 | # Specifies the header that your server uses for sending files.
41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
43 |
44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45 | # config.force_ssl = true
46 |
47 | # Use the lowest log level to ensure availability of diagnostic information
48 | # when problems arise.
49 | config.log_level = :debug
50 |
51 | # Prepend all log lines with the following tags.
52 | # config.log_tags = [ :subdomain, :uuid ]
53 |
54 | # Use a different logger for distributed setups.
55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
56 |
57 | # Use a different cache store in production.
58 | # config.cache_store = :mem_cache_store
59 |
60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61 | # config.action_controller.asset_host = 'http://assets.example.com'
62 |
63 | # Ignore bad email addresses and do not raise email delivery errors.
64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65 | # config.action_mailer.raise_delivery_errors = false
66 |
67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68 | # the I18n.default_locale when a translation cannot be found).
69 | config.i18n.fallbacks = true
70 |
71 | # Send deprecation notices to registered listeners.
72 | config.active_support.deprecation = :notify
73 |
74 | # Use default logging formatter so that PID and timestamp are not suppressed.
75 | config.log_formatter = ::Logger::Formatter.new
76 | end
77 |
--------------------------------------------------------------------------------
/test_app/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure static file server for tests with Cache-Control for performance.
16 | config.serve_static_files = true
17 | config.static_cache_control = 'public, max-age=3600'
18 |
19 | # Show full error reports and disable caching.
20 | config.consider_all_requests_local = true
21 | config.action_controller.perform_caching = false
22 |
23 | # Raise exceptions instead of rendering exception templates.
24 | config.action_dispatch.show_exceptions = false
25 |
26 | # Disable request forgery protection in test environment.
27 | config.action_controller.allow_forgery_protection = false
28 |
29 | # Tell Action Mailer not to deliver emails to the real world.
30 | # The :test delivery method accumulates sent emails in the
31 | # ActionMailer::Base.deliveries array.
32 | config.action_mailer.delivery_method = :test
33 |
34 | # Randomize the order test cases are executed.
35 | config.active_support.test_order = :random
36 |
37 | # Print deprecation notices to the stderr.
38 | config.active_support.deprecation = :stderr
39 |
40 | # Raises error for missing translations
41 | # config.action_view.raise_on_missing_translations = true
42 | end
43 |
--------------------------------------------------------------------------------
/test_app/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11 | # Rails.application.config.assets.precompile += %w( search.js )
12 |
--------------------------------------------------------------------------------
/test_app/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/test_app/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.action_dispatch.cookies_serializer = :json
4 |
--------------------------------------------------------------------------------
/test_app/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/test_app/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/test_app/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/test_app/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.session_store :cookie_store, key: '_test_app_session'
4 |
--------------------------------------------------------------------------------
/test_app/config/initializers/simple_form.rb:
--------------------------------------------------------------------------------
1 | # Use this setup block to configure all options available in SimpleForm.
2 | SimpleForm.setup do |config|
3 | # Wrappers are used by the form builder to generate a
4 | # complete input. You can remove any component from the
5 | # wrapper, change the order or even add your own to the
6 | # stack. The options given below are used to wrap the
7 | # whole input.
8 | config.wrappers :default, class: :input,
9 | hint_class: :field_with_hint, error_class: :field_with_errors do |b|
10 | ## Extensions enabled by default
11 | # Any of these extensions can be disabled for a
12 | # given input by passing: `f.input EXTENSION_NAME => false`.
13 | # You can make any of these extensions optional by
14 | # renaming `b.use` to `b.optional`.
15 |
16 | # Determines whether to use HTML5 (:email, :url, ...)
17 | # and required attributes
18 | b.use :html5
19 |
20 | # Calculates placeholders automatically from I18n
21 | # You can also pass a string as f.input placeholder: "Placeholder"
22 | b.use :placeholder
23 |
24 | ## Optional extensions
25 | # They are disabled unless you pass `f.input EXTENSION_NAME => true`
26 | # to the input. If so, they will retrieve the values from the model
27 | # if any exists. If you want to enable any of those
28 | # extensions by default, you can change `b.optional` to `b.use`.
29 |
30 | # Calculates maxlength from length validations for string inputs
31 | b.optional :maxlength
32 |
33 | # Calculates pattern from format validations for string inputs
34 | b.optional :pattern
35 |
36 | # Calculates min and max from length validations for numeric inputs
37 | b.optional :min_max
38 |
39 | # Calculates readonly automatically from readonly attributes
40 | b.optional :readonly
41 |
42 | ## Inputs
43 | b.use :label_input
44 | b.use :hint, wrap_with: { tag: :span, class: :hint }
45 | b.use :error, wrap_with: { tag: :span, class: :error }
46 |
47 | ## full_messages_for
48 | # If you want to display the full error message for the attribute, you can
49 | # use the component :full_error, like:
50 | #
51 | # b.use :full_error, wrap_with: { tag: :span, class: :error }
52 | end
53 |
54 | # The default wrapper to be used by the FormBuilder.
55 | config.default_wrapper = :default
56 |
57 | # Define the way to render check boxes / radio buttons with labels.
58 | # Defaults to :nested for bootstrap config.
59 | # inline: input + label
60 | # nested: label > input
61 | config.boolean_style = :nested
62 |
63 | # Default class for buttons
64 | config.button_class = 'btn'
65 |
66 | # Method used to tidy up errors. Specify any Rails Array method.
67 | # :first lists the first message for each field.
68 | # Use :to_sentence to list all errors for each field.
69 | # config.error_method = :first
70 |
71 | # Default tag used for error notification helper.
72 | config.error_notification_tag = :div
73 |
74 | # CSS class to add for error notification helper.
75 | config.error_notification_class = 'error_notification'
76 |
77 | # ID to add for error notification helper.
78 | # config.error_notification_id = nil
79 |
80 | # Series of attempts to detect a default label method for collection.
81 | # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
82 |
83 | # Series of attempts to detect a default value method for collection.
84 | # config.collection_value_methods = [ :id, :to_s ]
85 |
86 | # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
87 | # config.collection_wrapper_tag = nil
88 |
89 | # You can define the class to use on all collection wrappers. Defaulting to none.
90 | # config.collection_wrapper_class = nil
91 |
92 | # You can wrap each item in a collection of radio/check boxes with a tag,
93 | # defaulting to :span.
94 | # config.item_wrapper_tag = :span
95 |
96 | # You can define a class to use in all item wrappers. Defaulting to none.
97 | # config.item_wrapper_class = nil
98 |
99 | # How the label text should be generated altogether with the required text.
100 | # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
101 |
102 | # You can define the class to use on all labels. Default is nil.
103 | # config.label_class = nil
104 |
105 | # You can define the default class to be used on forms. Can be overriden
106 | # with `html: { :class }`. Defaulting to none.
107 | # config.default_form_class = nil
108 |
109 | # You can define which elements should obtain additional classes
110 | # config.generate_additional_classes_for = [:wrapper, :label, :input]
111 |
112 | # Whether attributes are required by default (or not). Default is true.
113 | # config.required_by_default = true
114 |
115 | # Tell browsers whether to use the native HTML5 validations (novalidate form option).
116 | # These validations are enabled in SimpleForm's internal config but disabled by default
117 | # in this configuration, which is recommended due to some quirks from different browsers.
118 | # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
119 | # change this configuration to true.
120 | config.browser_validations = false
121 |
122 | # Collection of methods to detect if a file type was given.
123 | # config.file_methods = [ :mounted_as, :file?, :public_filename ]
124 |
125 | # Custom mappings for input types. This should be a hash containing a regexp
126 | # to match as key, and the input type that will be used when the field name
127 | # matches the regexp as value.
128 | # config.input_mappings = { /count/ => :integer }
129 |
130 | # Custom wrappers for input types. This should be a hash containing an input
131 | # type as key and the wrapper that will be used for all inputs with specified type.
132 | # config.wrapper_mappings = { string: :prepend }
133 |
134 | # Namespaces where SimpleForm should look for custom input classes that
135 | # override default inputs.
136 | # config.custom_inputs_namespaces << "CustomInputs"
137 |
138 | # Default priority for time_zone inputs.
139 | # config.time_zone_priority = nil
140 |
141 | # Default priority for country inputs.
142 | # config.country_priority = nil
143 |
144 | # When false, do not use translations for labels.
145 | # config.translate_labels = true
146 |
147 | # Automatically discover new inputs in Rails' autoload path.
148 | # config.inputs_discovery = true
149 |
150 | # Cache SimpleForm inputs discovery
151 | # config.cache_discovery = !Rails.env.development?
152 |
153 | # Default class for inputs
154 | # config.input_class = nil
155 |
156 | # Define the default class of the input wrapper of the boolean input.
157 | config.boolean_label_class = 'checkbox'
158 |
159 | # Defines if the default input wrapper class should be included in radio
160 | # collection wrappers.
161 | # config.include_default_input_wrapper_class = true
162 |
163 | # Defines which i18n scope will be used in Simple Form.
164 | # config.i18n_scope = 'simple_form'
165 | end
166 |
--------------------------------------------------------------------------------
/test_app/config/initializers/simple_form_bootstrap.rb:
--------------------------------------------------------------------------------
1 | # Use this setup block to configure all options available in SimpleForm.
2 | SimpleForm.setup do |config|
3 | config.error_notification_class = 'alert alert-danger'
4 | config.button_class = 'btn btn-default'
5 | config.boolean_label_class = nil
6 |
7 | config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
8 | b.use :html5
9 | b.use :placeholder
10 | b.optional :maxlength
11 | b.optional :pattern
12 | b.optional :min_max
13 | b.optional :readonly
14 | b.use :label, class: 'control-label'
15 |
16 | b.use :input, class: 'form-control'
17 | b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
18 | b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
19 | end
20 |
21 | config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
22 | b.use :html5
23 | b.use :placeholder
24 | b.optional :maxlength
25 | b.optional :readonly
26 | b.use :label, class: 'control-label'
27 |
28 | b.use :input
29 | b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
30 | b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
31 | end
32 |
33 | config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
34 | b.use :html5
35 | b.optional :readonly
36 |
37 | b.wrapper tag: 'div', class: 'checkbox' do |ba|
38 | ba.use :label_input
39 | end
40 |
41 | b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
42 | b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
43 | end
44 |
45 | config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
46 | b.use :html5
47 | b.optional :readonly
48 | b.use :label, class: 'control-label'
49 | b.use :input
50 | b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
51 | b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
52 | end
53 |
54 | config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
55 | b.use :html5
56 | b.use :placeholder
57 | b.optional :maxlength
58 | b.optional :pattern
59 | b.optional :min_max
60 | b.optional :readonly
61 | b.use :label, class: 'col-sm-3 control-label'
62 |
63 | b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
64 | ba.use :input, class: 'form-control'
65 | ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
66 | ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
67 | end
68 | end
69 |
70 | config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
71 | b.use :html5
72 | b.use :placeholder
73 | b.optional :maxlength
74 | b.optional :readonly
75 | b.use :label, class: 'col-sm-3 control-label'
76 |
77 | b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
78 | ba.use :input
79 | ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
80 | ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
81 | end
82 | end
83 |
84 | config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
85 | b.use :html5
86 | b.optional :readonly
87 |
88 | b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
89 | wr.wrapper tag: 'div', class: 'checkbox' do |ba|
90 | ba.use :label_input
91 | end
92 |
93 | wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
94 | wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
95 | end
96 | end
97 |
98 | config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
99 | b.use :html5
100 | b.optional :readonly
101 |
102 | b.use :label, class: 'col-sm-3 control-label'
103 |
104 | b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
105 | ba.use :input
106 | ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
107 | ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
108 | end
109 | end
110 |
111 | config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
112 | b.use :html5
113 | b.use :placeholder
114 | b.optional :maxlength
115 | b.optional :pattern
116 | b.optional :min_max
117 | b.optional :readonly
118 | b.use :label, class: 'sr-only'
119 |
120 | b.use :input, class: 'form-control'
121 | b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
122 | b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
123 | end
124 |
125 | config.wrappers :multi_select, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
126 | b.use :html5
127 | b.optional :readonly
128 | b.use :label, class: 'control-label'
129 | b.wrapper tag: 'div', class: 'form-inline' do |ba|
130 | ba.use :input, class: 'form-control'
131 | ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
132 | ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
133 | end
134 | end
135 | # Wrappers for forms and inputs using the Bootstrap toolkit.
136 | # Check the Bootstrap docs (http://getbootstrap.com)
137 | # to learn about the different styles for forms and inputs,
138 | # buttons and other elements.
139 | config.default_wrapper = :vertical_form
140 | config.wrapper_mappings = {
141 | check_boxes: :vertical_radio_and_checkboxes,
142 | radio_buttons: :vertical_radio_and_checkboxes,
143 | file: :vertical_file_input,
144 | boolean: :vertical_boolean,
145 | datetime: :multi_select,
146 | date: :multi_select,
147 | time: :multi_select
148 | }
149 | end
150 |
--------------------------------------------------------------------------------
/test_app/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9 | end
10 |
--------------------------------------------------------------------------------
/test_app/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/test_app/config/locales/simple_form.en.yml:
--------------------------------------------------------------------------------
1 | en:
2 | simple_form:
3 | "yes": 'Yes'
4 | "no": 'No'
5 | required:
6 | text: 'required'
7 | mark: '*'
8 | # You can uncomment the line below if you need to overwrite the whole required html.
9 | # When using html, text and mark won't be used.
10 | # html: '*'
11 | error_notification:
12 | default_message: "Please review the problems below:"
13 | # Examples
14 | # labels:
15 | # defaults:
16 | # password: 'Password'
17 | # user:
18 | # new:
19 | # email: 'E-mail to sign in.'
20 | # edit:
21 | # email: 'E-mail.'
22 | # hints:
23 | # defaults:
24 | # username: 'User name to sign in.'
25 | # password: 'No special characters, please.'
26 | # include_blanks:
27 | # defaults:
28 | # age: 'Rather not say'
29 | # prompts:
30 | # defaults:
31 | # age: 'Select your age'
32 |
--------------------------------------------------------------------------------
/test_app/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | root to: 'test#index'
3 | end
4 |
--------------------------------------------------------------------------------
/test_app/config/secrets.yml:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rake secret` to generate a secure secret key.
9 |
10 | # Make sure the secrets in this file are kept private
11 | # if you're sharing your code publicly.
12 |
13 | development:
14 | secret_key_base: a58aec9dbe91c0268acd47f3f2cb998a1bd2a801402851c78668e86729e27a07371ccd66120a6b206e1cc76cbf8db810d889fa7ee109a7ea0711e7188446a2d5
15 |
16 | test:
17 | secret_key_base: d91774821e17adcc20d37124cefb34736dffbd68591aba2fb85bb9170e731aa0a29837bd68dc334de4317c8aff763ccf218d384986b8f931f592eb8386666c48
18 |
19 | # Do not keep production secrets in the repository,
20 | # instead read values from the environment.
21 | production:
22 | secret_key_base: a58aec9dbe91c0268acd47f3f2cb998a1bd2a801402851c78668e86729e27a07371ccd66120a6b206e1cc76cbf8db810d889fa7ee109a7ea0711e7188446a2d5
23 |
--------------------------------------------------------------------------------
/test_app/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 |
--------------------------------------------------------------------------------
/test_app/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/lib/assets/.keep
--------------------------------------------------------------------------------
/test_app/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/lib/tasks/.keep
--------------------------------------------------------------------------------
/test_app/lib/templates/erb/scaffold/_form.html.erb:
--------------------------------------------------------------------------------
1 | <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2 | <%%= f.error_notification %>
3 |
4 |
5 | <%- attributes.each do |attribute| -%>
6 | <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7 | <%- end -%>
8 |
9 |
10 |
11 | <%%= f.button :submit %>
12 |
13 | <%% end %>
14 |
--------------------------------------------------------------------------------
/test_app/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/log/.keep
--------------------------------------------------------------------------------
/test_app/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/test_app/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The change you wanted was rejected.
62 |
Maybe you tried to change something you didn't have access to.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/test_app/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/test_app/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/public/favicon.ico
--------------------------------------------------------------------------------
/test_app/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/test_app/test/controllers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/test/controllers/.keep
--------------------------------------------------------------------------------
/test_app/test/fixtures/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/test/fixtures/.keep
--------------------------------------------------------------------------------
/test_app/test/helpers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/test/helpers/.keep
--------------------------------------------------------------------------------
/test_app/test/integration/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/test/integration/.keep
--------------------------------------------------------------------------------
/test_app/test/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/test/mailers/.keep
--------------------------------------------------------------------------------
/test_app/test/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/test/models/.keep
--------------------------------------------------------------------------------
/test_app/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | ENV['RAILS_ENV'] ||= 'test'
2 | require File.expand_path('../../config/environment', __FILE__)
3 | require 'rails/test_help'
4 |
5 | class ActiveSupport::TestCase
6 | # Add more helper methods to be used by all tests here...
7 | end
8 |
--------------------------------------------------------------------------------
/test_app/vendor/assets/javascripts/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/vendor/assets/javascripts/.keep
--------------------------------------------------------------------------------
/test_app/vendor/assets/stylesheets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kostia/jquery-minicolors-rails/39aa380d06a824400080882bbb9d8e01f4a9e019/test_app/vendor/assets/stylesheets/.keep
--------------------------------------------------------------------------------
/vendor/assets/javascripts/jquery.minicolors.js:
--------------------------------------------------------------------------------
1 | //
2 | // jQuery MiniColors: A tiny color picker built on jQuery
3 | //
4 | // Developed by Cory LaViska for A Beautiful Site, LLC
5 | //
6 | // Licensed under the MIT license: http://opensource.org/licenses/MIT
7 | //
8 | (function (factory) {
9 | if(typeof define === 'function' && define.amd) {
10 | // AMD. Register as an anonymous module.
11 | define(['jquery'], factory);
12 | } else if(typeof exports === 'object') {
13 | // Node/CommonJS
14 | module.exports = factory(require('jquery'));
15 | } else {
16 | // Browser globals
17 | factory(jQuery);
18 | }
19 | }(function ($) {
20 | 'use strict';
21 |
22 | // Defaults
23 | $.minicolors = {
24 | defaults: {
25 | animationSpeed: 50,
26 | animationEasing: 'swing',
27 | change: null,
28 | changeDelay: 0,
29 | control: 'hue',
30 | defaultValue: '',
31 | format: 'hex',
32 | hide: null,
33 | hideSpeed: 100,
34 | inline: false,
35 | keywords: '',
36 | letterCase: 'lowercase',
37 | opacity: false,
38 | position: 'bottom left',
39 | show: null,
40 | showSpeed: 100,
41 | theme: 'default',
42 | swatches: []
43 | }
44 | };
45 |
46 | // Public methods
47 | $.extend($.fn, {
48 | minicolors: function(method, data) {
49 |
50 | switch(method) {
51 | // Destroy the control
52 | case 'destroy':
53 | $(this).each(function() {
54 | destroy($(this));
55 | });
56 | return $(this);
57 |
58 | // Hide the color picker
59 | case 'hide':
60 | hide();
61 | return $(this);
62 |
63 | // Get/set opacity
64 | case 'opacity':
65 | // Getter
66 | if(data === undefined) {
67 | // Getter
68 | return $(this).attr('data-opacity');
69 | } else {
70 | // Setter
71 | $(this).each(function() {
72 | updateFromInput($(this).attr('data-opacity', data));
73 | });
74 | }
75 | return $(this);
76 |
77 | // Get an RGB(A) object based on the current color/opacity
78 | case 'rgbObject':
79 | return rgbObject($(this), method === 'rgbaObject');
80 |
81 | // Get an RGB(A) string based on the current color/opacity
82 | case 'rgbString':
83 | case 'rgbaString':
84 | return rgbString($(this), method === 'rgbaString');
85 |
86 | // Get/set settings on the fly
87 | case 'settings':
88 | if(data === undefined) {
89 | return $(this).data('minicolors-settings');
90 | } else {
91 | // Setter
92 | $(this).each(function() {
93 | var settings = $(this).data('minicolors-settings') || {};
94 | destroy($(this));
95 | $(this).minicolors($.extend(true, settings, data));
96 | });
97 | }
98 | return $(this);
99 |
100 | // Show the color picker
101 | case 'show':
102 | show($(this).eq(0));
103 | return $(this);
104 |
105 | // Get/set the hex color value
106 | case 'value':
107 | if(data === undefined) {
108 | // Getter
109 | return $(this).val();
110 | } else {
111 | // Setter
112 | $(this).each(function() {
113 | if(typeof(data) === 'object' && data !== 'null') {
114 | if(data.opacity) {
115 | $(this).attr('data-opacity', keepWithin(data.opacity, 0, 1));
116 | }
117 | if(data.color) {
118 | $(this).val(data.color);
119 | }
120 | } else {
121 | $(this).val(data);
122 | }
123 | updateFromInput($(this));
124 | });
125 | }
126 | return $(this);
127 |
128 | // Initializes the control
129 | default:
130 | if(method !== 'create') data = method;
131 | $(this).each(function() {
132 | init($(this), data);
133 | });
134 | return $(this);
135 |
136 | }
137 |
138 | }
139 | });
140 |
141 | // Initialize input elements
142 | function init(input, settings) {
143 | var minicolors = $('');
144 | var defaults = $.minicolors.defaults;
145 | var size;
146 | var swatches;
147 | var swatch;
148 | var panel;
149 | var i;
150 |
151 | // Do nothing if already initialized
152 | if(input.data('minicolors-initialized')) return;
153 |
154 | // Handle settings
155 | settings = $.extend(true, {}, defaults, settings);
156 |
157 | // The wrapper
158 | minicolors
159 | .addClass('minicolors-theme-' + settings.theme)
160 | .toggleClass('minicolors-with-opacity', settings.opacity);
161 |
162 | // Custom positioning
163 | if(settings.position !== undefined) {
164 | $.each(settings.position.split(' '), function() {
165 | minicolors.addClass('minicolors-position-' + this);
166 | });
167 | }
168 |
169 | // Input size
170 | if(settings.format === 'rgb') {
171 | size = settings.opacity ? '25' : '20';
172 | } else {
173 | size = settings.keywords ? '11' : '7';
174 | }
175 |
176 | // The input
177 | input
178 | .addClass('minicolors-input')
179 | .data('minicolors-initialized', false)
180 | .data('minicolors-settings', settings)
181 | .prop('size', size)
182 | .wrap(minicolors)
183 | .after(
184 | '' +
185 | '
' +
188 | '
' +
191 | '
' +
192 | '
' +
193 | '
' +
194 | '
' +
195 | '
'
196 | );
197 |
198 | // The swatch
199 | if(!settings.inline) {
200 | input.after('');
201 | input.next('.minicolors-input-swatch').on('click', function(event) {
202 | event.preventDefault();
203 | input.focus();
204 | });
205 | }
206 |
207 | // Prevent text selection in IE
208 | panel = input.parent().find('.minicolors-panel');
209 | panel.on('selectstart', function() { return false; }).end();
210 |
211 | // Swatches
212 | if(settings.swatches && settings.swatches.length !== 0) {
213 | panel.addClass('minicolors-with-swatches');
214 | swatches = $('')
215 | .appendTo(panel);
216 | for(i = 0; i < settings.swatches.length; ++i) {
217 | swatch = settings.swatches[i];
218 | swatch = isRgb(swatch) ? parseRgb(swatch, true) : hex2rgb(parseHex(swatch, true));
219 | $('')
220 | .appendTo(swatches)
221 | .data('swatch-color', settings.swatches[i])
222 | .find('.minicolors-swatch-color')
223 | .css({
224 | backgroundColor: rgb2hex(swatch),
225 | opacity: swatch.a
226 | });
227 | settings.swatches[i] = swatch;
228 | }
229 | }
230 |
231 | // Inline controls
232 | if(settings.inline) input.parent().addClass('minicolors-inline');
233 |
234 | updateFromInput(input, false);
235 |
236 | input.data('minicolors-initialized', true);
237 | }
238 |
239 | // Returns the input back to its original state
240 | function destroy(input) {
241 | var minicolors = input.parent();
242 |
243 | // Revert the input element
244 | input
245 | .removeData('minicolors-initialized')
246 | .removeData('minicolors-settings')
247 | .removeProp('size')
248 | .removeClass('minicolors-input');
249 |
250 | // Remove the wrap and destroy whatever remains
251 | minicolors.before(input).remove();
252 | }
253 |
254 | // Shows the specified dropdown panel
255 | function show(input) {
256 | var minicolors = input.parent();
257 | var panel = minicolors.find('.minicolors-panel');
258 | var settings = input.data('minicolors-settings');
259 |
260 | // Do nothing if uninitialized, disabled, inline, or already open
261 | if(
262 | !input.data('minicolors-initialized') ||
263 | input.prop('disabled') ||
264 | minicolors.hasClass('minicolors-inline') ||
265 | minicolors.hasClass('minicolors-focus')
266 | ) return;
267 |
268 | hide();
269 |
270 | minicolors.addClass('minicolors-focus');
271 | panel
272 | .stop(true, true)
273 | .fadeIn(settings.showSpeed, function() {
274 | if(settings.show) settings.show.call(input.get(0));
275 | });
276 | }
277 |
278 | // Hides all dropdown panels
279 | function hide() {
280 | $('.minicolors-focus').each(function() {
281 | var minicolors = $(this);
282 | var input = minicolors.find('.minicolors-input');
283 | var panel = minicolors.find('.minicolors-panel');
284 | var settings = input.data('minicolors-settings');
285 |
286 | panel.fadeOut(settings.hideSpeed, function() {
287 | if(settings.hide) settings.hide.call(input.get(0));
288 | minicolors.removeClass('minicolors-focus');
289 | });
290 |
291 | });
292 | }
293 |
294 | // Moves the selected picker
295 | function move(target, event, animate) {
296 | var input = target.parents('.minicolors').find('.minicolors-input');
297 | var settings = input.data('minicolors-settings');
298 | var picker = target.find('[class$=-picker]');
299 | var offsetX = target.offset().left;
300 | var offsetY = target.offset().top;
301 | var x = Math.round(event.pageX - offsetX);
302 | var y = Math.round(event.pageY - offsetY);
303 | var duration = animate ? settings.animationSpeed : 0;
304 | var wx, wy, r, phi;
305 |
306 | // Touch support
307 | if(event.originalEvent.changedTouches) {
308 | x = event.originalEvent.changedTouches[0].pageX - offsetX;
309 | y = event.originalEvent.changedTouches[0].pageY - offsetY;
310 | }
311 |
312 | // Constrain picker to its container
313 | if(x < 0) x = 0;
314 | if(y < 0) y = 0;
315 | if(x > target.width()) x = target.width();
316 | if(y > target.height()) y = target.height();
317 |
318 | // Constrain color wheel values to the wheel
319 | if(target.parent().is('.minicolors-slider-wheel') && picker.parent().is('.minicolors-grid')) {
320 | wx = 75 - x;
321 | wy = 75 - y;
322 | r = Math.sqrt(wx * wx + wy * wy);
323 | phi = Math.atan2(wy, wx);
324 | if(phi < 0) phi += Math.PI * 2;
325 | if(r > 75) {
326 | r = 75;
327 | x = 75 - (75 * Math.cos(phi));
328 | y = 75 - (75 * Math.sin(phi));
329 | }
330 | x = Math.round(x);
331 | y = Math.round(y);
332 | }
333 |
334 | // Move the picker
335 | if(target.is('.minicolors-grid')) {
336 | picker
337 | .stop(true)
338 | .animate({
339 | top: y + 'px',
340 | left: x + 'px'
341 | }, duration, settings.animationEasing, function() {
342 | updateFromControl(input, target);
343 | });
344 | } else {
345 | picker
346 | .stop(true)
347 | .animate({
348 | top: y + 'px'
349 | }, duration, settings.animationEasing, function() {
350 | updateFromControl(input, target);
351 | });
352 | }
353 | }
354 |
355 | // Sets the input based on the color picker values
356 | function updateFromControl(input, target) {
357 |
358 | function getCoords(picker, container) {
359 | var left, top;
360 | if(!picker.length || !container) return null;
361 | left = picker.offset().left;
362 | top = picker.offset().top;
363 |
364 | return {
365 | x: left - container.offset().left + (picker.outerWidth() / 2),
366 | y: top - container.offset().top + (picker.outerHeight() / 2)
367 | };
368 | }
369 |
370 | var hue, saturation, brightness, x, y, r, phi;
371 | var hex = input.val();
372 | var opacity = input.attr('data-opacity');
373 |
374 | // Helpful references
375 | var minicolors = input.parent();
376 | var settings = input.data('minicolors-settings');
377 | var swatch = minicolors.find('.minicolors-input-swatch');
378 |
379 | // Panel objects
380 | var grid = minicolors.find('.minicolors-grid');
381 | var slider = minicolors.find('.minicolors-slider');
382 | var opacitySlider = minicolors.find('.minicolors-opacity-slider');
383 |
384 | // Picker objects
385 | var gridPicker = grid.find('[class$=-picker]');
386 | var sliderPicker = slider.find('[class$=-picker]');
387 | var opacityPicker = opacitySlider.find('[class$=-picker]');
388 |
389 | // Picker positions
390 | var gridPos = getCoords(gridPicker, grid);
391 | var sliderPos = getCoords(sliderPicker, slider);
392 | var opacityPos = getCoords(opacityPicker, opacitySlider);
393 |
394 | // Handle colors
395 | if(target.is('.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider')) {
396 |
397 | // Determine HSB values
398 | switch(settings.control) {
399 | case 'wheel':
400 | // Calculate hue, saturation, and brightness
401 | x = (grid.width() / 2) - gridPos.x;
402 | y = (grid.height() / 2) - gridPos.y;
403 | r = Math.sqrt(x * x + y * y);
404 | phi = Math.atan2(y, x);
405 | if(phi < 0) phi += Math.PI * 2;
406 | if(r > 75) {
407 | r = 75;
408 | gridPos.x = 69 - (75 * Math.cos(phi));
409 | gridPos.y = 69 - (75 * Math.sin(phi));
410 | }
411 | saturation = keepWithin(r / 0.75, 0, 100);
412 | hue = keepWithin(phi * 180 / Math.PI, 0, 360);
413 | brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
414 | hex = hsb2hex({
415 | h: hue,
416 | s: saturation,
417 | b: brightness
418 | });
419 |
420 | // Update UI
421 | slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 }));
422 | break;
423 |
424 | case 'saturation':
425 | // Calculate hue, saturation, and brightness
426 | hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360);
427 | saturation = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
428 | brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
429 | hex = hsb2hex({
430 | h: hue,
431 | s: saturation,
432 | b: brightness
433 | });
434 |
435 | // Update UI
436 | slider.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: brightness }));
437 | minicolors.find('.minicolors-grid-inner').css('opacity', saturation / 100);
438 | break;
439 |
440 | case 'brightness':
441 | // Calculate hue, saturation, and brightness
442 | hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360);
443 | saturation = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
444 | brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
445 | hex = hsb2hex({
446 | h: hue,
447 | s: saturation,
448 | b: brightness
449 | });
450 |
451 | // Update UI
452 | slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 }));
453 | minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (brightness / 100));
454 | break;
455 |
456 | default:
457 | // Calculate hue, saturation, and brightness
458 | hue = keepWithin(360 - parseInt(sliderPos.y * (360 / slider.height()), 10), 0, 360);
459 | saturation = keepWithin(Math.floor(gridPos.x * (100 / grid.width())), 0, 100);
460 | brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
461 | hex = hsb2hex({
462 | h: hue,
463 | s: saturation,
464 | b: brightness
465 | });
466 |
467 | // Update UI
468 | grid.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: 100 }));
469 | break;
470 | }
471 |
472 | // Handle opacity
473 | if(settings.opacity) {
474 | opacity = parseFloat(1 - (opacityPos.y / opacitySlider.height())).toFixed(2);
475 | } else {
476 | opacity = 1;
477 | }
478 |
479 | updateInput(input, hex, opacity);
480 | }
481 | else {
482 | // Set swatch color
483 | swatch.find('span').css({
484 | backgroundColor: hex,
485 | opacity: opacity
486 | });
487 |
488 | // Handle change event
489 | doChange(input, hex, opacity);
490 | }
491 | }
492 |
493 | // Sets the value of the input and does the appropriate conversions
494 | // to respect settings, also updates the swatch
495 | function updateInput(input, value, opacity) {
496 | var rgb;
497 |
498 | // Helpful references
499 | var minicolors = input.parent();
500 | var settings = input.data('minicolors-settings');
501 | var swatch = minicolors.find('.minicolors-input-swatch');
502 |
503 | if(settings.opacity) input.attr('data-opacity', opacity);
504 |
505 | // Set color string
506 | if(settings.format === 'rgb') {
507 | // Returns RGB(A) string
508 |
509 | // Checks for input format and does the conversion
510 | if(isRgb(value)) {
511 | rgb = parseRgb(value, true);
512 | }
513 | else {
514 | rgb = hex2rgb(parseHex(value, true));
515 | }
516 |
517 | opacity = input.attr('data-opacity') === '' ? 1 : keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 0, 1);
518 | if(isNaN(opacity) || !settings.opacity) opacity = 1;
519 |
520 | if(input.minicolors('rgbObject').a <= 1 && rgb && settings.opacity) {
521 | // Set RGBA string if alpha
522 | value = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')';
523 | } else {
524 | // Set RGB string (alpha = 1)
525 | value = 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')';
526 | }
527 | } else {
528 | // Returns hex color
529 |
530 | // Checks for input format and does the conversion
531 | if(isRgb(value)) {
532 | value = rgbString2hex(value);
533 | }
534 |
535 | value = convertCase(value, settings.letterCase);
536 | }
537 |
538 | // Update value from picker
539 | input.val(value);
540 |
541 | // Set swatch color
542 | swatch.find('span').css({
543 | backgroundColor: value,
544 | opacity: opacity
545 | });
546 |
547 | // Handle change event
548 | doChange(input, value, opacity);
549 | }
550 |
551 | // Sets the color picker values from the input
552 | function updateFromInput(input, preserveInputValue) {
553 | var hex, hsb, opacity, keywords, alpha, value, x, y, r, phi;
554 |
555 | // Helpful references
556 | var minicolors = input.parent();
557 | var settings = input.data('minicolors-settings');
558 | var swatch = minicolors.find('.minicolors-input-swatch');
559 |
560 | // Panel objects
561 | var grid = minicolors.find('.minicolors-grid');
562 | var slider = minicolors.find('.minicolors-slider');
563 | var opacitySlider = minicolors.find('.minicolors-opacity-slider');
564 |
565 | // Picker objects
566 | var gridPicker = grid.find('[class$=-picker]');
567 | var sliderPicker = slider.find('[class$=-picker]');
568 | var opacityPicker = opacitySlider.find('[class$=-picker]');
569 |
570 | // Determine hex/HSB values
571 | if(isRgb(input.val())) {
572 | // If input value is a rgb(a) string, convert it to hex color and update opacity
573 | hex = rgbString2hex(input.val());
574 | alpha = keepWithin(parseFloat(getAlpha(input.val())).toFixed(2), 0, 1);
575 | if(alpha) {
576 | input.attr('data-opacity', alpha);
577 | }
578 | } else {
579 | hex = convertCase(parseHex(input.val(), true), settings.letterCase);
580 | }
581 |
582 | if(!hex){
583 | hex = convertCase(parseInput(settings.defaultValue, true), settings.letterCase);
584 | }
585 | hsb = hex2hsb(hex);
586 |
587 | // Get array of lowercase keywords
588 | keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
589 | return $.trim(a.toLowerCase());
590 | });
591 |
592 | // Set color string
593 | if(input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1) {
594 | value = convertCase(input.val());
595 | } else {
596 | value = isRgb(input.val()) ? parseRgb(input.val()) : hex;
597 | }
598 |
599 | // Update input value
600 | if(!preserveInputValue) input.val(value);
601 |
602 | // Determine opacity value
603 | if(settings.opacity) {
604 | // Get from data-opacity attribute and keep within 0-1 range
605 | opacity = input.attr('data-opacity') === '' ? 1 : keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 0, 1);
606 | if(isNaN(opacity)) opacity = 1;
607 | input.attr('data-opacity', opacity);
608 | swatch.find('span').css('opacity', opacity);
609 |
610 | // Set opacity picker position
611 | y = keepWithin(opacitySlider.height() - (opacitySlider.height() * opacity), 0, opacitySlider.height());
612 | opacityPicker.css('top', y + 'px');
613 | }
614 |
615 | // Set opacity to zero if input value is transparent
616 | if(input.val().toLowerCase() === 'transparent') {
617 | swatch.find('span').css('opacity', 0);
618 | }
619 |
620 | // Update swatch
621 | swatch.find('span').css('backgroundColor', hex);
622 |
623 | // Determine picker locations
624 | switch(settings.control) {
625 | case 'wheel':
626 | // Set grid position
627 | r = keepWithin(Math.ceil(hsb.s * 0.75), 0, grid.height() / 2);
628 | phi = hsb.h * Math.PI / 180;
629 | x = keepWithin(75 - Math.cos(phi) * r, 0, grid.width());
630 | y = keepWithin(75 - Math.sin(phi) * r, 0, grid.height());
631 | gridPicker.css({
632 | top: y + 'px',
633 | left: x + 'px'
634 | });
635 |
636 | // Set slider position
637 | y = 150 - (hsb.b / (100 / grid.height()));
638 | if(hex === '') y = 0;
639 | sliderPicker.css('top', y + 'px');
640 |
641 | // Update panel color
642 | slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 }));
643 | break;
644 |
645 | case 'saturation':
646 | // Set grid position
647 | x = keepWithin((5 * hsb.h) / 12, 0, 150);
648 | y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height());
649 | gridPicker.css({
650 | top: y + 'px',
651 | left: x + 'px'
652 | });
653 |
654 | // Set slider position
655 | y = keepWithin(slider.height() - (hsb.s * (slider.height() / 100)), 0, slider.height());
656 | sliderPicker.css('top', y + 'px');
657 |
658 | // Update UI
659 | slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: hsb.b }));
660 | minicolors.find('.minicolors-grid-inner').css('opacity', hsb.s / 100);
661 | break;
662 |
663 | case 'brightness':
664 | // Set grid position
665 | x = keepWithin((5 * hsb.h) / 12, 0, 150);
666 | y = keepWithin(grid.height() - Math.ceil(hsb.s / (100 / grid.height())), 0, grid.height());
667 | gridPicker.css({
668 | top: y + 'px',
669 | left: x + 'px'
670 | });
671 |
672 | // Set slider position
673 | y = keepWithin(slider.height() - (hsb.b * (slider.height() / 100)), 0, slider.height());
674 | sliderPicker.css('top', y + 'px');
675 |
676 | // Update UI
677 | slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 }));
678 | minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (hsb.b / 100));
679 | break;
680 |
681 | default:
682 | // Set grid position
683 | x = keepWithin(Math.ceil(hsb.s / (100 / grid.width())), 0, grid.width());
684 | y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height());
685 | gridPicker.css({
686 | top: y + 'px',
687 | left: x + 'px'
688 | });
689 |
690 | // Set slider position
691 | y = keepWithin(slider.height() - (hsb.h / (360 / slider.height())), 0, slider.height());
692 | sliderPicker.css('top', y + 'px');
693 |
694 | // Update panel color
695 | grid.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: 100 }));
696 | break;
697 | }
698 |
699 | // Fire change event, but only if minicolors is fully initialized
700 | if(input.data('minicolors-initialized')) {
701 | doChange(input, value, opacity);
702 | }
703 | }
704 |
705 | // Runs the change and changeDelay callbacks
706 | function doChange(input, value, opacity) {
707 | var settings = input.data('minicolors-settings');
708 | var lastChange = input.data('minicolors-lastChange');
709 | var obj, sel, i;
710 |
711 | // Only run if it actually changed
712 | if(!lastChange || lastChange.value !== value || lastChange.opacity !== opacity) {
713 |
714 | // Remember last-changed value
715 | input.data('minicolors-lastChange', {
716 | value: value,
717 | opacity: opacity
718 | });
719 |
720 | // Check and select applicable swatch
721 | if(settings.swatches && settings.swatches.length !== 0) {
722 | if(!isRgb(value)) {
723 | obj = hex2rgb(value);
724 | }
725 | else {
726 | obj = parseRgb(value, true);
727 | }
728 | sel = -1;
729 | for(i = 0; i < settings.swatches.length; ++i) {
730 | if(obj.r === settings.swatches[i].r && obj.g === settings.swatches[i].g && obj.b === settings.swatches[i].b && obj.a === settings.swatches[i].a) {
731 | sel = i;
732 | break;
733 | }
734 | }
735 |
736 | input.parent().find('.minicolors-swatches .minicolors-swatch').removeClass('selected');
737 | if(sel !== -1) {
738 | input.parent().find('.minicolors-swatches .minicolors-swatch').eq(i).addClass('selected');
739 | }
740 | }
741 |
742 | // Fire change event
743 | if(settings.change) {
744 | if(settings.changeDelay) {
745 | // Call after a delay
746 | clearTimeout(input.data('minicolors-changeTimeout'));
747 | input.data('minicolors-changeTimeout', setTimeout(function() {
748 | settings.change.call(input.get(0), value, opacity);
749 | }, settings.changeDelay));
750 | } else {
751 | // Call immediately
752 | settings.change.call(input.get(0), value, opacity);
753 | }
754 | }
755 | input.trigger('change').trigger('input');
756 | }
757 | }
758 |
759 | // Generates an RGB(A) object based on the input's value
760 | function rgbObject(input) {
761 | var rgb,
762 | opacity = $(input).attr('data-opacity');
763 | if( isRgb($(input).val()) ) {
764 | rgb = parseRgb($(input).val(), true);
765 | } else {
766 | var hex = parseHex($(input).val(), true);
767 | rgb = hex2rgb(hex);
768 | }
769 | if( !rgb ) return null;
770 | if( opacity !== undefined ) $.extend(rgb, { a: parseFloat(opacity) });
771 | return rgb;
772 | }
773 |
774 | // Generates an RGB(A) string based on the input's value
775 | function rgbString(input, alpha) {
776 | var rgb,
777 | opacity = $(input).attr('data-opacity');
778 | if( isRgb($(input).val()) ) {
779 | rgb = parseRgb($(input).val(), true);
780 | } else {
781 | var hex = parseHex($(input).val(), true);
782 | rgb = hex2rgb(hex);
783 | }
784 | if( !rgb ) return null;
785 | if( opacity === undefined ) opacity = 1;
786 | if( alpha ) {
787 | return 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')';
788 | } else {
789 | return 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')';
790 | }
791 | }
792 |
793 | // Converts to the letter case specified in settings
794 | function convertCase(string, letterCase) {
795 | return letterCase === 'uppercase' ? string.toUpperCase() : string.toLowerCase();
796 | }
797 |
798 | // Parses a string and returns a valid hex string when possible
799 | function parseHex(string, expand) {
800 | string = string.replace(/^#/g, '');
801 | if(!string.match(/^[A-F0-9]{3,6}/ig)) return '';
802 | if(string.length !== 3 && string.length !== 6) return '';
803 | if(string.length === 3 && expand) {
804 | string = string[0] + string[0] + string[1] + string[1] + string[2] + string[2];
805 | }
806 | return '#' + string;
807 | }
808 |
809 | // Parses a string and returns a valid RGB(A) string when possible
810 | function parseRgb(string, obj) {
811 | var values = string.replace(/[^\d,.]/g, '');
812 | var rgba = values.split(',');
813 |
814 | rgba[0] = keepWithin(parseInt(rgba[0], 10), 0, 255);
815 | rgba[1] = keepWithin(parseInt(rgba[1], 10), 0, 255);
816 | rgba[2] = keepWithin(parseInt(rgba[2], 10), 0, 255);
817 | if(rgba[3]) {
818 | rgba[3] = keepWithin(parseFloat(rgba[3], 10), 0, 1);
819 | }
820 |
821 | // Return RGBA object
822 | if( obj ) {
823 | if (rgba[3]) {
824 | return {
825 | r: rgba[0],
826 | g: rgba[1],
827 | b: rgba[2],
828 | a: rgba[3]
829 | };
830 | } else {
831 | return {
832 | r: rgba[0],
833 | g: rgba[1],
834 | b: rgba[2]
835 | };
836 | }
837 | }
838 |
839 | // Return RGBA string
840 | if(typeof(rgba[3]) !== 'undefined' && rgba[3] <= 1) {
841 | return 'rgba(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ', ' + rgba[3] + ')';
842 | } else {
843 | return 'rgb(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ')';
844 | }
845 |
846 | }
847 |
848 | // Parses a string and returns a valid color string when possible
849 | function parseInput(string, expand) {
850 | if(isRgb(string)) {
851 | // Returns a valid rgb(a) string
852 | return parseRgb(string);
853 | } else {
854 | return parseHex(string, expand);
855 | }
856 | }
857 |
858 | // Keeps value within min and max
859 | function keepWithin(value, min, max) {
860 | if(value < min) value = min;
861 | if(value > max) value = max;
862 | return value;
863 | }
864 |
865 | // Checks if a string is a valid RGB(A) string
866 | function isRgb(string) {
867 | var rgb = string.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
868 | return (rgb && rgb.length === 4) ? true : false;
869 | }
870 |
871 | // Function to get alpha from a RGB(A) string
872 | function getAlpha(rgba) {
873 | rgba = rgba.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+(\.\d{1,2})?|\.\d{1,2})[\s+]?/i);
874 | return (rgba && rgba.length === 6) ? rgba[4] : '1';
875 | }
876 |
877 | // Converts an HSB object to an RGB object
878 | function hsb2rgb(hsb) {
879 | var rgb = {};
880 | var h = Math.round(hsb.h);
881 | var s = Math.round(hsb.s * 255 / 100);
882 | var v = Math.round(hsb.b * 255 / 100);
883 | if(s === 0) {
884 | rgb.r = rgb.g = rgb.b = v;
885 | } else {
886 | var t1 = v;
887 | var t2 = (255 - s) * v / 255;
888 | var t3 = (t1 - t2) * (h % 60) / 60;
889 | if(h === 360) h = 0;
890 | if(h < 60) { rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3; }
891 | else if(h < 120) {rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3; }
892 | else if(h < 180) {rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3; }
893 | else if(h < 240) {rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3; }
894 | else if(h < 300) {rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3; }
895 | else if(h < 360) {rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3; }
896 | else { rgb.r = 0; rgb.g = 0; rgb.b = 0; }
897 | }
898 | return {
899 | r: Math.round(rgb.r),
900 | g: Math.round(rgb.g),
901 | b: Math.round(rgb.b)
902 | };
903 | }
904 |
905 | // Converts an RGB string to a hex string
906 | function rgbString2hex(rgb){
907 | rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
908 | return (rgb && rgb.length === 4) ? '#' +
909 | ('0' + parseInt(rgb[1],10).toString(16)).slice(-2) +
910 | ('0' + parseInt(rgb[2],10).toString(16)).slice(-2) +
911 | ('0' + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
912 | }
913 |
914 | // Converts an RGB object to a hex string
915 | function rgb2hex(rgb) {
916 | var hex = [
917 | rgb.r.toString(16),
918 | rgb.g.toString(16),
919 | rgb.b.toString(16)
920 | ];
921 | $.each(hex, function(nr, val) {
922 | if(val.length === 1) hex[nr] = '0' + val;
923 | });
924 | return '#' + hex.join('');
925 | }
926 |
927 | // Converts an HSB object to a hex string
928 | function hsb2hex(hsb) {
929 | return rgb2hex(hsb2rgb(hsb));
930 | }
931 |
932 | // Converts a hex string to an HSB object
933 | function hex2hsb(hex) {
934 | var hsb = rgb2hsb(hex2rgb(hex));
935 | if(hsb.s === 0) hsb.h = 360;
936 | return hsb;
937 | }
938 |
939 | // Converts an RGB object to an HSB object
940 | function rgb2hsb(rgb) {
941 | var hsb = { h: 0, s: 0, b: 0 };
942 | var min = Math.min(rgb.r, rgb.g, rgb.b);
943 | var max = Math.max(rgb.r, rgb.g, rgb.b);
944 | var delta = max - min;
945 | hsb.b = max;
946 | hsb.s = max !== 0 ? 255 * delta / max : 0;
947 | if(hsb.s !== 0) {
948 | if(rgb.r === max) {
949 | hsb.h = (rgb.g - rgb.b) / delta;
950 | } else if(rgb.g === max) {
951 | hsb.h = 2 + (rgb.b - rgb.r) / delta;
952 | } else {
953 | hsb.h = 4 + (rgb.r - rgb.g) / delta;
954 | }
955 | } else {
956 | hsb.h = -1;
957 | }
958 | hsb.h *= 60;
959 | if(hsb.h < 0) {
960 | hsb.h += 360;
961 | }
962 | hsb.s *= 100/255;
963 | hsb.b *= 100/255;
964 | return hsb;
965 | }
966 |
967 | // Converts a hex string to an RGB object
968 | function hex2rgb(hex) {
969 | hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
970 | return {
971 | r: hex >> 16,
972 | g: (hex & 0x00FF00) >> 8,
973 | b: (hex & 0x0000FF)
974 | };
975 | }
976 |
977 | // Handle events
978 | $([document])
979 | // Hide on clicks outside of the control
980 | .on('mousedown.minicolors touchstart.minicolors', function(event) {
981 | if(!$(event.target).parents().add(event.target).hasClass('minicolors')) {
982 | hide();
983 | }
984 | })
985 | // Start moving
986 | .on('mousedown.minicolors touchstart.minicolors', '.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider', function(event) {
987 | var target = $(this);
988 | event.preventDefault();
989 | $(event.delegateTarget).data('minicolors-target', target);
990 | move(target, event, true);
991 | })
992 | // Move pickers
993 | .on('mousemove.minicolors touchmove.minicolors', function(event) {
994 | var target = $(event.delegateTarget).data('minicolors-target');
995 | if(target) move(target, event);
996 | })
997 | // Stop moving
998 | .on('mouseup.minicolors touchend.minicolors', function() {
999 | $(this).removeData('minicolors-target');
1000 | })
1001 | // Selected a swatch
1002 | .on('click.minicolors', '.minicolors-swatches li', function(event) {
1003 | event.preventDefault();
1004 | var target = $(this), input = target.parents('.minicolors').find('.minicolors-input'), color = target.data('swatch-color');
1005 | updateInput(input, color, getAlpha(color));
1006 | updateFromInput(input);
1007 | })
1008 | // Show panel when swatch is clicked
1009 | .on('mousedown.minicolors touchstart.minicolors', '.minicolors-input-swatch', function(event) {
1010 | var input = $(this).parent().find('.minicolors-input');
1011 | event.preventDefault();
1012 | show(input);
1013 | })
1014 | // Show on focus
1015 | .on('focus.minicolors', '.minicolors-input', function() {
1016 | var input = $(this);
1017 | if(!input.data('minicolors-initialized')) return;
1018 | show(input);
1019 | })
1020 | // Update value on blur
1021 | .on('blur.minicolors', '.minicolors-input', function() {
1022 | var input = $(this);
1023 | var settings = input.data('minicolors-settings');
1024 | var keywords;
1025 | var hex;
1026 | var rgba;
1027 | var swatchOpacity;
1028 | var value;
1029 |
1030 | if(!input.data('minicolors-initialized')) return;
1031 |
1032 | // Get array of lowercase keywords
1033 | keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
1034 | return $.trim(a.toLowerCase());
1035 | });
1036 |
1037 | // Set color string
1038 | if(input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1) {
1039 | value = input.val();
1040 | } else {
1041 | // Get RGBA values for easy conversion
1042 | if(isRgb(input.val())) {
1043 | rgba = parseRgb(input.val(), true);
1044 | } else {
1045 | hex = parseHex(input.val(), true);
1046 | rgba = hex ? hex2rgb(hex) : null;
1047 | }
1048 |
1049 | // Convert to format
1050 | if(rgba === null) {
1051 | value = settings.defaultValue;
1052 | } else if(settings.format === 'rgb') {
1053 | value = settings.opacity ?
1054 | parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') :
1055 | parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')');
1056 | } else {
1057 | value = rgb2hex(rgba);
1058 | }
1059 | }
1060 |
1061 | // Update swatch opacity
1062 | swatchOpacity = settings.opacity ? input.attr('data-opacity') : 1;
1063 | if(value.toLowerCase() === 'transparent') swatchOpacity = 0;
1064 | input
1065 | .closest('.minicolors')
1066 | .find('.minicolors-input-swatch > span')
1067 | .css('opacity', swatchOpacity);
1068 |
1069 | // Set input value
1070 | input.val(value);
1071 |
1072 | // Is it blank?
1073 | if(input.val() === '') input.val(parseInput(settings.defaultValue, true));
1074 |
1075 | // Adjust case
1076 | input.val(convertCase(input.val(), settings.letterCase));
1077 |
1078 | })
1079 | // Handle keypresses
1080 | .on('keydown.minicolors', '.minicolors-input', function(event) {
1081 | var input = $(this);
1082 | if(!input.data('minicolors-initialized')) return;
1083 | switch(event.keyCode) {
1084 | case 9: // tab
1085 | hide();
1086 | break;
1087 | case 13: // enter
1088 | case 27: // esc
1089 | hide();
1090 | input.blur();
1091 | break;
1092 | }
1093 | })
1094 | // Update on keyup
1095 | .on('keyup.minicolors', '.minicolors-input', function() {
1096 | var input = $(this);
1097 | if(!input.data('minicolors-initialized')) return;
1098 | updateFromInput(input, true);
1099 | })
1100 | // Update on paste
1101 | .on('paste.minicolors', '.minicolors-input', function() {
1102 | var input = $(this);
1103 | if(!input.data('minicolors-initialized')) return;
1104 | setTimeout(function() {
1105 | updateFromInput(input, true);
1106 | }, 1);
1107 | });
1108 | }));
1109 |
--------------------------------------------------------------------------------
/vendor/assets/javascripts/jquery.minicolors.simple_form.js:
--------------------------------------------------------------------------------
1 | $(document).on(window.Turbolinks ? 'turbolinks:load' : 'ready', function() {
2 | $('[data-minicolors]').each(function(i, elem) {
3 | var input = $(this);
4 | input.minicolors(input.data('minicolors'));
5 | });
6 | });
7 |
--------------------------------------------------------------------------------