htmlbeautifier 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b82dd8d2489286ab4474e1690d0a47ff91ffce8
4
- data.tar.gz: e20a70c076be7e6eda31e456b0fd56715c1554ce
3
+ metadata.gz: a56b2b5efa4d86724c29098dd2877d5e480cc3f8
4
+ data.tar.gz: 191861084a908515224d0df8cb6bce30d962090d
5
5
  SHA512:
6
- metadata.gz: 9da8945658fddb13a0af61e5d61e05b381ffdb8168247d22fe6026043c41822cce4bce45910e844cb8f5183f01a790836a209802531cd4e13a1bbd67b0092877
7
- data.tar.gz: 224c74e0769b2e208505cd0d1461f4c971ed9a264f2ed78bf27c6311c5fa037e40295b8beb607fed7edf114e354138805cec3e766432b9a3a8e08e0b66a86950
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 the number of spaces to indent (the default is 2):
43
+ You can also specify how to indent (the default is two spaces):
44
44
 
45
45
  ```ruby
46
- beautiful = HtmlBeautifier.beautify(messy, tab_stops: 4)
46
+ beautiful = HtmlBeautifier.beautify(messy, indent: "\t")
47
47
  ```
48
48
 
49
49
  ## Installation
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  executable = File.basename(__FILE__)
13
13
 
14
- options = { tab_stops: 2 }
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[:tab_stops] = num
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",
@@ -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
- tab_stops: 2,
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 = " " * options[:tab_stops]
14
+ @tab = options[:indent]
14
15
  @stop_on_errors = options[:stop_on_errors]
15
- @level = 0
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 << ("\n" + @tab * @level) if @new_line && !@empty
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
@@ -1,8 +1,8 @@
1
1
  module HtmlBeautifier #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 1
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join(".")
8
8
  end
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.1.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: 2015-07-27 00:00:00.000000000 Z
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