From 4055479ff3129013c85278ed2fc8f49d2b281507 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Sat, 19 Oct 2013 15:31:49 -0700 Subject: [PATCH] Clean page classes of invalid CSS characters and make sure they don't start with a number --- .../middleman-more/core_extensions/default_helpers.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index 84d6f645..62a5b0bf 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -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