Added application inclusion
This commit is contained in:
parent
a7fada480d
commit
4312d31268
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
../../lib
|
|
@ -56,6 +56,20 @@ module Hyde
|
|||
@origin.filter(&block)
|
||||
block
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue