smalruby-editor 0.0.8-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of smalruby-editor might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rspec +4 -0
- data/.rubocop.yml +19 -0
- data/.ruby-version +1 -0
- data/.simplecov +7 -0
- data/.travis.yml +23 -0
- data/LEGAL +13 -0
- data/LICENSE +22 -0
- data/Procfile +1 -0
- data/README.rdoc +46 -0
- data/Rakefile +9 -0
- data/app/assets/images/.keep +0 -0
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/javascripts/application.js +21 -0
- data/app/assets/javascripts/editor.js.coffee.erb +139 -0
- data/app/assets/stylesheets/application.css +19 -0
- data/app/assets/stylesheets/editor.css.scss +19 -0
- data/app/assets/stylesheets/flatstrap-custom.css.scss +2 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/concerns/.keep +0 -0
- data/app/controllers/editor_controller.rb +5 -0
- data/app/controllers/source_codes_controller.rb +106 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/helpers/editor_helper.rb +2 -0
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/models/concerns/.keep +0 -0
- data/app/models/source_code.rb +49 -0
- data/app/views/editor/index.html.erb +23 -0
- data/app/views/layouts/application.html.erb +15 -0
- data/bin/bundle +3 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/smalruby-editor +80 -0
- data/config/application.rb +16 -0
- data/config/boot.rb +17 -0
- data/config/database.yml.mysql2 +48 -0
- data/config/database.yml.sqlite3 +31 -0
- data/config/database.yml.travis +5 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +30 -0
- data/config/environments/production.rb +86 -0
- data/config/environments/standalone.rb +16 -0
- data/config/environments/test.rb +46 -0
- data/config/initializers/backtrace_silencers.rb +9 -0
- data/config/initializers/filter_parameter_logging.rb +4 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/secret_token.rb +17 -0
- data/config/initializers/session_store.rb +4 -0
- data/config/initializers/wrap_parameters.rb +15 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +68 -0
- data/config/unicorn.rb +23 -0
- data/config.ru +4 -0
- data/db/migrate/20131216121603_create_source_codes.rb +9 -0
- data/db/migrate/20131219045113_add_filename_to_source_code.rb +5 -0
- data/db/schema.rb +23 -0
- data/db/seeds.rb +7 -0
- data/lib/assets/.keep +0 -0
- data/lib/smalruby_editor/version.rb +3 -0
- data/lib/smalruby_editor.rb +46 -0
- data/lib/tasks/.keep +0 -0
- data/lib/tasks/gem.rake +10 -0
- data/lib/tasks/rspec.rake +16 -0
- data/lib/tasks/rubocop.rake +3 -0
- data/log/.keep +0 -0
- data/public/404.html +58 -0
- data/public/422.html +58 -0
- data/public/500.html +57 -0
- data/public/assets/application-759ce4d1ac1e0e3991e6d350c8f98fc5.js +5267 -0
- data/public/assets/application-759ce4d1ac1e0e3991e6d350c8f98fc5.js.gz +0 -0
- data/public/assets/application-f51ea0e777d97f12a8ce84308f31eb57.css +4791 -0
- data/public/assets/application-f51ea0e777d97f12a8ce84308f31eb57.css.gz +0 -0
- data/public/assets/favicon-c7ae857bb9d06de8742ae2d337157e83.ico +0 -0
- data/public/assets/loading-e8e6dd7833131c92a6c3b9c8ccc6a6ac.gif +0 -0
- data/public/assets/manifest-f86249f9779f8f4d7c8fc148e4361b4f.json +1 -0
- data/public/assets/progressbar-82023a146fba2a0f6d925629ed2b09c5.gif +0 -0
- data/public/favicon.ico +0 -0
- data/public/fonts/FontAwesome.otf +0 -0
- data/public/fonts/fontawesome-webfont.eot +0 -0
- data/public/fonts/fontawesome-webfont.ttf +0 -0
- data/public/fonts/fontawesome-webfont.woff +0 -0
- data/public/robots.txt +5 -0
- data/smalruby-editor.gemspec +81 -0
- data/spec/acceptance/readme.md +3 -0
- data/spec/acceptance/standalone/save.feature +32 -0
- data/spec/acceptance/text_editor/base.feature +24 -0
- data/spec/acceptance/text_editor/check.feature +25 -0
- data/spec/acceptance/text_editor/load.feature +81 -0
- data/spec/acceptance/text_editor/save.feature +34 -0
- data/spec/controllers/editor_controller_spec.rb +12 -0
- data/spec/controllers/source_codes_controller_spec.rb +469 -0
- data/spec/fixtures/files/01.rb +57 -0
- data/spec/fixtures/files/favicon.ico +0 -0
- data/spec/helpers/editor_helper_spec.rb +14 -0
- data/spec/lib/smalruby_editor_spec.rb +66 -0
- data/spec/models/source_code_spec.rb +55 -0
- data/spec/spec_helper.rb +156 -0
- data/spec/steps/ace_steps.rb +59 -0
- data/spec/steps/global_variable.rb +39 -0
- data/spec/steps/text_editor_steps.rb +183 -0
- data/spec/support/assets.rb +18 -0
- data/spec/support/capybara.rb +17 -0
- data/spec/support/env.rb +15 -0
- data/spec/turnip_helper.rb +2 -0
- data/vendor/assets/javascripts/.keep +0 -0
- data/vendor/assets/stylesheets/.keep +0 -0
- metadata +407 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 952849fa0d74cd9cebdccfddd7cebc62331729f4
|
4
|
+
data.tar.gz: f490fa958cb3f410b487debd06804e154b6b8aac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 337c5aec647bcd02daa8240517bfb1073ae864873a6d0f24ff5f30455ef9ef44b558f6363ae45629d79ed4a8a41994e01dc5cdce75ae2ff8f4b0bc6f06d32b93
|
7
|
+
data.tar.gz: 7736e15f8c418abee725e19ba163207caa4960eb3882301e3dd08a768957ea2e7a726713045b830b70bbd54162f5a0734030d19b44c3a48ac150e86cef633c86
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*.log
|
16
|
+
/tmp
|
17
|
+
|
18
|
+
/config/database.yml
|
19
|
+
|
20
|
+
/public/assets
|
21
|
+
|
22
|
+
/.env
|
23
|
+
/coverage
|
24
|
+
/pkg
|
25
|
+
/features
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
AllCops:
|
2
|
+
Excludes:
|
3
|
+
- db/seeds.rb
|
4
|
+
- spec/fixtures/**
|
5
|
+
|
6
|
+
AsciiComments:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
# メソッドの戻り値としてブロックの値を使う場合にもエラーになるため無効
|
10
|
+
# にしている
|
11
|
+
Blocks:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
# WindowsだとEndOfLine copが動作しないため無効にしている
|
18
|
+
EndOfLine:
|
19
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p353
|
data/.simplecov
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
|
6
|
+
before_script:
|
7
|
+
- cp config/database.yml.travis config/database.yml
|
8
|
+
- mysql -e 'create database myapp_test;'
|
9
|
+
|
10
|
+
script:
|
11
|
+
- export COVERALLS='1'
|
12
|
+
- RAILS_ENV=test bundle exec rake db:migrate --trace
|
13
|
+
- bundle exec rake db:test:prepare
|
14
|
+
- bundle exec rake
|
15
|
+
|
16
|
+
deploy:
|
17
|
+
provider: heroku
|
18
|
+
api_key:
|
19
|
+
secure: HqZ7FylThjaB3XguCZJbccu7dB8CvWIWFlZpWLLfJwfUkjvoEC1F6VPFakFbwjLXLsvaKlYLakzL+bhaLnxu+HyeNmCrvpIRR2j8EuHmSkxdWrlxAZRV2ojHuDpZuVNaEzd7YtcBCoPiTvqnxWzhAfzZWbPrZfCdA1f+5t5/So0=
|
20
|
+
app: smalruby
|
21
|
+
on:
|
22
|
+
repo: smalruby/smalruby-editor
|
23
|
+
run: "rake db:migrate"
|
data/LEGAL
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
LEGAL NOTICE INFORMATION
|
2
|
+
------------------------
|
3
|
+
|
4
|
+
All the files in this distribution are covered under either the
|
5
|
+
smalruby-editor's license (see the file LICENSE) except some files
|
6
|
+
mentioned below.
|
7
|
+
|
8
|
+
public/fonts/FontAwesome.otf, public/fonts/fontawesome-webfont.eot,
|
9
|
+
public/fonts/fontawesome-webfont.ttf,
|
10
|
+
public/fonts/fontawesome-webfont.woff:
|
11
|
+
|
12
|
+
These's license is SIL Open Font License (OFL) 1.1:
|
13
|
+
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL .
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kouji Takao
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Procfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
== smalruby-editor
|
2
|
+
|
3
|
+
{<img src="https://badge.fury.io/rb/smalruby-editor.png" alt="Gem Version" />}[http://badge.fury.io/rb/smalruby-editor]
|
4
|
+
{<img src="https://travis-ci.org/smalruby/smalruby-editor.png?branch=master" alt="Build Status" />}[https://travis-ci.org/smalruby/smalruby-editor]
|
5
|
+
{<img src="https://coveralls.io/repos/smalruby/smalruby-editor/badge.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/smalruby/smalruby-editor?branch=master]
|
6
|
+
{<img src="https://codeclimate.com/github/smalruby/smalruby-editor.png" />}[https://codeclimate.com/github/smalruby/smalruby-editor]
|
7
|
+
{<img src="https://gemnasium.com/takaokouji/smalruby-editor.png" alt="Dependency Status" />}[https://gemnasium.com/takaokouji/smalruby-editor]
|
8
|
+
|
9
|
+
The smalruby-editor is a visual programming editor that can create a Ruby script by combining individual blocks similar to Scratch. It can also enter the program as better than Scratch.
|
10
|
+
|
11
|
+
The smalruby-editor is a part of the Smalruby Project.
|
12
|
+
|
13
|
+
The Smalruby(smɔ́ːrúːbi) Project will provide a Ruby learning environment for middle school students from the upper grades of elementary school. The goal of this project is to achieve software and community sites such as the {Scratch}[http://scratch.mit.edu/] in Ruby. The Scratch has experience as educational programming environment can be used in elementary school. This project consists of the following elements.
|
14
|
+
|
15
|
+
== Installation (for Developer)
|
16
|
+
|
17
|
+
requirements:
|
18
|
+
|
19
|
+
* Windows or UNIX like OS (Mac OS X, Linux, etc...)
|
20
|
+
* Ruby 2.0.0-p353 or higher.
|
21
|
+
* MySQL
|
22
|
+
* Git
|
23
|
+
|
24
|
+
execute below commands.
|
25
|
+
|
26
|
+
git clone https://github.com/smalruby/smalruby-editor.git
|
27
|
+
cd smalruby-editor
|
28
|
+
bundle
|
29
|
+
rake db:create
|
30
|
+
rake db:migrate
|
31
|
+
rake
|
32
|
+
rails server
|
33
|
+
|
34
|
+
access <tt>localhost:3000</tt> with your web browser.
|
35
|
+
|
36
|
+
== Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (<tt>git checkout -b my-new-feature</tt>)
|
40
|
+
3. Commit your changes (<tt>git commit -am 'Add some feature'</tt>)
|
41
|
+
4. Push to the branch (<tt>git push origin my-new-feature</tt>)
|
42
|
+
5. Create new Pull Request
|
43
|
+
|
44
|
+
== License
|
45
|
+
|
46
|
+
MIT (see link:LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
|
6
|
+
SmalrubyEditor::Application.load_tasks
|
7
|
+
|
8
|
+
task(:default).clear
|
9
|
+
task default: [:rubocop, :spec]
|
File without changes
|
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require turbolinks
|
16
|
+
//= require ace/ace
|
17
|
+
//= require ace/theme-github.js
|
18
|
+
//= require ace/mode-ruby.js
|
19
|
+
//= require bootstrap.js
|
20
|
+
//= require jquery-fileupload/basic
|
21
|
+
//= require_tree .
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# Place all the behaviors and hooks related to the matching controller here.
|
2
|
+
# All this logic will automatically be available in application.js.
|
3
|
+
# You can use CoffeeScript in this file: http://coffeescript.org/
|
4
|
+
|
5
|
+
changed = false
|
6
|
+
|
7
|
+
successMessage = (title, msg = '', selector = '#messages') ->
|
8
|
+
html = $('<div class="alert alert-success" style="display: none">')
|
9
|
+
.append("<h4><i class=\"icon-star\"></i>#{title}</h4>")
|
10
|
+
.append(msg)
|
11
|
+
$(selector).append(html)
|
12
|
+
html.fadeIn('slow')
|
13
|
+
.delay(3000)
|
14
|
+
.fadeOut('slow')
|
15
|
+
|
16
|
+
errorMessage = (msg, selector = '#messages') ->
|
17
|
+
html = $('<div class="alert alert-error" style="display: none">')
|
18
|
+
.append('<button type="button" class="close" data-dismiss="alert">×</button>')
|
19
|
+
.append('<h4><i class="icon-exclamation-sign"></i>エラー</h4>')
|
20
|
+
.append(msg)
|
21
|
+
$(selector).append(html)
|
22
|
+
html.fadeIn('slow')
|
23
|
+
.delay(10000)
|
24
|
+
.fadeOut('slow')
|
25
|
+
|
26
|
+
$ ->
|
27
|
+
saving = false
|
28
|
+
|
29
|
+
textEditor = ace.edit('text-editor')
|
30
|
+
textEditor.setTheme('ace/theme/github')
|
31
|
+
textEditor.setShowInvisibles(true)
|
32
|
+
|
33
|
+
textEditor.focus()
|
34
|
+
textEditor.gotoLine(0, 0)
|
35
|
+
|
36
|
+
textEditor.on 'change', (e) ->
|
37
|
+
changed = true
|
38
|
+
|
39
|
+
session = textEditor.getSession()
|
40
|
+
session.setMode('ace/mode/ruby')
|
41
|
+
session.setTabSize(2)
|
42
|
+
session.setUseSoftTabs(true)
|
43
|
+
|
44
|
+
$('#check-button').click (e) ->
|
45
|
+
e.preventDefault()
|
46
|
+
$.ajax
|
47
|
+
url: '/source_codes/check'
|
48
|
+
type: 'POST'
|
49
|
+
data:
|
50
|
+
source_code:
|
51
|
+
data: session.getDocument().getValue()
|
52
|
+
dataType: 'json'
|
53
|
+
success: (data, textStatus, jqXHR) ->
|
54
|
+
if data.length == 0
|
55
|
+
successMessage('チェックしました', 'ただし、プログラムを動かすとエラーが見つかるかもしれません。')
|
56
|
+
else
|
57
|
+
for errorInfo in data
|
58
|
+
do (errorInfo) ->
|
59
|
+
msg = "#{errorInfo.row}行"
|
60
|
+
if errorInfo.column > 0
|
61
|
+
msg += "、#{errorInfo.column}文字"
|
62
|
+
errorMessage(msg + ": #{errorInfo.message}")
|
63
|
+
|
64
|
+
$('#save-button').click (e) ->
|
65
|
+
e.preventDefault()
|
66
|
+
filename = $.trim($('#filename').val())
|
67
|
+
if filename.length <= 0
|
68
|
+
errorMessage('セーブする前にプログラムに名前をつけてね!')
|
69
|
+
$('#filename').focus()
|
70
|
+
else
|
71
|
+
afterSave = ->
|
72
|
+
saving = true
|
73
|
+
changed = false
|
74
|
+
successMessage('セーブしました')
|
75
|
+
$.ajax
|
76
|
+
url: '/source_codes/'
|
77
|
+
type: 'POST'
|
78
|
+
data:
|
79
|
+
source_code:
|
80
|
+
filename: filename
|
81
|
+
data: session.getDocument().getValue()
|
82
|
+
dataType: 'json'
|
83
|
+
success: (data, textStatus, jqXHR) ->
|
84
|
+
<% if Rails.env == 'standalone' %>
|
85
|
+
$.ajax
|
86
|
+
url: '/source_codes/write'
|
87
|
+
type: 'DELETE'
|
88
|
+
dataType: 'json'
|
89
|
+
success: (data, textStatus, jqXHR) ->
|
90
|
+
if data.source_code.error && confirm("前に#{filename}という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")
|
91
|
+
$.ajax
|
92
|
+
url: '/source_codes/write'
|
93
|
+
type: 'DELETE'
|
94
|
+
data:
|
95
|
+
force: true
|
96
|
+
dataType: 'json'
|
97
|
+
success: (data, textStatus, jqXHR) ->
|
98
|
+
afterSave()
|
99
|
+
else
|
100
|
+
afterSave()
|
101
|
+
<% else %>
|
102
|
+
afterSave()
|
103
|
+
$('#download-link').click()
|
104
|
+
<% end %>
|
105
|
+
|
106
|
+
$('#filename').keypress (e) ->
|
107
|
+
e = window.event if !e
|
108
|
+
if e.keyCode == 13
|
109
|
+
$('#save-button').click()
|
110
|
+
false
|
111
|
+
else
|
112
|
+
true
|
113
|
+
|
114
|
+
$('#load-button').click (e) ->
|
115
|
+
e.preventDefault()
|
116
|
+
if changed
|
117
|
+
return unless confirm('まだセーブしていないのでロードするとプログラムが消えてしまうよ!\nそれでもロードしますか?')
|
118
|
+
$(@).parent().find('input[name="source_code[file]"]').click()
|
119
|
+
|
120
|
+
$('#file-form').fileupload
|
121
|
+
dataType: 'json'
|
122
|
+
done: (e, data) ->
|
123
|
+
info = data.result.source_code
|
124
|
+
if info.error
|
125
|
+
errorMessage(info.filename + 'は' + info.error)
|
126
|
+
else
|
127
|
+
$('#filename').val(info.filename)
|
128
|
+
session.getDocument().setValue(info.data)
|
129
|
+
textEditor.focus()
|
130
|
+
textEditor.moveCursorTo(0, 0)
|
131
|
+
changed = false
|
132
|
+
successMessage('ロードしました')
|
133
|
+
|
134
|
+
window.onbeforeunload = (event) ->
|
135
|
+
if !saving && session.getDocument().getValue().length > 0
|
136
|
+
return '作成中のプログラムが消えてしまうよ!'
|
137
|
+
else
|
138
|
+
saving = false
|
139
|
+
return
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require flatstrap-custom
|
12
|
+
*= require_self
|
13
|
+
*= require_tree .
|
14
|
+
*/
|
15
|
+
|
16
|
+
html, body {
|
17
|
+
height: 100%;
|
18
|
+
margin: 0;
|
19
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// Place all the styles related to the editor controller here.
|
2
|
+
// They will automatically be included in application.css.
|
3
|
+
// You can use Sass (SCSS) here: http://sass-lang.com/
|
4
|
+
|
5
|
+
#messages {
|
6
|
+
position: absolute;
|
7
|
+
right: 20px;
|
8
|
+
z-index: 9999;
|
9
|
+
}
|
10
|
+
|
11
|
+
#text-editor {
|
12
|
+
position: absolute;
|
13
|
+
left: 0;
|
14
|
+
top: 60px;
|
15
|
+
right: 0;
|
16
|
+
bottom: 0;
|
17
|
+
|
18
|
+
font-size: 16pt;
|
19
|
+
}
|
File without changes
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'nkf'
|
3
|
+
|
4
|
+
class SourceCodesController < ApplicationController
|
5
|
+
before_filter :check_whether_standalone, only: :write
|
6
|
+
|
7
|
+
def check
|
8
|
+
render json: SourceCode.new(source_code_params).check_syntax
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
sc = SourceCode.create!(source_code_params)
|
13
|
+
session[:source_code] = {
|
14
|
+
id: sc.id,
|
15
|
+
digest: sc.digest,
|
16
|
+
}
|
17
|
+
render json: { source_code: { id: sc.id } }
|
18
|
+
end
|
19
|
+
|
20
|
+
def download
|
21
|
+
send_data(source_code.data,
|
22
|
+
filename: url_encode_filename(source_code.filename),
|
23
|
+
disposition: 'attachment',
|
24
|
+
type: 'text/plain; charset=utf-8')
|
25
|
+
|
26
|
+
destroy_source_code_and_delete_session(source_code)
|
27
|
+
end
|
28
|
+
|
29
|
+
def write
|
30
|
+
res = { source_code: { filename: source_code.filename } }
|
31
|
+
|
32
|
+
write_source_code(source_code)
|
33
|
+
|
34
|
+
destroy_source_code_and_delete_session(source_code)
|
35
|
+
|
36
|
+
render json: res
|
37
|
+
rescue => e
|
38
|
+
res[:source_code][:error] = e.message
|
39
|
+
render json: res
|
40
|
+
end
|
41
|
+
|
42
|
+
def load
|
43
|
+
f = params[:source_code][:file]
|
44
|
+
info = get_file_info(f)
|
45
|
+
if /\Atext\/plain/ =~ info[:type]
|
46
|
+
info[:data] = NKF.nkf('-w', f.read)
|
47
|
+
else
|
48
|
+
info[:error] = 'Rubyのプログラムではありません'
|
49
|
+
end
|
50
|
+
|
51
|
+
render json: { source_code: info }, content_type: request.format
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def check_whether_standalone
|
57
|
+
unless Rails.env == 'standalone'
|
58
|
+
fail "#{self.class.name}##{action_name}はstandaloneモードのみの機能です"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def source_code_params
|
63
|
+
params.require(:source_code).permit(:data, :filename)
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_file_info(file)
|
67
|
+
{
|
68
|
+
filename: file.original_filename,
|
69
|
+
type: MIME.check(file.path).try(:content_type) || file.content_type,
|
70
|
+
size: file.size,
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def url_encode_filename(filename)
|
75
|
+
if request.env['HTTP_USER_AGENT'] =~ /MSIE|Trident/
|
76
|
+
return ERB::Util.url_encode(filename)
|
77
|
+
else
|
78
|
+
filename
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def source_code
|
83
|
+
return @source_code if @source_code
|
84
|
+
sc = SourceCode.find(session[:source_code][:id])
|
85
|
+
unless sc.digest == session[:source_code][:digest]
|
86
|
+
fail ActiveRecord::RecordNotFound
|
87
|
+
end
|
88
|
+
@source_code = sc
|
89
|
+
end
|
90
|
+
|
91
|
+
def write_source_code(source_code)
|
92
|
+
path = Pathname("~/#{source_code.filename}").expand_path.to_s
|
93
|
+
|
94
|
+
fail 'すでに同じ名前のプログラムがあります' if File.exist?(path) && params[:force].blank?
|
95
|
+
|
96
|
+
File.open(path, 'w') do |f|
|
97
|
+
f.write(source_code.data)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def destroy_source_code_and_delete_session(source_code)
|
102
|
+
source_code.destroy
|
103
|
+
|
104
|
+
session[:source_code] = nil
|
105
|
+
end
|
106
|
+
end
|
data/app/mailers/.keep
ADDED
File without changes
|
data/app/models/.keep
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require 'open3'
|
5
|
+
require 'digest/sha2'
|
6
|
+
|
7
|
+
# ソースコードを表現するモデル
|
8
|
+
class SourceCode < ActiveRecord::Base
|
9
|
+
validates :filename, presence: true
|
10
|
+
validate :validate_filename
|
11
|
+
validates :data, presence: true, allow_blank: true
|
12
|
+
|
13
|
+
# シンタックスをチェックする
|
14
|
+
def check_syntax
|
15
|
+
_, stderr_str, status = *open3_capture3_ruby_c
|
16
|
+
return [] if status.success?
|
17
|
+
|
18
|
+
stderr_str.lines.each.with_object([]) { |line, res|
|
19
|
+
if (md = /^.*:(\d+): (.*)$/.match(line))
|
20
|
+
res << { row: md[1].to_i, column: 0, message: md[2] }
|
21
|
+
elsif (md = /( +)\^$/.match(line))
|
22
|
+
res[-1][:column] = md[1].length
|
23
|
+
end
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# ハッシュ値を計算する
|
28
|
+
def digest
|
29
|
+
Digest::SHA256.hexdigest(data)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def open3_capture3_ruby_c
|
35
|
+
tempfile = Tempfile.new('smalruby-editor')
|
36
|
+
tempfile.write(data)
|
37
|
+
path = tempfile.path
|
38
|
+
tempfile.close
|
39
|
+
ruby_cmd = File.join(RbConfig::CONFIG['bindir'],
|
40
|
+
RbConfig::CONFIG['RUBY_INSTALL_NAME'])
|
41
|
+
Open3.capture3("#{ruby_cmd} -c #{path}")
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_filename
|
45
|
+
if File.basename(filename) != filename
|
46
|
+
errors.add(:filename, 'includes directory separator(s)')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<div class="navbar navbar-inverse">
|
2
|
+
<div class="navbar-inner">
|
3
|
+
<ul class="nav">
|
4
|
+
<li class="active"><a id="ruby-tab" href="#" onclick="window.event.preventDefault(); return false;">Ruby</a></li>
|
5
|
+
</ul>
|
6
|
+
|
7
|
+
<%= form_tag(source_codes_load_path, id: "file-form", class: "navbar-form pull-right", method: "post", multipart: true) do %>
|
8
|
+
<button id="check-button" type="button" class="btn btn-primary">チェック</button>
|
9
|
+
<input id="filename" type="text" class="span4" placeholder="プログラムの名前を入れてね(例:01.rb)">
|
10
|
+
<button id="save-button" type="button" class="btn btn-primary">セーブ</button>
|
11
|
+
<% unless Rails.env == 'standalone' %>
|
12
|
+
<%= link_to '', source_codes_download_path, id: 'download-link', style: 'display: none', 'data-method' => 'delete' %>
|
13
|
+
<% end %>
|
14
|
+
<button id="load-button" class="btn btn-primary">ロード</button>
|
15
|
+
<input id="load-file" type="file" name="source_code[file]" style="display: none">
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div id="messages">
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div id="text-editor"></div>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>smalruby-editor</title>
|
5
|
+
<%= favicon_link_tag %>
|
6
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
7
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
8
|
+
<%= csrf_meta_tags %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<%= yield %>
|
13
|
+
|
14
|
+
</body>
|
15
|
+
</html>
|
data/bin/bundle
ADDED
data/bin/rails
ADDED
data/bin/rake
ADDED