Permalink
Browse files

rewiring stuff to not use the database

- collections now use static .json files in static/data
  TODO: cache these in local storage via a collection that somehow intercepts the call to fetch()
  TODO: once cache is set up, label it with some sort of version. or just expect ppl to clear their cache every once in a while...?
- all collections use the same model (there is only one model now)
- all collections are very similar now...
  • Loading branch information...
1 parent 2ddd04e commit ba4b377fd9bc87ef55a81f040d149e14a8b08438 @rgarcia rgarcia committed Dec 11, 2011
View
@@ -1,26 +1,24 @@
# Runnning locally
-Make sure you MongoDB running on your system. For example, on Ubuntu, type
-
- apt-get install mongodb
-
-Download the content:
-
- cd scraper
- npm install # downloads dependencies for scrapers
- (cd css-mdn; ./run.sh)
- (cd css-cssinfos; ./run.sh)
- (cd html-mdn; ./run.sh)
- (cd js-mdn; node scrape.js)
- (cd dom-mdn node scrape.js)
-
Run the server:
npm install # downloads dependencies for web server
node web.js
Open http://localhost:5000/ in your browser.
+# Scraper
+
+The `static/data/` directory contains our scrape of the sites we get content from. Right now we don't update this very often. If you want the most up-to-date content, you can run the scrapers:
+
+ cd scraper
+ npm install # downloads dependencies for scrapers
+ (cd css-mdn; node scrape.js)
+ (cd html-mdn; node scrape.js)
+ (cd js-mdn; node scrape.js)
+ (cd dom-mdn; node scrape.js)
+ (cd jquery; node scrape.js)
+
# Notes
How to use the r.js optimizer:
View
20 app.js
@@ -1,11 +1,11 @@
define([
'express',
- 'mongoose',
- 'controllers/loader',
+ // 'mongoose',
+ // 'controllers/loader',
'module',
'path',
'./config'
-], function (express, mongoose, controllerLoader, module, path, config) {
+], function (express,/* mongoose, controllerLoader,*/ module, path, config) {
var app = null;
@@ -20,20 +20,20 @@ define([
app.listen(config.app_port);
app.configure(function() {
- var db = mongoose.connect(config.mongo_uri, function(err) {
- if (err)
- throw err;
- else
- console.log('connected to ' + config.mongo_uri);
- });
+ // var db = mongoose.connect(config.mongo_uri, function(err) {
+ // if (err)
+ // throw err;
+ // else
+ // console.log('connected to ' + config.mongo_uri);
+ // });
app.use(express.logger({ format: ':method :url :status' }));
var filename = module.uri;
var staticDir = path.dirname(filename) + '/static';
console.log('initializing static: ' + staticDir);
app.use(express.static(staticDir));
app.use(express.bodyParser());
app.use(express.methodOverride());
- controllerLoader.bootControllers(app);
+ //controllerLoader.bootControllers(app);
console.log('instacss version now running on port ' + config.app_port);
});
},
View
@@ -9,8 +9,7 @@ define([], function() {
environment: global.process.env.NODE_ENV || 'development',
// MONGOLAB_URI is provided by heroku mongolab add-on
- mongo_uri: global.process.env.MONGOLAB_URI || 'mongodb://127.0.0.1/instacss',
+ //mongo_uri: global.process.env.MONGOLAB_URI || 'mongodb://127.0.0.1/instacss',
};
});
-
View
@@ -1,31 +0,0 @@
-define(['mongoose'], function(mongoose) {
-
- var Schema = mongoose.Schema;
- var ObjectId = Schema.ObjectId;
-
- var PropValue = new Schema({
- value : String,
- description : String,
- });
-
- var Example = new Schema({
- description : String,
- code : String,
- });
-
- var CSSProp = new Schema({
- id : ObjectId,
- name : { type: String, required: true },
- srcUrl : { type: String, required: true },
- description : { type: String, required: true },
- version : { type: String, required: true },
- defaultValue : String,
- inherited : String,
- jsSyntax : String,
- values : [PropValue],
- examples : [Example]
- });
-
- return mongoose.model('CSSProp',CSSProp);
-
-});
View
@@ -1,17 +0,0 @@
-define(['mongoose'], function(mongoose) {
-
- var Schema = mongoose.Schema;
- var ObjectId = Schema.ObjectId;
-
- var JQEntry = new Schema({
- id : ObjectId,
- title : { type: String, required: true }, // e.g. length
- fullTitle : { type: String, required: true }, // e.g. Array.length
- sectionNames : [String], // ordering important
- sectionHTMLs : [String]
- });
-
- return mongoose.model('JQEntry', JQEntry);
-
-});
-
View
@@ -1,17 +0,0 @@
-define(['mongoose'], function(mongoose) {
-
- var Schema = mongoose.Schema;
- var ObjectId = Schema.ObjectId;
-
- var MDNDomObj = new Schema({
- id : ObjectId,
- title : { type: String, required: true }, // e.g. length
- fullTitle : { type: String, required: true }, // e.g. Array.length
- sectionNames : [String], // ordering important
- sectionHTMLs : [String]
- });
-
- return mongoose.model('MDNDomObj', MDNDomObj);
-
-});
-
View
@@ -1,15 +0,0 @@
-define(['mongoose'], function(mongoose) {
-
- var Schema = mongoose.Schema;
- var ObjectId = Schema.ObjectId;
-
- var MDNHtmlElement = new Schema({
- id : ObjectId,
- title : { type: String, required: true },
- sectionNames : [String], // ordering important
- sectionHTMLs : [String]
- });
-
- return mongoose.model('MDNHtmlElement', MDNHtmlElement);
-
-});
View
@@ -1,17 +0,0 @@
-define(['mongoose'], function(mongoose) {
-
- var Schema = mongoose.Schema;
- var ObjectId = Schema.ObjectId;
-
- var MDNJsObj = new Schema({
- id : ObjectId,
- title : { type: String, required: true }, // e.g. length
- fullTitle : { type: String, required: true }, // e.g. Array.length
- sectionNames : [String], // ordering important
- sectionHTMLs : [String]
- });
-
- return mongoose.model('MDNJsObj', MDNJsObj);
-
-});
-
View
@@ -1,15 +0,0 @@
-define(['mongoose'], function(mongoose) {
-
- var Schema = mongoose.Schema;
- var ObjectId = Schema.ObjectId;
-
- var MozDevCSSProp = new Schema({
- id : ObjectId,
- title : { type: String, required: true },
- sectionNames : [String], // ordering important
- sectionHTMLs : [String]
- });
-
- return mongoose.model('MozDevCSSProp',MozDevCSSProp);
-
-});
View
@@ -1,17 +0,0 @@
-define(['mongoose'], function(mongoose) {
-
- var Schema = mongoose.Schema;
- var ObjectId = Schema.ObjectId;
-
- var PHPExtension = new Schema({
- id : ObjectId,
- title : { type: String, required: true }, // e.g. length
- fullTitle : { type: String, required: true }, // e.g. Array.length
- sectionNames : [String], // ordering important
- sectionHTMLs : [String]
- });
-
- return mongoose.model('PHPExtension', PHPExtension);
-
-});
-
@@ -2,18 +2,18 @@ define([
'jQuery',
'Underscore',
'Backbone',
- 'models/jqentry'
-], function($, _, Backbone, JQEntry) {
+ 'models/sectionscrape'
+], function($, _, Backbone, SectionScrape) {
var jqEntryPattern = new RegExp("^(\\W*)(.+)$");
var JQEntry = Backbone.Collection.extend({
- url: '/jqentry',
- model: JQEntry,
+ url: '/data/jquery.json',
+ model: SectionScrape,
comparator: function(model) {
- var title = model.get('fullTitle');
+ var title = model.get('title');
var results = jqEntryPattern.exec(title);
var prefix = results[1];
var name = results[2];
@@ -30,4 +30,3 @@ define([
return JQEntry;
});
-
@@ -2,18 +2,17 @@ define([
'jQuery',
'Underscore',
'Backbone',
- 'models/mdndomobj'
-], function($, _, Backbone, MDNDomObj) {
+ 'models/sectionscrape'
+], function($, _, Backbone, SectionScrape) {
var MDNDomObj = Backbone.Collection.extend({
- url: '/mdndomobj',
- model: MDNDomObj,
+ url: '/data/dom-mdn.json',
+ model: SectionScrape,
comparator: function(model) {
- return model.get('fullTitle');
+ return model.get('title');
},
});
return MDNDomObj;
});
-
@@ -2,16 +2,16 @@ define([
'jQuery',
'Underscore',
'Backbone',
- 'models/mdnhtmlelement'
-], function($, _, Backbone, MDNHtmlElement) {
+ 'models/sectionscrape'
+], function($, _, Backbone, SectionScrape) {
// Handle the following cases:
// <xyz>
var htmlElementPattern = new RegExp("^(\\W*)(.+)$");
var MDNHtmlElemnts = Backbone.Collection.extend({
- url: '/mdnhtmlelement',
- model: MDNHtmlElement,
+ url: '/data/html-mdn.json',
+ model: SectionScrape,
comparator: function(model) {
var title = model.get('title');
@@ -2,18 +2,18 @@ define([
'jQuery',
'Underscore',
'Backbone',
- 'models/mdnjsobj'
-], function($, _, Backbone, MDNJsObj) {
+ 'models/sectionscrape'
+], function($, _, Backbone, SectionScrape) {
var MDNJsObj = Backbone.Collection.extend({
- url: '/mdnjsobj',
- model: MDNJsObj,
+ url: '/data/js-mdn.json',
+ model: SectionScrape,
comparator: function(model) {
- return model.get('fullTitle');
+ return model.get('title');
},
+
});
return MDNJsObj;
});
-
@@ -2,8 +2,8 @@ define([
'jQuery',
'Underscore',
'Backbone',
- 'models/mozdevcssprop'
-], function($, _, Backbone, MozDevCSSProp) {
+ 'models/sectionscrape'
+], function($, _, Backbone, SectionScrape) {
// Handle the following cases:
// -xyz
@@ -15,17 +15,17 @@ define([
var cssPropsPattern = new RegExp("^(\\W*)(.+)$");
var MozDevCSSProps = Backbone.Collection.extend({
- url: '/mozdevcssprop',
- model: MozDevCSSProp,
+ url: '/data/css-mdn.json',
+ model: SectionScrape,
- comparator: function(model) {
- var title = model.get('title');
- var results = cssPropsPattern.exec(title);
- var prefix = results[1];
- var name = results[2].toLowerCase();
+ comparator: function(model) {
+ var title = model.get('title');
+ var results = cssPropsPattern.exec(title);
+ var prefix = results[1];
+ var name = results[2].toLowerCase();
- return prefix ? ('1' + title) : ('0' + name);
- },
+ return prefix ? ('1' + title) : ('0' + name);
+ },
});
@@ -2,18 +2,17 @@ define([
'jQuery',
'Underscore',
'Backbone',
- 'models/phpext'
-], function($, _, Backbone, PhpExt) {
+ 'models/SectionScrape'
+], function($, _, Backbone, SectionScrape) {
var PhpExt = Backbone.Collection.extend({
- url: '/phpext',
- model: PhpExt,
+ url: '/data/php.json',
+ model: SectionScrape,
comparator: function(model) {
- return model.get('fullTitle').toLowerCase();
+ return model.get('title').toLowerCase();
},
});
return PhpExt;
});
-
Oops, something went wrong.

0 comments on commit ba4b377

Please sign in to comment.