Clean page classes of invalid CSS characters and make sure they don't start with a number

This commit is contained in:
Ben Hollis 2013-10-19 15:31:49 -07:00
parent fd85ca90a3
commit 4055479ff3

View file

@ -141,7 +141,14 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
parts = path.split('.').first.split('/')
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
classes.join(' ')
classes.map do |c|
# Replace weird class name characters
c = c.gsub(/[^a-zA-Z0-9\-_]/, '-')
# Class names can't start with a digit
c = "x#{c}" if c =~ /\A\d/
c
end.join(' ')
end
# Get the path of a file of a given type