Skip to content

Commit 3002101

Browse files
committedSep 16, 2015
Initial commit
0 parents  commit 3002101

13 files changed

+240
-0
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
npm-debug.log
3+
node_modules

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0 - First Release
2+
* Every feature added
3+
* Every bug fixed

‎LICENSE.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2015 <Your name here>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ember-tabs package
2+
3+
Makes atom.io work better with Ember pods.
4+
5+
Without `ember-tabs` you end up with a bunch of tabs all named `template.hbs` or `component.js`. This attempts to find tabs in an ember pod structure, and prepends the pod name.
6+
7+
![screenshot](http://i.imgur.com/PAsMJQP.png)
8+
9+
## Currently very experimental, but should work.

‎keymaps/ember-tabs.cson

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Keybindings require three things to be fully defined: A selector that is
2+
# matched against the focused element, the keystroke and the command to
3+
# execute.
4+
#
5+
# Below is a basic keybinding which registers on all platforms by applying to
6+
# the root workspace element.
7+
8+
# For more detailed documentation see
9+
# https://atom.io/docs/latest/behind-atom-keymaps-in-depth
10+
'atom-workspace':
11+
'ctrl-alt-o': 'ember-tabs:toggle'

‎lib/ember-pods-project.coffee

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
fs = require "fs"
2+
3+
module.exports =
4+
class EmberPodsProject
5+
emberCliSettings: {}
6+
7+
constructor: (@rootPath) ->
8+
9+
isEmberPodsProject: (callback) =>
10+
@checkDotEmberCliFile callback
11+
12+
checkDotEmberCliFile: (callback) =>
13+
dotEmberCliFile = "#{@rootPath}/.ember-cli"
14+
fs.exists dotEmberCliFile, (didExist) =>
15+
if didExist
16+
fs.readFile dotEmberCliFile, (err, contents) =>
17+
if err
18+
callback(false)
19+
else
20+
try
21+
@emberCliSettings = JSON.parse(contents)
22+
catch
23+
console.log "[ember-tabs] Invalid .ember-cli file"
24+
callback(false)
25+
return
26+
27+
callback @emberCliSettings["usePods"]
28+
else
29+
callback(false)
30+
31+
readPodModulePrefix: =>
32+
# read from config/environment.js podModulePrefix

‎lib/ember-tabs.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports =
2+
activate: (state) ->
3+
EmberPodsProject = require './ember-pods-project'
4+
TabWatcher = require './tab-watcher'
5+
6+
for path in atom.project.getPaths()
7+
project = new EmberPodsProject path
8+
9+
project.isEmberPodsProject (yesOrNo) =>
10+
if yesOrNo
11+
@tabWatcher = new TabWatcher() unless @tabWatcher
12+
else
13+
console.log "[ember-tabs] Did not detect ember project with pods enabled."
14+
15+
deactivate: ->
16+
17+
serialize: ->

‎lib/tab-watcher.coffee

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module.exports =
2+
class TabWatcher
3+
constructor: ->
4+
console.log "[ember-tabs] Shimming tabs..."
5+
6+
atom.workspace.observeTextEditors =>
7+
# Race condition, tab view not added before this callback is called
8+
setTimeout @updateTabTitles, 10
9+
10+
updateTabTitles: =>
11+
tabPackage = atom.packages.getLoadedPackage("tabs")
12+
13+
if !tabPackage.mainModule.tabBarViews
14+
setTimeout @updateTabTitles, 50
15+
return
16+
17+
tabBar = tabPackage.mainModule.tabBarViews[0]
18+
19+
for tab in tabBar.getTabs()
20+
@updateTabTitle(tab)
21+
22+
updateTabTitle: (tab) =>
23+
item = tab.item
24+
25+
return if !item || !item.emitter || item._emberTabsGetTitle
26+
27+
item._emberTabsGetTitle = item.getTitle
28+
item._emberTabsGetLongTitle = item.getLongTitle
29+
30+
item.getTitle = =>
31+
@getEmberPodName(item)
32+
33+
item.getLongTitle = =>
34+
@getEmberPodName(item)
35+
36+
item.emitter.emit "did-change-title", tab.item.getTitle()
37+
38+
getEmberPodName: (item) =>
39+
filePath = item.getPath()
40+
pieces = filePath?.split("/")
41+
42+
return item._emberTabsGetTitle() unless pieces
43+
return item._emberTabsGetTitle() unless @isEmberPackagePath(filePath)
44+
45+
fileType = pieces.pop()
46+
podName = pieces.pop()
47+
48+
"#{podName}/#{fileType}"
49+
50+
# TODO: Try to read `podModulePrefix`
51+
isEmberPackagePath: (filePath) =>
52+
filePath.indexOf("/app/") != -1

‎menus/ember-tabs.cson

Whitespace-only changes.

‎package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "ember-tabs",
3+
"main": "./lib/ember-tabs",
4+
"version": "0.0.0",
5+
"description": "Makes Atom work better with Ember pods.",
6+
"keywords": [
7+
"ember",
8+
"ember pods"
9+
],
10+
"activationHooks": [],
11+
"repository": "https://github.com/erkie/ember-tabs",
12+
"license": "MIT",
13+
"engines": {
14+
"atom": ">=1.0.0 <2.0.0"
15+
},
16+
"dependencies": {
17+
}
18+
}

‎spec/ember-tabs-spec.coffee

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
EmberTabs = require '../lib/ember-tabs'
2+
3+
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
4+
#
5+
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
6+
# or `fdescribe`). Remove the `f` to unfocus the block.
7+
8+
describe "EmberTabs", ->
9+
[workspaceElement, activationPromise] = []
10+
11+
beforeEach ->
12+
workspaceElement = atom.views.getView(atom.workspace)
13+
activationPromise = atom.packages.activatePackage('ember-tabs')
14+
15+
describe "when the ember-tabs:toggle event is triggered", ->
16+
it "hides and shows the modal panel", ->
17+
# Before the activation event the view is not on the DOM, and no panel
18+
# has been created
19+
expect(workspaceElement.querySelector('.ember-tabs')).not.toExist()
20+
21+
# This is an activation event, triggering it will cause the package to be
22+
# activated.
23+
atom.commands.dispatch workspaceElement, 'ember-tabs:toggle'
24+
25+
waitsForPromise ->
26+
activationPromise
27+
28+
runs ->
29+
expect(workspaceElement.querySelector('.ember-tabs')).toExist()
30+
31+
emberTabsElement = workspaceElement.querySelector('.ember-tabs')
32+
expect(emberTabsElement).toExist()
33+
34+
emberTabsPanel = atom.workspace.panelForItem(emberTabsElement)
35+
expect(emberTabsPanel.isVisible()).toBe true
36+
atom.commands.dispatch workspaceElement, 'ember-tabs:toggle'
37+
expect(emberTabsPanel.isVisible()).toBe false
38+
39+
it "hides and shows the view", ->
40+
# This test shows you an integration test testing at the view level.
41+
42+
# Attaching the workspaceElement to the DOM is required to allow the
43+
# `toBeVisible()` matchers to work. Anything testing visibility or focus
44+
# requires that the workspaceElement is on the DOM. Tests that attach the
45+
# workspaceElement to the DOM are generally slower than those off DOM.
46+
jasmine.attachToDOM(workspaceElement)
47+
48+
expect(workspaceElement.querySelector('.ember-tabs')).not.toExist()
49+
50+
# This is an activation event, triggering it causes the package to be
51+
# activated.
52+
atom.commands.dispatch workspaceElement, 'ember-tabs:toggle'
53+
54+
waitsForPromise ->
55+
activationPromise
56+
57+
runs ->
58+
# Now we can test for view visibility
59+
emberTabsElement = workspaceElement.querySelector('.ember-tabs')
60+
expect(emberTabsElement).toBeVisible()
61+
atom.commands.dispatch workspaceElement, 'ember-tabs:toggle'
62+
expect(emberTabsElement).not.toBeVisible()

‎spec/ember-tabs-view-spec.coffee

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
EmberTabsView = require '../lib/ember-tabs-view'
2+
3+
describe "EmberTabsView", ->
4+
it "has one valid test", ->
5+
expect("life").toBe "easy"

‎styles/ember-tabs.less

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// The ui-variables file is provided by base themes provided by Atom.
2+
//
3+
// See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less
4+
// for a full listing of what's available.
5+
@import "ui-variables";
6+
7+
.ember-tabs {
8+
}

0 commit comments

Comments
 (0)
Please sign in to comment.