From 32374bba2949dd37e36addbe7402e9c29c5c481a Mon Sep 17 00:00:00 2001 From: Dongri Jin Date: Sat, 29 Mar 2014 08:30:19 +0900 Subject: [PATCH] Initial Import --- .gitignore | 3 +++ LICENSE.md | 20 +++++++++++++++++ README.md | 5 +++++ keymaps/convert-to-utf8.cson | 12 +++++++++++ lib/convert-to-utf8.coffee | 31 +++++++++++++++++++++++++++ menus/convert-to-utf8.cson | 17 +++++++++++++++ package.json | 18 ++++++++++++++++ spec/convert-to-utf8-spec.coffee | 29 +++++++++++++++++++++++++ spec/convert-to-utf8-view-spec.coffee | 6 ++++++ stylesheets/convert-to-utf8.less | 8 +++++++ 10 files changed, 149 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 keymaps/convert-to-utf8.cson create mode 100644 lib/convert-to-utf8.coffee create mode 100644 menus/convert-to-utf8.cson create mode 100644 package.json create mode 100644 spec/convert-to-utf8-spec.coffee create mode 100644 spec/convert-to-utf8-view-spec.coffee create mode 100644 stylesheets/convert-to-utf8.less diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ade14b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +node_modules diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0c5f665 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2014 Dongri + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f800b54 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# convert-to-utf8 package + +ConvertToUTF8 package for editing and saving files encoded in Shift_JIS, etc. + +![A screenshot of your spankin' package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif) diff --git a/keymaps/convert-to-utf8.cson b/keymaps/convert-to-utf8.cson new file mode 100644 index 0000000..90ebedf --- /dev/null +++ b/keymaps/convert-to-utf8.cson @@ -0,0 +1,12 @@ +# Keybindings require three things to be fully defined: A selector that is +# matched against the focused element, the keystroke and the command to +# execute. +# +# Below is a basic keybinding which registers on all platforms by applying to +# the root workspace element. + +# For more detailed documentation see +# https://atom.io/docs/latest/advanced/keymaps + +# '.workspace': +# 'ctrl-alt-o': 'convert-to-utf8:toggle' diff --git a/lib/convert-to-utf8.coffee b/lib/convert-to-utf8.coffee new file mode 100644 index 0000000..cd24624 --- /dev/null +++ b/lib/convert-to-utf8.coffee @@ -0,0 +1,31 @@ +fs = require 'fs' +jconv = require 'jconv' + +module.exports = + + activate: (state) -> + atom.workspaceView.command "convert-to-utf8:open_shift_jis", => @open_shift_jis() + atom.workspaceView.command "convert-to-utf8:save_shift_jis", => @save_shift_jis() + + deactivate: -> + #@convertToUtf8View.destroy() + + serialize: -> + #convertToUtf8ViewState: @convertToUtf8View.serialize() + + open_shift_jis: -> + editor = atom.workspace.getActiveEditor() + uri = editor.getUri() + buffer = fs.readFileSync(uri) + text = jconv.convert( buffer, 'SJIS', 'UTF8' ) + convertedText = text.toString('UTF8') + atom.workspace.getActiveEditor().setText(convertedText) + atom.workspace.saveActivePaneItem() + + save_shift_jis: -> + editor = atom.workspace.getActiveEditor() + uri = editor.getUri() + buffer = fs.readFileSync(uri) + text = jconv.convert( buffer, 'UTF8', 'SJIS' ) + convertedText = text.toString('BINARY'); + fs.writeFileSync( uri, text ) diff --git a/menus/convert-to-utf8.cson b/menus/convert-to-utf8.cson new file mode 100644 index 0000000..219fbb1 --- /dev/null +++ b/menus/convert-to-utf8.cson @@ -0,0 +1,17 @@ +# See https://atom.io/docs/latest/creating-a-package#menus for more details +# 'context-menu': +# '.overlayer': +# 'Enable convert-to-utf8': 'convert-to-utf8:toggle' + +'menu': [ + { + 'label': 'Packages' + 'submenu': [ + 'label': 'ConvertToUTF8' + 'submenu': [ + { 'label': 'Open With Shift-JIS', 'command': 'convert-to-utf8:open_shift_jis' } + { 'label': 'Save To Shift-JIS', 'command': 'convert-to-utf8:save_shift_jis' } + ] + ] + } +] diff --git a/package.json b/package.json new file mode 100644 index 0000000..c2816fd --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "convert-to-utf8", + "main": "./lib/convert-to-utf8", + "version": "0.0.1", + "description": "ConvertToUTF8 package for editing and saving files encoded in Shift_JIS, etc", + "activationEvents": [ + "convert-to-utf8:open_shift_jis", + "convert-to-utf8:save_shift_jis" + ], + "repository": "https://github.com/dongri/convert-to-utf8", + "license": "MIT", + "engines": { + "atom": ">0.50.0" + }, + "dependencies": { + "jconv": "0.1.5" + } +} diff --git a/spec/convert-to-utf8-spec.coffee b/spec/convert-to-utf8-spec.coffee new file mode 100644 index 0000000..0ceb7ff --- /dev/null +++ b/spec/convert-to-utf8-spec.coffee @@ -0,0 +1,29 @@ +ConvertToUtf8 = require '../lib/convert-to-utf8' + +# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. +# +# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` +# or `fdescribe`). Remove the `f` to unfocus the block. + +describe "ConvertToUtf8", -> + activationPromise = null + + beforeEach -> + atom.workspaceView = new WorkspaceView + activationPromise = atom.packages.activatePackage('convertToUtf8') + + describe "when the convert-to-utf8:toggle event is triggered", -> + it "attaches and then detaches the view", -> + expect(atom.workspaceView.find('.convert-to-utf8')).not.toExist() + + # This is an activation event, triggering it will cause the package to be + # activated. + atom.workspaceView.trigger 'convert-to-utf8:toggle' + + waitsForPromise -> + activationPromise + + runs -> + expect(atom.workspaceView.find('.convert-to-utf8')).toExist() + atom.workspaceView.trigger 'convert-to-utf8:toggle' + expect(atom.workspaceView.find('.convert-to-utf8')).not.toExist() diff --git a/spec/convert-to-utf8-view-spec.coffee b/spec/convert-to-utf8-view-spec.coffee new file mode 100644 index 0000000..bfbd349 --- /dev/null +++ b/spec/convert-to-utf8-view-spec.coffee @@ -0,0 +1,6 @@ +ConvertToUtf8View = require '../lib/convert-to-utf8-view' +{WorkspaceView} = require 'atom' + +describe "ConvertToUtf8View", -> + it "has one valid test", -> + expect("life").toBe "easy" diff --git a/stylesheets/convert-to-utf8.less b/stylesheets/convert-to-utf8.less new file mode 100644 index 0000000..f93b0ff --- /dev/null +++ b/stylesheets/convert-to-utf8.less @@ -0,0 +1,8 @@ +// The ui-variables file is provided by base themes provided by Atom. +// +// See https://github.com/atom/atom-dark-ui/blob/master/stylesheets/ui-variables.less +// for a full listing of what's available. +@import "ui-variables"; + +.convert-to-utf8 { +}