-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
509 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
label: "## Table of Contents" | ||
patterns: | ||
- "README.md" | ||
root_dir: "." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "bundler/gem_tasks" | ||
require "rake/testtask" | ||
|
||
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) | ||
|
||
load "rails/tasks/engine.rake" | ||
load "rails/tasks/statistics.rake" | ||
require "bundler/gem_tasks" | ||
|
||
Rake::TestTask.new do |test| | ||
test.libs << "test" | ||
test.test_files = FileList["test/**/*_test.rb"] | ||
test.warning = false | ||
desc "Run tests" | ||
task :test, [:file] do |_, args| | ||
command = (ARGV.length > 1) ? | ||
"bin/rails test #{ARGV[1..].join(" ")}" : | ||
"bin/rails test:all" | ||
puts command | ||
exec command | ||
end | ||
|
||
task default: :test |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,69 @@ | ||
import { Idiomorph } from 'idiomorph' | ||
import schema from './schema' | ||
|
||
const input = /INPUT/i | ||
const inputTypes = /date|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/i | ||
const textarea = /TEXTAREA/i | ||
let _method | ||
let _delay = 0 | ||
|
||
const trixEditor = /TRIX-EDITOR/i | ||
|
||
const morphAllowed = node => { | ||
if (node.nodeType !== Node.ELEMENT_NODE) return true | ||
if (node !== document.activeElement) return true | ||
function isElement(node) { | ||
return node.nodeType === Node.ELEMENT_NODE | ||
} | ||
|
||
// don't morph elements marked as turbo permanent | ||
if ( | ||
function isTurboPermanent(node) { | ||
if (!isElement(node)) return false | ||
return ( | ||
node.hasAttribute(schema.turboPermanentAttribute) && | ||
node.getAttribute(schema.turboPermanentAttribute) !== 'false' | ||
) | ||
return false | ||
} | ||
|
||
// don't morph active textarea | ||
if (node.tagName.match(textarea)) return false | ||
function isActive(node) { | ||
if (!isElement(node)) return false | ||
return node === document.activeElement | ||
} | ||
|
||
// don't morph active trix-editor | ||
if (node.tagName.match(trixEditor)) return false | ||
function morphAllowed(node) { | ||
if (isTurboPermanent(node)) return false | ||
if (isActive(node) && node.tagName.match(trixEditor)) return false | ||
return true | ||
} | ||
|
||
// don't morph active inputs | ||
return node.tagName.match(input) && node.getAttribute('type').match(inputTypes) | ||
const defaultOptions = { | ||
callbacks: { beforeNodeMorphed: (oldNode, _newNode) => morphAllowed(oldNode) }, | ||
morphStyle: 'outerHTML', | ||
ignoreActiveValue: true, | ||
head: { style: 'merge' } | ||
} | ||
|
||
const callbacks = { | ||
beforeNodeMorphed: (oldNode, _newNode) => morphAllowed(oldNode) | ||
function morph(element, html, options = {}) { | ||
const callbacks = { ...defaultOptions.callbacks, ...options.callbacks } | ||
options = { ...defaultOptions, ...options, callbacks } | ||
|
||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
Idiomorph.morph(element, html, options) | ||
resolve() | ||
}, _delay) | ||
}) | ||
} | ||
|
||
const morph = (element, html) => Idiomorph.morph(element, html, { callbacks }) | ||
_method = morph | ||
|
||
export default { | ||
get delay() { | ||
return _delay | ||
}, | ||
|
||
set delay(ms) { | ||
_delay = ms | ||
}, | ||
|
||
export default morph | ||
get method() { | ||
return _method | ||
}, | ||
|
||
set method(fn) { | ||
_method = fn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env ruby | ||
# This command will automatically be run when you run "rails" with Rails gems | ||
# installed from the root of your application. | ||
|
||
ENGINE_ROOT = File.expand_path("..", __dir__) | ||
ENGINE_PATH = File.expand_path("../lib/xengine/engine", __dir__) | ||
APP_PATH = File.expand_path("../test/dummy/config/application", __dir__) | ||
|
||
# Set up gems listed in the Gemfile. | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) | ||
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) | ||
|
||
require "rails/all" | ||
require "rails/engine/commands" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
$: << File.expand_path("../test", __dir__) | ||
|
||
require "bundler/setup" | ||
require "rails/plugin/test" | ||
exec "rake test #{ARGV.join " "}".strip |
Oops, something went wrong.