From d05faeac399904f303f1a61a28606a32bb0178d4 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Mon, 11 Sep 2023 21:42:19 +0400 Subject: [PATCH] moving files to pc --- lib/hyde/probe.rb | 11 +++++++++++ lib/hyde/probe/binding.rb | 16 ---------------- lib/hyde/probe/handler.rb | 3 --- lib/hyde/probe/http_method.rb | 4 ---- lib/hyde/probe/serve_handler.rb | 3 --- lib/hyde/template.rb | 30 ++++++++++++++++++++++++++++++ 6 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 lib/hyde/probe/binding.rb create mode 100644 lib/hyde/template.rb diff --git a/lib/hyde/probe.rb b/lib/hyde/probe.rb index 9d91bcc..ec13920 100644 --- a/lib/hyde/probe.rb +++ b/lib/hyde/probe.rb @@ -16,6 +16,17 @@ module Hyde autoload :TRACEHandler, "hyde/probe/http_method" autoload :PATCHHandler, "hyde/probe/http_method" autoload :ServeHandler, "hyde/probe/serve_handler" + + # Binding that provides execution context for Probes. + class ProbeBinding + include Hyde::DSL::ProbeMethods + include Hyde::DSL::CommonMethods + + def initialize(origin) + @origin = origin + end + end + # Test probe. Also base for all "reactive" nodes. class Probe < Hyde::Node # @param path [Object] diff --git a/lib/hyde/probe/binding.rb b/lib/hyde/probe/binding.rb deleted file mode 100644 index 1d0fb79..0000000 --- a/lib/hyde/probe/binding.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative "../dsl/probe_methods" -require_relative "../dsl/common_methods" - -module Hyde - # Binding that provides execution context for Probes. - class ProbeBinding - include Hyde::DSL::ProbeMethods - include Hyde::DSL::CommonMethods - - def initialize(origin) - @origin = origin - end - end -end diff --git a/lib/hyde/probe/handler.rb b/lib/hyde/probe/handler.rb index 58142ee..205d905 100644 --- a/lib/hyde/probe/handler.rb +++ b/lib/hyde/probe/handler.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require_relative '../probe' -require_relative 'binding' - module Hyde # Probe that executes a callback on request class Handler < Hyde::Probe diff --git a/lib/hyde/probe/http_method.rb b/lib/hyde/probe/http_method.rb index 0daf5fd..7b4ed4a 100644 --- a/lib/hyde/probe/http_method.rb +++ b/lib/hyde/probe/http_method.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -require_relative '../probe' -require_relative 'binding' -require_relative 'handler' - module Hyde # Probe that executes callback on a GET class GETHandler < Hyde::Handler diff --git a/lib/hyde/probe/serve_handler.rb b/lib/hyde/probe/serve_handler.rb index d6f1c8a..a2b65e6 100644 --- a/lib/hyde/probe/serve_handler.rb +++ b/lib/hyde/probe/serve_handler.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require_relative '../probe' -require_relative 'binding' - module Hyde # Probe that sends files from a location class ServeHandler < Hyde::Probe diff --git a/lib/hyde/template.rb b/lib/hyde/template.rb new file mode 100644 index 0000000..65e9346 --- /dev/null +++ b/lib/hyde/template.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Hyde + # Adapter class for template engines + # @abstract This class does not actually do anything template related. + class Template + # @param filename [String] + # @param context [Binding, nil] + # @param locals [Hash{Symbol => Object}, nil] + def initialize(filename, context: nil, locals: nil) + @data = File.read(filename) + @context = context or binding + @locals.each do |k, v| + @context.local_variable_set(k, v) + end + end + + # Prepare template before rendering. + # (This method is an interface stub) + def prepare + @template = nil # your template generator goes here + end + + # Render template + # (This method is an interface stub) + def render + (@template ||= prepare).render(@context) + end + end +end