Sha256: 20de24186761e350b5f5c2e308f89f4839a0c4dd393d74e5cf74a5b7a822f8a4

Contents?: true

Size: 732 Bytes

Versions: 4

Compression:

Stored size: 732 Bytes

Contents

# -*- coding: utf-8 -*-
require 'nkf'

class EditorController < ApplicationController
  def index
  end

  def save_file
    send_data(params[:source], filename: params[:filename],
              disposition: 'attachment', type: 'text/plain; charset=utf-8')
  end

  def load_file
    f = params['load_file']
    mime_type = MIME.check(f.path)
    content_type = mime_type.try(:content_type) || f.content_type
    res = {
      name: f.original_filename,
      type: content_type,
      size: f.size,
    }
    if /\Atext\/plain/ =~ content_type
      res[:source] = NKF.nkf('-w', f.read)
    else
      res[:error] = 'Rubyのプログラムではありません'
    end
    render json: res, content_type: request.format
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
smalruby-editor-0.0.5 app/controllers/editor_controller.rb
smalruby-editor-0.0.4 app/controllers/editor_controller.rb
smalruby-editor-0.0.3 app/controllers/editor_controller.rb
smalruby-editor-0.0.2 app/controllers/editor_controller.rb