Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'aendrew-adding_jshint'
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoma committed Dec 20, 2016
2 parents 734a921 + 847642a commit e2aa1b0
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 189 deletions.
98 changes: 98 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
// JSHint Configuration File
// Via https://github.com/jshint/jshint/blob/master/examples/.jshintrc
// See http://jshint.com/docs/ for more details

"maxerr" : 50, // {int} Maximum error before stopping

// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"indent" : 2, // {int} Number of spaces to use for indentation
"latedef" : false, // true: Require variables/functions to be defined before being used
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : true, // true: Prohibit use of empty blocks
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : false, // true: Prohibit use of `++` & `--`
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // Unused variables:
// true : all variables, last function parameter
// "vars" : all variables only
// "strict" : all variables, all function parameters
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
"maxlen" : false, // {int} Max number of characters per line

// Relaxing
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // true: Tolerate use of `== null`
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// (ex: `for each`, multiple try/catch, function expression…)
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : false, // true: Tolerate functions being defined in loops
"multistr" : false, // true: Tolerate multi-line strings
"noyield" : false, // true: Tolerate generator functions with no yield statement in them.
"notypeof" : false, // true: Tolerate invalid typeof operator values
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function

// Environments
"browser" : true, // Web Browser (window, document, etc)
"browserify" : false, // Browserify (node.js code in the browser)
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jasmine" : false, // Jasmine
"jquery" : false, // jQuery
"mocha" : true, // Mocha
"mootools" : false, // MooTools
"node" : true, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
"phantom" : false, // PhantomJS
"prototypejs" : false, // Prototype and Scriptaculous
"qunit" : false, // QUnit
"rhino" : false, // Rhino
"shelljs" : false, // ShellJS
"typed" : false, // Globals for typed array constructions
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface

// Custom Globals
"globals" : {
"define": true, // For AMD in tabletop.js
"Backbone": true, // For backbone.tabletopSync.js
"Tabletop": true, // Same.
"_": true // Ditto
}
}
77 changes: 47 additions & 30 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
module.exports = function(grunt) {
'use strict';

grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-uglify');
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');

grunt.initConfig({
connect: {
testing: {
options: {
port: 8080
}
},
secure: {
options: {
port: 8081,
keepalive: true,
protocol: 'https'
}
}
},
uglify: {
options: {
mangle: false
},
tabletop: {
files: {
'src/tabletop.min.js': ['src/tabletop.js']
}
}
grunt.initConfig({
uglify: {
options: {
mangle: false,
quoteStyle: 1
},
tabletop: {
files: {
'src/tabletop.min.js': ['src/tabletop.js']
}
}
},
connect: {
testing: {
options: {
port: 8080
}
},
secure: {
options: {
port: 8081,
keepalive: true,
protocol: 'https'
}
});
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js',
'src/{,*/}*.js',
'!src/{,*/}*.min.js',
]
}
}
});

grunt.registerTask("default", ["uglify","connect"]);
}
grunt.registerTask('default', ['jshint', 'uglify', 'connect']);
};
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ Copy that! In theory you're interested in the `1sbyMINQHPsJctjAtMW0lCfLrcpMqoGMO

_Now you're going to feed your spreadsheet into Tabletop_

Include the Tabletop JavaScript file in your HTML, then try the following, substituting your URL for `public_spreadsheet_url`
Include the Tabletop JavaScript file in your HTML, then try the following, substituting your URL for `publicSpreadsheetUrl`

<script type="text/javascript">
window.onload = function() { init() };

var public_spreadsheet_url = 'https://docs.google.com/spreadsheets/d/1sbyMINQHPsJctjAtMW0lCfLrcpMqoGMOJj6AN-sNQrc/pubhtml';
var publicSpreadsheetUrl = 'https://docs.google.com/spreadsheets/d/1sbyMINQHPsJctjAtMW0lCfLrcpMqoGMOJj6AN-sNQrc/pubhtml';

function init() {
Tabletop.init( { key: public_spreadsheet_url,
Tabletop.init( { key: publicSpreadsheetUrl,
callback: showInfo,
simpleSheet: true } )
}
Expand Down Expand Up @@ -151,7 +151,7 @@ For example:

#### simple_url

`simple_url`, if true, changes all requests to `KEY` and `KEY-SHEET_ID`. Defaults to `false`.
`simpleUrl`, if true, changes all requests to `KEY` and `KEY-SHEET_ID`. Defaults to `false`.

#### proxy

Expand All @@ -173,16 +173,14 @@ For example:

`parameterize` changes the src of all injected scripts. Instead of `src`, `src` is URI encoded and appended to `parameterize`, e.g. set it to `http://example.herokuapp.com/?url=`. Mostly for [gs-proxy](https://github.com/MinnPost/gs-proxy).

#### callbackCOntext
#### callbackContext

`callbackContext` sets the `this` for your callback. It's the tabletop object by default.

#### prettyColumnNames

`prettyColumnNames` can be true or false (default to true, unless `proxy` is enabled&dagger;). Since Google doesn't pass us exactly the same column names as in the header ('$ Processed' becomes 'processed'), it takes an extra request to correct them. If you don't want the extra request, you'll want to set it to `false`

See the **unfriendly_headers** example for more info. Only works for newer Google Sheets.

> &dagger; prettyColumnNames doesn't work with [Flatware](https://github.com/jsoma/flatware), is why we disable it with a proxy by default
## Tabletop object attributes and methods
Expand All @@ -195,9 +193,9 @@ Once you've initialized a `tabletop` object you can access its good parts.

`.sheets(name)` is how you access a specific sheet. Say I have a worksheet called **Cats I Know**, I'll access it via `tabletop.sheets("Cats I Know")`

#### .model_names
#### .modelNames

`.model_names` are the names of the models [read: sheets] that Tabletop knows about. The sheet names do *not* reflect their ordering in the original spreadsheet.
`.modelNames` are the names of the models [read: sheets] that Tabletop knows about. The sheet names do *not* reflect their ordering in the original spreadsheet.

#### .foundSheetNames

Expand All @@ -223,17 +221,17 @@ Tabletop refers to sheets as **Models,** which have a few extra abilities compar

`.name` is the name of the worksheet it came from (the tab at the bottom of the spreadsheet)

#### .column_names
#### .columnNames

`.column_names` gives you the names of the columns in that table
`.columnNames` gives you the names of the columns in that table

#### .original_columns
#### .originalColumns

`.original_columns` gives you the names of the columns that Google sends on the first pass (numbers stripped, lowercase, etc)
`.originalColumns` gives you the names of the columns that Google sends on the first pass (numbers stripped, lowercase, etc)

#### .pretty_columns
#### .prettyColumns

`.pretty_columns` gives you the mapping between the column headers in the spreadsheet and the and the `column_names`. Disabled by passing `prettyColumnNames: false` when initializing Tabletop.
`.prettyColumns` gives you the mapping between the column headers in the spreadsheet and the and the `columnNames`. Disabled by passing `prettyColumnNames: false` when initializing Tabletop.

#### .all()

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tabletop",
"version": "1.4.3",
"version": "1.5.0",
"description": "**Tabletop.js** takes a Google Spreadsheet and makes it easily accessible through JavaScript. With zero dependencies!",
"main": "src/tabletop.js",
"directories": {
Expand Down Expand Up @@ -32,5 +32,9 @@
},
"engines": {
"node": ">=0.10.0"
},
"devDependencies": {
"grunt-contrib-jshint": "^0.11.2",
"jshint-stylish": "^2.0.0"
}
}
27 changes: 15 additions & 12 deletions src/backbone.tabletopSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
Backbone.tabletopSync only supports the 'read' method, and will fail
loudly on any other operations
*/

'use strict';

Backbone.tabletopSync = function(method, model, options, error) {
// Backwards compatibility with Backbone <= 0.3.3
if (typeof options == 'function') {
if (typeof options === 'function') {
options = {
success: options,
error: error
Expand All @@ -22,53 +25,53 @@ Backbone.tabletopSync = function(method, model, options, error) {

var instance = tabletopOptions.instance;

if(typeof(instance) == "undefined") {
if(typeof(instance) === 'undefined') {
instance = Tabletop.init( { key: tabletopOptions.key,
wanted: [ tabletopOptions.sheet ],
wait: true } )
wait: true } );
tabletopOptions.instance = instance;
} else {
instance.addWanted(tabletopOptions.sheet);
}

if(typeof(tabletopOptions.sheet) == "undefined") {
if(typeof(tabletopOptions.sheet) === 'undefined') {
return;
}

var sheet = instance.sheets( tabletopOptions.sheet );

if(typeof(sheet) === "undefined") {
if(typeof(sheet) === 'undefined') {
// Hasn't been fetched yet, let's fetch!

// Let's make sure we aren't re-requesting a sheet that doesn't exist
if(typeof(instance.foundSheetNames) !== 'undefined' && _.indexOf(instance.foundSheetNames, tabletopOptions.sheet) === -1) {
throw("Can't seem to find sheet " + tabletopOptions.sheet);
throw('Can\'t seem to find sheet ' + tabletopOptions.sheet);
}

instance.fetch( function() {
Backbone.tabletopSync(method, model, options, error);
})
});
return;
}

switch (method) {
case "read":
case 'read':
if(model.id) {
resp = _.find( sheet.all(), function(item) {
return model.id == item[model.idAttribute];
return model.id === item[model.idAttribute];
}, this);
} else {
resp = sheet.all();
}
break;
default:
throw("Backbone.tabletopSync is read-only");
throw('Backbone.tabletopSync is read-only');
}

if (resp) {
options.success(resp);
} else {
options.error("Record not found");
options.error('Record not found');
}

};
};
Loading

0 comments on commit e2aa1b0

Please sign in to comment.