Created
March 8, 2014 13:46
-
-
Save fredericobenevides/9430809 to your computer and use it in GitHub Desktop.
Override the Slim parser to add default whitespace for some tags.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Override the Slim parser to add default whitespace for some tags. | |
module Slim | |
class Parser < Temple::Parser | |
alias :old_parse_tag :parse_tag | |
WHITESPACE_MODIFIER = '<' | |
TAGS_TO_ADD_WHITESPACE = %w[. # div span] | |
def parse_tag(tag) | |
insert_whitespace = false | |
TAGS_TO_ADD_WHITESPACE.each do |t| | |
insert_whitespace = true if t == tag | |
end | |
if insert_whitespace | |
if @line =~ /(^.*)\s(.*)/ | |
@line = "#{$1}#{WHITESPACE_MODIFIER} #{$2}" | |
else | |
@line << WHITESPACE_MODIFIER | |
end | |
end | |
old_parse_tag tag | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment