middleman-scrub 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
+ SHA1:
3
+ metadata.gz: 5739863e0db95214f51e9f36e52e504c73d7122b
4
+ data.tar.gz: 741614d06f80b490f94dad319eec2e8b4f8de57a
5
+ SHA512:
6
+ metadata.gz: 1e00ef50a170a262145a61bebcbb8e280487655d329063adffb888aca50abb2b48a9e8afbbb63020853bffa5743e058e4d612b0be604ed89578a7d5e1f0d35ea
7
+ data.tar.gz: cf8af61d5fb0516658c9f17ecc8e4e1321e70c641ced114eafd5384f11212083ae4ce07931d51cbe10bc65cabd3c7a729a94def199ce94b7e23b26bc5050149d
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ # Ignore bundler lock file
2
+ /Gemfile.lock
3
+
4
+ # Ignore pkg folder
5
+ /pkg
6
+
7
+ /tmp
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ before_script:
5
+ - bundle update
6
+ rvm:
7
+ - 2.4.0
8
+ - 2.3.1
9
+ - 2.2.4
10
+
11
+ branches:
12
+ only:
13
+ - master
14
+
15
+ script: bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # If you do not have OpenSSL installed, update
2
+ # the following line to use "http://" instead
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in middleman-scrub.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2017 Uchio KONDO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # middleman-scrub
2
+
3
+ [![Build Status](https://travis-ci.org/udzura/middleman-scrub.svg?branch=master)](https://travis-ci.org/udzura/middleman-scrub)
4
+
5
+ Scrub the invalid letters which source file contains.
6
+
7
+ ## Usage
8
+
9
+ ```ruby
10
+ activate :scrub
11
+ ```
12
+
13
+ ### Config
14
+
15
+ ```
16
+ activate :scrub,
17
+ scrub_regexp: /[あ-お]/, # To add target letters
18
+ target_filename: /\.html$/, # To specify target files
19
+ verbose: true # Debug
20
+ ```
21
+
22
+ ## License
23
+
24
+ [MIT.](https://udzura.mit-license.org/)
data/Rakefile ADDED
@@ -0,0 +1,14 @@
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'
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task test: ['cucumber']
13
+
14
+ task default: :test
@@ -0,0 +1,11 @@
1
+ Feature: middleman-scrub is activated
2
+
3
+ Scenario: Activate middleman-scrub
4
+ Given a fixture app "empty-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ activate :scrub
8
+ """
9
+ When I run `middleman build --verbose`
10
+ Then the exit status should be 0
11
+ And the output should not contain "Unknown Extension: scrub"
@@ -0,0 +1,37 @@
1
+ Feature: scrub the invalid letters
2
+
3
+ Scenario: ignore files that does not contain invalid letters
4
+ Given a fixture app "sample-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ page '/*.html', layout: false
8
+ activate :scrub
9
+ """
10
+ When I run `middleman build --verbose`
11
+ Then the exit status should be 0
12
+ And the file "build/test001.html" should contain 'OK'
13
+
14
+ Scenario: scrub letters specified in config.rb
15
+ Given a fixture app "sample-app"
16
+ And a file named "config.rb" with:
17
+ """
18
+ page '/*.html', layout: false
19
+ activate :scrub, :scrub_regexp => /[あ-お]/
20
+ """
21
+ When I run `middleman build --verbose`
22
+ Then the exit status should be 0
23
+ And the file "build/test002.html" should contain 'かきくけこ'
24
+ And the file "build/test002.html" should not contain 'あいうえお'
25
+
26
+ Scenario: scrub invalid letters by default
27
+ Given a fixture app "sample-app"
28
+ And a file named "config.rb" with:
29
+ """
30
+ page '/*.html', layout: false
31
+ activate :scrub
32
+ """
33
+ When I run `middleman build --verbose`
34
+ Then the exit status should be 0
35
+ And the file "build/test003.html" should contain 'あいうえお'
36
+ And the file "build/test003.html" should not contain invalid letters
37
+
@@ -0,0 +1,6 @@
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, 'features', 'support', 'extra_step_defs')
5
+
6
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-scrub')
@@ -0,0 +1,13 @@
1
+ unless defined? EXTRA_STEP_DEFINED
2
+
3
+ Then /^the file "([^"]*)" should not contain '([^']*)'$/ do |file, partial_content|
4
+ expect(file).not_to have_file_content(Regexp.new(Regexp.escape(partial_content)), true)
5
+ end
6
+
7
+ Then /^the file "([^"]*)" should not contain invalid letters$/ do |file|
8
+ expect(file).not_to have_file_content(/[\u0000\u0001\u000b]/, true)
9
+ end
10
+
11
+ EXTRA_STEP_DEFINED = 1
12
+
13
+ end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ # OK
2
+
3
+ Example app
@@ -0,0 +1,2 @@
1
+ あいうえお
2
+ かきくけこ
@@ -0,0 +1,2 @@
1
+ <%= "\u0000\u0001\u000b" %>
2
+ あいうえお
@@ -0,0 +1,40 @@
1
+ # Require core library
2
+ require 'middleman-core'
3
+
4
+ # Extension namespace
5
+ class ::Middleman::Scrub < ::Middleman::Extension
6
+ option :scrub_regexp,
7
+ /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]/, 'A regexp to match for scrubbing target chars'
8
+ option :target_filename,
9
+ /\.(html|xml|rss|txt)\z/, 'Target filename convention to be scrubbed'
10
+ option :verbose, false, 'Verbose mode'
11
+
12
+ def initialize(app, options_hash={}, &block)
13
+ super
14
+ end
15
+
16
+ def after_configuration
17
+ debug("Configured. Regexp: #{options.scrub_regexp}")
18
+ end
19
+
20
+ def after_build(builder)
21
+ files = Dir.glob("#{app.config[:build_dir]}/**/*")
22
+ .select{|f| options.target_filename.match(f) }
23
+
24
+ files.each do |f|
25
+ content_orig = File.read(f)
26
+ content = content_orig.gsub(options.scrub_regexp, "")
27
+ if content != content_orig
28
+ File.write(f, content)
29
+ end
30
+ debug("Scrubbed: #{f}")
31
+ end
32
+ end
33
+
34
+ private
35
+ def debug(msg)
36
+ STDERR.puts(msg) if options.verbose
37
+ end
38
+ end
39
+
40
+ require 'middleman-scrub/version'
@@ -0,0 +1,3 @@
1
+ module MiddlemanScrub
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "middleman-core"
2
+
3
+ ::Middleman::Extensions.register :scrub do
4
+ require "middleman-scrub/extension"
5
+ ::Middleman::Scrub
6
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'middleman-scrub/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "middleman-scrub"
7
+ s.version = MiddlemanScrub::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Uchio Kondo"]
10
+ s.email = ["udzura@udzura.jp"]
11
+ s.homepage = "https://github.com/udzura/middleman-scrub"
12
+ s.summary = %q{Scrub the created files by middleman}
13
+ s.description = %q{Scrub the created files by middleman}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # The version of middleman-core your extension depends on
21
+ s.add_runtime_dependency("middleman-core", [">= 4.2.1"])
22
+
23
+ s.add_development_dependency "middleman-cli"
24
+ s.add_development_dependency "bundler", "~> 1.13"
25
+ s.add_development_dependency "rake", "~> 10.0"
26
+ s.add_development_dependency "cucumber", "~> 1.3"
27
+ s.add_development_dependency "capybara"
28
+ s.add_development_dependency "aruba", "~> 0.14"
29
+ s.add_development_dependency "pandoc-ruby"
30
+ s.add_development_dependency "kramdown"
31
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-scrub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Uchio Kondo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-06 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.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: middleman-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.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: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
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.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pandoc-ruby
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: kramdown
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Scrub the created files by middleman
140
+ email:
141
+ - udzura@udzura.jp
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - Gemfile
149
+ - LICENSE
150
+ - README.md
151
+ - Rakefile
152
+ - features/activate.feature
153
+ - features/scrub.feature
154
+ - features/support/env.rb
155
+ - features/support/extra_step_defs.rb
156
+ - fixtures/empty-app/config.rb
157
+ - fixtures/empty-app/source/.gitkeep
158
+ - fixtures/sample-app/config.rb
159
+ - fixtures/sample-app/source/.gitkeep
160
+ - fixtures/sample-app/source/test001.html.md
161
+ - fixtures/sample-app/source/test002.html.md
162
+ - fixtures/sample-app/source/test003.html.md.erb
163
+ - lib/middleman-scrub.rb
164
+ - lib/middleman-scrub/extension.rb
165
+ - lib/middleman-scrub/version.rb
166
+ - middleman-scrub.gemspec
167
+ homepage: https://github.com/udzura/middleman-scrub
168
+ licenses: []
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 2.5.1
187
+ signing_key:
188
+ specification_version: 4
189
+ summary: Scrub the created files by middleman
190
+ test_files:
191
+ - features/activate.feature
192
+ - features/scrub.feature
193
+ - features/support/env.rb
194
+ - features/support/extra_step_defs.rb