Created
November 27, 2014 01:19
-
-
Save mahm/13290e8e3f21fde8142f to your computer and use it in GitHub Desktop.
Rails3.1 + Ruby2.0 with Sprockets
This file contains 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
# Rails 3.2.13以前のバージョン + Ruby2.0の組み合わせだと適切にDirectiveをパースできない不具合がある | |
# ref: https://github.com/sstephenson/sprockets/issues/352 | |
directive_pattern = / | |
^ \W* = \s* (\w+.*?) (\*\/)? $ | |
/x | |
Sprockets::DirectiveProcessor.class_eval do | |
remove_const(:DIRECTIVE_PATTERN) | |
const_set(:DIRECTIVE_PATTERN, directive_pattern) | |
def directives | |
@directives ||= header.lines.each_with_index.map { |line, index| | |
if directive = line[Sprockets::DirectiveProcessor::DIRECTIVE_PATTERN, 1] | |
name, *args = Shellwords.shellwords(directive) | |
# 2.0系からprivateメソッドのrespond_to?には第2引数が必要になった | |
if respond_to?("process_#{name}_directive", true) | |
[index + 1, name, *args] | |
end | |
end | |
}.compact | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment