adzerk-oss / boot-bookmarklet Goto Github PK
View Code? Open in Web Editor NEWA Boot task for generating bookmarklets from ClojureScript namespaces
A Boot task for generating bookmarklets from ClojureScript namespaces
After running the command boot build
with a configuration like so:
(set-env! :dependencies '[[adzerk/boot-bookmarklet "0.2.0" :scope "test"]])
(require '[adzerk.boot-bookmarklet :refer (bookmarklet external-bookmarklet)])
(deftask build
[]
(comp
(speak)
(bookmarklet :ids #{"hello"})
(target)))
I get the output
Writing main.cljs.edn...
Compiling ClojureScript...
WARNING: No ClojureScript in project dependencies but ClojureScript was found in classpath. Adding direct dependency is adviced.
• main.js
Writing bookmarklets.html...
Writing target dir(s)...
Then running open target/bookmarklets.html
will open it in a browser that will look like so. Clicking this will produce the expected result, But I can't drag the link. The URL of the <a>
tag is:
javascript:%20var%20CLOSURE_UNCOMPILED_DEFINES%20%3D%20null%3B%0Aif%28typeof%20goog%20%3D%3D%20%22undefined%22%29%20document.write%28%27%3Cscript%20src%3D%22main.out%2Fgoog%2Fbase.js%22%3E%3C%2Fscript%3E%27%29%3B%0Adocument.write%28%27%3Cscript%20src%3D%22main.out%2Fcljs_deps.js%22%3E%3C%2Fscript%3E%27%29%3B%0Adocument.write%28%27%3Cscript%3Eif%20%28typeof%20goog%20%21%3D%20%22undefined%22%29%20%7B%20goog.require%28%22boot.cljs.main647%22%29%3B%20%7D%20else%20%7B%20console.warn%28%22ClojureScript%20could%20not%20load%20%3Amain%2C%20did%20you%20forget%20to%20specify%20%3Aasset-path%3F%22%29%3B%20%7D%3B%3C%2Fscript%3E%27%29%3B%0A
That URL would be the following Javascript:
var CLOSURE_UNCOMPILED_DEFINES = null;
if(typeof goog == "undefined") document.write('<script src="main.out/goog/base.js"></script>');
document.write('<script src="main.out/cljs_deps.js"></script>');
document.write('<script>if (typeof goog != "undefined") { goog.require("boot.cljs.main647"); } else { console.warn("ClojureScript could not load :main, did you forget to specify :asset-path?"); };</script>');
It looks like it's trying to load a local file, which does not seem right for a bookmarklet. It's also impossible to drag the URL.
You can view all the files here.
URL-encoded JS compiled from CLJS can easily exceed the 2000-character limit in URLs, making the bookmarklet unusable. A lot of bookmarklets (even vanilla JS ones) just source an external JS file that is hosted somewhere.
It might be nice to add a task option (or perhaps a separate task) to auto-generate a bookmarklet that does this. Maybe you could even compose this with another task that would upload the compiled JS to somewhere like S3 or Dropbox.
The simplest thing would be just a task that takes any number of script URLs and generates a bookmarklet that sources them. It could be as simple as splicing each URL into this (source):
javascript: (function () {
var jsCode = document.createElement('script');
jsCode.setAttribute('src', 'http://path/to/external/file.js');
document.body.appendChild(jsCode);
}());
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.