Skip to content

Commit

Permalink
Initial Import
Browse files Browse the repository at this point in the history
  • Loading branch information
dongri committed Mar 28, 2014
0 parents commit 32374bb
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
20 changes: 20 additions & 0 deletions LICENSE.md
@@ -0,0 +1,20 @@
Copyright (c) 2014 Dongri <dongirab@gmail.com>

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.
5 changes: 5 additions & 0 deletions 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)
12 changes: 12 additions & 0 deletions 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'
31 changes: 31 additions & 0 deletions 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 )
17 changes: 17 additions & 0 deletions 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' }
]
]
}
]
18 changes: 18 additions & 0 deletions 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"
}
}
29 changes: 29 additions & 0 deletions 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()
6 changes: 6 additions & 0 deletions 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"
8 changes: 8 additions & 0 deletions 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 {
}

0 comments on commit 32374bb

Please sign in to comment.