rack-capture 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +18 -0
- data/.rubocop.yml +12 -0
- data/CHANGELOG.md +60 -0
- data/Gemfile +7 -3
- data/Gemfile.lock +24 -1
- data/README.md +13 -0
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/rack/capture.rb +23 -17
- data/lib/rack/capture/version.rb +3 -1
- data/rack-capture.gemspec +5 -2
- metadata +7 -4
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f79f70c288700c5f342644d33ea160284c03f736bcf7087ed283040b9c2e7ba
|
4
|
+
data.tar.gz: 491769ee97aa6a55ded4ddb4db0b6c57625806bf4f4f7af9b3773e6e8e738894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77ed9519baed02126f4bf1075c482ae3915e24042844eb6b7c4157aa809cef3021887c0fa5873c29f1b5b2728cd6a450aa4a0a460ec45ef840b52177eb28a2c8
|
7
|
+
data.tar.gz: 506a67af2aeeebb56e2a8e0abb079b4a8dae933988eb422cc6b3af6347ca3c43aa98d4d86290222a2785bbe148db660844b9581f6932b691ea91e3f786489fd5
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
runs-on: ubuntu-18.04
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: '2.7.2'
|
16
|
+
- run: bundle install --jobs=$(($(nproc) - 1)) --retry=3
|
17
|
+
- run: bundle exec rubocop --color --parallel
|
18
|
+
- run: bundle exec rspec --force-color
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## Unreleased
|
9
|
+
|
10
|
+
## 0.4.0 - 2020-11-06
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Add `:output_directory_path` option.
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- Change default output path from `"dist"` to `"output"`.
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
|
22
|
+
- Fix output file name on GET /script_name/.
|
23
|
+
|
24
|
+
## 0.3.0 - 2020-11-06
|
25
|
+
|
26
|
+
### Added
|
27
|
+
|
28
|
+
- Add `:script_name` option.
|
29
|
+
|
30
|
+
### Changed
|
31
|
+
|
32
|
+
- Change least require ruby version from 2.4.0 to 2.5.0.
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
- Fix frozen bug when a frozen body is passsed.
|
37
|
+
|
38
|
+
## 0.2.0 - 2020-11-06
|
39
|
+
|
40
|
+
### Changed
|
41
|
+
|
42
|
+
- Change least require ruby version from 2.3.0 to 2.4.0.
|
43
|
+
|
44
|
+
## 0.1.2 - 2020-10-28
|
45
|
+
|
46
|
+
### Fixed
|
47
|
+
|
48
|
+
- Fix wrong module name.
|
49
|
+
|
50
|
+
## 0.1.1 - 2020-10-28
|
51
|
+
|
52
|
+
### Added
|
53
|
+
|
54
|
+
- Add Rack::Capture.call.
|
55
|
+
|
56
|
+
## 0.1.0 - 2020-10-28
|
57
|
+
|
58
|
+
### Added
|
59
|
+
|
60
|
+
- Add Rack::Capture.
|
data/Gemfile
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in rack-capture.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
gem
|
7
|
-
gem
|
8
|
+
gem 'fakefs'
|
9
|
+
gem 'rake', '~> 12.0'
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
gem 'rubocop'
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-capture (0.
|
4
|
+
rack-capture (0.4.0)
|
5
5
|
rack
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
ast (2.4.1)
|
10
11
|
diff-lcs (1.4.4)
|
12
|
+
fakefs (1.2.2)
|
13
|
+
parallel (1.19.2)
|
14
|
+
parser (2.7.2.0)
|
15
|
+
ast (~> 2.4.1)
|
11
16
|
rack (2.2.3)
|
17
|
+
rainbow (3.0.0)
|
12
18
|
rake (12.3.3)
|
19
|
+
regexp_parser (1.8.2)
|
20
|
+
rexml (3.2.4)
|
13
21
|
rspec (3.9.0)
|
14
22
|
rspec-core (~> 3.9.0)
|
15
23
|
rspec-expectations (~> 3.9.0)
|
@@ -23,14 +31,29 @@ GEM
|
|
23
31
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
32
|
rspec-support (~> 3.9.0)
|
25
33
|
rspec-support (3.9.4)
|
34
|
+
rubocop (1.2.0)
|
35
|
+
parallel (~> 1.10)
|
36
|
+
parser (>= 2.7.1.5)
|
37
|
+
rainbow (>= 2.2.2, < 4.0)
|
38
|
+
regexp_parser (>= 1.8)
|
39
|
+
rexml
|
40
|
+
rubocop-ast (>= 1.0.1)
|
41
|
+
ruby-progressbar (~> 1.7)
|
42
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
43
|
+
rubocop-ast (1.1.1)
|
44
|
+
parser (>= 2.7.1.5)
|
45
|
+
ruby-progressbar (1.10.1)
|
46
|
+
unicode-display_width (1.7.0)
|
26
47
|
|
27
48
|
PLATFORMS
|
28
49
|
ruby
|
29
50
|
|
30
51
|
DEPENDENCIES
|
52
|
+
fakefs
|
31
53
|
rack-capture!
|
32
54
|
rake (~> 12.0)
|
33
55
|
rspec (~> 3.0)
|
56
|
+
rubocop
|
34
57
|
|
35
58
|
BUNDLED WITH
|
36
59
|
2.1.4
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Rack::Capture
|
2
2
|
|
3
|
+
[![](https://badge.fury.io/rb/rack-capture.svg)](https://rubygems.org/gems/rack-capture)
|
4
|
+
[![test](https://github.com/r7kamura/rack-capture/workflows/test/badge.svg)](https://github.com/r7kamura/rack-capture/actions?query=workflow%3Atest)
|
5
|
+
|
3
6
|
Generate static files from Rack application and URLs.
|
4
7
|
|
5
8
|
## Installation
|
@@ -23,6 +26,8 @@ Or install it yourself as:
|
|
23
26
|
Call `Rack::Capture.call` to generate static file.
|
24
27
|
|
25
28
|
```ruby
|
29
|
+
require 'rack/capture'
|
30
|
+
|
26
31
|
%w[
|
27
32
|
http://example.com/
|
28
33
|
http://example.com/articles
|
@@ -36,8 +41,16 @@ Call `Rack::Capture.call` to generate static file.
|
|
36
41
|
app: my_rack_application,
|
37
42
|
url: url
|
38
43
|
)
|
44
|
+
end
|
39
45
|
```
|
40
46
|
|
47
|
+
### Arguments
|
48
|
+
|
49
|
+
- `:app` - Rack application to be used for rendering response
|
50
|
+
- `:url` - URL
|
51
|
+
- `:output_directory_path` - Where to output files (default: `"output"`)
|
52
|
+
- `:script_name` - Rack SCRIPT_NAME, commonly used for GitHub Pages project sites (default: `""`)
|
53
|
+
|
41
54
|
## Development
|
42
55
|
|
43
56
|
### Setup
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'rack/capture'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "rack/capture"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/lib/rack/capture.rb
CHANGED
@@ -1,27 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
require 'rack'
|
3
5
|
require 'rack/capture/version'
|
4
6
|
|
5
|
-
module
|
7
|
+
module Rack
|
6
8
|
class Capture
|
7
9
|
class << self
|
8
|
-
|
9
|
-
|
10
|
-
def call(
|
11
|
-
app:,
|
12
|
-
url:
|
13
|
-
)
|
14
|
-
new(app: app, url: url).call
|
10
|
+
def call(**args)
|
11
|
+
new(**args).call
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
18
15
|
# @param [#call] app Rack application.
|
16
|
+
# @param [String] output_directory_path
|
17
|
+
# @param [String] script_name
|
19
18
|
# @param [String] url
|
20
19
|
def initialize(
|
21
20
|
app:,
|
22
|
-
url
|
21
|
+
url:,
|
22
|
+
output_directory_path: 'output',
|
23
|
+
script_name: ''
|
23
24
|
)
|
24
25
|
@app = app
|
26
|
+
@output_directory_path = output_directory_path
|
27
|
+
@script_name = script_name
|
25
28
|
@url = url
|
26
29
|
end
|
27
30
|
|
@@ -31,7 +34,7 @@ module R7k
|
|
31
34
|
destination.parent.mkpath
|
32
35
|
content = ''
|
33
36
|
response.body.each do |element|
|
34
|
-
content
|
37
|
+
content += element
|
35
38
|
end
|
36
39
|
destination.write(content)
|
37
40
|
end
|
@@ -40,11 +43,9 @@ module R7k
|
|
40
43
|
|
41
44
|
# @param [Rack::Response] response
|
42
45
|
def calculate_destination(response:)
|
43
|
-
destination = ::Pathname.new("
|
46
|
+
destination = ::Pathname.new("#{@output_directory_path}#{path_info}")
|
44
47
|
if response.content_type&.include?('text/html')
|
45
|
-
if
|
46
|
-
destination += 'index'
|
47
|
-
end
|
48
|
+
destination += 'index' if path_info == '/'
|
48
49
|
destination = destination.sub_ext('.html')
|
49
50
|
end
|
50
51
|
destination
|
@@ -56,16 +57,21 @@ module R7k
|
|
56
57
|
::Rack::Response.new(body, status, headers)
|
57
58
|
end
|
58
59
|
|
60
|
+
# @return [String]
|
61
|
+
def path_info
|
62
|
+
uri.path.delete_prefix(@script_name)
|
63
|
+
end
|
64
|
+
|
59
65
|
# @return [Hash]
|
60
66
|
def rack_env
|
61
67
|
{
|
62
68
|
'HTTP_HOST' => @host,
|
63
|
-
'PATH_INFO' =>
|
69
|
+
'PATH_INFO' => path_info,
|
64
70
|
'QUERY_STRING' => uri.query || '',
|
65
71
|
'rack.url_scheme' => rack_url_scheme,
|
66
72
|
'REQUEST_METHOD' => 'GET',
|
67
|
-
'SCRIPT_NAME' =>
|
68
|
-
'SERVER_NAME' => uri.host
|
73
|
+
'SCRIPT_NAME' => @script_name,
|
74
|
+
'SERVER_NAME' => uri.host
|
69
75
|
}
|
70
76
|
end
|
71
77
|
|
data/lib/rack/capture/version.rb
CHANGED
data/rack-capture.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/rack/capture/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
@@ -9,12 +11,13 @@ Gem::Specification.new do |spec|
|
|
9
11
|
spec.summary = 'Generate static files from Rack application and URLs.'
|
10
12
|
spec.homepage = 'https://github.com/r7kamura/rack-capture'
|
11
13
|
spec.license = 'MIT'
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
13
15
|
|
14
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
15
17
|
spec.metadata['source_code_uri'] = spec.homepage
|
18
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
16
19
|
|
17
|
-
spec.files
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
21
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
22
|
end
|
20
23
|
spec.require_paths = ['lib']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-capture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -31,9 +31,11 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".github/workflows/test.yml"
|
34
35
|
- ".gitignore"
|
35
36
|
- ".rspec"
|
36
|
-
- ".
|
37
|
+
- ".rubocop.yml"
|
38
|
+
- CHANGELOG.md
|
37
39
|
- Gemfile
|
38
40
|
- Gemfile.lock
|
39
41
|
- LICENSE.txt
|
@@ -50,6 +52,7 @@ licenses:
|
|
50
52
|
metadata:
|
51
53
|
homepage_uri: https://github.com/r7kamura/rack-capture
|
52
54
|
source_code_uri: https://github.com/r7kamura/rack-capture
|
55
|
+
changelog_uri: https://github.com/r7kamura/rack-capture/blob/master/CHANGELOG.md
|
53
56
|
post_install_message:
|
54
57
|
rdoc_options: []
|
55
58
|
require_paths:
|
@@ -58,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
61
|
requirements:
|
59
62
|
- - ">="
|
60
63
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
64
|
+
version: 2.5.0
|
62
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
66
|
requirements:
|
64
67
|
- - ">="
|