Class: HTML2Slim::ERBConverter
- Defined in:
- lib/html2slim/converter.rb
Instance Method Summary collapse
-
#initialize(file) ⇒ ERBConverter
constructor
A new instance of ERBConverter.
Methods inherited from Converter
Constructor Details
#initialize(file) ⇒ ERBConverter
Returns a new instance of ERBConverter.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/html2slim/converter.rb', line 15 def initialize(file) # open.read makes it works for files & IO erb = File.exist?(file) ? open(file).read : file erb.gsub!(/<%(.+?)\s*\{\s*(\|.+?\|)?\s*%>/){ %(<%#{$1} do #{$2}%>) } # case, if, for, unless, until, while, and blocks... erb.gsub!(/<%(-\s+)?((\s*(case|if|for|unless|until|while) .+?)|.+?do\s*(\|.+?\|)?\s*)-?%>/){ %(<ruby code="#{$2.gsub(/"/, '"')}">) } # else erb.gsub!(/<%-?\s*else\s*-?%>/, %(</ruby><ruby code="else">)) # elsif erb.gsub!(/<%-?\s*(elsif .+?)\s*-?%>/){ %(</ruby><ruby code="#{$1.gsub(/"/, '"')}">) } # when erb.gsub!(/<%-?\s*(when .+?)\s*-?%>/){ %(</ruby><ruby code="#{$1.gsub(/"/, '"')}">) } erb.gsub!(/<%\s*(end|}|end\s+-)\s*%>/, %(</ruby>)) erb.gsub!(/<%-?(.+?)\s*-?%>/m){ %(<ruby code="#{$1.gsub(/"/, '"')}"></ruby>) } @slim ||= Hpricot(erb).to_slim end |