Permalink
Browse files

Adding initial library files and updating README

  • Loading branch information...
1 parent 727ac6e commit b10573efed35760f8b78ad7e3c28756044d6354d @jgable committed Sep 20, 2012
Showing with 73 additions and 0 deletions.
  1. +3 −0 index.js
  2. +46 −0 lib/jsPaths.coffee
  3. +24 −0 package.json
View
3 index.js
@@ -0,0 +1,3 @@
+require("coffee-script");
+
+module.exports = require("./lib/jsPaths");
View
46 lib/jsPaths.coffee
@@ -0,0 +1,46 @@
+
+
+exportPathsHelper = (assetsModule, log) ->
+ assets = assetsModule.instance
+
+ context = assets.options.helperContext
+
+ baseUrlDir = context.js.root
+
+ prePath = "#{baseUrlDir}/"
+ prePathLength = prePath.length
+
+ trimJsExt = (file) ->
+ # Trim the end of the file if it has a .js extension
+ return file.slice(0, -3) if file.slice(-3) == ".js"
+
+ file
+
+ #console.log assets.cachedRoutePaths
+ exportPaths = {}
+ for own route, paths of assets.cachedRoutePaths
+ trimmedRoute = route
+ trimmedRoute = route.slice prePathLength if route.slice(0, prePathLength) == prePath
+
+ # Trim the end of the file if it has a .js extension
+ trimmedRoute = trimJsExt trimmedRoute
+
+ exportPaths[trimmedRoute] = trimJsExt paths[0]
+
+ getPathsScript = (varName = "connectAssets") ->
+ """
+ <script type="text/javascript">
+ var #{varName} = #{JSON.stringify(exportPaths)};
+ </script>
+ """
+
+ jsUrl = (fileName) ->
+ # Strip the leading /
+ fileName = fileName.slice(1) if fileName[0] is "/"
+ assets.cachedRoutePaths[fileName]?[0]
+
+ context.exportPaths = getPathsScript
+ context.jsUrl = jsUrl
+
+module.exports = (assets, log) ->
+ exportPathsHelper assets, log
View
24 package.json
@@ -0,0 +1,24 @@
+{
+ "name": "connect-assets-jspaths",
+ "version": "0.0.1",
+ "homepage": "https://jgable.github.com/connect-assets-jspaths",
+ "description": "Helps with getting the paths to your connect-assets javascript files.",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jgable/connect-assets-jspaths.git"
+ },
+ "keywords": [
+ "connect-assets",
+ "javascript",
+ "requirejs"
+ ],
+ "author": "Jacob Gable <jacob.gable@gmail.com>",
+ "license": "MIT",
+ "dependencies": {
+ "coffee-script": "~1.3.3"
+ }
+}

0 comments on commit b10573e

Please sign in to comment.