Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Csv adapter with self parser #34

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = (grunt) ->
{dest: 'example/example.js', src: 'example/example.coffee'}
{dest: 'example/example-js.js', src: 'example/example-js.coffee'}
{dest: 'example/test.js', src: 'example/test.coffee'}
{dest: 'example/example-csv.js', src: 'example/example-csv.coffee'}
]

qunit:
Expand Down
95 changes: 95 additions & 0 deletions example/example-csv.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
###
Added Quote Example
TODO: Add More cases :)
###
readFile = (name) ->
q = new XMLHttpRequest()
q.open 'GET', name, false
q.send()
return q.responseText

require.config
baseUrl: '../js'
paths: JSON.parse readFile '../requirejs-paths.json'

require ['droplet'], (droplet) ->

# Example palette
window.editor = new droplet.Editor document.getElementById('editor'), {
# Csv TESTING:
mode: 'csv'
modeOptions: {
blockFunctions: ['pen', 'dot', 'blarg']
}
palette: [
{
name: 'Draw'
color: 'Blue'
blocks: [
{block:'Ford, 1997, E350', title: 'Three blocks'}
{block:'Ford, 1998', title: 'Two blocks'}
{block:'Ford', title: 'Single block'}
{block:'# Comment it', title: 'Comment block'}
{block: 'Ford,,,Ford',title: 'Special'}
{block: '__', title: 'Empty'}
]
}
]
}

# Example program (fizzbuzz)
examplePrograms = {
fizzbuzz: '''
# Example 1
1997,Ford,E350
# Example 1
"1997","Ford","E350"
# Example 1
1997,Ford,E350,"Super, luxurious truck"
# Example 1
1997,Ford,E350,"Super, ""luxurious"" truck"
# Example 1
1997,Ford,E350,"Go get one now
they are going fast"
'''
empty: ''
}

editor.setEditorState false
editor.aceEditor.getSession().setUseWrapMode true
editor.aceEditor.getSession().setMode 'ace/mode/csv'

# Initialize to starting text
startingText = localStorage.getItem 'example'
editor.setValue startingText or examplePrograms.fizzbuzz

# Update textarea on ICE editor change
onChange = ->
localStorage.setItem 'example', editor.getValue()

editor.on 'change', onChange

editor.aceEditor.on 'change', onChange

# Trigger immediately
do onChange

document.getElementById('which_example').addEventListener 'change', ->
editor.setValue examplePrograms[@value]

editor.clearUndoStack()

messageElement = document.getElementById 'message'
displayMessage = (text) ->
messageElement.style.display = 'inline'
messageElement.innerText = text
setTimeout (->
messageElement.style.display = 'none'
), 2000

document.getElementById('toggle').addEventListener 'click', ->
editor.toggleBlocks()
if $('#palette_dialog').dialog 'isOpen'
$('#palette_dialog').dialog 'close'
else
$("#palette_dialog").dialog 'open'
104 changes: 104 additions & 0 deletions example/example-csv.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

<!-- Added a Quote example -->
<html>
<head>
<title>ICE Editor Demo</title>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/themes/smoothness/jquery-ui.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
font-family: sans-serif;
overflow: hidden;
margin: 0px; padding: 0px;
}
#out {
height: 200px;
width: 500px;
}
#editor {
position: absolute;
top: 0px;
bottom: 0px;
right: 0px;
left: 0px;
background-color: #EEE;
z-index: 0;
}
#out_wrapper {
position: absolute;
top: 0px; left: 0; right: 900px; bottom: 0;
}
#out {
width: 100%; height: 100%;
}
#toolbar {
z-index: 9999;
position: absolute;
height: 70px;
width: 320px;
bottom: 0;
right: 0;
}
#message {
color: #F00;
display: none;
font-family: inherit;
font-size: 13px;
padding-left: 10px;
}
#which_example {
height: 30px;
line-height: 30px;
vertical-align: top;
font-size: 13px;
position: absolute;
background: #FFF;
top: 0;
width: 150px;
right: 160px;
cursor: pointer;
}
#toggle {
height: 30px;
line-height: 30px;
position: absolute;
right: 0;
top: 0;
width: 150px;
cursor: pointer;
}
#palette_dialog {
min-height: 500px !important;
z-index: 1 !important;
padding: 0px !important;
width: 100%;
position: relative;
}
</style>
</head>
<body>
<div id='editor'>
</div>
<div id='toolbar'>
<button id='toggle'>Toggle Blocks</button>
<select id='which_example'>
<option value='fizzbuzz'>Fizzbuzz</option>
<option value='Quote'>Quote</option>
<option value='empty'>Empty</option>
</select>
<span id='message'></span>
</div>
<div id='logs'><div id="logsContent"></div></div>
<div id='closeLogs'>x</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>
<script src="../vendor/sax.js"></script>
<script src="../vendor/ace/ace.js"></script>
<script src="../vendor/quadtree.js"></script>
<script src="../vendor/acorn.js"></script>
<script src="../vendor/require.js"></script>
<script src="example-csv.js"></script>
<script src="//localhost:35729/livereload.js"></script>
<link rel="stylesheet" type="text/css" href="../css/droplet.css"/>
</body>
</html>
1 change: 1 addition & 0 deletions requirejs-paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"droplet-draw": "draw",
"droplet-coffee": "coffee",
"droplet-javascript": "javascript",
"droplet-csv": "csv",
"droplet-parser": "parser",
"droplet-helper": "helper",
"droplet": "main"
Expand Down
Loading