Commits

ryanackley committed 61a50f4

Added RoR support and fixed up other stuff

  • Participants
  • Parent commits baf481e

Comments (0)

Files changed (6)

File FileUrlProject.js

 		// It's not necessary to cache the urls since it's just a matter of tacking on the 'file://' 
 		// in the front but I don't want to post an update 
 		// to the devtools panel unless I know it's an actual project url.
-		return this.projectUrls[path];
+		return [this.projectUrls[path]];
 	},
 	resetUrls : function(){
 		this.projectUrls = {};

File FileWatcher.js

-var FileWatcher = function(tabId, project, path){
+var FileWatcher = function(tabId, project, path, fsRoot){
 	this.tabId = tabId;
 	this.project = project;
 	this.recentUpdateHandler = new RecentUpdateHandler(2000);
+	this.fsRoot = fsRoot;
 	nativeFileSupport.watchDirectory(tabId.toString(), path, this.fileChanged.bind(this));
 }
 
 		if (urls && urls.length){
 			var port = chrome.tabs.connect(this.tabId, {name: 'fileChange'});
 			var ran = Math.round(Math.random()*10000000);
+			var self = this;
 			urls.asyncEach(function(url, done){
-				$.ajax({type: 'GET',
-						url: url + '?r=' + ran,
-						dataType: 'text',
-						success: function(data){
-							port.postMessage({url: url, content: data});
-							done();
-						},
-						error: done});
+				var sendContentToDevtools = function(data){
+					port.postMessage({url: url, content: data});
+					done();
+				}
+				
+				if (url.indexOf('file://') == 0){
+					Gito.FileUtils.readFile(self.fsRoot, url.substring(7), 'Text', sendContentToDevtools, done);
+				}
+				else{
+					$.ajax({type: 'GET',
+							url: url + '?r=' + ran,
+							dataType: 'text',
+							success: sendContentToDevtools,
+							error: done});
+				}
 			}, 
 			function(){
 				port.disconnect();

File ProjectManager.js

 					else{
 						sendResponse({success: true, msg: 'Content for url ' + url + ' matches local file ' + path });
 					}
-				});
+				}, function(){});
 			}
 		}
 	},
 	watchDirectory : function(tabId, path){
 		if (!this.watchersByTab[tabId]){
 			var currentProject = this.projectsByTab[tabId];
-			this.watchersByTab[tabId] = new FileWatcher(tabId, currentProject, path);
+			this.watchersByTab[tabId] = new FileWatcher(tabId, currentProject, path, this.fsRoot);
 		}
 	},
 	cleanUp : function(tabId){

File RubyOnRailsProject.js

+var slash = navigator.platform.indexOf('Win') == 0 ? '\\' : '/';
+
+var RubyOnRails31Project = function(root, routes){
+	this.routes = routes;
+	this.rootPath = root.fullPath;
+	//used to strip off .coffee, .less, .scss, etc. off the end of a file name
+	this.stripRegex = /(\.js|\.css)\.[a-zA-Z]+$/
+	this.projectUrls = {};
+}
+
+RubyOnRails31Project.prototype = {
+	filePathForUrl : function(url){
+		var routes = this.routes;
+		for (var i = 0; i < routes.length; i++){
+			var match = url.match(routes[i].from);
+			if (match){
+				var partialPath = match[0].replace(routes[i].from, routes[i].to);
+				var path = this.rootPath + (partialPath.charAt(0) == '/' ? '' : '/') + partialPath;
+				this.projectUrls[path] = url;
+			}
+		}
+		return null;
+	},
+	
+	urlsForFilePath : function(path){
+		var strippedPath = path.replace(this.stripRegex, '$1');
+		var url = this.projectUrls[strippedPath];
+		if (url){
+			return [url];
+		}
+	 	return [];
+	},
+	resetUrls : function(){
+		this.projectUrls = {};
+	}
+}
+
+ProjectTypes.push(
+    {
+		name: 'Ruby on Rails (3.1 or higher)',
+		key: 'ror3.1',
+		locationType : 'local',
+		createProject : function(root, callback){
+			routes = [
+				{from: /\/assets\/(.+\.js)/,
+				 to: slash + ['app','assets','javascripts'].join(slash) + slash + '$1'},
+				{from: /\/assets\/(.+\.css)/,
+				 to: slash + ['app','assets','stylesheets'].join(slash) + slash + '$1'}
+			];
+			var project = new RubyOnRails31Project(root, routes);
+			callback(project);
+		} 
+    }
+);
+
+/*var RubyOnRails31Project = function(){
+	this.processedMap = {};	
+}
+
+RubyOnRails31Project.prototype = {
+    _loadResourceMappings : function(dir, prefix, callback){
+		Gito.FileUtils.ls(dir, function(jsEntries){
+			for (var i = 0; i < jsEntries.length; i++){
+				var jsEntry = jsEntries[i];
+				var jsIdx = jsEntry.name.indexOf('.js.');
+				if (jsIdx != -1){
+					jsEntry
+				}
+			}
+		});
+	},
+	load : function(root, callback){
+		this.root = root;
+		this.assetRoot = root.fullPath + slash + ['app','assets'].join(slash) + slash;
+		callback();
+	},
+	filePathForUrl : function(url, type){
+		var pieces = url.split('/');
+		for (var min = 0; min < pieces.length; min++){
+			if (pieces[min] == 'assets'){
+				break;
+			}
+		}
+		var last = pieces.length - 1
+		if (min >= last){
+			return null;
+		}
+		
+		var partialPath = pieces.slice(min).join('/');
+		if (type == 'script'){
+			partialPath = 'javascripts/' + partialPath;
+		}
+		else{
+			partialPath = 'stylesheets/' + partialPath; 
+		}
+		
+		return this.root.fullPath + '/assets/' + partialPath
+	},
+	urlsForFilePath : function(path){
+		var assetRoot = this.assetRoot;
+		if (path.indexOf(assetRoot) == 0){
+			var partialPath = path.substring(assetRoot.length);
+			if (partialPath.indexOf('javascripts') == 0){
+				
+			}
+			else if (partialPath.indexOf('stylesheets') == 0){
+				
+			}
+		}
+		return [];
+	},
+	resetUrls : function(){
+		this.projectUrls = {};
+	}
+}*/
+

File background.html

     	</script>
     	<script src="file_utils.js"></script>
 		<script src="AtlassianPluginProject.js"></script>
+		<script src="RubyOnRailsProject.js"></script>
 		<script src="FileUrlProject.js"></script>
 		<script src="zepto1.0rc1.js"></script>
 		<script src="RecentUpdateHandler.js"></script>

File editorpanel.html

 	<script src="Logger.js"></script>
 	<script>
 		
+		var projectTypes;
+		
 		var checkProjectState = function(){
-			var projectState = window.devtoolsWindow.projectState,
-				disabled = 'false';
+			var projectState = window.devtoolsWindow.projectState;
+				
 			if (projectState.type == 'fileUrl'){
-				disabled = 'true';
+				$('#project-type').attr('disabled', 'true');
+				$('#native-browse').attr('disabled', 'true');
 			}
-			$('#project-type').attr('disabled', disabled);
-			$('#native-browse').attr('disabled', disabled);
+			else if (projectState.type){
+				var typeSelect = document.getElementById('project-type');
+				$('#project-type').removeAttr('disabled');
+				$('#native-browse').removeAttr('disabled');
+				
+				for (var i = 0; i < projectTypes.length; i++){
+					if (projectTypes[i].key === projectState.type){
+						typeSelect.selectedIndex = i;
+						break;
+					}
+				}
+				$('#local-file-path').text(projectState.path);
+			}
+			
 		}
 		
 		var initUI = function(){
-			checkProjectState();
 			var typeSelect = document.getElementById('project-type');
 			
-			backgroundMsgSupport.getProjectTypes(function(projectTypes){
+			backgroundMsgSupport.getProjectTypes(function(types){
+				projectTypes = types;
 				for (var i = 0; i < projectTypes.length; ++i) {
 					var projectType = projectTypes[i];
 					typeSelect.add(new Option(projectType.name, i));
 				}
+				checkProjectState();
 			});
 			$(typeSelect).on('change', function(e){
 				var index = typeSelect.selectedIndex;