New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate correct default css path for namespaced classes. #12
Generate correct default css path for namespaced classes. #12
Conversation
CSS background property is a shortcut for background-color. After processing scss background automatically substitute with background-color. That caused spec to file. Change background to background-color in tests and fixtures.
a757d6b
to
125632f
Compare
lib/inline_styles_mailer.rb
Outdated
|
||
path = self.name.underscore | ||
modified_path = path.gsub(/\//, '/_') | ||
@stylesheets = [modified_path == path ? "_#{path}*" : "#{modified_path}*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you're doing here and I like it. This will cope with paths two levels deep.
# Two levels
Foo::Bar.name.underscore.gsub /\//, '/_'
=> 'foo/_bar' # good
But we might as well make it work for any number of levels, which the above code doesn't:
# Three levels
Foo::Bar::Po.name.underscore.gsub /\//, '/_'
=> 'foo/_bar/_po' # bad
This regex will do it and also remove the need for the test because it works with just one level too:
# One level
Foo.name.underscore.sub /^(.*\/)*(.*)$/, '\1_\2*'
=> '_foo*' # good
# Two levels
Foo::Bar.name.underscore.sub /^(.*\/)*(.*)$/, '\1_\2*'
=> 'foo/_bar*' # good
# Three levels
Foo::Bar::Po.name.underscore.sub /^(.*\/)*(.*)$/, '\1_\2*'
=> 'foo/bar/_po*' # good
The method can then be:
def stylesheets
return @stylesheets if defined? @stylesheets
[self.name.underscore.sub(/^(.*\/)*(.*)$/, '\1_\2*')]
end
I'm not sure it's even worth memoizing that method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Thanks for catching this!
@@ -1,7 +1,7 @@ | |||
language: ruby | |||
matrix: | |||
include: | |||
- rvm: 2.0.0 | |||
- rvm: 2.0.0-p648 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks for fixing that.
CSS background property is a shortcut for background-color.
After processing scss background automatically substitute with background-color.
That caused spec to file. Change background to background-color in tests and fixtures.