Skip to content

Commit

Permalink
Add 'Link Code' button to rspec example
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Dec 19, 2013
1 parent e6f0721 commit de6f0a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 13 additions & 2 deletions source/javascripts/playground-rspec.js.rb
Expand Up @@ -20,13 +20,22 @@ def initialize

@result = Element['#result-frame']

@ruby.value = RUBY

Element.find('#run-code').on(:click) { run_code }
@link = Element.find('#link-code')

hash = `decodeURIComponent(location.hash)`

if hash.start_with? '#code:'
@ruby.value = hash[6..-1]
else
@ruby.value = RUBY.strip
end

run_code
end

def run_code
@link[:href] = "#code:#{`encodeURIComponent(#{@ruby.value})`}"
js = Opal.compile @ruby.value

update_iframe(<<-HTML)
Expand All @@ -48,6 +57,8 @@ def run_code
</body>
</html>
HTML
rescue => e
alert "#{e.class}: #{e.message}"
end

def update_iframe(html)
Expand Down
6 changes: 4 additions & 2 deletions source/rspec.html.haml
@@ -1,4 +1,3 @@

!!!
%html
%head
Expand All @@ -15,10 +14,13 @@
%a.navbar-brand Opal Playground - RSpec
.container
.collapse.navbar-collapse
%ul.nav.navbar-nav
%ul.nav.navbar-nav(style="padding: 7px")
%li
%button.btn.btn-primary#run-code
Run Code (Cmd+Enter)
%li
%a.btn.btn-default#link-code(style="padding: 6px")
Link Code

.row
.col-md-6(style="height: 100%")
Expand Down

0 comments on commit de6f0a3

Please sign in to comment.