Ejemplo n.º 1
0
// FralaParser gets the directory contents of tests/design (if it exists) and parse the files with Frala.
func FralaParser(rootDirectory string, files []string) {
	if len(rootDirectory) != 0 && rootDirectory != "/" { // If the rootDirectory has content but NOT /
		rootDirectory += "/" // Append / to end of rootDirectory

		var fileNamesWithoutDir []string                             // Define filesWithoutDir as an empty []string that'll contain names of files without the directory string
		languagesToRecurse := []string{frala.Config.DefaultLanguage} // Set languagesToRecurse to a string slicen with Default Language by default

		if len(frala.Config.Languages) != 0 { // If pre-defined languages have been set
			languagesToRecurse = frala.Config.Languages // Set languagesToRecurse to the languages defined
		}

		for _, fileName := range files { // For each file in files
			fileNamesWithoutDir = append(fileNamesWithoutDir, filepath.Base(fileName)) // Append only the file name
		}

		for _, language := range languagesToRecurse { // For each language
			frala.Config.DefaultLanguage = language                                   // Change DefaultLanguage in Frala to language
			frala.Config.Direction = frala.GetDirection(frala.Config.DefaultLanguage) // Ensure we have an accurate Direction against the updated DefaultLanguage

			listOfParseResponses := frala.MultiParse(files) // Parse all the HTML files in tests/design, return the ParseResponses

			for fileName, parseResponse := range listOfParseResponses { // For each file and parseResponse in listOfParseResponses
				if len(parseResponse.Content) != 0 && parseResponse.Error == nil { // If there is content returned from the parsing and there is no error
					codeutilsShared.WriteOrUpdateFile(rootDirectory+language+"/"+filepath.Base(fileName), []byte(parseResponse.Content), codeutilsShared.UniversalFileMode) // Update the file in lang specific design dir
				}
			}

			CompressHTML(rootDirectory+language, fileNamesWithoutDir) // Compress all the HTML files provided in this language directory
		}

		for _, fileName := range fileNamesWithoutDir { // For each file in fileNamesWithoutDir
			os.Remove(rootDirectory + fileName) // Remove the file in tests/design now that we have compressed forms in each individual language folder in tests/design
		}
	}
}
Ejemplo n.º 2
0
// ParseFiles will parse the files provided and export parsed to target directory
func ParseFiles(parseFiles string) {
	filesToParse := strings.Split(parseFiles, ",")   // Split the comma-separated parseFiles to filesToParse
	parseResponses := frala.MultiParse(filesToParse) // Parse each file

	for fileName, parseResponse := range parseResponses { // For each parseResponse
		if parseResponse.Error == nil { // If there was no issue parsing this file
			if parseResponse.Content != "" { // If the content is not empty
				fileNameNoPath := filepath.Base(fileName) // Get the base filename
				fmt.Println("Writing content to: " + TargetDirectory + fileNameNoPath)
				os.MkdirAll(TargetDirectory, 0755) // Ensure the directory exists
				ioutil.WriteFile(TargetDirectory+fileNameNoPath, []byte(parseResponse.Content), 0755)
			} else { // If there was no content in the parseResponse.Content
				fmt.Println("No content provided via parsing: " + fileName)
			}
		} else { // If there was an issue parsing this file
			fmt.Println(parseResponse.Error) // Print the error
		}
	}
}