smalruby-editor 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.simplecov +7 -0
  6. data/.travis.yml +23 -0
  7. data/Gemfile +77 -0
  8. data/Gemfile.lock +258 -0
  9. data/LICENSE +22 -0
  10. data/Procfile +1 -0
  11. data/README.rdoc +45 -0
  12. data/Rakefile +6 -0
  13. data/app/assets/images/.keep +0 -0
  14. data/app/assets/images/favicon.ico +0 -0
  15. data/app/assets/javascripts/application.js +21 -0
  16. data/app/assets/javascripts/editor.js.coffee +52 -0
  17. data/app/assets/stylesheets/application.css +20 -0
  18. data/app/assets/stylesheets/editor.css.scss +13 -0
  19. data/app/controllers/application_controller.rb +5 -0
  20. data/app/controllers/concerns/.keep +0 -0
  21. data/app/controllers/editor_controller.rb +22 -0
  22. data/app/helpers/application_helper.rb +2 -0
  23. data/app/helpers/editor_helper.rb +2 -0
  24. data/app/mailers/.keep +0 -0
  25. data/app/models/.keep +0 -0
  26. data/app/models/concerns/.keep +0 -0
  27. data/app/views/editor/index.html.erb +16 -0
  28. data/app/views/layouts/application.html.erb +15 -0
  29. data/bin/bundle +3 -0
  30. data/bin/rails +4 -0
  31. data/bin/rake +4 -0
  32. data/bin/smalruby-editor +86 -0
  33. data/config.ru +4 -0
  34. data/config/application.rb +28 -0
  35. data/config/boot.rb +4 -0
  36. data/config/database.yml.mysql2 +39 -0
  37. data/config/database.yml.sqlite3 +25 -0
  38. data/config/database.yml.travis +5 -0
  39. data/config/environment.rb +5 -0
  40. data/config/environments/development.rb +29 -0
  41. data/config/environments/production.rb +80 -0
  42. data/config/environments/standalone.rb +15 -0
  43. data/config/environments/test.rb +36 -0
  44. data/config/initializers/backtrace_silencers.rb +7 -0
  45. data/config/initializers/filter_parameter_logging.rb +4 -0
  46. data/config/initializers/inflections.rb +16 -0
  47. data/config/initializers/mime_types.rb +5 -0
  48. data/config/initializers/secret_token.rb +12 -0
  49. data/config/initializers/session_store.rb +3 -0
  50. data/config/initializers/wrap_parameters.rb +14 -0
  51. data/config/locales/en.yml +23 -0
  52. data/config/routes.rb +63 -0
  53. data/config/unicorn.rb +22 -0
  54. data/db/schema.rb +16 -0
  55. data/db/seeds.rb +7 -0
  56. data/lib/assets/.keep +0 -0
  57. data/lib/smalruby_editor.rb +4 -0
  58. data/lib/smalruby_editor/version.rb +3 -0
  59. data/lib/tasks/.keep +0 -0
  60. data/lib/tasks/gem.rake +5 -0
  61. data/lib/tasks/rspec.rake +16 -0
  62. data/log/.keep +0 -0
  63. data/public/404.html +58 -0
  64. data/public/422.html +58 -0
  65. data/public/500.html +57 -0
  66. data/public/favicon.ico +0 -0
  67. data/public/robots.txt +5 -0
  68. data/smalruby-editor.gemspec +50 -0
  69. data/spec/acceptance/editor.feature +58 -0
  70. data/spec/controllers/editor_controller_spec.rb +52 -0
  71. data/spec/fixtures/files/01.rb +57 -0
  72. data/spec/helpers/editor_helper_spec.rb +14 -0
  73. data/spec/spec_helper.rb +70 -0
  74. data/spec/steps/editor_steps.rb +106 -0
  75. data/vendor/assets/javascripts/.keep +0 -0
  76. data/vendor/assets/stylesheets/.keep +0 -0
  77. metadata +367 -0
data/Rakefile ADDED
@@ -0,0 +1,6 @@
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
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
+ }
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
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
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module EditorHelper
2
+ 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
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby.exe
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
data/bin/rails ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby.exe
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
data/bin/rake ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby.exe
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -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,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -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,4 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -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,5 @@
1
+ test:
2
+ adapter: mysql2
3
+ database: myapp_test
4
+ username: travis
5
+ encoding: utf8
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ SmalrubyEditor::Application.initialize!
@@ -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