mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
make page_classes prefix configurable
This commit is contained in:
parent
1e57eb5c1b
commit
9a2c1533e3
2 changed files with 19 additions and 3 deletions
|
@ -15,3 +15,18 @@ Feature: Built-in page_classes view helper
|
|||
Given the Server is running at "page-classes-app"
|
||||
When I go to "/sub1/sub2/page-classes.html"
|
||||
Then I should see "sub1 sub1_sub2 sub1_sub2_page-classes"
|
||||
|
||||
Scenario: The page starts with a number
|
||||
Given the Server is running at "page-classes-app"
|
||||
When I go to "/1-starts-with-numeric.html"
|
||||
Then I should see "x1-starts-with-numeric"
|
||||
|
||||
Scenario: The folder starts with a number
|
||||
Given the Server is running at "page-classes-app"
|
||||
When I go to "/1-folder/1-inside-with-numeric.html"
|
||||
Then I should see "x1-folder x1-folder_1-inside-with-numeric"
|
||||
|
||||
Scenario: Custom prefix for numeric
|
||||
Given the Server is running at "page-classes-app"
|
||||
When I go to "/2-starts-with-numeric-custom.html"
|
||||
Then I should see "haaaaay2-starts-with-numeric-custom"
|
|
@ -132,7 +132,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
# Generate body css classes based on the current path
|
||||
#
|
||||
# @return [String]
|
||||
def page_classes
|
||||
def page_classes(options={})
|
||||
path = current_path.dup
|
||||
path << index_file if path.end_with?('/')
|
||||
path = ::Middleman::Util.strip_leading_slash(path)
|
||||
|
@ -141,12 +141,13 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
parts = path.split('.').first.split('/')
|
||||
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
|
||||
|
||||
prefix = options[:numeric_prefix] || "x"
|
||||
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 = "#{prefix}#{c}" if c =~ /\A\d/
|
||||
c
|
||||
end.join(' ')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue