/**
 * Copyright 2012 55 Minutes (http://www.55minutes.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package fiftyfive.wicket.js.locator;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Helper class that parses JavaScript files for special
 * <a href="http://getsprockets.org/">Sprockets</a> comments
 * like these:
 * <pre class="example">
 * //= require library_name
 * //= require ./file_name</pre>
 * <p>
 * Note that paths can also be surrounded by quotes, but they are completely optional:
 * <pre class="example">
 * //= require "library_name"
 * //= require "./file_name"</pre>
 * 
 * @since 4.0
 */
public class SprocketsParserImplV4 implements SprocketsParser
{
    private static final Logger LOGGER = LoggerFactory.getLogger(
        SprocketsParserImplV4.class
    );
    
    static final Pattern REQ = Pattern.compile("^\\s*//=\\s*require\\s+(\\S.*\\S)\\s*$");
    
    public List<Sprocket> parseSprockets(BufferedReader javascript)
        throws IOException
    {
        List<Sprocket> sprockets = new ArrayList<Sprocket>();
        
        while(true)
        {
            String line = javascript.readLine();
            if(null == line) break;
            
            Matcher require = REQ.matcher(line);
            if(!require.find()) continue;
            
            String path = stripQuotes(require.group(1));
            boolean isLibrary = !(path.startsWith("./") || path.startsWith("../"));
            sprockets.add(new Sprocket(isLibrary, path));
        }
        return sprockets;
    }
    
    private String stripQuotes(String path)
    {
        String[] quotes = new String[] { "\"", "'" };
        for(String q : quotes)
        {
            if(path.startsWith(q) && path.endsWith(q))
            {
                path = path.substring(1, path.length() - 1);
                break;
            }
        }
        return path;
    }
}

Introduce parse logic for new sprockets syntax
Introduce parse logic for new sprockets syntax

Previously we used `<>` and `""` to differentiate library references and local paths, respectively, in sprockets `//= require` declarations. Taking a cue from the latest version of sprockets, change this syntax such that `//= require` implies a library reference, unless the path starts with `./` or `../`.
