Skip to content

Instantly share code, notes, and snippets.

@fredericobenevides
Created March 8, 2014 13:46
Show Gist options
  • Save fredericobenevides/9430809 to your computer and use it in GitHub Desktop.
Save fredericobenevides/9430809 to your computer and use it in GitHub Desktop.
Override the Slim parser to add default whitespace for some tags.
# 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