htmlbeautifier 1.1.1 → 1.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 +4 -4
- data/README.md +3 -3
- data/bin/htmlbeautifier +14 -2
- data/lib/htmlbeautifier.rb +8 -1
- data/lib/htmlbeautifier/builder.rb +6 -4
- data/lib/htmlbeautifier/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a56b2b5efa4d86724c29098dd2877d5e480cc3f8
|
|
4
|
+
data.tar.gz: 191861084a908515224d0df8cb6bce30d962090d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c21dd2ce56776f1ef0dd3ccb496eda14c5f83363660d95098d96bf9af287d63f98ce512011b9433e3a5136e0ed19d273b8bda4465fe21e892c1cc22c9e873bea
|
|
7
|
+
data.tar.gz: 0d14c894a17c9841abaef8f41121f10cb7701cd2a4a1fc1721692aca02fc70af0274d1a2317746d0be1aba69ead804dedae0d5ecf5bbc4ccf8415335fa444480
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Ideal for tidying up Rails templates.
|
|
|
5
5
|
|
|
6
6
|
## What it does
|
|
7
7
|
|
|
8
|
-
* Normalises hard tabs to spaces
|
|
8
|
+
* Normalises hard tabs to spaces (or vice versa)
|
|
9
9
|
* Removes trailing spaces
|
|
10
10
|
* Indents after opening HTML elements
|
|
11
11
|
* Outdents before closing elements
|
|
@@ -40,10 +40,10 @@ require 'htmlbeautifier'
|
|
|
40
40
|
beautiful = HtmlBeautifier.beautify(messy)
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
You can also specify
|
|
43
|
+
You can also specify how to indent (the default is two spaces):
|
|
44
44
|
|
|
45
45
|
```ruby
|
|
46
|
-
beautiful = HtmlBeautifier.beautify(messy,
|
|
46
|
+
beautiful = HtmlBeautifier.beautify(messy, indent: "\t")
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
## Installation
|
data/bin/htmlbeautifier
CHANGED
|
@@ -11,7 +11,7 @@ end
|
|
|
11
11
|
|
|
12
12
|
executable = File.basename(__FILE__)
|
|
13
13
|
|
|
14
|
-
options = {
|
|
14
|
+
options = { indent: " " }
|
|
15
15
|
parser = OptionParser.new do |opts|
|
|
16
16
|
opts.banner = "Usage: #{executable} [options] [file ...]"
|
|
17
17
|
opts.separator <<END
|
|
@@ -30,7 +30,19 @@ END
|
|
|
30
30
|
"-t", "--tab-stops NUMBER", Integer,
|
|
31
31
|
"Set number of spaces per indent (default #{options[:tab_stops]})"
|
|
32
32
|
) do |num|
|
|
33
|
-
options[:
|
|
33
|
+
options[:indent] = " " * num
|
|
34
|
+
end
|
|
35
|
+
opts.on(
|
|
36
|
+
"-T", "--tab",
|
|
37
|
+
"Indent using tabs"
|
|
38
|
+
) do
|
|
39
|
+
options[:indent] = "\t"
|
|
40
|
+
end
|
|
41
|
+
opts.on(
|
|
42
|
+
"-i", "--indent-by NUMBER", Integer,
|
|
43
|
+
"Indent the output by NUMBER steps (default 0)."
|
|
44
|
+
) do |num|
|
|
45
|
+
options[:initial_level] = num
|
|
34
46
|
end
|
|
35
47
|
opts.on(
|
|
36
48
|
"-e", "--stop-on-errors",
|
data/lib/htmlbeautifier.rb
CHANGED
|
@@ -8,11 +8,18 @@ module HtmlBeautifier
|
|
|
8
8
|
# html must be an object that responds to +#to_s+.
|
|
9
9
|
#
|
|
10
10
|
# Available options are:
|
|
11
|
-
# tab_stops - an integer for the number of spaces to indent, default 2
|
|
11
|
+
# tab_stops - an integer for the number of spaces to indent, default 2.
|
|
12
|
+
# Deprecated: see indent.
|
|
13
|
+
# indent - what to indent with (" ", "\t" etc.), default " "
|
|
12
14
|
# stop_on_errors - raise an exception on a badly-formed document. Default
|
|
13
15
|
# is false, i.e. continue to process the rest of the document.
|
|
16
|
+
# initial_level - The entire output will be indented by this number of steps.
|
|
17
|
+
# Default is 0.
|
|
14
18
|
#
|
|
15
19
|
def self.beautify(html, options = {})
|
|
20
|
+
if options[:tab_stops]
|
|
21
|
+
options[:indent] = " " * options[:tab_stops]
|
|
22
|
+
end
|
|
16
23
|
"".tap { |output|
|
|
17
24
|
HtmlParser.new.scan html.to_s, Builder.new(output, options)
|
|
18
25
|
}
|
|
@@ -4,15 +4,16 @@ require "htmlbeautifier/ruby_indenter"
|
|
|
4
4
|
module HtmlBeautifier
|
|
5
5
|
class Builder
|
|
6
6
|
DEFAULT_OPTIONS = {
|
|
7
|
-
|
|
7
|
+
indent: " ",
|
|
8
|
+
initial_level: 0,
|
|
8
9
|
stop_on_errors: false
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
def initialize(output, options = {})
|
|
12
13
|
options = DEFAULT_OPTIONS.merge(options)
|
|
13
|
-
@tab =
|
|
14
|
+
@tab = options[:indent]
|
|
14
15
|
@stop_on_errors = options[:stop_on_errors]
|
|
15
|
-
@level =
|
|
16
|
+
@level = options[:initial_level]
|
|
16
17
|
@new_line = false
|
|
17
18
|
@empty = true
|
|
18
19
|
@ie_cc_levels = []
|
|
@@ -37,7 +38,8 @@ module HtmlBeautifier
|
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def emit(*strings)
|
|
40
|
-
@output <<
|
|
41
|
+
@output << "\n" if @new_line && !@empty
|
|
42
|
+
@output << (@tab * @level) if @new_line
|
|
41
43
|
@output << strings.join("")
|
|
42
44
|
@new_line = false
|
|
43
45
|
@empty = false
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: htmlbeautifier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paul Battley
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
88
88
|
version: '0'
|
|
89
89
|
requirements: []
|
|
90
90
|
rubyforge_project:
|
|
91
|
-
rubygems_version: 2.4.5
|
|
91
|
+
rubygems_version: 2.4.5.1
|
|
92
92
|
signing_key:
|
|
93
93
|
specification_version: 4
|
|
94
94
|
summary: HTML/ERB beautifier
|