smalruby-editor 0.0.1
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 +24 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.simplecov +7 -0
- data/.travis.yml +23 -0
- data/Gemfile +77 -0
- data/Gemfile.lock +258 -0
- data/LICENSE +22 -0
- data/Procfile +1 -0
- data/README.rdoc +45 -0
- data/Rakefile +6 -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 +52 -0
- data/app/assets/stylesheets/application.css +20 -0
- data/app/assets/stylesheets/editor.css.scss +13 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/concerns/.keep +0 -0
- data/app/controllers/editor_controller.rb +22 -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/views/editor/index.html.erb +16 -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 +86 -0
- data/config.ru +4 -0
- data/config/application.rb +28 -0
- data/config/boot.rb +4 -0
- data/config/database.yml.mysql2 +39 -0
- data/config/database.yml.sqlite3 +25 -0
- data/config/database.yml.travis +5 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +29 -0
- data/config/environments/production.rb +80 -0
- data/config/environments/standalone.rb +15 -0
- data/config/environments/test.rb +36 -0
- data/config/initializers/backtrace_silencers.rb +7 -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 +12 -0
- data/config/initializers/session_store.rb +3 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +63 -0
- data/config/unicorn.rb +22 -0
- data/db/schema.rb +16 -0
- data/db/seeds.rb +7 -0
- data/lib/assets/.keep +0 -0
- data/lib/smalruby_editor.rb +4 -0
- data/lib/smalruby_editor/version.rb +3 -0
- data/lib/tasks/.keep +0 -0
- data/lib/tasks/gem.rake +5 -0
- data/lib/tasks/rspec.rake +16 -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/favicon.ico +0 -0
- data/public/robots.txt +5 -0
- data/smalruby-editor.gemspec +50 -0
- data/spec/acceptance/editor.feature +58 -0
- data/spec/controllers/editor_controller_spec.rb +52 -0
- data/spec/fixtures/files/01.rb +57 -0
- data/spec/helpers/editor_helper_spec.rb +14 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/steps/editor_steps.rb +106 -0
- data/vendor/assets/javascripts/.keep +0 -0
- data/vendor/assets/stylesheets/.keep +0 -0
- metadata +367 -0
data/Rakefile
ADDED
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-clouds.js
|
18
|
+
//= require ace/mode-ruby.js
|
19
|
+
//= require bootstrap.js
|
20
|
+
//= require jquery-fileupload/basic
|
21
|
+
//= require_tree .
|
@@ -0,0 +1,52 @@
|
|
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
|
+
$ ->
|
6
|
+
textEditor = ace.edit('text-editor')
|
7
|
+
textEditor.setTheme('ace/theme/clouds')
|
8
|
+
textEditor.setShowInvisibles(true)
|
9
|
+
|
10
|
+
session = textEditor.getSession()
|
11
|
+
session.setMode('ace/mode/ruby')
|
12
|
+
session.setTabSize(2)
|
13
|
+
session.setUseSoftTabs(true)
|
14
|
+
|
15
|
+
# FIXME: エディタの切り替え機能を実装するときに以下の処理を削除する。
|
16
|
+
# なお、navbarの中のリンクの見た目をよくするためにa要素を使っているのだが、
|
17
|
+
# デフォルトではRubyをクリックするとリンク先に遷移してしまう。そこでリンク
|
18
|
+
# をクリックしてもリンク先に遷移しないようにしている。
|
19
|
+
$('ul.nav li a').click (e) ->
|
20
|
+
e.preventDefault()
|
21
|
+
false
|
22
|
+
|
23
|
+
$('#save-button').click ->
|
24
|
+
filename = $.trim($('#filename').val())
|
25
|
+
if filename.length <= 0
|
26
|
+
$('#filename').focus()
|
27
|
+
else
|
28
|
+
data =
|
29
|
+
filename: filename
|
30
|
+
source: session.getDocument().getValue()
|
31
|
+
location.href = '/editor/save_file?' + $.param(data)
|
32
|
+
|
33
|
+
$('#load-button').click ->
|
34
|
+
$(@).parent().find('input[name="load_file"]').click()
|
35
|
+
|
36
|
+
$('#filename').keypress (e) ->
|
37
|
+
e = window.event if !e
|
38
|
+
if e.keyCode == 13
|
39
|
+
$('#save-button').click()
|
40
|
+
false
|
41
|
+
else
|
42
|
+
true
|
43
|
+
|
44
|
+
$('#file-form').fileupload(
|
45
|
+
dataType: 'json'
|
46
|
+
add: (e, data) ->
|
47
|
+
data.submit()
|
48
|
+
done: (e, data) ->
|
49
|
+
file = data.result
|
50
|
+
$('#filename').val(file.name)
|
51
|
+
session.getDocument().setValue(file.source)
|
52
|
+
)
|
@@ -0,0 +1,20 @@
|
|
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
|
12
|
+
*= require font-awesome
|
13
|
+
*= require_self
|
14
|
+
*= require_tree .
|
15
|
+
*/
|
16
|
+
|
17
|
+
html, body {
|
18
|
+
height: 100%;
|
19
|
+
margin: 0;
|
20
|
+
}
|
@@ -0,0 +1,13 @@
|
|
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
|
+
#text-editor {
|
6
|
+
position: absolute;
|
7
|
+
left: 0;
|
8
|
+
top: 60px;
|
9
|
+
right: 0;
|
10
|
+
bottom: 0;
|
11
|
+
|
12
|
+
font-size: 16pt;
|
13
|
+
}
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'nkf'
|
2
|
+
|
3
|
+
class EditorController < ApplicationController
|
4
|
+
def index
|
5
|
+
end
|
6
|
+
|
7
|
+
def save_file
|
8
|
+
send_data(params[:source], filename: params[:filename],
|
9
|
+
disposition: 'attachment', type: 'text/plain; charset=utf-8')
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_file
|
13
|
+
f = params['load_file']
|
14
|
+
res = {
|
15
|
+
name: f.original_filename,
|
16
|
+
type: f.content_type,
|
17
|
+
size: f.size,
|
18
|
+
source: NKF.nkf('-w', f.read),
|
19
|
+
}
|
20
|
+
render json: res, content_type: request.format
|
21
|
+
end
|
22
|
+
end
|
data/app/mailers/.keep
ADDED
File without changes
|
data/app/models/.keep
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="navbar navbar-inverse">
|
2
|
+
<div class="navbar-inner">
|
3
|
+
<ul class="nav">
|
4
|
+
<li class="active"><a id="ruby-tab" href="#">Ruby</a></li>
|
5
|
+
</ul>
|
6
|
+
|
7
|
+
<%= form_tag(editor_load_file_path, id: "file-form", class: "navbar-form pull-right", method: "post", multipart: true) do %>
|
8
|
+
<input id="filename" type="text" class="span4" placeholder="プログラムの名前を入れてね(例:01.rb)">
|
9
|
+
<button id="save-button" type="button" class="btn btn-primary">セーブ</button>
|
10
|
+
<a id="load-button" class="btn btn-primary">ロード</a>
|
11
|
+
<input id="load-file" type="file" name="load_file" style="display: none">
|
12
|
+
<% end %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<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
data/bin/smalruby-editor
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
ENV['RAILS_ENV'] = 'standalone'
|
5
|
+
ENV['SECRET_KEY_BASE'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
|
7
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
8
|
+
require_relative '../config/boot'
|
9
|
+
|
10
|
+
lib = File.expand_path('../../lib', __FILE__)
|
11
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
12
|
+
require 'smalruby_editor'
|
13
|
+
|
14
|
+
home_dir = Pathname('~/.smalruby-editor').expand_path
|
15
|
+
ENV['SMALRUBY_EDITOR_HOME'] = home_dir.to_s
|
16
|
+
log_dir, db_dir, config_dir, tmp_dir = *%w(log db config tmp).map { |s|
|
17
|
+
home_dir.join(s)
|
18
|
+
}.tap { |dir|
|
19
|
+
FileUtils.mkdir_p(dir)
|
20
|
+
}
|
21
|
+
|
22
|
+
database_yml_path = config_dir.join('database.yml')
|
23
|
+
db_path = db_dir.join("#{ENV['RAILS_ENV']}.sqlite3").to_s
|
24
|
+
if !File.exist?(database_yml_path)
|
25
|
+
File.open(database_yml_path, 'w') do |f|
|
26
|
+
f.write(<<-EOS)
|
27
|
+
standalone:
|
28
|
+
adapter: sqlite3
|
29
|
+
database: #{db_path}
|
30
|
+
pool: 5
|
31
|
+
timeout: 5000
|
32
|
+
EOS
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#Create required tmp directories if not found
|
37
|
+
%w(cache pids sessions sockets).each do |dir_to_make|
|
38
|
+
FileUtils.mkdir_p(tmp_dir.join(dir_to_make))
|
39
|
+
end
|
40
|
+
|
41
|
+
Dir.chdir(File.expand_path('../../', APP_PATH))
|
42
|
+
require 'rails/commands/server'
|
43
|
+
|
44
|
+
module Rails
|
45
|
+
class Server < ::Rack::Server
|
46
|
+
def initialize(tmp_dir)
|
47
|
+
super()
|
48
|
+
set_environment
|
49
|
+
|
50
|
+
@tmp_dir = tmp_dir
|
51
|
+
end
|
52
|
+
|
53
|
+
def start
|
54
|
+
url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
|
55
|
+
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
|
56
|
+
puts "=> smalruby-editor #{SmalrubyEditor::VERSION} starting in #{Rails.env} on #{url}"
|
57
|
+
puts "=> Run `smalruby-editor -h` for more startup options"
|
58
|
+
trap(:INT) { exit }
|
59
|
+
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
|
60
|
+
|
61
|
+
super
|
62
|
+
ensure
|
63
|
+
# The '-h' option calls exit before @options is set.
|
64
|
+
# If we call 'options' with it unset, we get double help banners.
|
65
|
+
puts 'Exiting' unless @options && options[:daemonize]
|
66
|
+
end
|
67
|
+
|
68
|
+
def default_options
|
69
|
+
super.merge({
|
70
|
+
Port: 3000,
|
71
|
+
DoNotReverseLookup: true,
|
72
|
+
environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
|
73
|
+
daemonize: false,
|
74
|
+
debugger: false,
|
75
|
+
pid: @tmp_dir.join("pids/server.pid").to_s,
|
76
|
+
config: File.expand_path("config.ru")
|
77
|
+
})
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Rails::Server.new(tmp_dir).tap do |server|
|
83
|
+
require APP_PATH
|
84
|
+
Dir.chdir(Rails.application.root)
|
85
|
+
server.start
|
86
|
+
end
|
data/config.ru
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "sprockets/railtie"
|
8
|
+
# require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
# Require the gems listed in Gemfile, including any gems
|
11
|
+
# you've limited to :test, :development, or :production.
|
12
|
+
Bundler.require(:default, Rails.env)
|
13
|
+
|
14
|
+
module SmalrubyEditor
|
15
|
+
class Application < Rails::Application
|
16
|
+
# Settings in config/environments/* take precedence over those specified here.
|
17
|
+
# Application configuration should go into files in config/initializers
|
18
|
+
# -- all .rb files in that directory are automatically loaded.
|
19
|
+
|
20
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
21
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
22
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
23
|
+
|
24
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
25
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
26
|
+
# config.i18n.default_locale = :de
|
27
|
+
end
|
28
|
+
end
|
data/config/boot.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# MySQL. Versions 4.1 and 5.0 are recommended.
|
2
|
+
#
|
3
|
+
# Install the MYSQL driver
|
4
|
+
# gem install mysql2
|
5
|
+
#
|
6
|
+
# Ensure the MySQL gem is defined in your Gemfile
|
7
|
+
# gem 'mysql2'
|
8
|
+
#
|
9
|
+
# And be sure to use new-style password hashing:
|
10
|
+
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
|
11
|
+
development:
|
12
|
+
adapter: mysql2
|
13
|
+
encoding: utf8
|
14
|
+
database: smalruby-editor_development
|
15
|
+
pool: 5
|
16
|
+
username: root
|
17
|
+
password:
|
18
|
+
host: localhost
|
19
|
+
|
20
|
+
# Warning: The database defined as "test" will be erased and
|
21
|
+
# re-generated from your development database when you run "rake".
|
22
|
+
# Do not set this db to the same as development or production.
|
23
|
+
test:
|
24
|
+
adapter: mysql2
|
25
|
+
encoding: utf8
|
26
|
+
database: smalruby-editor_test
|
27
|
+
pool: 5
|
28
|
+
username: root
|
29
|
+
password:
|
30
|
+
host: localhost
|
31
|
+
|
32
|
+
production:
|
33
|
+
adapter: mysql2
|
34
|
+
encoding: utf8
|
35
|
+
database: smalruby-editor_production
|
36
|
+
pool: 5
|
37
|
+
username: root
|
38
|
+
password:
|
39
|
+
host: localhost
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|
@@ -0,0 +1,29 @@
|
|
1
|
+
SmalrubyEditor::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send.
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raise an error on page load if there are pending migrations
|
23
|
+
config.active_record.migration_error = :page_load
|
24
|
+
|
25
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
+
# This option may cause significant delays in view rendering with a large
|
27
|
+
# number of complex assets.
|
28
|
+
config.assets.debug = true
|
29
|
+
end
|