Skip to content

Instantly share code, notes, and snippets.

@mahm
Created November 27, 2014 01:19
Show Gist options
  • Save mahm/13290e8e3f21fde8142f to your computer and use it in GitHub Desktop.
Save mahm/13290e8e3f21fde8142f to your computer and use it in GitHub Desktop.
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