Ejemplo n.º 1
0
func ReadAsset(assetUrl string) (result string, err error) {
	filePath := ResolvePath(assetUrl)
	fileExt := path.Ext(filePath)

	switch fileExt {
	case ".js", ".css":
		if Config.BundleAssets {
			data := bytes.NewBuffer([]byte(""))
			contents := []string{}
			_, err = ReadAssetsFunc(filePath, assetUrl, func(filePath string, content string) {
				contents = append(contents, content)
			})
			if err != nil {
				return
			}
			data.Write([]byte(strings.Join(contents, "\n")))
			result = string(data.Bytes())
		} else {
			result, err = ReadRawAsset(filePath, assetUrl)
		}
	case ".sass", ".scss", ".coffee":
		interpreter.Config.SASS.LineNumbers = Config.SASS.LineNumbers
		interpreter.Config.SASS.DebugInfo = Config.SASS.DebugInfo
		result, err = interpreter.Compile(filePath)
	default:
		err = errors.New("Unsupported Asset: " + assetUrl)
	}

	return
}
Ejemplo n.º 2
0
func compileSassAndCoffee(filePath string) (string, error) {
	interpreter.Config.AssetsPath = Config.AssetsPath
	interpreter.Config.SASS.LineNumbers = Config.SASS.LineNumbers
	interpreter.Config.SASS.DebugInfo = Config.SASS.DebugInfo
	interpreter.Config.Verbose = Config.Verbose
	result, err := interpreter.Compile(filePath)
	return result, err
}
Ejemplo n.º 3
0
func Diagnose() bool {
	var err error

	fmt.Println("== Diagnosing\n")

	allGood := true
	_, filename, _, _ := runtime.Caller(0)
	assetsPath := path.Dir(filename) + "/assets"

	_, err = bash("node-sass --version")
	if err != nil {
		fmt.Println("-- SASS is disabled because the required npm is not found.")
		fmt.Println("   (install it if you wish to use SASS: npm install -g [email protected])\n")
		allGood = false
	} else {
		_, err = interpreter.Compile(assetsPath + "/stylesheets/font.sass")
		if err != nil {
			fmt.Println("-- SASS is disabled because error raised while compiling. Error:")
			fmt.Printf("%s\n", err.Error())
			allGood = false
		}
	}

	_, err = bash("coffee -v")
	if err != nil {
		fmt.Println("-- CoffeeScript is disabled because the required npm is not found.")
		fmt.Println("   (install it if you wish to use CoffeeScript : npm install -g [email protected])")
		allGood = false
	} else {
		_, err = interpreter.Compile(assetsPath + "/javascripts/app.coffee")
		if err != nil {
			fmt.Println("-- CoffeeScript is disabled because error raised while compiling. Error: ")
			fmt.Printf("%s\n", err.Error())
			allGood = false
		}
	}

	if allGood {
		fmt.Println("-- Great, your environment seems perfect for Train.")
	} else {
		fmt.Println("-- (Please create an issue at github.com/shaoshing/train/issues if you need help)")
	}

	return allGood
}
Ejemplo n.º 4
0
func diagnose() bool {
	var err error

	fmt.Println("== Diagnosing\n")

	var rubyVersion string
	rubyVersion, err = bash(`ruby -e "puts RUBY_VERSION"`)
	if err != nil {
		fmt.Println("-- SASS and CoffeeScript are disabled because ruby is not installed.")
		fmt.Println("   (visit https://github.com/sstephenson/rbenv/#installation for installation instructions)")
		return false
	}

	if !strings.Contains(rubyVersion, "1.9") {
		fmt.Printf("-- Train requires Ruby version to be 1.9.x; you have %s", rubyVersion)
		fmt.Println("   (Please install required Ruby version if you wish to use SASS or CoffeeScript)")
		return false
	}

	allGood := true
	_, filename, _, _ := runtime.Caller(1)
	assetsPath := path.Dir(filename) + "/assets"

	_, err = bash("gem which sass")
	if err != nil {
		fmt.Println("-- SASS is disabled because the required gem is not found.")
		fmt.Println("   (install it if you wish to use SASS: gem install sass)\n")
		allGood = false
	} else {
		_, err = interpreter.Compile(assetsPath + "/stylesheets/font.sass")
		if err != nil {
			fmt.Println("-- SASS is disabled because error raised while compiling. Error:")
			fmt.Printf("%s\n", err.Error())
			fmt.Println("(this might related to your Ruby Environment; try re-installing Ruby)\n")
			allGood = false
		}
	}

	_, err = bash("gem which coffee-script")
	if err != nil {
		fmt.Println("-- CoffeeScript is disabled because the required gem is not found.")
		fmt.Println("   (install it if you wish to use CoffeeScript : gem install coffee-script)")
		allGood = false
	} else {
		_, err = interpreter.Compile(assetsPath + "/javascripts/app.coffee")
		if err != nil {
			fmt.Println("-- CoffeeScript is disabled because error raised while compiling. Error: ")
			fmt.Printf("%s\n", err.Error())
			fmt.Println("(this might related to your Ruby Environment; try re-installing Ruby)\n")
			allGood = false
		}
	}

	if allGood {
		fmt.Println("-- Great, your environment seems perfect for Train.")
	} else {
		fmt.Println("-- (Please create an issue at github.com/shaoshing/train/issues if you need help)")
	}

	return allGood
}