html_pretty 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.
data/README.md CHANGED
@@ -1,2 +1,2 @@
1
- html-pretty
2
- ===========
1
+ html-pretty [![Build Status](https://secure.travis-ci.org/fengb/html_pretty.png)](http://travis-ci.org/fengb/html_pretty)
2
+ ===========
data/Rakefile CHANGED
@@ -1,46 +1,45 @@
1
-
2
-
3
- namespace :output do
4
- def work_dir
5
- 'compare'
6
- end
7
-
8
- def src_file
9
- "#{work_dir}/_orig.html"
1
+ namespace :compare do
2
+ def src_str
3
+ @src_str ||= IO.read("compare/_orig.html")
10
4
  end
11
5
 
12
- def orig_str
13
- IO.read(orig_file)
6
+ def comptask(taskname, options={}, &block)
7
+ desc "Output comparison for #{taskname}"
8
+ task taskname do
9
+ require options.delete(:require) || taskname.to_s
10
+ File.open("compare/#{taskname}.html", 'w') do |outfile|
11
+ block.call(outfile, src_str)
12
+ end
13
+ end
14
14
  end
15
15
 
16
- def dst_file(t)
17
- "#{work_dir}/#{t.rpartition(':').last}.html"
16
+ comptask :html_pretty do |outfile, instr|
17
+ outfile.write HtmlPretty.run(src_str)
18
18
  end
19
19
 
20
- task :html_pretty do |t|
21
- sh "ruby -Ilib bin/html_pretty #{orig_file} >#{dst_file(t)}"
20
+ comptask :htmlbeautifier do |outfile, instr|
21
+ HtmlBeautifier::Beautifier.new(outfile).scan(instr)
22
22
  end
23
23
 
24
- task :htmlbeautifier do |t|
25
- sh "htmlbeautifier <#{orig_file} >#{dst_file(t)}"
24
+ comptask :rexml, :require => 'rexml/document' do |outfile, instr|
25
+ REXML::Document.new(instr).write(outfile, 2)
26
26
  end
27
27
 
28
- task :tidy do |t|
29
- sh "tidy -i -q #{orig_file} >#{dst_file(t)} 2>&1"
28
+ comptask :nokogiri do |outfile, instr|
29
+ outfile.write Nokogiri::XML(instr, &:noblanks).to_xhtml(:indent => 2)
30
30
  end
31
+ end
32
+ desc "Output all comparisons"
33
+ task :compare => %w[compare:html_pretty compare:htmlbeautifier compare:rexml compare:nokogiri]
31
34
 
32
- task :rexml do |t|
33
- require 'rexml/document'
34
- doc = REXML::Document.new(orig_str)
35
- File.open(dst_file(t), 'w'){|f| doc.write f, 2}
36
- end
35
+ require 'rspec/core/rake_task'
36
+ RSpec::Core::RakeTask.new(:spec) do |rt|
37
+ rt.fail_on_error = false
38
+ end
37
39
 
38
- task :nokogiri do |t|
39
- require 'nokogiri'
40
- doc = Nokogiri::XML(orig_str, &:noblanks)
41
- File.open(dst_file(t), 'w'){|f| f.write doc.to_xhtml(:indent => 2)}
42
- end
40
+ require 'cucumber/rake/task'
41
+ Cucumber::Rake::Task.new(:features) do |t|
42
+ t.cucumber_opts = "features --format progress"
43
43
  end
44
- task :output => 'output:html_pretty'
45
44
 
46
- task :default => :output
45
+ task :default => [:spec, :features]
@@ -1,3 +1,3 @@
1
1
  module HtmlPretty
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/html_pretty.rb CHANGED
@@ -14,7 +14,17 @@ module HtmlPretty
14
14
  elsif blob =~ SPECIAL
15
15
  out << " " * indent << blob << "\n"
16
16
  else
17
- blob = blob.gsub(/^[ \t]*\n/, "") # kill blank lines
17
+ # Remove all newlines within a tag definition
18
+ # Example: '<a\nb=1\nc=2>' => '<a b=1 c=2>'
19
+ blob = blob.split(/(<.*?>)/).map do |blub|
20
+ if blub.start_with?('<')
21
+ blub.gsub(/\n/, ' ')
22
+ else
23
+ blub
24
+ end
25
+ end.join
26
+
27
+ blob = blob.gsub(/^[ \t]*\n/, '') # kill blank lines
18
28
  blob = blob.gsub(/^[ \t]+/, '') # kill opening whitespace
19
29
  blob = blob.gsub(/[ \t]+$/, '') # kill closing whitespace
20
30
  blob = blob.gsub(/[ \t]+/, ' ') # collapse all whitespace
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_pretty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-24 00:00:00.000000000 Z
12
+ date: 2013-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -27,6 +27,54 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: cucumber
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.3.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.3.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: htmlbeautifier
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: nokogiri
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
30
78
  description: html_pretty is yet another HTML prettifier. It purposefully does not
31
79
  do parsing or validation.
32
80
  email: benjamin.feng@gmail.com