rails-static-router 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed5f5ce3ad32c88587aeb6fcbc59cf2154be0169
4
+ data.tar.gz: d640729f05619c6caca6928498a76c7c350297bc
5
+ SHA512:
6
+ metadata.gz: 6076b9cdbe743910d5cdc04bba8e2495faecf3abb374435b6ac0ff0ef5e1566529d1b9ccca98d67ad1d1ef3c742a010d821a20a365cd16550d440debf2ece96d
7
+ data.tar.gz: 49e69a8eb45e2e32f96d994a0f83ed75edae853c67971516be71b65f3dd76af26de76018d3a2e294c9ea590da4b3897b4d77ebf1dd345058ac10a1fec8853d87
@@ -0,0 +1,15 @@
1
+ # This file is for unifying the coding style for different editors and IDEs
2
+ # editorconfig.org
3
+
4
+ root = true
5
+
6
+ [*]
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ [*.md]
15
+ trim_trailing_whitespace = false
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ *~
3
+ .bundle
4
+ .rvmrc
5
+ .yardoc
6
+ Gemfile.lock
7
+ Gemfile.*.lock
8
+ coverage/*
9
+ doc/*
10
+ log/*
11
+ measurement/*
12
+ pkg/*
13
+ spec/examples.txt
14
+ spec/reports/*
15
+ test/coverage
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --order random
3
+ --require spec_helper
4
+ --format documentation --color
5
+ --format html --out spec/reports/rspec_results.html
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ sudo: false
3
+
4
+ matrix:
5
+ include:
6
+ - gemfile: gemfiles/rails41.gemfile
7
+ rvm: 2.3.7
8
+ - gemfile: gemfiles/rails42.gemfile
9
+ rvm: 2.3.7
10
+ - gemfile: gemfiles/rails50.gemfile
11
+ rvm: 2.4.4
12
+ - gemfile: gemfiles/rails51.gemfile
13
+ rvm: 2.4.4
@@ -0,0 +1,27 @@
1
+ appraise 'rails41' do
2
+ gem 'rails', '~> 4.1.0'
3
+ gem 'sqlite3'
4
+
5
+ gem 'rspec-rails'
6
+ end
7
+
8
+ appraise 'rails42' do
9
+ gem 'rails', '~> 4.2.0'
10
+ gem 'sqlite3'
11
+
12
+ gem 'rspec-rails'
13
+ end
14
+
15
+ appraise 'rails50' do
16
+ gem 'rails', '~> 5.0.0'
17
+ gem 'sqlite3'
18
+
19
+ gem 'rspec-rails'
20
+ end
21
+
22
+ appraise 'rails51' do
23
+ gem 'rails', '~> 5.1.0'
24
+ gem 'sqlite3'
25
+
26
+ gem 'rspec-rails'
27
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Eliot Sykes
4
+ Copyright (c) 2018 Muhammad Mufid Afif
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+
@@ -0,0 +1,104 @@
1
+ # Rails Static Router [![Build Status](https://travis-ci.org/mufid/rails-static-router.svg?branch=master)](https://travis-ci.org/mufid/rails-static-router)
2
+
3
+ Enjoy static routes in your Rails `config/routes.rb`.
4
+
5
+ <!-- MarkdownTOC depth=0 autolink=true bracket=round -->
6
+
7
+ - [Installation](#installation)
8
+ - [Example use](#example-use)
9
+ - [Why?](#why)
10
+ - [TODO](#todo)
11
+ - [Contributors](#contributors)
12
+
13
+ <!-- /MarkdownTOC -->
14
+
15
+ ## Installation
16
+
17
+ 1. Put `gem 'rails-static-router'` in your `Gemfile`
18
+ 2. Restart app
19
+
20
+ ## Example use
21
+
22
+ ```ruby
23
+ Rails.application.routes.draw do
24
+ ...
25
+ # This route will serve public/index.html at the /login URL path, and have
26
+ # URL helper named `login_path`:
27
+ get "/login", to: static("index.html")
28
+
29
+ # This route will serve public/index.html at the /register URL path, and
30
+ # have URL helper named `new_user_registration_path`:
31
+ get "/register", to: static("index.html"), as: :new_user_registration
32
+ ...
33
+ end
34
+ ```
35
+
36
+ `bin/rake routes` output for the above routes:
37
+
38
+ ```
39
+ Prefix Verb URI Pattern Controller#Action
40
+ login GET /login(.:format) static('index.html')
41
+ new_user_registration GET /register(.:format) static('index.html')
42
+ ```
43
+
44
+ ## Compatibility
45
+
46
+ This gem is compatible with Rails 4.1+.
47
+
48
+ ## Why?
49
+
50
+ This introduces a `static(path_to_file)` helper method to route to static files
51
+ from within `routes.rb`. It is inspired by Rails' existing `redirect(...)` method.
52
+
53
+ Some benefits of this technique over alternatives (such as rack-rewrite,
54
+ nginx/httpd-configured rewrites):
55
+
56
+ - Named URL helper method for static file available throughout app, for
57
+ example in mail templates, view templates, and tests.
58
+
59
+ - Route discoverable via `bin/rake routes` and Routing Error page in development.
60
+
61
+ - Takes advantage of ActionDispatch's built-in gzip handling. Controller action
62
+ based solutions for rendering static files tend to not use this.
63
+
64
+ - Handy for Single Page Apps that serve the same static HTML file for multiple
65
+ paths, as is often the case with Ember & Angular apps.
66
+
67
+ - Heroku-like production environments work with this that do use the Rails app
68
+ to serve static files.
69
+
70
+ - Leaves door open for nginx, Apache, Varnish and friends to serve the static
71
+ files directly for improved performance in production environments via symlinks
72
+ and/or other artifacts generated at deploy time.
73
+
74
+ ## Contributors
75
+
76
+ - Eliot Sykes https://eliotsykes.com/
77
+ - Muhammad Mufid Afif https://mufid.github.io
78
+ - Your name here! Contributions are welcome and easy. Fork the GitHub repo, make your changes, then submit your pull request. Don't hesitate to ask if you'd like some help.
79
+
80
+ ## Contributing
81
+
82
+ We are using Appraisals to test against multiple Rails version. To set it
83
+ up for the first time, please run:
84
+
85
+ bundle install
86
+ bundle exec appraisal install
87
+
88
+ After Appraisal installed, use this command to run the test:
89
+
90
+ bundle exec appraisal rake test
91
+
92
+ To test it agains multiple Ruby version, you may want to use rvm.
93
+ For example:
94
+
95
+ # Test it against all specified Rails version
96
+ # with Ruby version 2.3.7
97
+ rvm install 2.3.7
98
+ rvm use 2.3.7
99
+ bundle exec appraisals rake test
100
+
101
+ # Test it against all specified Rails version
102
+ # with Ruby version 2.4.4
103
+ rvm install 2.4.4
104
+ bundle exec appraisals rake test
@@ -0,0 +1,18 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ # RSpec Rails available via Appraisal
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task test: :spec
9
+ rescue LoadError
10
+ end
11
+
12
+ require 'rubocop/rake_task'
13
+ RuboCop::RakeTask.new
14
+
15
+ require 'reek/rake/task'
16
+ Reek::Rake::Task.new
17
+
18
+ task default: %i[spec]
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ *.gemfile.lock
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.1.0"
6
+ gem "sqlite3"
7
+ gem "rspec-rails"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.0"
6
+ gem "sqlite3"
7
+ gem "rspec-rails"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+ gem "sqlite3"
7
+ gem "rspec-rails"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.1.0"
6
+ gem "sqlite3"
7
+ gem "rspec-rails"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,109 @@
1
+ # Example use:
2
+ #
3
+ # Rails.application.routes.draw do
4
+ # ...
5
+ # # This route will serve public/index.html at the /login URL path, and have
6
+ # # URL helper named `login_path`:
7
+ # get "/login", to: static("index.html")
8
+ #
9
+ # # This route will serve public/index.html at the /register URL path, and
10
+ # # have URL helper named `new_user_registration_path`:
11
+ # get "/register", to: static("index.html"), as: :new_user_registration
12
+ # ...
13
+ # end
14
+ #
15
+ # `bin/rake routes` output for the above routes:
16
+ #
17
+ # Prefix Verb URI Pattern Controller#Action
18
+ # login GET /login(.:format) static('index.html')
19
+ # new_user_registration GET /register(.:format) static('index.html')
20
+ #
21
+ #
22
+ # Why?
23
+ #
24
+ # static(path_to_file) helper method used to route to static files
25
+ # from within routes.rb. Inspired by Rails' existing redirect(...) method.
26
+ #
27
+ # Some benefits of this technique over alternatives (such as rack-rewrite,
28
+ # nginx/httpd-configured rewrites):
29
+ #
30
+ # - Named URL helper method for static file available throughout app, for
31
+ # example in mail templates, view templates, and tests.
32
+ #
33
+ # - Route discoverable via `bin/rake routes` and Routing Error page in development.
34
+ #
35
+ # - Takes advantage of ActionDispatch's built-in gzip handling. Controller action
36
+ # based solutions for rendering static files tend to not use this.
37
+ #
38
+ # - Handy for Single Page Apps that serve the same static HTML file for multiple
39
+ # paths, as is often the case with Ember & Angular apps.
40
+ #
41
+ # - Heroku-like production environments work with this that do use the Rails app
42
+ # to serve static files.
43
+ #
44
+ # - Leaves door open for nginx, Apache, Varnish and friends to serve the static
45
+ # files directly for improved performance in production environments via symlinks
46
+ # and/or other artifacts generated at deploy time.
47
+ #
48
+
49
+ # Required if serve_static_assets set to false
50
+ require 'action_dispatch/middleware/static'
51
+
52
+ module ActionDispatch
53
+ module Routing
54
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('4.2')
55
+ class StaticResponder < Endpoint; end
56
+ else
57
+ class StaticResponder; end
58
+ end
59
+
60
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('5.0')
61
+ class StaticResponder
62
+ def file_handler
63
+ @file_handler ||= ::ActionDispatch::FileHandler.new(
64
+ Rails.configuration.paths["public"].first
65
+ )
66
+ end
67
+ end
68
+ else
69
+ class StaticResponder
70
+ def file_handler
71
+ @file_handler ||= ::ActionDispatch::FileHandler.new(
72
+ Rails.configuration.paths["public"].first,
73
+ Rails.configuration.static_cache_control
74
+ )
75
+ end
76
+ end
77
+ end
78
+
79
+ class StaticResponder
80
+
81
+ attr_accessor :path
82
+
83
+ def initialize(path)
84
+ self.path = path
85
+ self.trigger_file_handler_initialization
86
+ end
87
+
88
+ def trigger_file_handler_initialization
89
+ file_handler
90
+ end
91
+
92
+ def call(env)
93
+ env["PATH_INFO"] = @file_handler.match?(path)
94
+ @file_handler.call(env)
95
+ end
96
+
97
+ def inspect
98
+ "static('#{path}')"
99
+ end
100
+
101
+ end
102
+
103
+ class Mapper
104
+ def static(path)
105
+ StaticResponder.new(path)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,2 @@
1
+ require 'rails_static_router/railtie'
2
+ require 'rails_static_router/version'
@@ -0,0 +1,7 @@
1
+ module RailsStaticRouter
2
+ class Railtie < Rails::Railtie
3
+ initializer 'rails_static_router.railtie' do
4
+ require 'action_dispatch/routing/static_responder'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module RailsStaticRouter
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path('./lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rails_static_router/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.authors = ['Eliot Sykes', 'Muhammad Mufid Afif']
7
+ spec.description = 'Enjoy static routes in your Rails `config/routes.rb`'
8
+ spec.email = ['mufidafif@icloud.com']
9
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?('spec/') }
10
+ spec.homepage = 'https://github.com/mufid/rails-static-router'
11
+ spec.licenses = %w[MIT]
12
+ spec.name = 'rails-static-router'
13
+ spec.require_paths = %w[lib]
14
+
15
+ spec.summary = spec.description
16
+ spec.version = RailsStaticRouter::VERSION
17
+
18
+ # Test and build tools
19
+ # The test shouldn't broken by the incompatible RSpec version.
20
+ # Thus, we need to lock the version.
21
+ spec.add_development_dependency "appraisal"
22
+ spec.add_development_dependency 'bundler', '~> 1.16'
23
+ spec.add_development_dependency 'rake', '~> 12.0'
24
+ spec.add_development_dependency 'simplecov'
25
+ spec.add_development_dependency 'simplecov-html'
26
+
27
+ # Docs, debugger, linter.
28
+ # We don't need to specify the lock version for these documentation
29
+ # Please do adjust our program so that it will always compatible
30
+ # with the latest version of these dependencies
31
+ spec.add_development_dependency 'maruku'
32
+ spec.add_development_dependency 'pry'
33
+ spec.add_development_dependency 'reek'
34
+ spec.add_development_dependency 'rubocop'
35
+ spec.add_development_dependency 'yard'
36
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-static-router
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eliot Sykes
8
+ - Muhammad Mufid Afif
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-04-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: appraisal
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.16'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.16'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '12.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '12.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: simplecov
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov-html
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: maruku
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: reek
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rubocop
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: yard
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ description: Enjoy static routes in your Rails `config/routes.rb`
155
+ email:
156
+ - mufidafif@icloud.com
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".editorconfig"
162
+ - ".gitignore"
163
+ - ".rspec"
164
+ - ".travis.yml"
165
+ - Appraisals
166
+ - Gemfile
167
+ - LICENSE
168
+ - README.md
169
+ - Rakefile
170
+ - gemfiles/.gitignore
171
+ - gemfiles/rails41.gemfile
172
+ - gemfiles/rails42.gemfile
173
+ - gemfiles/rails50.gemfile
174
+ - gemfiles/rails51.gemfile
175
+ - lib/action_dispatch/routing/static_responder.rb
176
+ - lib/rails-static-router.rb
177
+ - lib/rails_static_router/railtie.rb
178
+ - lib/rails_static_router/version.rb
179
+ - rails-static-router.gemspec
180
+ homepage: https://github.com/mufid/rails-static-router
181
+ licenses:
182
+ - MIT
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ requirements: []
199
+ rubyforge_project:
200
+ rubygems_version: 2.6.14
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: Enjoy static routes in your Rails `config/routes.rb`
204
+ test_files: []