codebasket
v1.0.1
Published
Codebasket is a client-side interface for [CodePicnic](https://codepicnic.com)'s consoles. It can be used as a simple web-based editor or as a web UI for other Docker-container-as-a-services.
Downloads
4
Readme
Codebasket
Codebasket is a client-side interface for CodePicnic's consoles. It can be used as a simple web-based editor or as a web UI for other Docker-container-as-a-services.
Requirements
- JavaScript 😉
- ACE editor
Installation
From NPM (Using Browserify or Webpack):
npm install codebasket
Using <script>
:
Use the codebasket.js
file located in the build
folder.
Usage
From NPM (Using Browserify or Webpack):
var CodeBasket = require('codebasket'),
basket = CodeBasket.create({
element: '#codebasket-test'
});
basket.render();
Using <script>
:
<div id="codebasket-test"></div>
<script src="codebasket.js"></script>
<script>
var basket = CodeBasket.create({
element: '#codebasket-test'
});
basket.render();
</script>
Also, you need to add the codebasket.css
file for style the interface. You can change the source (in SASS) by editing the sass
folder.
Options
The options available for CodeBasket.create
are:
element
: The container's selector where the interface will be built.items
: An array with items (iframes, files or browsers) for the console.sidebarItems
: An object with files definitions that will appear in the sidebar (name, type, files inside a directory).sidebarActions
: An array with actions specifically defined for the sidebar.toolbarOptions
: An array with options shown as buttons in the console's toolbar.options
: An array with options shown as a list in the console's settings dropdown.ui
: An object with the following properties:sidebarSize
: (number, default:200
) Default sidebar size.isFullScreen
: (boolean, default:false
) Indicates if the console will be in full screen layout by default (sidebar and tabs hidden).isSidebarVisible
: (boolean, default:true
) Indicates if the sidebar is visible by default.isProgressBarVisible
: (boolean, default:false
) Indicates if the progress bar in the footer is visible.isAddTabVisible
: (boolean, default:true
) Indicates if the "Add" button will be shown (useful for client-side consoles if you want to allow your users to keep adding new tabs).addAction
: (function, default:null
) Overrides the "Add" button's functionality.
Item specification
An item can be an iframe, file or browser and are placed in the tabs container. The fields available for all the items are the following:
{
type: "file"|"browser"|"iframe", // default "iframe"
isVisible: true|false, // if the item will be shown in the tabs container (default false)
content: "", // if the item is `file` type
name: "", // can be same as title
language: "", // if the item is `file` type
title: "", // can be same as name
id: "", // unique identifier, can be autogenerated
location: "URL", // if the item is `browser` or `iframe`
}
File
To add a file in a CodeBasket instance you can use the following fields:
{
type: "file",
isVisible: true|false, // if the item will be shown in the tabs container
content: "", // the file's content
name: "", // usually the file's full path
title: "", // can be same as name
language: "", // file's language, to activate syntax highlighting and autocomplete
id: "", // unique identifier, can be autogenerated
}
Browser
To add a browser in a CodeBasket instance you can use the following fields:
{
type: "browser"
isVisible: true|false, // if the item will be shown in the tabs container
name: "", // a simple name like "Result"
title: "", // can be same as name
id: "", // unique identifier, can be autogenerated
location: "URL", // the browser's initial location
}
Iframe
To add an iframe in a CodeBasket instance you can use the following fields:
{
type: "iframe"
isVisible: true|false, // if the item will be shown in the tabs container
name: "", // a simple name like "Readme" or "Getting started"
title: "", // can be same as name
id: "", // unique identifier, can be autogenerated
location: "URL", // the iframe's page location
}
SidebarItem specification
A SidebarItem is placed inside the CodeBasket's sidebar, represents a file or folder, and accepts these fields:
{
name: "", // file's name
path: "", // file's absolute path
type: "" // file's MIME type
}
SidebarAction specification
A SidebarAction allow interactivity in the sidebar and can perform actions with the sidebar's files and folders, like saving or creating a new one. SidebarActions are rendered as buttons on the top of the sidebar and accepts these fields:
{
title: "", // button's tooltip's content
icon: "", // font-based classes for icons (eg: FontAwesome)
action: function() {} // to be called when the SidebarAction is clicked
}
ToolbarOption specification
A ToolbarOption is similar to a SidebarAction, but placed at the right of the tabs container and work in similar way. These ToolbarOptions perform actions for the whole CodeBasket instance, like adding a new browser or running the CodeBasket's content.
ToolbarOption accepts the following fields:
{
title: "", // button's tooltip's content
icon: "", // font-based classes for icons (eg: FontAwesome)
href: "", // ToolbarOption can be a link too
action: function() {} // to be called when the ToolbarOption is clicked
}
Events
CodeBasket fires DOM events for specific actions:
codebasket:ready
: Fired when the CodeBasket instance is rendered and ready to use.codebasket:sidebarsizechange
: Fired when the sidebar changed its width.codebasket:change
: Fired when there is a change in the code editor's value (eg: when the user wrote in the code editor).codebasket:changesession
: Fired when the code editor changed from EditSession (eg: when the user opened or went to another file).codebasket:openfolder
: Fired when a folder is opened (clicked) in the sidebar.codebasket:openfile
: Fired when a file is opened (clicked) in the sidebar.codebasket:removeentry
: Fired when a file or folder is removed from the sidebar.codebasket:dropfiles
: Fired when a local file is dropped in the sidebar.codebasket:addsession
: Fired when a new EditSession is added (eg: when the user opened a new file)codebasket:addlibrary
: Fired when a client-side library is added to the CodeBasket instance (only for client-side consoles).codebasket:removelibrary
: Fired when a client-side library is removed from the CodeBasket instance (only for client-side consoles).codebasket:tabselected
: Fired when another tab is selected.codebasket:renameitem
: Fired when an item is renamed (eg: double-clicking in the tab).codebasket:itemchangedpane
: Fired when an item changed its location (from top to down panes or vice versa).
Building
Clone the repository:
git clone https://github.com/CodePicnic/codebasket
And run the dist
task in your terminal (you must have Gulp installed in your machine):
gulp dist
To create a minified version run:
NODE_ENV=production gulp dist
Requirements
- Browserify
- Gulp
- PhantomJS
- ACE editor (inside
test
directory)
Testing
Run gulp test
in your terminal (you can also open the test/runner.html
file in a browser).
Browser support
Tested in:
- Google Chrome
- Mozilla Firefox
- Apple Safari
- Opera
License
MIT License. Copyright 2016 Gustavo Leon. http://github.com/hpneo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.