Browse Source

Added application inclusion

master
Yessiest 8 months ago
parent
commit
4312d31268
  1. 10
      examples/plugins/config.ru
  2. 13
      examples/plugins/helloworld.ru
  3. 1
      examples/plugins/lib
  4. 14
      lib/hyde/dsl/methods_path.rb

10
examples/plugins/config.ru

@ -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

13
examples/plugins/helloworld.ru

@ -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

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

14
lib/hyde/dsl/methods_path.rb

@ -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…
Cancel
Save