-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Pipe] Add support client reloading (#457)
* Add parens Add support for client reloading - Add Hot reloading for CSS - Add reloading for files on public folder - Allow reloading browser after server reload Add development restriction Add watcher dependency Add reload spec Add missing dependency Change spec path set host binding to 0.0.0.0 (#459) Update database.cr Update logger.cr Remove duplicated dependency Add indenting space Using Amber Loggger Remove watcher require * Fixes failing spec
- Loading branch information
1 parent
11ec348
commit 3af084d
Showing
16 changed files
with
259 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "../../../../spec_helper" | ||
|
||
class FakeEnvironment < Amber::Environment::Env | ||
def development? | ||
true | ||
end | ||
end | ||
|
||
module Amber | ||
module Pipe | ||
describe Reload do | ||
headers = HTTP::Headers.new | ||
headers["Accept"] = "text/html" | ||
request = HTTP::Request.new("GET", "/reload", headers) | ||
|
||
Amber::Server.router.draw :web do | ||
get "/reload", HelloController, :index | ||
end | ||
|
||
context "when environment is in development mode" do | ||
pipeline = Pipeline.new | ||
pipeline.build :web do | ||
plug Amber::Pipe::Reload.new(FakeEnvironment.new) | ||
end | ||
pipeline.prepare_pipelines | ||
|
||
it "contains injected code in response.body" do | ||
response = create_request_and_return_io(pipeline, request) | ||
|
||
response.body.should contain "Code injected by Amber Framework" | ||
end | ||
end | ||
|
||
context "when environment is NOT in development mode" do | ||
pipeline = Pipeline.new | ||
pipeline.build :web do | ||
plug Amber::Pipe::Reload.new | ||
end | ||
pipeline.prepare_pipelines | ||
|
||
it "does not have injected reload code in response.body" do | ||
response = create_request_and_return_io(pipeline, request) | ||
|
||
response.body.should_not contain "Code injected by Amber Framework" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "../../support/client_reload" | ||
|
||
module Amber | ||
module Pipe | ||
# Reload clients browsers using `ClientReload`. | ||
# | ||
# NOTE: Amber::Pipe::Reload is intended for use in a development environment. | ||
# ``` | ||
# pipeline :web do | ||
# plug Amber::Pipe::Reload.new | ||
# end | ||
# ``` | ||
class Reload < Base | ||
def initialize(@env : Amber::Environment::Env = Amber.env) | ||
Support::ClientReload.new | ||
end | ||
|
||
def call(context : HTTP::Server::Context) | ||
if @env.development? && context.format == "html" | ||
context.response << Support::ClientReload::INJECTED_CODE | ||
end | ||
call_next(context) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.