<commit_before>require.config({
	baseUrl: 'app',

	paths : {
		jquery: '../components/jquery/jquery.min',
		modernizr: '../components/modernizr/modernizr'
	}
});

require(['jquery', 'modernizr'], function($, modernizr) {
	// use app here
	$('#status').html('If you can read this text, your stack should be alright.');
	console.log("Fubar!");
}); 
<commit_msg>Add app code to main.js<commit_after>require.config({
	baseUrl: 'app',

	paths : {
		jquery: '../components/jquery/jquery.min',
		modernizr: '../components/modernizr/modernizr',
		underscore: '../components/underscore/underscore',
		backbone: '../components/backbone/backbone'
	}
});

var $;
var _;
var Backbone;

var app = {
	templates: {}
};

function main() {
	console.log("underscore", _);

	_.extend(app, Backbone.Events);

	var File = Backbone.Model.extend({
		defaults: {
			name: 'unnamed',
			length: 0,
			content: ''
		},

		initialize: function() {
			this.on('change:content', this.nameChanged);
		},

		nameChanged: function(what, to) {
			this.set('length', to.length);
		},

		idAttribute: 'name'
	});

	var Files = Backbone.Collection.extend({
		model: File,
		url: '/files'
	});

	var FilenameView = Backbone.View.extend({
		template: _.template(app.templates.filename),

		initialize: function() {
			this.listenTo(this.model, 'change', this.render);
		},

		tagName: 'li',

		render: function() {
			var json = this.model.toJSON();
			this.$el.html(this.template(this.model.toJSON()));
			return this;
		}
	});

	var FileContentView = Backbone.View.extend({
		el: '#content',

		initialize: function() {
			this.$name = this.$el.find('.name');
			this.$filename = this.$el.find('.filename');
			this.$textarea = this.$el.find('textarea');
			this.$status = this.$el.find('.status');
			this.$save = this.$el.find('.save');
			this.$refresh = this.$el.find('.refresh');
			this.setModel(null);
		},

		events: {
			'click .save': 'save',
			'click .refresh': 'refresh'
		},

		setFile: function(name) {
			var model = app.files.findWhere({ name: name });
			this.setModel(model);
		},

		setModel: function(model) {
			if (this.model) {
				this.stopListening(this.model);
			}
			this.model = model;
			if (this.model) {
				this.listenTo(this.model, 'sync', this.render);
			}
			this.render();
		},

		render: function() {
			var hasModel = this.model != null;

			if (hasModel) {
				this.$filename.html(this.model.get('name'));
				this.$textarea.val(this.model.get('content'))
					.attr('readonly', false);
			} else {
				this.$filename.html('(no file)');
				this.$textarea.val('')
					.attr('readonly', true);
			}

			this.$save.attr('disabled', !hasModel);
			this.$refresh.attr('disabled', !hasModel);

			return this;
		},

		save: function() {
			if (this.model) {
				// TODO report "saving..." state
				this.$status.html('Saving...');
				var that = this;
				var xhr = this.model.save({
					content: this.$textarea.val()
				}, {
					wait: true
				});
				xhr.fail(function(xhr) {
					alert("Error saving file: " + xhr.responseText);
					that.$status.html('Error saving file.');
				});
				xhr.success(function(what) {
					that.$status.html('Saved.');
				});
			}
		},

		refresh: function() {
			if (this.model) {
				var xhr = this.model.fetch();
				xhr.fail(function(xhr) {
					console.log("Failed to refresh", xhr.responseText);
				});
				xhr.success(function(what) {
	//				console.log("Success", what);
				});
			}
		}

	});

	var FilesView = Backbone.View.extend({
		el: '#files',

		initialize: function() {
			this.listenTo(app.files, 'reset', this.addAll);
			var xhr = app.files.fetch({ reset: true });
			xhr.error(function(xhr) {
				alert("Error loading files: " + xhr.responseText);
			});
			xhr.success(function(what) {
				app.trigger('initialLoad');
			});
		},

		addOne: function(file) {
			var view = new FilenameView({ model: file });
			this.$el.append(view.render().el);
		},

		addAll: function() {
			var that = this;
			this.$el.empty();
			app.files.each(function(file) {
				that.addOne(file);
			});
		}
	});

	var Workspace = Backbone.Router.extend({
		routes: {
			'*name': 'setFile'
		},

		setFile: function(name) {
			app.fileContentView.setFile(name);
		}
	});

	app.files = new Files();
	window.gf = app.files;
	console.log("App.files", app.files);
	app.filesView = new FilesView();
	app.fileContentView = new FileContentView();
	app.router = new Workspace();

	app.once('initialLoad', function() {
		Backbone.history.start();
	});
}

require(['jquery', 'modernizr', 'underscore', 'backbone'], function($, modernizr) {
	// use app here
	$('#status').html('If you can read this text, your stack should be alright.');
	console.log("Fubar!");
	$.ajax('/templates/filename.template').done(function(result) {
		app.templates.filename = result;
		main();
	});
}); 

{'fraction_non_alphanumeric': 0.19696339434276205, 'fraction_numerical': 0.00020798668885191348, 'mean_word_length': 3.2822796081923418, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3053191', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1653, 'n_words': 310}