Last active
August 29, 2015 14:12
-
-
Save blahutka/a34797be330b9ec4945c to your computer and use it in GitHub Desktop.
Question parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App = Ember.Application.create() | |
App.Router.map -> | |
# put your routes here | |
App.IndexRoute = Ember.Route.extend(model: -> | |
parsedInput: 'ol' | |
) | |
App.IndexController = Ember.Controller.extend( | |
out: 'start' | |
preview: 'non' | |
builder: {} | |
actions: | |
create: -> | |
link = /link:([^\s]*)/gi | |
option_reg = /select:([^:]*)\|/gi | |
while (has_link = link.exec(@get 'parsedInput' )) isnt null | |
index = has_link.index | |
options = has_link[1] | |
match = has_link[0] | |
created_link = "<a href='#'>#{options}</a> " | |
@builder[index] ||= {index: null, replace: null, with: null} | |
@builder[index].index = index | |
@builder[index].replace = match | |
@builder[index].options = options | |
@builder[index].with = created_link | |
while (has_select = option_reg.exec(@get 'parsedInput' )) isnt null | |
options = has_select[1].split('|') | |
match = has_select[0] | |
index = has_select.index | |
view = Ember.View.create( | |
template: @container.lookup('template:question-select') | |
controller: Ember.Controller.create({options: options}) | |
tagName: 'span' | |
) | |
view.createElement() | |
@builder[index] ||= {index: null, replace: null, with: null} | |
@builder[index].index = index | |
@builder[index].replace = match | |
@builder[index].options = options | |
@builder[index].with = view.element.outerHTML | |
if Object.keys(@builder).length | |
parse_out = @get('parsedInput') | |
for key of @builder | |
parse_out = parse_out.replace(@builder[key].replace, @builder[key].with) | |
@set 'out', parse_out | |
else | |
@set 'out', @get 'parsedInput' | |
#@set 'out', @get('preview') | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Ember Starter Kit</title> | |
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v2.0.0.js"></script> | |
<script src="http://builds.emberjs.com/tags/v1.9.0/ember.js"></script> | |
</head> | |
<body> | |
<script type="text/x-handlebars"> | |
<h2>Welcome to Ember.js</h2> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="index"> | |
<em>Test render dynamic views, parsing text</em> <br><br> | |
{{{out}}} <br> <br> | |
{{textarea value=parsedInput action="create" onEvent="keyPress"}} | |
<br> | |
</script> | |
<script type="text/x-handlebars" data-template-name="my-input"> | |
<input type="text" {{bind-attr value=name}}> <br> | |
{{link-to name}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="question-select"> | |
<select name="question"> | |
{{#each option in options}} | |
<option value="">{{option}}</option> | |
{{/each}} | |
</select> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment