Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Embed JavaScript & ClojureScript Live Code Snippets In Your Blog / Website!

12/18/2017

0 Comments

 
Giving someone a snippet of code for them to copy into their editor and run is cool, but giving them live code that they can run right there in their browser is like wow. These days I'm all about JavaScript and ClojureScript, and in this post I'll show you how to embed them. Let's go!

Scratch-pad, REPL-ish, Web-apps

Online editors like plunkr and klipse not only let you share your code, but they let you experiment with code in a different environment from your current project. They allow you to just dump code out and try things and hack away parts and refactor and completely throw it out if you need to. Sometimes I like to do this, and I think it is especially useful for learning clojure, playing around with core functions and data structures, and you can even easily import other libraries into your web project environment! Of course this doesn't replace git, leiningen, intellij, or webpack, the command shell, etc..., but I really do think these live web editors are great little tools that can help when developing applications in addition to being an awesome way to show some code on a blog page.   

Embed JavaScript With Plunkr

I like to use plunkr to embed html and javascript code snippets. I'm able to ebed this bit of html in my blog post's html to get this nice, live code editor in my page!
<iframe style="width: 100%; height: 600px" 
src="https://embed.plnkr.co/lhzZMEcVKN42gsNrX35A/" 
frameborder="0" allowfullscren="allowfullscren"></iframe>
You can replace the value of the src attribute to any plunkr URL to display it!

Embed ClojureScript With Klipse

For ClojureScript I like to use the klipse webapp. This one require one extra little step that is mentioned in the github README, but all you have to do is straight up copy this "setup code" for javascript / html:
<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_js: '.language-klipse-eval-js', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>
Then, just like in the javascript plunkr example, you need embed an iframe with the url to your klipse clojurescript project. You can hit Ctrl + s in the klipse web-app to get the URL with the current code in it.
<iframe style="width: 100%; height: 600px" 
src="http://app.klipse.tech/?cljs_in=(println%20%22hello!%22)%0A42" 
frameborder="0" allowfullscren="allowfullscren"></iframe>
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Want FREE access to
    my daily stock tips 
    ​newsletters??
    Sign up here:

    - Triple Gainers
    - Rippers N' Dippers
    - Growingest Growers
    ​

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2021