This repository has been archived by the owner on May 12, 2021. It is now read-only.
forked from searls/chrome-ext-skeleton
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrote the app using isolated jasmine tests
- Loading branch information
Showing
57 changed files
with
11,789 additions
and
1,407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
require './app' | ||
|
||
guard 'sprockets2', :sprockets => App.sprockets, :digest => false do | ||
watch(%r{^assets/.+$}) | ||
watch('app.rb') | ||
group :a do | ||
guard 'sprockets2', :sprockets => App.sprockets, :digest => false do | ||
watch(%r{^assets/.+$}) | ||
watch('app.rb') | ||
end | ||
end | ||
|
||
spec_location = "spec/%s_spec" | ||
guard 'jasmine-headless-webkit' do | ||
watch(%r{^src/(.*)\.(coffee|js)$}) { |m| newest_js_file(spec_location % m[1]) } | ||
watch(%r{^spec/helpers*}) | ||
watch(%r{^spec/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) } | ||
end | ||
group :j do | ||
spec_location = "spec/%s_spec" | ||
guard 'jasmine-headless-webkit' do | ||
watch(%r{^src/(.*)\.(coffee|js)$}) { |m| newest_js_file(spec_location % m[1]) } | ||
watch(%r{^spec/helpers*}) | ||
watch(%r{^spec/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
//= require ./vendor/jquery-min.js | ||
//= require ./vendor/underscore-min.js | ||
//= require ./vendor/backbone-min.js | ||
//= require ./vendor/jquery-min | ||
//= require ./vendor/underscore-min | ||
//= require ./vendor/backbone-min | ||
//= require_tree ./vendor | ||
|
||
//= require src/bootstrap | ||
//= require_tree ./src/helpers | ||
//= require_tree ./src/models | ||
//= require_tree ./src/collections | ||
//= require_tree ./src/views | ||
//= require_tree ./src | ||
|
||
//= require_tree . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
window.app = | ||
views: {} | ||
models: {} | ||
collections: {} | ||
configuration: {} | ||
initializers: {} | ||
helpers: {} | ||
dom: {} | ||
|
||
|
||
_.mixin(_.str.exports()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class app.collections.Configurations extends Backbone.Collection | ||
model: app.models.Configuration | ||
localStorage: new Backbone.LocalStorage("Configurations") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class app.collections.DictionaryEntries extends Backbone.Collection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class app.configuration.FetchesConfig | ||
fetch: -> | ||
configs = new app.collections.Configurations | ||
configs.fetch() | ||
if config = configs.at(0) | ||
config | ||
else | ||
configs.add({}) | ||
configs.at(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class app.dom.ReplacesWords | ||
replace: (entries) -> | ||
$("*").each (el, i) -> | ||
if $(this).children().length == 0 | ||
replaceAsNeeded = (word) -> | ||
match = _(entries).find (entry) -> entry.original == word | ||
if match then match.replacement else word | ||
|
||
$(this).text _($(this).text()).chain().words().reduce((memo, word) -> | ||
"#{memo} #{replaceAsNeeded(word)}" | ||
, "").value() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class app.helpers.SuperView extends Backbone.View | ||
render: -> | ||
@$el.html(JST[@template](@serialize?())) | ||
@trigger('rendered') | ||
|
||
serialize: -> model: @model?.toJSON() |
8 changes: 8 additions & 0 deletions
8
assets/javascripts/src/initializers/listens-for-messages.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class app.initializers.ListensForMessages | ||
listen: -> | ||
$(document).ready -> | ||
if $('body').hasClass('js-background-page') | ||
chrome.extension.onRequest.addListener (request, sender, sendResponse) -> | ||
response = switch request.type | ||
when "config" then new app.configuration.FetchesConfig().fetch().toJSON() | ||
sendResponse(response) |
7 changes: 7 additions & 0 deletions
7
assets/javascripts/src/initializers/renders-configuration.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class app.initializers.RendersConfiguration | ||
render: -> | ||
$(window.document).ready -> | ||
if $('body').hasClass('js-options-page') | ||
config = new app.configuration.FetchesConfig().fetch() | ||
view = new app.views.Configuration(model: config) | ||
$('.root').append(view.render().el) |
5 changes: 5 additions & 0 deletions
5
assets/javascripts/src/initializers/transforms-content.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class app.initializers.TransformsContent | ||
transform: -> | ||
chrome.extension.sendRequest {type: "config"}, (config) -> | ||
$(document).ready -> | ||
new app.dom.ReplacesWords().replace(config.dictionary.entries) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class app.models.Configuration extends Backbone.RelationalModel | ||
relations: [ | ||
{ | ||
type: Backbone.HasOne | ||
key: 'dictionary' | ||
relatedModel: 'app.models.Dictionary' | ||
} | ||
] | ||
|
||
defaults: -> | ||
dictionary: new app.models.Dictionary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class app.models.DictionaryEntry extends Backbone.RelationalModel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class app.models.Dictionary extends Backbone.RelationalModel | ||
relations: [ | ||
{ | ||
type: Backbone.HasMany | ||
key: 'entries' | ||
relatedModel: 'app.models.DictionaryEntry' | ||
collectionType: 'app.collections.DictionaryEntries' | ||
} | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
new app.initializers.ListensForMessages().listen() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
new app.initializers.TransformsContent().transform() | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
new app.initializers.RendersConfiguration().render() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class app.views.Configuration extends app.helpers.SuperView | ||
template: "templates/configuration" | ||
events: | ||
"click .js-save": "save" | ||
"click .js-reset": "reset" | ||
|
||
initialize: -> | ||
@bind('rendered', @renderDictionary) | ||
|
||
renderDictionary: -> | ||
@$('.fields').append(new app.views.Dictionary(model: @model.get('dictionary')).render().el) | ||
|
||
save: (e) -> | ||
e.preventDefault() | ||
@model.save() | ||
|
||
reset: -> | ||
@model.destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class app.views.DictionaryEntry extends app.helpers.SuperView | ||
template: "templates/dictionary-entry" | ||
events: | ||
"click .js-remove": "handleRemove" | ||
"change :input": "handleChange" | ||
|
||
handleRemove: -> | ||
@model.collection.remove(@model) | ||
@remove() | ||
|
||
handleChange: (e) -> | ||
$input = $(e.target) | ||
@model.set($input.attr('name'), $input.val()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class app.views.Dictionary extends app.helpers.SuperView | ||
template: "templates/dictionary" | ||
events: | ||
"click .js-add": "handleAdd" | ||
|
||
initialize: -> | ||
@bind('rendered', @renderItems) | ||
|
||
handleAdd: (e) -> | ||
e.preventDefault() | ||
@model.get('entries').add({}) | ||
@renderItem(@model.get('entries').last()) | ||
|
||
renderItems: -> | ||
@model.get('entries').each (item) => | ||
@renderItem(item) | ||
|
||
renderItem: (item) -> | ||
entryView = new app.views.DictionaryEntry(model: item) | ||
@$el.append(entryView.render().el) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<form class="form-inline"> | ||
<div class="fields"> | ||
</div> | ||
<div class="well"> | ||
<button class="js-save">Save</button> | ||
<button class="js-reset">Delete</button> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div> | ||
<input type="text" class="input" placeholder="replace this word" name="original" value="<%= @model.original %>" /> | ||
<input type="text" class="input" placeholder="with this word" name="replacement" value="<%= @model.replacement %>" /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<button class="js-add">Add</button> |
Oops, something went wrong.