Coder Social home page Coder Social logo

marcneuwirth / executr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hubspot/executr

0.0 1.0 0.0 255 KB

Let your users execute the CoffeeScript in your documentation #hubspot-open-source

License: MIT License

Shell 0.03% JavaScript 98.22% CoffeeScript 1.75%

executr's Introduction

executr

Let your users execute and play with the CoffeeScript and JavaScript in your documentation

Example

See our messenger documentation for an example: http://hubspot.github.com/messenger/

Including

<!-- You should already have jQuery included -->

<!-- Code Mirror is used to make the code blocks editable -->
<script type="text/javascript" src="lib/CodeMirror/codemirror.js"></script>

<!-- Include the CodeMirror languages you're going to use -->
<script type="text/javascript" src="lib/CodeMirror/mode/coffeescript/coffeescript.js"></script>
<script type="text/javascript" src="lib/coffee-script.js"></script>

<script type="text/javascript" src="build/js/executr.js"></script>

<link rel="stylesheet" type="text/css" media="screen" href="lib/CodeMirror/codemirror.css">
<link rel="stylesheet" type="text/css" media="screen" href="build/css/executr.css">

Usage

The code blocks you wish to be executable should be wrapped in <code executable></code>.

Run $.executr on the container of multiple code elements, the body, or a single code block.

The blocks will be converted into CodeMirror Editors, and a run button will be added. If you're not interested in the code being editable, take a look at the v1.1 tag.

Only the text (not tags) in the block will be executed, feel free to wrap your already-syntax-highlighted code.

The code editor will assume the height + 10px and width of the code element.

<pre><code executable>
$ ->
  alert "Testing!"
</code></pre>
$(function(){
  $('body').executr();
});

You can also make javascript executable, by either adding a data-type="javascript" attribute to the code block, or by adding defaultType: 'javascript' to the executr call.

<code data-type="javascript" executable>
alert("Testing!");
</code>

Other Options

$.executr can be passed the following options

{
    codeSelector: 'code[executable]' # The jQuery selector items to be bound must match

    outputTo: 'div.output' # An element which should receive the output.
    appendOutput: true # Whether output should replace the contents of outputTo, or append to it

    defaultType: 'coffeescript' # The default source languange, if not supplied as a data-type attribute
    coffeeOptions: {} # Extra options for the CoffeeScript compiler

    codeMirrorOptions: {} # Extra options for CodeMirror

    setUp: -> # Code to run before each code block
    tearDown: -> # Code to run after each code block
}

Events

Executr will fire two events on the element it is bound to:

  • executrBeforeExecute(code string, normalized code language, executr options)
  • executrAfterExecute(code output, code string, normalized code language, executr options)

Contributing

You can build the project by running ./build.sh. It requires the CoffeeScript compiler.

executr's People

Contributors

zackbloom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.