Skip to content
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

Conversation

ssemakov
Copy link
Contributor

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.

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.
@ssemakov ssemakov force-pushed the fix-default-paths-for-namespaced-classes branch from a757d6b to 125632f Compare May 23, 2017 12:22

path = self.name.underscore
modified_path = path.gsub(/\//, '/_')
@stylesheets = [modified_path == path ? "_#{path}*" : "#{modified_path}*"]
Copy link
Owner

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.

Copy link
Contributor Author

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
Copy link
Owner

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.

@billhorsman billhorsman merged commit 24224a8 into billhorsman:master May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants