nitrolinks-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/Gemfile +15 -1
- data/MIT-LICENSE +20 -0
- data/README.md +2 -2
- data/Rakefile +24 -2
- data/app/assets/javascripts/nitrolinks/testing.coffee +195 -0
- data/bin/rails +18 -0
- data/config/cucumber.yml +8 -0
- data/lib/nitrolinks/rails/version.rb +1 -1
- data/lib/tasks/cucumber.rake +76 -0
- data/nitrolinks-rails.gemspec +2 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02876071ee063c5549016d3b2067f0d2556b0e19
|
4
|
+
data.tar.gz: 854ba5bc3278599e9ba3875bec3bd1fb21cfe526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0163b8b372e197a13b997ca96fd0cb929c6cd187b63b32f789d5e64036d270b82c0ffd306bf8141f358dedd212a32e35364e333cd9c444fc6c57ae25ec381299
|
7
|
+
data.tar.gz: 08facc91ca92d4f09d0c3d047e820bdbf296ac583c07c3886ef4be89ed5c683661019aa6aabca9bfed030d07d87abee2c5f1d17e927e09a201cc244488d6b64d
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in nitrolinks-rails.gemspec
|
4
3
|
gemspec
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem "cucumber-rails", ">= 1.5.0", require: false
|
7
|
+
gem 'selenium-webdriver'
|
8
|
+
gem 'chromedriver-helper', '>= 1.1.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :test, :development do
|
12
|
+
gem "slim-rails", "~> 3.1"
|
13
|
+
gem 'sass-rails', '~> 5.0'
|
14
|
+
gem 'coffee-rails', '~> 4.2'
|
15
|
+
end
|
16
|
+
|
17
|
+
# To use a debugger
|
18
|
+
# gem 'byebug', group: [:development, :test]
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Wayne Duran
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,2 +1,24 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Nitrolinks::Rails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../features/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
require 'bundler/gem_tasks'
|
24
|
+
|
@@ -0,0 +1,195 @@
|
|
1
|
+
whenReady = (fn) ->
|
2
|
+
if (if document.attachEvent then document.readyState == 'complete' else document.readyState != 'loading')
|
3
|
+
fn()
|
4
|
+
else
|
5
|
+
document.addEventListener "DOMContentLoaded", ->
|
6
|
+
fn()
|
7
|
+
|
8
|
+
select = (selector) ->
|
9
|
+
selectAll(selector)[0]
|
10
|
+
|
11
|
+
selectAll = (selector) ->
|
12
|
+
document.querySelectorAll(selector)
|
13
|
+
|
14
|
+
eventListen = (event, handler) ->
|
15
|
+
document.addEventListener event, (e) ->
|
16
|
+
handler.call document, e
|
17
|
+
|
18
|
+
last = (collection) ->
|
19
|
+
if collection.length > 0
|
20
|
+
collection[collection.length - 1]
|
21
|
+
|
22
|
+
class NitrolinksTesting
|
23
|
+
constructor: (@window, @document) ->
|
24
|
+
@active = false
|
25
|
+
@store = new NitrolinksTestStore(@window.localStorage)
|
26
|
+
@domLoadKey = 'nitroDomLoad'
|
27
|
+
@fetchLoadKey = 'nitroFetchLoad'
|
28
|
+
@cacheLoadKey = 'nitroCacheLoad'
|
29
|
+
@loadCount = 0
|
30
|
+
@errors = []
|
31
|
+
|
32
|
+
init: ->
|
33
|
+
@listen()
|
34
|
+
|
35
|
+
body: ->
|
36
|
+
select('body')
|
37
|
+
|
38
|
+
markAsLoading: (from)->
|
39
|
+
@active = true
|
40
|
+
@body().classList.add('testing-visiting')
|
41
|
+
|
42
|
+
markAsDoneLoading: ->
|
43
|
+
@active = false
|
44
|
+
@body().classList.remove('testing-visiting')
|
45
|
+
|
46
|
+
listen: ->
|
47
|
+
eventListen 'nitrolinks:visit', =>
|
48
|
+
@markAsLoading('nitrolinks:visit')
|
49
|
+
|
50
|
+
loads = (e) =>
|
51
|
+
@loadCount += 1
|
52
|
+
@markAsDoneLoading()
|
53
|
+
@showDebugData()
|
54
|
+
|
55
|
+
eventListen 'nitrolinks:load', loads
|
56
|
+
eventListen 'nitrolinks:load-blank', loads
|
57
|
+
|
58
|
+
eventListen 'nitrolinks:load-from-fetch', (e) =>
|
59
|
+
@addToFetched(e.detail.url)
|
60
|
+
|
61
|
+
eventListen 'nitrolinks:load-from-cache', (e) =>
|
62
|
+
@addToCached(e.detail.url)
|
63
|
+
|
64
|
+
@window.addEventListener 'error', (e) =>
|
65
|
+
@addToErrors(e)
|
66
|
+
|
67
|
+
whenReady =>
|
68
|
+
return unless select('#nitro-debugging')
|
69
|
+
@addToLoaded(@window.location.href)
|
70
|
+
@showDebugData()
|
71
|
+
@markAsDoneLoading()
|
72
|
+
|
73
|
+
addToFetched: (url) ->
|
74
|
+
@addToArrayStored(@fetchLoadKey, url)
|
75
|
+
|
76
|
+
addToLoaded: (url) ->
|
77
|
+
@addToArrayStored(@domLoadKey, url)
|
78
|
+
|
79
|
+
addToCached: (url) ->
|
80
|
+
@addToArrayStored(@cacheLoadKey, url)
|
81
|
+
|
82
|
+
addToArrayStored: (key, input) ->
|
83
|
+
loads = @store.get(key, [])
|
84
|
+
loads.push input
|
85
|
+
@store.set(key, loads)
|
86
|
+
|
87
|
+
addToErrors: (e) ->
|
88
|
+
if e.error
|
89
|
+
@errors.push e.error.message
|
90
|
+
else
|
91
|
+
@errors.push e
|
92
|
+
console.log e
|
93
|
+
@loadShowerFromCollection(@errorsEl(), @errors)
|
94
|
+
|
95
|
+
showDebugData: ->
|
96
|
+
if select('#nitro-debugging')
|
97
|
+
@showNitroLoadCount()
|
98
|
+
@showDomLoads()
|
99
|
+
@showFetchLoads()
|
100
|
+
@showCacheLoads()
|
101
|
+
|
102
|
+
showNitroLoadCount: ->
|
103
|
+
select('#nitro-debugging .nitro-load-count').textContent = @loadCount
|
104
|
+
|
105
|
+
errorsEl: ->
|
106
|
+
select('#nitro-debugging .javascript-errors')
|
107
|
+
|
108
|
+
domEl: ->
|
109
|
+
select('#nitro-debugging .dom-loads')
|
110
|
+
|
111
|
+
showDomLoads: ->
|
112
|
+
@loadShowerFromCollection(@domEl(), @errors)
|
113
|
+
|
114
|
+
loadShower: ($el, storeKey) ->
|
115
|
+
@loadShowerFromCollection($el, @store.get(storeKey, []))
|
116
|
+
|
117
|
+
loadShowerFromCollection: ($el, loads) ->
|
118
|
+
htmlStr = ''
|
119
|
+
for load in loads
|
120
|
+
htmlStr += "<li>#{load}</li>"
|
121
|
+
$el.innerHTML = htmlStr
|
122
|
+
|
123
|
+
fetchEl: ->
|
124
|
+
select('#nitro-debugging .fetch-loads')
|
125
|
+
|
126
|
+
showFetchLoads: ->
|
127
|
+
@loadShower(@fetchEl(), @fetchLoadKey)
|
128
|
+
|
129
|
+
cacheEl: ->
|
130
|
+
select('#nitro-debugging .cache-loads')
|
131
|
+
|
132
|
+
showCacheLoads: ->
|
133
|
+
@loadShower(@cacheEl(), @cacheLoadKey)
|
134
|
+
|
135
|
+
clearDomLoads: ->
|
136
|
+
@store.remove(@domLoadKey)
|
137
|
+
@clearSessionLoads()
|
138
|
+
|
139
|
+
clearSessionLoads: ->
|
140
|
+
@store.remove(@fetchLoadKey)
|
141
|
+
@store.remove(@cacheLoadKey)
|
142
|
+
|
143
|
+
domLoadCount: ->
|
144
|
+
@store.get(@domLoadKey, []).length
|
145
|
+
|
146
|
+
isPageFetched: (path) ->
|
147
|
+
@compareItem(@fetchEl(), path)
|
148
|
+
|
149
|
+
isPageNormallyLoaded: (path) ->
|
150
|
+
@compareItem(@domEl(), path, (item) ->
|
151
|
+
@urlPath(item.textContent)
|
152
|
+
)
|
153
|
+
|
154
|
+
isPageCacheRestored: (path) ->
|
155
|
+
@compareItem(@cacheEl(), path)
|
156
|
+
|
157
|
+
compareItem: (el, path, comparator) ->
|
158
|
+
comparator ||= (item) ->
|
159
|
+
item.textContent
|
160
|
+
lastItem = last(el.querySelectorAll('li'))
|
161
|
+
if lastItem
|
162
|
+
comparator(lastItem) == path
|
163
|
+
else
|
164
|
+
false
|
165
|
+
|
166
|
+
urlPath: (urlStr) ->
|
167
|
+
url = new URL(urlStr)
|
168
|
+
if url.origin == url.toString()
|
169
|
+
url.pathname
|
170
|
+
else
|
171
|
+
url.toString().replace(url.origin, '')
|
172
|
+
|
173
|
+
hasJavascriptErrors: ->
|
174
|
+
@errorsEl().querySelectorAll('li').length > 0
|
175
|
+
|
176
|
+
class NitrolinksTestStore
|
177
|
+
constructor: (@localStore) ->
|
178
|
+
|
179
|
+
set: (key, value) ->
|
180
|
+
@localStore.setItem(key, JSON.stringify(value))
|
181
|
+
|
182
|
+
get: (key, def = null) ->
|
183
|
+
stored = @localStore.getItem(key)
|
184
|
+
if stored
|
185
|
+
JSON.parse stored
|
186
|
+
else
|
187
|
+
def
|
188
|
+
|
189
|
+
remove: (key) ->
|
190
|
+
@localStore.removeItem(key)
|
191
|
+
|
192
|
+
whenReady =>
|
193
|
+
@nitroTesting = new NitrolinksTesting(window, document)
|
194
|
+
@nitroTesting.init()
|
195
|
+
|
data/bin/rails
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
6
|
+
ENGINE_PATH = File.expand_path('../../lib/nitrolinks/rails/engine', __FILE__)
|
7
|
+
APP_PATH = File.expand_path('../../features/dummy/config/application', __FILE__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
# Pick the frameworks you want:
|
14
|
+
require "action_controller/railtie"
|
15
|
+
require "action_view/railtie"
|
16
|
+
require "sprockets/railtie"
|
17
|
+
|
18
|
+
require 'rails/engine/commands'
|
data/config/cucumber.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<%
|
2
|
+
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
3
|
+
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
4
|
+
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags 'not @wip'"
|
5
|
+
%>
|
6
|
+
default: <%= std_opts %> features
|
7
|
+
wip: --tags @wip:3 --wip features
|
8
|
+
rerun: "<%= rerun_opts %> --format rerun --out rerun.txt --strict --tags 'not @wip'"
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
|
8
|
+
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
|
9
|
+
|
10
|
+
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
|
11
|
+
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'cucumber/rake/task'
|
15
|
+
|
16
|
+
namespace :cucumber do
|
17
|
+
Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t|
|
18
|
+
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
|
19
|
+
t.fork = true # You may get faster startup if you set this to false
|
20
|
+
t.profile = 'default'
|
21
|
+
end
|
22
|
+
|
23
|
+
Cucumber::Rake::Task.new({:wip => 'test:prepare'}, 'Run features that are being worked on') do |t|
|
24
|
+
t.binary = vendored_cucumber_bin
|
25
|
+
t.fork = true # You may get faster startup if you set this to false
|
26
|
+
t.profile = 'wip'
|
27
|
+
end
|
28
|
+
|
29
|
+
Cucumber::Rake::Task.new({:rerun => 'test:prepare'}, 'Record failing features and run only them if any exist') do |t|
|
30
|
+
t.binary = vendored_cucumber_bin
|
31
|
+
t.fork = true # You may get faster startup if you set this to false
|
32
|
+
t.profile = 'rerun'
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Run all features'
|
36
|
+
task :all => [:ok, :wip]
|
37
|
+
|
38
|
+
task :statsetup do
|
39
|
+
require 'rails/code_statistics'
|
40
|
+
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
|
41
|
+
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
|
42
|
+
end
|
43
|
+
|
44
|
+
task :annotations_setup do
|
45
|
+
Rails.application.configure do
|
46
|
+
if config.respond_to?(:annotations)
|
47
|
+
config.annotations.directories << 'features'
|
48
|
+
config.annotations.register_extensions('feature') { |tag| /#\s*(#{tag}):?\s*(.*)$/ }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
desc 'Alias for cucumber:ok'
|
54
|
+
task :cucumber => 'cucumber:ok'
|
55
|
+
|
56
|
+
task :default => :cucumber
|
57
|
+
|
58
|
+
task :features => :cucumber do
|
59
|
+
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
|
60
|
+
end
|
61
|
+
|
62
|
+
# In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon.
|
63
|
+
task 'test:prepare' do
|
64
|
+
end
|
65
|
+
|
66
|
+
task :stats => 'cucumber:statsetup'
|
67
|
+
|
68
|
+
task :notes => 'cucumber:annotations_setup'
|
69
|
+
rescue LoadError
|
70
|
+
desc 'cucumber rake task not available (cucumber not installed)'
|
71
|
+
task :cucumber do
|
72
|
+
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/nitrolinks-rails.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = "Single-page Apps feel with less overhead"
|
13
13
|
spec.description = "Like Pjax and Turbolinks but with smarter DOM updating"
|
14
14
|
spec.homepage = "https://github.com/asartalo/nitrolinks-rails"
|
15
|
+
spec.license = "MIT"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
18
|
f.match(%r{^(test|spec|features)/})
|
@@ -19,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
22
|
spec.add_dependency "rails", "~> 5.1"
|
23
|
+
spec.add_dependency 'coffee-rails', '~> 4.2'
|
22
24
|
|
23
25
|
spec.add_development_dependency "bundler", "~> 1.13"
|
24
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nitrolinks-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wayne Duran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coffee-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,18 +91,24 @@ files:
|
|
77
91
|
- ".rspec"
|
78
92
|
- ".travis.yml"
|
79
93
|
- Gemfile
|
94
|
+
- MIT-LICENSE
|
80
95
|
- README.md
|
81
96
|
- Rakefile
|
82
97
|
- app/assets/javascripts/nitrolinks.coffee
|
98
|
+
- app/assets/javascripts/nitrolinks/testing.coffee
|
83
99
|
- app/assets/javascripts/nitrolinks/utilities.coffee
|
100
|
+
- bin/rails
|
101
|
+
- config/cucumber.yml
|
84
102
|
- lib/nitrolinks/rails.rb
|
85
103
|
- lib/nitrolinks/rails/controller.rb
|
86
104
|
- lib/nitrolinks/rails/engine.rb
|
87
105
|
- lib/nitrolinks/rails/version.rb
|
106
|
+
- lib/tasks/cucumber.rake
|
88
107
|
- nitrolinks-rails.gemspec
|
89
108
|
- vendor/assets/javascripts/set-dom.js
|
90
109
|
homepage: https://github.com/asartalo/nitrolinks-rails
|
91
|
-
licenses:
|
110
|
+
licenses:
|
111
|
+
- MIT
|
92
112
|
metadata: {}
|
93
113
|
post_install_message:
|
94
114
|
rdoc_options: []
|