Skip to content

Commit

Permalink
Merge pull request #188 from Shopify/rm-decaffeinate
Browse files Browse the repository at this point in the history
Remove coffeescript from this library
  • Loading branch information
rafaelfranca authored Sep 13, 2023
2 parents fc9e3c1 + a1371d9 commit b807f33
Show file tree
Hide file tree
Showing 57 changed files with 4,342 additions and 3,619 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Build

on: [push, pull_request]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Setup Firefox
uses: browser-actions/[email protected]
- name: Setup Geckodriver
uses: browser-actions/[email protected]
- name: Start xvfb
run: /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- name: Run tests
run: bundle exec rake ci
env:
DISPLAY: ":99.0"
DRIVER: "selenium"
24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

11 changes: 2 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ PATH
remote: .
specs:
turbograft (0.4.8)
coffee-rails

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -87,20 +86,12 @@ GEM
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.3)
coffee-rails (5.0.0)
coffee-script (>= 2.2.0)
railties (>= 5.2.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.2.2)
crass (1.0.6)
daemons (1.4.1)
date (3.3.3)
erubi (1.12.0)
eventmachine (1.2.7)
execjs (2.9.0)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.1)
Expand Down Expand Up @@ -209,6 +200,7 @@ GEM
timeout (0.4.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
webrick (1.8.1)
websocket (1.2.9)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
Expand Down Expand Up @@ -238,6 +230,7 @@ DEPENDENCIES
teaspoon-mocha
thin
turbograft!
webrick

BUNDLED WITH
2.4.8
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Turbograft was built with simplicity in mind. It intends to offer the smallest a

## Status
[![Gem Version](https://badge.fury.io/rb/turbograft.svg)](http://badge.fury.io/rb/turbograft)
[![Build Status](https://travis-ci.org/Shopify/turbograft.svg?branch=master)](http://travis-ci.org/Shopify/turbograft)
[![Build](https://github.com/Shopify/turbograft/actions/workflows/build.yml/badge.svg)](https://github.com/Shopify/turbograft/actions/workflows/build.yml)

## Installation

Expand Down Expand Up @@ -189,9 +189,10 @@ There is an example app that you can boot to play with TurboGraft. Open the con

When turbograft replaces or removes a node it uses native DOM API to do so. If any objects use jQuery to listen to events on a node then these objects will leak when the node is replaced because jQuery will still have references to it. To clean these up you'll need to tell jQuery that they're removed. This can be done with something like:

```coffeescript
document.addEventListener 'page:after-node-removed', (event) ->
$(event.data).remove()
```js
document.addEventListener('page:after-node-removed', function(event) {
$(event.data).remove();
});
```

## Contributing
Expand Down
30 changes: 0 additions & 30 deletions lib/assets/javascripts/turbograft.coffee

This file was deleted.

37 changes: 37 additions & 0 deletions lib/assets/javascripts/turbograft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//= require_self
//= require_tree ./turbograft

if (window.TurboGraft == null) { window.TurboGraft = { handlers: {} }; }

TurboGraft.tgAttribute = function(attr) {
if (attr.slice(0, 3) === 'tg-') {
return `data-${attr}`;
} else {
return `data-tg-${attr}`;
}
};

TurboGraft.getTGAttribute = function(node, attr) {
const tgAttr = TurboGraft.tgAttribute(attr);
return node.getAttribute(tgAttr) || node.getAttribute(attr);
};

TurboGraft.removeTGAttribute = function(node, attr) {
const tgAttr = TurboGraft.tgAttribute(attr);
node.removeAttribute(tgAttr);
node.removeAttribute(attr);
};

TurboGraft.hasTGAttribute = function(node, attr) {
const tgAttr = TurboGraft.tgAttribute(attr);
return node.hasAttribute(tgAttr) || node.hasAttribute(attr);
};

TurboGraft.querySelectorAllTGAttribute = function(node, attr, value = null) {
const tgAttr = TurboGraft.tgAttribute(attr);
if (value) {
return node.querySelectorAll(`[${tgAttr}=${value}], [${attr}=${value}]`);
} else {
return node.querySelectorAll(`[${tgAttr}], [${attr}]`);
}
};
34 changes: 0 additions & 34 deletions lib/assets/javascripts/turbograft/click.coffee

This file was deleted.

44 changes: 44 additions & 0 deletions lib/assets/javascripts/turbograft/click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// The Click class handles clicked links, verifying if Turbolinks should
// take control by inspecting both the event and the link. If it should,
// the page change process is initiated. If not, control is passed back
// to the browser for default functionality.
window.Click = class Click {
static installHandlerLast(event) {
if (!event.defaultPrevented) {
document.removeEventListener('click', Click.handle, false);
document.addEventListener('click', Click.handle, false);
}
}

static handle(event) {
return new Click(event);
}

constructor(event) {
this.event = event;
if (this.event.defaultPrevented) { return; }
this._extractLink();
if (this._validForTurbolinks()) {
Turbolinks.visit(this.link.href);
this.event.preventDefault();
}
}

_extractLink() {
let link = this.event.target;
while (!!link.parentNode && (link.nodeName !== 'A')) { link = link.parentNode; }
if ((link.nodeName === 'A') && (link.href.length !== 0)) { this.link = new Link(link); }
}

_validForTurbolinks() {
return (this.link != null) && !this.link.shouldIgnore() && !this._nonStandardClick();
}

_nonStandardClick() {
return (this.event.which > 1) ||
this.event.metaKey ||
this.event.ctrlKey ||
this.event.shiftKey ||
this.event.altKey;
}
};
24 changes: 0 additions & 24 deletions lib/assets/javascripts/turbograft/component_url.coffee

This file was deleted.

53 changes: 53 additions & 0 deletions lib/assets/javascripts/turbograft/component_url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* The ComponentUrl class converts a basic URL string into an object
* that behaves similarly to document.location.
*
* If an instance is created from a relative URL, the current document
* is used to fill in the missing attributes (protocol, host, port).
*/
window.ComponentUrl = class ComponentUrl {
constructor(original, link) {
if (original == null) {
original = document.location.href;
}
if (link == null) {
link = document.createElement('a');
}
if (original.constructor === ComponentUrl) {
return original;
}
this.original = original;
this.link = link;
this._parse();
}

withoutHash() {
return this.href.replace(this.hash, '');
};

// Intention revealing function alias
withoutHashForIE10compatibility() {
return this.withoutHash();
};

hasNoHash() {
return this.hash.length === 0;
};

_parse() {
this.link.href = this.original;
this.href = this.link.href;
this.protocol = this.link.protocol;
this.host = this.link.host;
this.hostname = this.link.hostname
this.port = this.link.port;
this.pathname = this.link.pathname;
this.search = this.link.search;
this.hash = this.link.hash;
this.origin = [this.protocol, '//', this.hostname].join('');
if (this.port.length !== 0) {
this.origin += ":" + this.port;
}
this.relative = [this.pathname, this.search, this.hash].join('');
return this.absolute = this.href;
};
};
9 changes: 0 additions & 9 deletions lib/assets/javascripts/turbograft/csrf_token.coffee

This file was deleted.

23 changes: 23 additions & 0 deletions lib/assets/javascripts/turbograft/csrf_token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
window.CSRFToken = class CSRFToken {
static get(doc) {
if (!doc) { doc = document; }
const tag = doc.querySelector('meta[name="csrf-token"]');

const object = {
node: tag
};

if (tag) {
object.token = tag.getAttribute('content');
}

return object;
}

static update(latest) {
const current = this.get();
if ((current.token != null) && (latest != null) && (current.token !== latest)) {
current.node.setAttribute('content', latest);
}
}
};
Loading

0 comments on commit b807f33

Please sign in to comment.