html5-beautifier 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/html5-beautifier.gemspec +20 -0
- data/lib/html5-beautifier.rb +7 -0
- data/lib/html5-beautifier/core_ext/string/beautify.rb +23 -0
- data/lib/html5-beautifier/version.rb +5 -0
- data/lib/html5-beautifier/xslt/html5-beautifier.xslt +51 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jari Jokinen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# HTML5 Beautifier
|
2
|
+
|
3
|
+
HTML5 Beautifier is a plugin for Ruby on Rails that process an HTML5 document and reformat it with a correct indentation.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "html5-beautifier"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install html5-beautifier
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
any_string.beautify
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
30
|
+
|
31
|
+
## Support
|
32
|
+
|
33
|
+
If you have any questions or issues with HTML5 Beautifier, or if you like to report a bug, please create an {issue on GitHub}[https://github.com/jarijokinen/html5-beautifier/issues].
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
MIT License. Copyright (c) 2012 Jari Jokinen. See {LICENSE}[[https://github.com/jarijokinen/html5-beautifier/LICENSE] for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'html5-beautifier/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "html5-beautifier"
|
8
|
+
gem.version = Html5::Beautifier::VERSION
|
9
|
+
gem.authors = ["Jari Jokinen"]
|
10
|
+
gem.email = ["info@jarijokinen.com"]
|
11
|
+
gem.description = %q{HTML5 Beautifier for Ruby on Rails}
|
12
|
+
gem.summary = %q{HTML5 Beautifier plugin for Ruby on Rails}
|
13
|
+
gem.homepage = "http://jarijokinen.com/html5-beautifier"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
|
18
|
+
gem.add_dependency "rails"
|
19
|
+
gem.add_dependency "nokogiri"
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class String
|
2
|
+
def beautify(indent_length = 2, indent_character = " ", exclude_elements = nil)
|
3
|
+
indent_string = indent_character * indent_length
|
4
|
+
|
5
|
+
if !exclude_elements
|
6
|
+
exclude_elements = [
|
7
|
+
"li", "a", "span", "p", "td", "small", "strong", "em", "br",
|
8
|
+
"h1", "h2", "h3", "h4", "h5", "h6"
|
9
|
+
]
|
10
|
+
end
|
11
|
+
exclude_elements = exclude_elements.map { |e| "name()!='#{e}'" }
|
12
|
+
|
13
|
+
xslt_file = File.join(File.dirname(__FILE__), "..", "..", "xslt", "html5-beautifier.xslt")
|
14
|
+
xslt_content = File.read(File.expand_path(xslt_file))
|
15
|
+
xslt_content.gsub!("__INDENT_STRING__", indent_string)
|
16
|
+
xslt_content.gsub!("__EXCLUDE_ELEMENTS__", exclude_elements.join(" and "))
|
17
|
+
doc = Nokogiri::HTML(self.gsub("\r", ""))
|
18
|
+
xslt = Nokogiri::XSLT(xslt_content)
|
19
|
+
html = xslt.apply_to(doc)
|
20
|
+
html.gsub!(/<script (.+?)\/>/, '<script \1></script>')
|
21
|
+
html
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
2
|
+
<xsl:output method="xml" omit-xml-declaration="yes" encoding="utf-8" />
|
3
|
+
<xsl:param name="indent-increment" select="'__INDENT_STRING__'" />
|
4
|
+
|
5
|
+
<xsl:template name="newline">
|
6
|
+
<xsl:text disable-output-escaping="yes">
|
7
|
+
</xsl:text>
|
8
|
+
</xsl:template>
|
9
|
+
|
10
|
+
<xsl:template match="/">
|
11
|
+
<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>
|
12
|
+
<xsl:apply-templates />
|
13
|
+
</xsl:template>
|
14
|
+
|
15
|
+
<xsl:template match="comment() | processing-instruction()">
|
16
|
+
<xsl:param name="indent" select="''" />
|
17
|
+
<xsl:call-template name="newline" />
|
18
|
+
<xsl:value-of select="$indent" />
|
19
|
+
<xsl:copy />
|
20
|
+
</xsl:template>
|
21
|
+
|
22
|
+
<xsl:template match="text()">
|
23
|
+
<xsl:param name="indent" select="''" />
|
24
|
+
<xsl:call-template name="newline" />
|
25
|
+
<xsl:value-of select="$indent" />
|
26
|
+
<xsl:value-of select="normalize-space(.)" />
|
27
|
+
</xsl:template>
|
28
|
+
|
29
|
+
<xsl:template match="text()[normalize-space(.)='']" />
|
30
|
+
|
31
|
+
<xsl:template match="*">
|
32
|
+
<xsl:param name="indent" select="''" />
|
33
|
+
<xsl:call-template name="newline" />
|
34
|
+
<xsl:value-of select="$indent" />
|
35
|
+
<xsl:choose>
|
36
|
+
<xsl:when test="count(child::*) > 0 and __EXCLUDE_ELEMENTS__">
|
37
|
+
<xsl:copy>
|
38
|
+
<xsl:copy-of select="@*" />
|
39
|
+
<xsl:apply-templates select="*|text()">
|
40
|
+
<xsl:with-param name="indent" select="concat($indent, $indent-increment)" />
|
41
|
+
</xsl:apply-templates>
|
42
|
+
<xsl:call-template name="newline" />
|
43
|
+
<xsl:value-of select="$indent" />
|
44
|
+
</xsl:copy>
|
45
|
+
</xsl:when>
|
46
|
+
<xsl:otherwise>
|
47
|
+
<xsl:copy-of select="." />
|
48
|
+
</xsl:otherwise>
|
49
|
+
</xsl:choose>
|
50
|
+
</xsl:template>
|
51
|
+
</xsl:stylesheet>
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html5-beautifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jari Jokinen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: HTML5 Beautifier for Ruby on Rails
|
47
|
+
email:
|
48
|
+
- info@jarijokinen.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- html5-beautifier.gemspec
|
59
|
+
- lib/html5-beautifier.rb
|
60
|
+
- lib/html5-beautifier/core_ext/string/beautify.rb
|
61
|
+
- lib/html5-beautifier/version.rb
|
62
|
+
- lib/html5-beautifier/xslt/html5-beautifier.xslt
|
63
|
+
homepage: http://jarijokinen.com/html5-beautifier
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: HTML5 Beautifier plugin for Ruby on Rails
|
87
|
+
test_files: []
|