diff --git a/.gitignore b/.gitignore index 4961ad588f1e8e6428748e00ab9fc8041d7379eb..32939b7bfde160033bff1db992d40a634622a7f0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ pkg /railties/doc /railties/tmp /guides/output +node_modules/ +/actionview/log diff --git a/.travis.yml b/.travis.yml index eafa06e44f14b0bae3c789689eb4b90662488919..ae4d78a31fd395d371c587a453818abe4581ae9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ cache: directories: - /tmp/cache/unicode_conformance - /tmp/beanstalkd-1.10 + - node_modules + - $HOME/.nvm services: - memcached @@ -21,6 +23,11 @@ before_install: - "gem update bundler" - "[ -f /tmp/beanstalkd-1.10/Makefile ] || (curl -L https://github.com/kr/beanstalkd/archive/v1.10.tar.gz | tar xz -C /tmp)" - "pushd /tmp/beanstalkd-1.10 && make && (./beanstalkd &); popd" + - "[[ $GEM != 'av:ujs' ]] || nvm install node" + - "[[ $GEM != 'av:ujs' ]] || node --version" + - "[[ $GEM != 'av:ujs' ]] || (cd actionview && npm install)" + - "[[ $GEM != 'av:ujs' ]] || [[ $(phantomjs --version) > '2' ]] || npm install -g phantomjs-prebuilt" + before_script: # Set Sauce Labs username and access key. Obfuscated, purposefully not encrypted. @@ -52,6 +59,8 @@ rvm: matrix: include: + - rvm: 2.4.0 + env: "GEM=av:ujs" - rvm: 2.2.6 env: "GEM=aj:integration" services: diff --git a/actionview/Rakefile b/actionview/Rakefile index cba4684076e7561387fc59d531c1173929ec658b..00ab92129d27e96935431463de089ccca30e31a7 100644 --- a/actionview/Rakefile +++ b/actionview/Rakefile @@ -1,4 +1,5 @@ require "rake/testtask" +require "fileutils" desc "Default Task" task default: :test @@ -25,6 +26,32 @@ namespace :test do t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION) end + task :ujs do + begin + Dir.mkdir("log") + pid = spawn("bundle exec rackup test/ujs/config.ru -p 4567 -s puma > log/test.log 2>&1") + + start_time = Time.now + + loop do + break if system("lsof -i :4567 >/dev/null") + + if Time.now - start_time > 5 + puts "Timed out after 5 seconds" + exit 1 + end + end + + system("npm run lint && phantomjs ../ci/phantomjs.js http://localhost:4567/") + status = $?.to_i + ensure + Process.kill("KILL", pid) if pid + FileUtils.rm_f("log") + end + + exit status + end + namespace :integration do desc "ActiveRecord Integration Tests" Rake::TestTask.new(:active_record) do |t| diff --git a/actionview/app/assets/javascripts/MIT-LICENSE b/actionview/app/assets/javascripts/MIT-LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..befcbdc7b7499bbce763d34dc9e4ecf9d62a4373 --- /dev/null +++ b/actionview/app/assets/javascripts/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2007-2017 Rails Core team + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/actionview/app/assets/javascripts/README.md b/actionview/app/assets/javascripts/README.md new file mode 100644 index 0000000000000000000000000000000000000000..92f3e8a3b32618f580f6468b2652f392eb0394cc --- /dev/null +++ b/actionview/app/assets/javascripts/README.md @@ -0,0 +1,49 @@ +Ruby on Rails unobtrusive scripting adapter. +======================================== + +This unobtrusive scripting support file is developed for the Ruby on Rails framework, but is not strictly tied to any specific backend. You can drop this into any application to: + +- force confirmation dialogs for various actions; +- make non-GET requests from hyperlinks; +- make forms or hyperlinks submit data asynchronously with Ajax; +- have submit buttons become automatically disabled on form submit to prevent double-clicking. + +These features are achieved by adding certain ["data" attributes][data] to your HTML markup. In Rails, they are added by the framework's template helpers. + +Requirements +------------ + +- HTML5 doctype (optional). + +If you don't use HTML5, adding "data" attributes to your HTML4 or XHTML pages might make them fail [W3C markup validation][validator]. However, this shouldn't create any issues for web browsers or other user agents. + +Installation using npm +------------ + +Run `npm install rails-ujs --save` to install the rails-ujs package. + +Installation using Yarn +------------ + +Run `yarn add rails-ujs` to install the rails-ujs package. + +Usage +------------ + +Require `rails-ujs` into your application.js manifest. + +```javascript +//= require rails-ujs +``` + +How to run tests +------------ + +Run `bundle exec rake ujs:server` first, and then run the web tests by visiting [[http://localhost:4567]] in your browser. + +## License +rails-ujs is released under the [MIT License](MIT-LICENSE). + +[data]: http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes "Embedding custom non-visible data with the data-* attributes" +[validator]: http://validator.w3.org/ +[csrf]: http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html diff --git a/actionview/coffeelint.json b/actionview/coffeelint.json new file mode 100644 index 0000000000000000000000000000000000000000..cf8bf2171bb844874adcde8e53ac141cd192030e --- /dev/null +++ b/actionview/coffeelint.json @@ -0,0 +1,135 @@ +{ + "arrow_spacing": { + "level": "warn" + }, + "braces_spacing": { + "level": "warn", + "spaces": 1, + "empty_object_spaces": 0 + }, + "camel_case_classes": { + "level": "error" + }, + "coffeescript_error": { + "level": "error" + }, + "colon_assignment_spacing": { + "level": "warn", + "spacing": { + "left": 0, + "right": 1 + } + }, + "cyclomatic_complexity": { + "level": "warn", + "value": 10 + }, + "duplicate_key": { + "level": "error" + }, + "empty_constructor_needs_parens": { + "level": "warn" + }, + "ensure_comprehensions": { + "level": "warn" + }, + "eol_last": { + "level": "warn" + }, + "indentation": { + "value": 2, + "level": "error" + }, + "line_endings": { + "level": "warn", + "value": "unix" + }, + "max_line_length": { + "value": 80, + "level": "ignore", + "limitComments": true + }, + "missing_fat_arrows": { + "level": "ignore" + }, + "newlines_after_classes": { + "value": 3, + "level": "warn" + }, + "no_backticks": { + "level": "error" + }, + "no_debugger": { + "level": "warn", + "console": false + }, + "no_empty_functions": { + "level": "warn" + }, + "no_empty_param_list": { + "level": "warn" + }, + "no_implicit_braces": { + "level": "ignore", + "strict": true + }, + "no_implicit_parens": { + "level": "ignore", + "strict": true + }, + "no_interpolation_in_single_quotes": { + "level": "warn" + }, + "no_nested_string_interpolation": { + "level": "warn" + }, + "no_plusplus": { + "level": "warn" + }, + "no_private_function_fat_arrows": { + "level": "warn" + }, + "no_stand_alone_at": { + "level": "warn" + }, + "no_tabs": { + "level": "error" + }, + "no_this": { + "level": "warn" + }, + "no_throwing_strings": { + "level": "error" + }, + "no_trailing_semicolons": { + "level": "error" + }, + "no_trailing_whitespace": { + "level": "error", + "allowed_in_comments": false, + "allowed_in_empty_lines": true + }, + "no_unnecessary_double_quotes": { + "level": "warn" + }, + "no_unnecessary_fat_arrows": { + "level": "warn" + }, + "non_empty_constructor_needs_parens": { + "level": "warn" + }, + "prefer_english_operator": { + "level": "ignore", + "doubleNotLevel": "warn" + }, + "space_operators": { + "level": "warn" + }, + "spacing_after_comma": { + "level": "warn" + }, + "transform_messes_up_line_numbers": { + "level": "warn" + } +} + diff --git a/actionview/package.json b/actionview/package.json index ec3306c299a30d1d48f0b7113432e675f8461eda..5c2ba75e8a3ba536220806152d149142d9790eb0 100644 --- a/actionview/package.json +++ b/actionview/package.json @@ -12,7 +12,7 @@ "scripts": { "build": "bundle exec blade build", "test": "echo \"See the README: https://github.com/rails/rails-ujs#how-to-run-tests\" && exit 1", - "lint": "coffeelint src && eslint test/public/test", + "lint": "coffeelint app/assets/javascripts && eslint test/public/test" }, "repository": { "type": "git", diff --git a/actionview/test/ujs/config.ru b/actionview/test/ujs/config.ru index 414c2063c3dbb385ac7e63c29a46fcb0aafde35d..48b7a4b53a452772edf7d16582feb170830aca16 100644 --- a/actionview/test/ujs/config.ru +++ b/actionview/test/ujs/config.ru @@ -1,3 +1,4 @@ $LOAD_PATH.unshift File.expand_path("..", __FILE__) require "server" + run UJS::Server diff --git a/actionview/test/ujs/server.rb b/actionview/test/ujs/server.rb index 25f70baf5f41daba954e3c11b9bcb5cbb47743a7..7deb208af062ab2431ac7eb3690cf1bae681608c 100644 --- a/actionview/test/ujs/server.rb +++ b/actionview/test/ujs/server.rb @@ -1,11 +1,10 @@ +require "rack" require "rails" require "action_controller/railtie" require "action_view/railtie" require "blade" require "json" -JQUERY_VERSIONS = %w[ 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.10.0 1.10.1 1.10.2 1.11.0 2.0.0 2.1.0].freeze - module UJS class Server < Rails::Application routes.append do @@ -18,7 +17,7 @@ class Server < Rails::Application config.cache_classes = false config.eager_load = false config.secret_key_base = "59d7a4dbd349fa3838d79e330e39690fc22b931e7dc17d9162f03d633d526fbb92dfdb2dc9804c8be3e199631b9c1fbe43fc3e4fc75730b515851849c728d5c7" - config.paths["app/views"].unshift("#{Rails.root / "views"}") + config.paths["app/views"].unshift("#{Rails.root}/views") config.public_file_server.enabled = true config.logger = Logger.new(STDOUT) config.log_level = :error @@ -26,32 +25,6 @@ class Server < Rails::Application end module TestsHelper - def jquery_link(version) - if params[:version] == version - "[#{version}]" - else - "#{version}".html_safe - end - end - - def cdn_link(cdn) - if params[:cdn] == cdn - "[#{cdn}]" - else - "#{cdn}".html_safe - end - end - - def jquery_src - if params[:version] == "edge" - "/vendor/jquery.js" - elsif params[:cdn] && params[:cdn] == "googleapis" - "https://ajax.googleapis.com/ajax/libs/jquery/#{params[:version]}/jquery.min.js" - else - "http://code.jquery.com/jquery-#{params[:version]}.js" - end - end - def test_to(*names) names = ["/vendor/qunit.js", "settings"] + names names.map { |name| script_tag name }.join("\n").html_safe @@ -61,10 +34,6 @@ def script_tag(src) src = "/test/#{src}.js" unless src.index("/") %().html_safe end - - def jquery_versions - JQUERY_VERSIONS - end end class TestsController < ActionController::Base @@ -72,8 +41,6 @@ class TestsController < ActionController::Base layout "application" def index - params[:version] ||= ENV["JQUERY_VERSION"] || "1.11.0" - params[:cdn] ||= "jquery" render :index end diff --git a/actionview/test/ujs/views/layouts/application.html.erb b/actionview/test/ujs/views/layouts/application.html.erb index e09b213b72d075f1db9598e67950a035e40fe263..a69cd2d7396cf72abd09f02347492cd5e6914a1e 100644 --- a/actionview/test/ujs/views/layouts/application.html.erb +++ b/actionview/test/ujs/views/layouts/application.html.erb @@ -3,30 +3,15 @@ <%= @title %> - - - <%= script_tag jquery_src %> + <%= script_tag "http://code.jquery.com/jquery-2.2.0.js" %>