middleman-html-beautify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 831d5c0f891beaee101dae3bb9bcd20db08e7d4d3c4f0a2722a76a32a8b602b0
4
+ data.tar.gz: 6156df30d031bae6ebde811305b48a82811feeb3cf99612fb24a2e9dfd47df27
5
+ SHA512:
6
+ metadata.gz: 625e52b3066f3c3ab899a6eee45b907bdfab983fadc401c939f0860b26b72b7c1de8c9f966485877751a3fa8e36fef79b1488f31c045037a4a42aa43df226137
7
+ data.tar.gz: 33a17d61b81beaeaf2b5cf434566962267b0066c80374c2b8673fcd4207dc4885e81b7b8012220fed748aa5cb1c2d588becc8f5c3a6e00d4c3735dad7a07042d
data/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # EditorConfig is awesome: http://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # We recommend you to keep these unchanged
7
+ [*]
8
+ charset = utf-8
9
+ end_of_line = lf
10
+ insert_final_newline = true
11
+ indent_style = space
12
+ indent_size = 2
13
+ trim_trailing_whitespace = true
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ /Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6.3
4
+ gemfile:
5
+ - Gemfile
6
+ script:
7
+ - bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in middleman-html-beautify.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 inotom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Middleman::HtmlBeautify
2
+
3
+ [![Build Status](https://travis-ci.org/inotom/middleman-html-beautify.svg?branch=master)](https://travis-ci.org/inotom/middleman-html-beautify)
4
+
5
+ `middleman-html-beautify` is an extension for the [Middleman](https://middlemanapp.com/) static site generator that beautify HTML via [HTML Beautifier](https://github.com/threedaymonk/htmlbeautifier).
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'middleman-html-beautify'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```
19
+ $ bundle install
20
+ ```
21
+
22
+
23
+ ## Usage
24
+
25
+ Add this line to your config.rb
26
+
27
+ ```ruby
28
+ activate :html_beautify
29
+ ```
30
+
31
+ There are default settings.
32
+
33
+ ```ruby
34
+ activate :html_beautify do |option|
35
+ option.keep_blank_lines = 0
36
+ option.indent = " "
37
+ option.initial_level = 0
38
+ option.stop_on_errors = false
39
+ end
40
+ ```
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => [:test]
4
+
5
+ task :test => [:cucumber]
6
+
7
+ require 'cucumber/rake/task'
8
+
9
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |task|
10
+ ENV['TEST'] = 'true'
11
+ task.cucumber_opts = '--color --strict --format pretty'
12
+ end
@@ -0,0 +1,84 @@
1
+ Feature: Beautify HTML
2
+
3
+ Scenario: Preview HTML with html_beautify disabled
4
+ Given a fixture app "basic-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ """
8
+ Given the Server is running at "basic-app"
9
+ When I go to "/index.html"
10
+ Then I should see:
11
+ """
12
+ <!doctype html>
13
+ <html>
14
+ <head>
15
+ <title>Hello World</title>
16
+ </head>
17
+ <body>
18
+
19
+ <h1>
20
+ Multi
21
+ Line
22
+ </h1>
23
+ <h2> Broken Up </h2>
24
+
25
+
26
+ </body>
27
+ </html>
28
+ """
29
+
30
+ Scenario: Preview HTML with html_beautify enabled
31
+ Given a fixture app "basic-app"
32
+ And a file named "config.rb" with:
33
+ """
34
+ activate :html_beautify
35
+ """
36
+ Given the Server is running at "basic-app"
37
+ When I go to "/index.html"
38
+ Then I should see:
39
+ """
40
+ <!doctype html>
41
+ <html>
42
+ <head>
43
+ <title>Hello World</title>
44
+ </head>
45
+ <body>
46
+ <h1>
47
+ Multi
48
+ Line
49
+ </h1>
50
+ <h2> Broken Up </h2>
51
+ </body>
52
+ </html>
53
+ """
54
+
55
+ Scenario: Preview HTML with html_beautify enabled and custom option
56
+ Given a fixture app "basic-app"
57
+ And a file named "config.rb" with:
58
+ """
59
+ activate :html_beautify do |option|
60
+ option.keep_blank_lines = 1
61
+ option.indent = "\t"
62
+ option.initial_level = 1
63
+ end
64
+ """
65
+ Given the Server is running at "basic-app"
66
+ When I go to "/index.html"
67
+ Then I should see:
68
+ """
69
+ <!doctype html>
70
+ <html>
71
+ <head>
72
+ <title>Hello World</title>
73
+ </head>
74
+ <body>
75
+
76
+ <h1>
77
+ Multi
78
+ Line
79
+ </h1>
80
+ <h2> Broken Up </h2>
81
+
82
+ </body>
83
+ </html>
84
+ """
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require "middleman-core"
3
+ require "middleman-core/step_definitions"
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-html-beautify')
@@ -0,0 +1 @@
1
+ activate :html_beautify
@@ -0,0 +1,16 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Hello World</title>
5
+ </head>
6
+ <body>
7
+
8
+ <h1>
9
+ Multi
10
+ Line
11
+ </h1>
12
+ <h2> Broken Up </h2>
13
+
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,7 @@
1
+ require 'middleman-core'
2
+ require 'middleman-html-beautify/version'
3
+
4
+ ::Middleman::Extensions.register(:html_beautify) do
5
+ require 'middleman-html-beautify/extension'
6
+ ::Middleman::HtmlBeautify::Extension
7
+ end
@@ -0,0 +1,58 @@
1
+ module Middleman
2
+ module HtmlBeautify
3
+ class Extension < ::Middleman::Extension
4
+ option :keep_blank_lines, 0, 'Keep blank lines count'
5
+ option :indent, ' ', 'Indent character'
6
+ option :initial_level, 0, 'Starting indent level'
7
+ option :stop_on_errors, false, 'Stop building with errors'
8
+
9
+ def initialize(*)
10
+ super
11
+ end
12
+
13
+ def after_configuration
14
+ app.use Rack, options.to_h
15
+ end
16
+
17
+ class Rack
18
+
19
+ DEFAULT_OPTIONS = {
20
+ keep_blank_lines: 0,
21
+ indent: ' ',
22
+ initial_level: 0,
23
+ stop_on_errors: false
24
+ }
25
+
26
+ def initialize app, options = {}
27
+ require 'htmlbeautifier'
28
+
29
+ @app = app
30
+
31
+ @options = DEFAULT_OPTIONS.merge(options)
32
+ end
33
+
34
+ def call env
35
+ status, headers, body = @app.call(env)
36
+
37
+ if headers.key? 'Content-Type' and headers['Content-Type'] =~ /html/
38
+ content = ''
39
+
40
+ body.each do |part|
41
+ content << part
42
+ end
43
+
44
+ content = HtmlBeautifier.beautify(content, @options)
45
+
46
+ headers['Content-Length'] = content.bytesize.to_s if headers['Content-Length']
47
+
48
+ [status, headers, [content]]
49
+ else
50
+ [status, headers, body]
51
+ end
52
+ ensure
53
+ body.close if body.respond_to?(:close)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module HtmlBeautify
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'middleman-html-beautify/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "middleman-html-beautify"
7
+ spec.version = Middleman::HtmlBeautify::VERSION
8
+ spec.authors = ["inotom"]
9
+ spec.email = ["wdf7322@yahoo.co.jp"]
10
+
11
+ spec.summary = %q{Beautify HTML string}
12
+ spec.description = %q{Beautify HTML string}
13
+ spec.homepage = "https://github.com/inotom/middleman-html-beautify"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_runtime_dependency 'middleman-core', '>= 4.3'
26
+ spec.add_runtime_dependency 'htmlbeautifier', '>= 1.3'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.17'
29
+ spec.add_development_dependency 'rake', '~> 12.0'
30
+ spec.add_development_dependency 'cucumber', '~> 1.3'
31
+ spec.add_development_dependency 'capybara', '~> 3.30'
32
+ spec.add_development_dependency 'aruba', '~> 0.5'
33
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-html-beautify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - inotom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: htmlbeautifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: capybara
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.30'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.30'
97
+ - !ruby/object:Gem::Dependency
98
+ name: aruba
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.5'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.5'
111
+ description: Beautify HTML string
112
+ email:
113
+ - wdf7322@yahoo.co.jp
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".editorconfig"
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - features/beautify.feature
126
+ - features/support/env.rb
127
+ - fixtures/basic-app/config.rb
128
+ - fixtures/basic-app/source/index.html
129
+ - lib/middleman-html-beautify.rb
130
+ - lib/middleman-html-beautify/extension.rb
131
+ - lib/middleman-html-beautify/version.rb
132
+ - middleman-html-beautify.gemspec
133
+ homepage: https://github.com/inotom/middleman-html-beautify
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.3.0
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubygems_version: 3.0.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Beautify HTML string
156
+ test_files:
157
+ - features/beautify.feature
158
+ - features/support/env.rb