import java.util.regex.Matcher; import java.util.regex.Pattern; import projectviewer.*; goToAction(action, msg){ txt = textArea.getText(); Pattern rp = Pattern.compile("def\\s+"+action+"\\b"); Matcher m = rp.matcher(txt); if(m.find()){ search = new PatternSearchMatcher(m.group(), false); match = search.nextMatch(txt, true, true, true, false); textArea.setCaretPosition(match.start); } else { Macros.message(view, msg); return false; } } goToFileOnCurrentLine() { mode = buffer.getMode().toString(); curLine = textArea.getLineText(textArea.getCaretLine()); curProject = ProjectViewer.getActiveProject(view); if(curProject == null){ Macros.error(view, "Couldn't find RoR project directory"); return false; } railsRoot = curProject.getRootPath(); dirPath = buffer.getDirectory(); curFile = buffer.getPath(); modules = "/"; // Example: render :partial => 'account/login' Pattern rp = Pattern.compile("render[\\s\\(].*:partial\\s*=>\\s*[\'\"](.+?)[\'\"]"); Matcher m = rp.matcher(curLine); if(m.find()){ partialName = m.group(1); if(partialName.lastIndexOf("/") != -1){ pieces = partialName.split("/"); partialName = pieces[pieces.length - 1]; for(int i = 0; i 'login' Pattern rp = Pattern.compile("render[\\s\\(].*:action\\s*=>\\s*[\'\"](.+?)[\'\"]"); Matcher m = rp.matcher(curLine); if(m.find()){ actionName = m.group(1); if(mode.equals("ruby")){ goToAction(actionName, "Couldn't find the \'"+actionName+"\' action"); } else { Macros.message(view, "Don't know where to go when rendering an action from outside a controller"); return false; } } // Example: redirect_to :action => 'login' Pattern rp = Pattern.compile("(redirect_to|redirect_back_or_default)[\\s\\(]"); Matcher m = rp.matcher(curLine); if(m.find()){ controller = action = ""; Pattern rp = Pattern.compile(".*:action\\s*=>\\s*[\'\"](.+?)[\'\"]"); Matcher m = rp.matcher(curLine); if(m.find()) action = m.group(1); Pattern rp = Pattern.compile(".*:controller\\s*=>\\s*[\'\"](.+?)[\'\"]"); Matcher m = rp.matcher(curLine); if(m.find()) controller = m.group(1); if(!mode.equals("ruby")){ Macros.message(view, "Don't know where to go when redirecting from outside a controller"); return false; } if(controller.length() == 0){ controllerFile = curFile; } else { if(controller.lastIndexOf("/") != -1){ pieces = controller.split("/"); controller = pieces[pieces.length - 1]; for(int i = 0; i Pattern rp = Pattern.compile(" Pattern rp = Pattern.compile("<%=.+javascript_include_tag.+[\'\"](.+?)[\'\"]"); Matcher m = rp.matcher(curLine); if(m.find()){ javascript = m.group(1); if(javascript.lastIndexOf(".js") == -1) javascript = javascript + ".js"; if(javascript.startsWith("/")){ publicFile = javascript.substring(1, javascript.length()); } else { publicFile = "javascripts/"+javascript; } fullPath = railsRoot + File.separator + "public" + File.separator + publicFile; jEdit.openFile(view, fullPath); } // Example: Pattern rp = Pattern.compile(" Pattern rp = Pattern.compile("<%=.+stylesheet_link_tag.+[\'\"](.+?)[\'\"]"); Matcher m = rp.matcher(curLine); if(m.find()){ stylesheet = m.group(1); if(stylesheet.lastIndexOf(".css") == -1) stylesheet = stylesheet + ".css"; if(stylesheet.startsWith("/")){ publicFile = stylesheet.substring(1, stylesheet.length()); } else { publicFile = "stylesheets/"+stylesheet; } fullPath = railsRoot + File.separator + "public" + File.separator + publicFile; jEdit.openFile(view, fullPath); } // Example: layout 'admin' Pattern rp = Pattern.compile("layout.+[\'\"](.+?)[\'\"]"); Matcher m = rp.matcher(curLine); if(m.find()){ layout = m.group(1); fullPath = railsRoot + File.separator + "app" + File.separator + "views" + File.separator + "layouts" + File.separator + layout + ".rhtml"; jEdit.openFile(view, fullPath); } } goToFileOnCurrentLine();