middleman-minify-html 3.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ Gemfile.lock
3
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ script: "bundle exec rake test"
6
+
7
+ branches:
8
+ only:
9
+ - master
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+
3
+ # git "git://github.com/middleman/middleman.git" do
4
+ # # gem "middleman"
5
+ # gem "middleman-core"
6
+ # # gem "middleman-more"
7
+ # end
8
+
9
+ # Specify your gem's dependencies in middleman-blog.gemspec
10
+ gemspec
11
+
12
+ group :development do
13
+ gem "cucumber", "~> 1.1.0"
14
+ gem "fivemat"
15
+ gem "aruba", "~> 0.4.11"
16
+ gem "rake", "~> 0.9.2"
17
+ gem "rspec", "~> 2.7"
18
+ # gem "rdoc", "~> 3.9"
19
+ # gem "yard"
20
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Thomas Reynolds
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # middleman-minify-html
2
+
3
+ # Install
4
+
5
+ ```
6
+ gem install middleman-minify-html
7
+ ```
8
+
9
+ If you already have a Middleman project:
10
+ Add `middleman-middleman-minify-html` to your `Gemfile`, and open your `config.rb` and add:
11
+
12
+ ```
13
+ activate :minify_html
14
+ ```
15
+
16
+ # Community
17
+
18
+ The official community forum is available at:
19
+
20
+ http://forum.middlemanapp.com/
21
+
22
+ # Bug Reports
23
+
24
+ GitHub Issues are used for managing bug reports and feature requests. If you run into issues, please search the issues and submit new problems:
25
+
26
+ https://github.com/middleman/middleman-minify-html/issues
27
+
28
+ The best way to get quick responses to your issues and swift fixes to your bugs is to submit detailed bug reports, include test cases and respond to developer questions in a timely manner. Even better, if you know Ruby, you can submit Pull Requests containing Cucumber Features which describe how your feature should work or exploit the bug you are submitting.
29
+
30
+ # Build & Dependency Status
31
+
32
+ [![Build Status](http://travis-ci.org/middleman/middleman-minify-html.png)](http://travis-ci.org/middleman/middleman-minify-html)
33
+
34
+ # How to Run Cucumber Tests
35
+
36
+ 1. Checkout Repository: `git clone https://github.com/middleman/middleman-minify-html.git`
37
+ 2. Install Bundler: `gem install bundler`
38
+ 3. Run `bundle install` inside the project root to install the gem dependencies.
39
+ 4. Run test cases: `bundle exec rake test`
40
+
41
+ # Donate
42
+
43
+ [![Click here to lend your support to Middleman](https://www.pledgie.com/campaigns/15807.png)](http://www.pledgie.com/campaigns/15807)
44
+
45
+ # License
46
+
47
+ Copyright (c) 2012 Thomas Reynolds. MIT Licensed, see [LICENSE] for details.
48
+
49
+ [LICENSE]: https://github.com/middleman/middleman-blog/blob/master/LICENSE
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task :test => ["cucumber"]
13
+
14
+ desc "Build HTML documentation"
15
+ task :doc do
16
+ sh 'bundle exec yard'
17
+ end
@@ -0,0 +1,32 @@
1
+ Feature: Minify HTML
2
+
3
+ Scenario: Preview HTML with minify_html disabled
4
+ Given "minify_html" feature is "disabled"
5
+ And the Server is running at "basic-app"
6
+ When I go to "/index.html"
7
+ Then I should see "13" lines
8
+
9
+ Scenario: Preview HTML with minify_html enabled
10
+ Given "minify_html" feature is "enabled"
11
+ And the Server is running at "basic-app"
12
+ When I go to "/index.html"
13
+ Then I should see "1" lines
14
+
15
+ Scenario: Build HTML with minify_html disabled
16
+ Given a fixture app "basic-app"
17
+ And a file named "config.rb" with:
18
+ """
19
+ """
20
+ And a successfully built app at "basic-app"
21
+ When I cd to "build"
22
+ Then the file "index.html" should contain " <h1>"
23
+
24
+ Scenario: Build HTML with minify_html enabled
25
+ Given a fixture app "basic-app"
26
+ And a file named "config.rb" with:
27
+ """
28
+ activate :minify_html
29
+ """
30
+ And a successfully built app at "basic-app"
31
+ When I cd to "build"
32
+ Then the file "index.html" should contain "<h1> Multi Line </h1> <h2> Broken Up </h2>"
@@ -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-minify-html')
File without changes
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Hello World</title>
5
+ </head>
6
+ <body>
7
+ <h1>
8
+ Multi
9
+ Line
10
+ </h1>
11
+ <h2> Broken Up </h2>
12
+ </body>
13
+ </html>
@@ -0,0 +1,6 @@
1
+ require "middleman-core"
2
+
3
+ ::Middleman::Extensions.register(:minify_html, ">= 3.0.0.beta.2") do
4
+ require "middleman-minify-html/extension"
5
+ ::Middleman::MinifyHtml
6
+ end
@@ -0,0 +1,68 @@
1
+ module Middleman
2
+ module MinifyHtml
3
+ class << self
4
+ def registered(app)
5
+ app.set :html_compressor, false
6
+
7
+ app.after_configuration do
8
+ unless respond_to?(:html_compressor) && html_compressor
9
+ require 'html_compressor'
10
+ set :html_compressor, ::HtmlCompressor::HtmlCompressor.new
11
+ end
12
+
13
+ # Setup Rack to watch for inline JS
14
+ use MinifyHtmlRack, :compressor => html_compressor
15
+ end
16
+ end
17
+ alias :included :registered
18
+ end
19
+
20
+ class MinifyHtmlRack
21
+
22
+ # Init
23
+ # @param [Class] app
24
+ # @param [Hash] options
25
+ def initialize(app, options={})
26
+ @app = app
27
+ @compressor = options[:compressor]
28
+ end
29
+
30
+ # Rack interface
31
+ # @param [Rack::Environmemt] env
32
+ # @return [Array]
33
+ def call(env)
34
+ status, headers, response = @app.call(env)
35
+
36
+ path = env["PATH_INFO"]
37
+
38
+ if path.end_with?('.html')
39
+ uncompressed_source = extract_response_text(response)
40
+ minified_html = @compressor.compress(uncompressed_source)
41
+
42
+ headers["Content-Length"] = ::Rack::Utils.bytesize(minified_html).to_s
43
+ response = [minified_html]
44
+ end
45
+
46
+ [status, headers, response]
47
+ end
48
+
49
+ private
50
+
51
+ def extract_response_text(response)
52
+ case(response)
53
+ when String
54
+ response
55
+ when Array
56
+ response.join
57
+ when Rack::Response
58
+ response.body.join
59
+ when Rack::File
60
+ File.read(response.path)
61
+ else
62
+ response.to_s
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module MinifyHtml
3
+ VERSION = "3.0.0.beta.2"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require "middleman-minify-html"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "middleman-minify-html/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "middleman-minify-html"
7
+ s.version = Middleman::MinifyHtml::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Thomas Reynolds"]
10
+ s.email = ["me@tdreyno.com"]
11
+ s.homepage = "https://github.com/middleman/middleman-minify-html"
12
+ s.summary = %q{A html whitespace minifier for Middleman}
13
+ s.description = %q{A html whitespace minifier for Middleman}
14
+
15
+ s.rubyforge_project = "middleman-minify-html"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency("middleman-core", [">= 3.0.0.beta.2"])
23
+ s.add_runtime_dependency("html_compressor")
24
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-minify-html
3
+ version: !ruby/object:Gem::Version
4
+ hash: 62196423
5
+ prerelease: 6
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 0
10
+ - beta
11
+ - 2
12
+ version: 3.0.0.beta.2
13
+ platform: ruby
14
+ authors:
15
+ - Thomas Reynolds
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2012-04-23 00:00:00 Z
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ type: :runtime
24
+ name: middleman-core
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 62196423
31
+ segments:
32
+ - 3
33
+ - 0
34
+ - 0
35
+ - beta
36
+ - 2
37
+ version: 3.0.0.beta.2
38
+ prerelease: false
39
+ requirement: *id001
40
+ - !ruby/object:Gem::Dependency
41
+ type: :runtime
42
+ name: html_compressor
43
+ version_requirements: &id002 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ prerelease: false
53
+ requirement: *id002
54
+ description: A html whitespace minifier for Middleman
55
+ email:
56
+ - me@tdreyno.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files: []
62
+
63
+ files:
64
+ - .gitignore
65
+ - .travis.yml
66
+ - Gemfile
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - features/preview.feature
71
+ - features/support/env.rb
72
+ - fixtures/basic-app/config.rb
73
+ - fixtures/basic-app/source/index.html
74
+ - lib/middleman-minify-html.rb
75
+ - lib/middleman-minify-html/extension.rb
76
+ - lib/middleman-minify-html/version.rb
77
+ - lib/middleman_extension.rb
78
+ - middleman-minify-html.gemspec
79
+ homepage: https://github.com/middleman/middleman-minify-html
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options: []
84
+
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">"
100
+ - !ruby/object:Gem::Version
101
+ hash: 25
102
+ segments:
103
+ - 1
104
+ - 3
105
+ - 1
106
+ version: 1.3.1
107
+ requirements: []
108
+
109
+ rubyforge_project: middleman-minify-html
110
+ rubygems_version: 1.8.18
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: A html whitespace minifier for Middleman
114
+ test_files:
115
+ - features/preview.feature
116
+ - features/support/env.rb