Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from grooves/master
Browse files Browse the repository at this point in the history
Release 1.0.4
  • Loading branch information
tshotoku committed May 8, 2015
2 parents 9905b15 + d17f94d commit 9ddcaa7
Show file tree
Hide file tree
Showing 26 changed files with 275 additions and 82 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[![wercker status](https://app.wercker.com/status/77b18717dfdfc349ba494ba51dcf8d6e/s "wercker status")](https://app.wercker.com/project/bykey/77b18717dfdfc349ba494ba51dcf8d6e)
[![Coverage Status](https://coveralls.io/repos/grooves/forkwell_for_chrome/badge.svg?branch=master)](https://coveralls.io/r/grooves/forkwell_for_chrome?branch=master)

# forkwell_for_chrome

Chrome extention for Forkwell Jobs. If you access a web site managed a company published Forkwell Jobs, this extention shows its job posting.

## Setup

### create extention

you need to install `nodejs` for using `npm`.

```
$ npm install -g gulp
$ cd ${PROJECT_ROOT}
$ gulp
# => create `dist` directory
```

## Install

### production

TODO: write chrome web store url

### development

Drag and drop `${PROJECT_ROOT}/dist` directroy into `chrome://extensions/` page.

## Contributing

If you have a problem, please create an issue or a pull request.

1. Fork it
1. Create your feature branch (git checkout -b my-new-feature)
1. Commit your changes (git commit -am 'Add some feature')
1. Push to the branch (git push origin my-new-feature)
1. Create new Pull Request
41 changes: 29 additions & 12 deletions gulpfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ plumber = require 'gulp-plumber'
notify = require 'gulp-notify'
zip = require 'gulp-zip'
jeditor = require 'gulp-json-editor'
browserify = require 'browserify'
source = require 'vinyl-source-stream'
buffer = require 'vinyl-buffer'

version = require('./package.json').version

Expand All @@ -24,41 +27,55 @@ gulp.task 'copy:manifest', ->
.pipe gulp.dest('dist')

gulp.task 'copy:images', ->
del.sync 'dist/images'
gulp.src 'src/images/*'
.pipe gulp.dest('dist/images')

gulp.task 'copy:vendor', ->
del.sync 'dist/vendor'
gulp.src 'vendor/**/*'
.pipe gulp.dest('dist/vendor')

gulp.task 'haml', ->
del.sync 'dist/html'
gulp.src 'src/haml/*.haml'
.pipe plumber
errorHandler: notify.onError('Error: <%= error.message %>')
.pipe haml()
.pipe gulp.dest('dist/html')

gulp.task 'coffee', ->
del.sync 'dist/javascripts'
gulp.src 'src/coffee/**/*.coffee'
.pipe plumber
errorHandler: notify.onError("Error: <%= error.message %>")
.pipe coffee(bare: true)
.pipe gulp.dest('dist/javascripts')
gulp.task 'coffee', ['coffee:background', 'coffee:popup']

gulp.task 'coffee:background', ->
browserify
entries: './src/coffee/background.coffee'
extensions: ['.coffee']
.transform 'coffeeify'
.bundle()
.pipe source('background.js')
.pipe gulp.dest('dist/javascripts')

gulp.task 'coffee:popup', ->
browserify
entries: './src/coffee/popup.coffee'
extensions: ['.coffee']
.transform 'coffeeify'
.bundle()
.pipe source('popup.js')
.pipe gulp.dest('dist/javascripts')

gulp.task 'sass', ->
del.sync 'dist/stylesheets'
gulp.src 'src/sass/*.sass'
.pipe plumber
errorHandler: notify.onError("Error: <%= error.message %>")
.pipe sass
indentedSyntax: true
.pipe gulp.dest('dist/stylesheets')

gulp.task 'build', ['copy:manifest', 'copy:images', 'copy:vendor', 'haml', 'coffee', 'sass']
gulp.task 'build', ['clean'], ->
gulp.start 'copy:manifest'
gulp.start 'copy:images'
gulp.start 'copy:vendor'
gulp.start 'haml'
gulp.start 'coffee'
gulp.start 'sass'

gulp.task 'watch', ->
gulp.watch 'src/manifest.json', ['copy:manifest']
Expand Down
20 changes: 17 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"name": "forkwell_for_chrome",
"version": "1.0.3",
"version": "1.0.4",
"description": "",
"main": "index.js",
"dependencies": {},
"dependencies": {
"bootstrap": "^3.3.4",
"jquery": "^2.1.4",
"underscore": "^1.8.3"
},
"devDependencies": {
"browserify": "^9.0.8",
"coffee-coverage": "^0.5.4",
"coffee-script": "^1.9.1",
"coffeeify": "^1.1.0",
"coveralls": "^2.11.2",
"del": "^1.1.1",
"dotenv": "^1.0.0",
"espower-coffee": "^0.10.0",
Expand All @@ -17,11 +25,17 @@
"gulp-plumber": "^1.0.0",
"gulp-sass": "^1.3.3",
"gulp-zip": "^2.0.3",
"istanbul": "^0.3.13",
"jsdom": "^3.1.2",
"mocha": "^2.2.1",
"power-assert": "^0.10.2"
"power-assert": "^0.10.2",
"sinon": "^1.14.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"scripts": {
"test": "mocha --opts test/mocha.opts -R dot",
"coveralls": "istanbul cover _mocha --report lcovonly -- -R dot --require coffee-coverage/register-istanbul && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"zip": "gulp zip",
"app_version": "gulp app_version --silent"
},
Expand Down
30 changes: 3 additions & 27 deletions src/coffee/background.coffee
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
fetchFromForkwellJobs = ->
host = 'https://jobs.forkwell.com'
url = "#{host}/api/v1/chrome/services.json"
$.getJSON url, (json) ->
chrome.storage.local.set json
global.$ = require 'jquery'

updatePopupByUrl = (url) ->
chrome.storage.local.get 'services', (items) ->
origin = $('<a>', href: url)[0].origin
jobs = items.services[origin]
if jobs
chrome.storage.local.set
popup: jobs
chrome.browserAction.setBadgeText
text: "#{jobs.length}"
else
chrome.storage.local.set
popup: null
chrome.browserAction.setBadgeText
text: ''

fetchFromForkwellJobs()

setInterval fetchFromForkwellJobs, 1000 * 60 * 60 * 24

chrome.tabs.onActivated.addListener (activeInfo) ->
chrome.tabs.get activeInfo.tabId, (tab) ->
updatePopupByUrl tab.url
BackgroundView = require './views/background_view'
new BackgroundView().render()
17 changes: 17 additions & 0 deletions src/coffee/models/popup.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Popup
fetchJobs: (callback) ->
chrome.storage.local.get 'popup', (items) ->
callback items.popup

setJobs: (jobs) ->
if jobs
@jobs = jobs
@badgeText = "#{jobs.length}"
else
@jobs = null
@badgeText = ''

chrome.storage.local.set popup: @jobs
chrome.browserAction.setBadgeText text: @badgeText

module.exports = Popup
16 changes: 16 additions & 0 deletions src/coffee/models/service.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Service
@fetch: ->
host = 'https://jobs.forkwell.com'
url = "#{host}/api/v1/chrome/services.json"
$.getJSON url, (json) ->
chrome.storage.local.set json

@findJobsByUrl: (url, callback) ->
chrome.storage.local.get 'services', (items) =>
jobs = items.services[@getOrigin(url)]
callback jobs

@getOrigin: (url) ->
$('<a>', href: url)[0].origin

module.exports = Service
12 changes: 6 additions & 6 deletions src/coffee/popup.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
global.$ = global.jQuery = require 'jquery'
global._ = require 'underscore'
require 'bootstrap'

$ ->
chrome.storage.local.get 'popup', (items) ->
if items.popup
for job in items.popup
$('#jobs').append new JobView(job).render().el
else
$('#jobs').append new NotFoundView().render().el
PopupView = require './views/popup_view'
new PopupView().render()
22 changes: 22 additions & 0 deletions src/coffee/views/background_view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Service = require '../models/service'
Popup = require '../models/popup'

class BackgroundView
INTERVAL_TIME = 1000 * 60 * 60 * 24

render: ->
Service.fetch()
setInterval (-> Service.fetch()), INTERVAL_TIME

chrome.tabs.onActivated.addListener (activeInfo) ->
chrome.tabs.get activeInfo.tabId, (tab) ->
Service.findJobsByUrl tab.url, (jobs) ->
popup = new Popup()
popup.setJobs jobs

chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) ->
Service.findJobsByUrl tab.url, (jobs) ->
popup = new Popup()
popup.setJobs jobs

module.exports = BackgroundView
2 changes: 2 additions & 0 deletions src/coffee/views/job_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ class JobView
render: ->
@el.html(compiled @json)
@

module.exports = JobView
2 changes: 2 additions & 0 deletions src/coffee/views/not_found_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ class NotFoundView
render: ->
@el.html(compiled())
@

module.exports = NotFoundView
15 changes: 15 additions & 0 deletions src/coffee/views/popup_view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
JobView = require './job_view'
NotFoundView = require './not_found_view'
Popup = require '../models/popup'

class PopupView
render: ->
popup = new Popup()
popup.fetchJobs (jobs) ->
if jobs
for job in jobs
$('#jobs').append new JobView(job).render().el
else
$('#jobs').append new NotFoundView().render().el

module.exports = PopupView
5 changes: 0 additions & 5 deletions src/haml/popup.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,4 @@
.row
%ul#jobs.list-group

%script(src="/vendor/javascripts/jquery.min.js")
%script(src="/vendor/javascripts/underscore-min.js")
%script(src="/vendor/javascripts/bootstrap.min.js")
%script(src="/javascripts/views/job_view.js")
%script(src="/javascripts/views/not_found_view.js")
%script(src="/javascripts/popup.js")
Binary file added src/images/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

"name": "Forkwell Jobs",
"description": "「スキル」と「こだわり」で選べる、エンジニア目線の求人・転職サイト",
"icons": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},

"browser_action": {
"default_icon": "images/icon.png",
Expand All @@ -17,7 +22,6 @@

"background": {
"scripts": [
"vendor/javascripts/jquery.min.js",
"javascripts/background.js"
]
},
Expand Down
10 changes: 0 additions & 10 deletions test/example_test.coffee

This file was deleted.

13 changes: 13 additions & 0 deletions test/helper.coffee
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
global.assert = require 'power-assert'
global.sinon = require 'sinon'
global.context = describe

global.$ = require('jquery')(require('jsdom').jsdom().parentWindow)
global._ = require 'underscore'

global.chrome =
storage:
local:
set: ->
get: ->
browserAction:
setBadgeText: ->
42 changes: 42 additions & 0 deletions test/models/popup_test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'test/helper'
Popup = require 'src/coffee/models/popup'

describe 'Popup', ->
describe '#setJobs', ->
popup = null

beforeEach ->
sinon.spy chrome.storage.local, 'set'
sinon.spy chrome.browserAction, 'setBadgeText'
popup = new Popup()
afterEach ->
chrome.storage.local.set.restore()
chrome.browserAction.setBadgeText.restore()

context 'when args have a job', ->
jobs = [{title: 'title'}]

beforeEach -> popup.setJobs(jobs)

it 'should update jobs and badgeText', ->
assert popup.jobs is jobs
assert popup.badgeText is '1'

it 'should update storage to jobs', ->
assert chrome.storage.local.set.args[0][0].popup is jobs

it 'should update badgeText to "1"', ->
assert chrome.browserAction.setBadgeText.args[0][0].text is '1'

context 'when args is undefined', ->
beforeEach -> popup.setJobs undefined

it 'should update jobs to null, and badgeText to ""', ->
assert popup.jobs is null
assert popup.badgeText is ''

it 'should update storage to null', ->
assert chrome.storage.local.set.args[0][0].popup is null

it 'should update badgeText to ""', ->
assert chrome.browserAction.setBadgeText.args[0][0].text is ''
Loading

0 comments on commit 9ddcaa7

Please sign in to comment.