private static IFile getPreferenceViewFile(IProject project, IPath viewPath, String action) { String[] viewExts = getAvailableViewExts(); String[] viewFiles = new String[] {Inflector.underscorize(action), Inflector.camelize(action)}; for (int iExt = 0; iExt < viewExts.length; ++iExt) { for (int iFile = 0; iFile < viewFiles.length; ++iFile) { IPath viewFilePath = viewPath.append(viewFiles[iFile] + viewExts[iExt]); IFile file = project.getFile(viewFilePath); if (file.exists()) { return file; } break; } } // never return 'null', use file.exists() to check exists IPath viewFilePath = viewPath.append(Inflector.underscorize(action) + getDefaultViewExt()); return project.getFile(viewFilePath); }
public static String getModelNamePlural(IFile modelFile) { IPath modelFilePath = modelFile.getProjectRelativePath(); String modelFilename = modelFilePath.lastSegment(); if (!CakePHPHelper.isModel(modelFile)) return null; String singular = modelFilename.substring(0, modelFilename.indexOf('.')); String plural = Inflector.pluralize(singular); return plural; }
public static IFile getViewFromAction(IFile controllerFile, String action) { if (!isController(controllerFile)) return null; IPath controllerFilePath = controllerFile.getProjectRelativePath(); String[] keys = splitAction(action); String view = keys[0]; if (view == null || view.length() == 0) { view = getControllerBaseName(controllerFilePath.lastSegment()); // view = view.substring(0, 1).toUpperCase() + view.substring(1); view = Inflector.humanize(view); } action = keys[1]; IPath viewPath = getAppFolderFromController(controllerFilePath).append(VIEWS).append(view); return getPreferenceViewFile(controllerFile.getProject(), viewPath, action); }
public static IFile getViewFromJSFile(IFile selectedFile) { if (!isJSFile(selectedFile)) return null; IPath selectedFilePath = selectedFile.getProjectRelativePath(); // String[] keys = splitAction(selectedFilePath.lastSegment()); String[] keys = selectedFilePath.lastSegment().split("\\."); String view = keys[0]; int segmentCount = selectedFilePath.segmentCount(); if (segmentCount < 3) { return null; } String modelName = selectedFilePath.segment(segmentCount - 2); // TODO: there's got to be a better way to do this IPath viewPath = getAppFolderFromJSFile(selectedFilePath) .append(VIEWS) .append(Inflector.pluralize(modelName)); return getPreferenceViewFile(selectedFile.getProject(), viewPath, view); }
private static String getModelName(String controllerFilename) { String singular = Inflector.singularize(getControllerBaseName(controllerFilename)); singular += PHP; return singular; }
private static String getModelNameFromViewPath(IPath viewFilePath) { String singular = Inflector.singularize(getPluralResourceNameFromViewPath(viewFilePath)); singular += PHP; return singular; }