diff --git a/examples/form2/form.ru b/examples/form2/form.ru new file mode 100644 index 0000000..fb6f8dd --- /dev/null +++ b/examples/form2/form.ru @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib") +require 'hyde' + +app = Hyde::Server.new do + root ENV["PWD"] + index ["index.html"] + post "/" do + formdata = form if form? + puts formdata.pretty_inspect + erubi(file("index.rhtml"), { formdata: formdata }).run + end + get "/" do + erubi(file("index.rhtml")).run + end +end + +run app diff --git a/examples/form2/index.rhtml b/examples/form2/index.rhtml new file mode 100644 index 0000000..fd77c5b --- /dev/null +++ b/examples/form2/index.rhtml @@ -0,0 +1,35 @@ + + + + Form upload test + + + +

Form upload test

+
+

Please enter the following details:

+

+ + + + + + + +
+ <% if (defined? formdata) and formdata %> +
+ + <% end %> + + + + diff --git a/examples/form2/lib b/examples/form2/lib new file mode 120000 index 0000000..58677dd --- /dev/null +++ b/examples/form2/lib @@ -0,0 +1 @@ +../../lib \ No newline at end of file diff --git a/examples/form2/readme.txt b/examples/form2/readme.txt new file mode 100644 index 0000000..c5e32c6 --- /dev/null +++ b/examples/form2/readme.txt @@ -0,0 +1 @@ +Example of handling forms in Hyde diff --git a/lib/hyde/dsl/constructors_probe.rb b/lib/hyde/dsl/constructors_probe.rb index 2acf5bf..7a0a669 100644 --- a/lib/hyde/dsl/constructors_probe.rb +++ b/lib/hyde/dsl/constructors_probe.rb @@ -6,7 +6,7 @@ module Hyde module ProbeConstructors # Create a new erb template # @see {Hyde::Template#new} - def erb(input, vars = nil) + def erb(input, vars = {}) Hyde::Templates::ERB.new(input, vars, parent: @origin) @@ -16,7 +16,7 @@ module Hyde # @see {Hyde::Template#new} # @param freeze [Boolean] whether to use frozen string literal # @param capture [Boolean] whether to enable output capturing - def erubi(input, vars = nil, freeze: true, capture: false) + def erubi(input, vars = {}, freeze: true, capture: false) Hyde::Templates::Erubi.new(input, vars, parent: @origin,