devfu-simple-tidy 0.1.0 → 0.1.1

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.
data/README.rdoc CHANGED
@@ -25,3 +25,18 @@ command line app (instead of the C library).
25
25
  </body>
26
26
  </html>
27
27
  => nil
28
+
29
+ Or, you can make instances of SimpleTidy for lower-level usage (eg. to get warnings)
30
+
31
+ >> tidy = SimpleTidy.new :indent_spaces => 2
32
+ => #<SimpleTidy:0x7fb5e56a70f0 @tidy_options={:indent_spaces=>2, :tidy_mark=>false}
33
+
34
+ >> tidy.clean '<html>foo</html>'
35
+ => "<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">\n\n<html>\n<head>\n <title></title>\n</head>\n\n<body>\n foo\n</body>\n</html>"
36
+
37
+ >> tidy.warnings
38
+ => ["line 1 column 1 - Warning: missing <!DOCTYPE> declaration", "line 1 column 7 - Warning: plain text isn't allowed in <head> elements", "line 1 column 7 - Warning: inserting implicit <body>", "line 1 column 7 - Warning: inserting missing 'title' element"]
39
+
40
+ == Configuration Options
41
+
42
+ For documentation on the options: <tt>man tidy</tt>. See the <b>DETAILED CONFIGURATION OPTIONS</b> section. All of these options should be supported.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/simple-tidy.rb CHANGED
@@ -28,7 +28,7 @@ class SimpleTidy
28
28
  private
29
29
 
30
30
  def get_output_and_warnings html
31
- stdin, stdout, stderr = Open3.popen3 "echo '#{ html }' | tidy #{ tidy_options_text }"
31
+ stdin, stdout, stderr = Open3.popen3 "tidy #{ tidy_options_text } #{ temp_file(html) }"
32
32
  output = stdout.read.strip
33
33
  warnings = stderr.read.split("\n").select {|line| line =~ /line \d+ column \d+ - Warning:/ }
34
34
  return output, warnings
@@ -57,4 +57,10 @@ private
57
57
  SINGLE_DASH_OPTIONS.include?(option) ? '-' : '--'
58
58
  end
59
59
 
60
+ def temp_file html
61
+ filename = "/tmp/simple-tidy-#{ Time.now.strftime('%Y%m%d%H%M%S') }.html"
62
+ File.open(filename, 'w'){|f| f << html }
63
+ filename
64
+ end
65
+
60
66
  end
@@ -42,4 +42,14 @@ describe SimpleTidy do
42
42
  SimpleTidy.clean( html, :indent_spaces => 2 ).should == SimpleTidy.new( :indent_spaces => 2 ).clean(html)
43
43
  end
44
44
 
45
+ it 'should work with quotes (and whatnot) in html' do
46
+ html = %[<html>\\\\ "why" 'hello' \'\"\'THERE\'\"\' ! !! ! \\\ .</html>]
47
+
48
+ SimpleTidy.new.clean(html).should ==
49
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" +
50
+ "<html>\n<head>\n<title></title>\n</head>\n<body>\n" +
51
+ %[\\\\ "why" 'hello' \'\"\'THERE\'\"\' ! !! ! \\\ .] +
52
+ "\n</body>\n</html>"
53
+ end
54
+
45
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devfu-simple-tidy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - remi