Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Rails3.1 + Ruby2.0 with Sprockets
# 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