Last active
August 29, 2015 14:15
-
-
Save timotta/94ee1bf8e582d01a2d6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sprockets/directive_processor' | |
| class MiddleIncludeProcessor < Sprockets::DirectiveProcessor | |
| def prepare | |
| @pathname = Pathname.new(file) | |
| @header = '' | |
| @body = data | |
| @included_pathnames = [] | |
| @compat = false | |
| end | |
| def evaluate(context, locals, &block) | |
| @context = context | |
| @lines ||= body.lines.each_with_index.map do |line, index| | |
| if directive = line[DIRECTIVE_PATTERN, 1] | |
| name, *args = Shellwords.shellwords(directive) | |
| if name == 'include' | |
| context.evaluate(args.first) | |
| end | |
| else | |
| line | |
| end | |
| end | |
| @result = @lines.compact.join | |
| end | |
| end |
Author
timotta
commented
Feb 11, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment