Added application inclusion

This commit is contained in:
Yessiest 2023-09-14 12:56:29 +04:00
parent a7fada480d
commit 4312d31268
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
require 'hyde'
app = Hyde::Server.new do
plugin "helloworld.ru"
end
run app

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
require 'hyde'
app = Hyde::Server.new do
get "/hello" do
header "content-type", "text/plain"
"Hello World!"
end
end
run app

1
examples/plugins/lib Symbolic link
View File

@ -0,0 +1 @@
../../lib

View File

@ -56,6 +56,20 @@ module Hyde
@origin.filter(&block) @origin.filter(&block)
block block
end end
# Include an application as a child of path.
# @param filename [String]
def plugin(filename)
self.define_singleton_method(:run) do |object|
unless object.is_a? Hyde::Node
raise StandardError, "not a node instance or subclass instance"
end
object
end
@origin.children.append(self.instance_eval(File.read(filename)))
self.singleton_class.undef_method :run
end
end end
end end
end end