rack-capture 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca614d90af90f94f06ccb59fc0a2a5ad476e70170bbc06bda2dbce601f9037c1
4
+ data.tar.gz: 79ed210bc2976e4e38952dd237e174c4a4057a03105903ad8fc245c09a70dd80
5
+ SHA512:
6
+ metadata.gz: 6cd08848f826f9f44c5144edcf21571166a7cf579565eabf1963309925690f7bf95d15b5192d8baf5957297103ec652c450bf3d4ebea0ab46c7ad78b7ed223bb
7
+ data.tar.gz: 90de2cc42390fa8783b8dcdabd19f00a561446c6518c012b6cfe9a35cfbdd5a8d2575cdf5afd32ee04623bee758a59814fd6f1980d5243b8a69e438fb9844422
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-capture.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-capture (0.1.0)
5
+ rack
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.4.4)
11
+ rack (2.2.3)
12
+ rake (12.3.3)
13
+ rspec (3.9.0)
14
+ rspec-core (~> 3.9.0)
15
+ rspec-expectations (~> 3.9.0)
16
+ rspec-mocks (~> 3.9.0)
17
+ rspec-core (3.9.3)
18
+ rspec-support (~> 3.9.3)
19
+ rspec-expectations (3.9.3)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.9.0)
22
+ rspec-mocks (3.9.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-support (3.9.4)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ rack-capture!
32
+ rake (~> 12.0)
33
+ rspec (~> 3.0)
34
+
35
+ BUNDLED WITH
36
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Ryo Nakamura
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.
@@ -0,0 +1,61 @@
1
+ # Rack::Capture
2
+
3
+ Generate static files from Rack application and URLs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rack-capture'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rack-capture
20
+
21
+ ## Usage
22
+
23
+ Call `Rack::Capture.call` to generate static file.
24
+
25
+ ```ruby
26
+ %w[
27
+ http://example.com/
28
+ http://example.com/articles
29
+ http://example.com/articles/2020-10-30.html
30
+ http://example.com/articles/2020-10-29.html
31
+ http://example.com/articles/2020-10-28.html
32
+ http://example.com/feed.xml
33
+ http://example.com/sitemap.txt
34
+ ].each do |url|
35
+ Rack::Capture.call(
36
+ app: my_rack_application,
37
+ url: url
38
+ )
39
+ ```
40
+
41
+ ## Development
42
+
43
+ ### Setup
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ ### Local install
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`.
50
+
51
+ ### Release
52
+
53
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/r7kamura/rack-capture.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rack/capture"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,86 @@
1
+ require 'pathname'
2
+ require 'rack'
3
+ require 'rack/capture/version'
4
+
5
+ module R7k
6
+ class Capture
7
+ class << self
8
+ # @param [#call] app Rack application.
9
+ # @param [String] url
10
+ def call(
11
+ app:,
12
+ url:
13
+ )
14
+ new(app: app, url: url).call
15
+ end
16
+ end
17
+
18
+ # @param [#call] app Rack application.
19
+ # @param [String] url
20
+ def initialize(
21
+ app:,
22
+ url:
23
+ )
24
+ @app = app
25
+ @url = url
26
+ end
27
+
28
+ def call
29
+ response = get_response
30
+ destination = calculate_destination(response: response)
31
+ destination.parent.mkpath
32
+ content = ''
33
+ response.body.each do |element|
34
+ content << element
35
+ end
36
+ destination.write(content)
37
+ end
38
+
39
+ private
40
+
41
+ # @param [Rack::Response] response
42
+ def calculate_destination(response:)
43
+ destination = ::Pathname.new("dist#{uri.path}")
44
+ if response.content_type&.include?('text/html')
45
+ if uri.path == '/'
46
+ destination += 'index'
47
+ end
48
+ destination = destination.sub_ext('.html')
49
+ end
50
+ destination
51
+ end
52
+
53
+ # @return [Rack::Response]
54
+ def get_response
55
+ status, headers, body = @app.call(rack_env)
56
+ ::Rack::Response.new(body, status, headers)
57
+ end
58
+
59
+ # @return [Hash]
60
+ def rack_env
61
+ {
62
+ 'HTTP_HOST' => @host,
63
+ 'PATH_INFO' => uri.path,
64
+ 'QUERY_STRING' => uri.query || '',
65
+ 'rack.url_scheme' => rack_url_scheme,
66
+ 'REQUEST_METHOD' => 'GET',
67
+ 'SCRIPT_NAME' => '',
68
+ 'SERVER_NAME' => uri.host,
69
+ }
70
+ end
71
+
72
+ # @return [String]
73
+ def rack_url_scheme
74
+ if uri.scheme == 'https'
75
+ 'https'
76
+ else
77
+ 'http'
78
+ end
79
+ end
80
+
81
+ # @return [URI]
82
+ def uri
83
+ @uri ||= ::URI.parse(@url)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Capture
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'lib/rack/capture/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'rack-capture'
5
+ spec.version = Rack::Capture::VERSION
6
+ spec.authors = ['Ryo Nakamura']
7
+ spec.email = ['r7kamura@gmail.com']
8
+
9
+ spec.summary = 'Generate static files from Rack application and URLs.'
10
+ spec.homepage = 'https://github.com/r7kamura/rack-capture'
11
+ spec.license = 'MIT'
12
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
13
+
14
+ spec.metadata['homepage_uri'] = spec.homepage
15
+ spec.metadata['source_code_uri'] = spec.homepage
16
+
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'rack'
23
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-capture
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - r7kamura@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/rack/capture.rb
45
+ - lib/rack/capture/version.rb
46
+ - rack-capture.gemspec
47
+ homepage: https://github.com/r7kamura/rack-capture
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/r7kamura/rack-capture
52
+ source_code_uri: https://github.com/r7kamura/rack-capture
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.1.2
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Generate static files from Rack application and URLs.
72
+ test_files: []