html2slim 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3eece9c3c64833b43a38e67031800308ca6575ca
4
- data.tar.gz: 63335c0229a9e8161aab1e8ac29c18a4e08703ee
3
+ metadata.gz: 44b797bc3773fce1d804c911e1d37cbbdda05f42
4
+ data.tar.gz: 56ac9b993d994e044c0066312b2c7c97e7d5d0dd
5
5
  SHA512:
6
- metadata.gz: b3bb20dd62fa408f22657ee9fda3bb3a10b9d157ccd97e42aa0c4b5e4d6c1615d43818f896b2566e76e102d86b6890506fa8a80ee42fa63eaeb6625f2d0e2195
7
- data.tar.gz: 654678b5831303841e368fbda3935b4963b79ccbce5258d9a703cd48562e44849db37ae306421e37ff03af15213771a01e4ee6eb892462df6132617bc7266fcb
6
+ metadata.gz: 6f73e26146faa023907be525d087665302d0108f06b28c9aac79f925d893e13dd700312c1c306f40c4d526efc6c89ab5dbfeee58e45a7acd189f4dd0db8bacf8
7
+ data.tar.gz: 68dec2af87d41e5a7cd11fde3cbef56ba2de2edafe05dcb2321e2cd9a7f9908ade5657367b081aebd0deae2677df600919c0379fba8c5568a965dfd3f69ddab3
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![Version](https://img.shields.io/gem/v/html2slim.svg)
2
+
1
3
  [![Build Status](https://travis-ci.org/slim-template/html2slim.png?branch=master)](https://travis-ci.org/slim-template/html2slim)
2
4
 
3
5
  [![Code climate](https://codeclimate.com/github/slim-template/html2slim.png)](https://codeclimate.com/github/slim-template/html2slim)
@@ -38,14 +40,14 @@ This project is released under the MIT license.
38
40
 
39
41
  ## Author
40
42
 
41
- [Maiz Lulkin] (https://github.com/joaomilho)
43
+ [Maiz Lulkin] (https://github.com/joaomilho) and [contributors](https://github.com/slim-template/html2slim/graphs/contributors)
42
44
 
43
45
  ## OFFICIAL REPO
44
46
 
45
- https://github.com/slim-template/html2slim
47
+ [https://github.com/slim-template/html2slim](https://github.com/slim-template/html2slim)
46
48
 
47
49
  ## ROADMAP
48
50
 
49
- 1. ERB support is pre-alpha, and works only for 90% of the cases. Lotsa weird regexes. Gotta improve that.
51
+ 1. ERB support is beta, and works only for ~92.6% of the cases. Lotsa weird regexes. Gotta improve that.
50
52
  2. Use temple.
51
53
  3. Merge with other *2slim gems. Would be handy.
@@ -85,6 +85,8 @@ module HTML2Slim
85
85
  else
86
86
  slim_file = destination || slim_file
87
87
  end
88
+
89
+ fail(ArgumentError, "Source and destination files can't be the same.") if @options[:input] != '-' && file == slim_file
88
90
 
89
91
  in_file = if @options[:input] == "-"
90
92
  $stdin
@@ -18,14 +18,14 @@ module HTML2Slim
18
18
 
19
19
  erb.gsub!(/<%(.+?)\s*\{\s*(\|.+?\|)?\s*%>/){ %(<%#{$1} do #{$2}%>) }
20
20
 
21
- # while, case, if, for and blocks...
22
- erb.gsub!(/<%(-\s+)?(\s*while .+?|\s*case .+?|\s*if .+?|\s*for .+?|.+?do\s*(\|.+?\|)?\s*)-?%>/){ %(<ruby code="#{$2.gsub(/"/, '&quot;')}">) }
21
+ # case, if, for, unless, until, while, and blocks...
22
+ erb.gsub!(/<%(-\s+)?((\s*(case|if|for|unless|until|while) .+?)|.+?do\s*(\|.+?\|)?\s*)-?%>/){ %(<ruby code="#{$2.gsub(/"/, '&quot;')}">) }
23
23
  # else
24
24
  erb.gsub!(/<%-?\s*else\s*-?%>/, %(</ruby><ruby code="else">))
25
25
  # elsif
26
- erb.gsub!(/<%-?\s*(elsif .+?)\s*-?%>/){ %(</ruby><ruby code="#{$1}">) }
26
+ erb.gsub!(/<%-?\s*(elsif .+?)\s*-?%>/){ %(</ruby><ruby code="#{$1.gsub(/"/, '&quot;')}">) }
27
27
  # when
28
- erb.gsub!(/<%-?\s*(when .+?)\s*-?%>/){ %(</ruby><ruby code="#{$1}">) }
28
+ erb.gsub!(/<%-?\s*(when .+?)\s*-?%>/){ %(</ruby><ruby code="#{$1.gsub(/"/, '&quot;')}">) }
29
29
  erb.gsub!(/<%\s*(end|}|end\s+-)\s*%>/, %(</ruby>))
30
30
  erb.gsub!(/<%(.+?)\s*-?%>/m){ %(<ruby code="#{$1.gsub(/"/, '&quot;')}"></ruby>) }
31
31
  @slim ||= Hpricot(erb).to_slim
@@ -44,6 +44,8 @@ class Hpricot::DocType
44
44
  end
45
45
 
46
46
  class Hpricot::Elem
47
+ BLANK_RE = /\A[[:space:]]*\z/
48
+
47
49
  def slim(lvl=0)
48
50
  r = ' ' * lvl
49
51
 
@@ -97,11 +99,11 @@ class Hpricot::Elem
97
99
  end
98
100
 
99
101
  def has_id?
100
- has_attribute?('id')
102
+ has_attribute?('id') && !(BLANK_RE === self['id'])
101
103
  end
102
104
 
103
105
  def has_class?
104
- has_attribute?('class')
106
+ has_attribute?('class') && !(BLANK_RE === self['class'])
105
107
  end
106
108
 
107
109
  def ruby?
@@ -1,3 +1,3 @@
1
1
  module HTML2Slim
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html2slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maiz Lulkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-18 00:00:00.000000000 Z
11
+ date: 2015-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hpricot