quickfix for template constructors

This commit is contained in:
Yessiest 2023-09-15 09:00:35 +04:00
parent 4312d31268
commit 3300f966a9
5 changed files with 58 additions and 2 deletions

19
examples/form2/form.ru Normal file
View File

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

View File

@ -0,0 +1,35 @@
<!DOCTYPE>
<html>
<head>
<title>Form upload test</title>
<style>
.form { display: flex; flex-direction: column }
</style>
</head>
<body>
<h1>Form upload test</h1>
<hr/>
<p> Please enter the following details: <p>
<form method="post"
class="form"
enctype="multipart/form-data">
<input type="text" name="form_name" placeholder="Name" required>
<input type="text" name="form_company" placeholder="Company" required>
<input type="text" name="form_phone" placeholder="Phone" required>
<textarea name="comment" placeholder="Comment"></textarea>
<input id="form_files" type="file" name="form_files[]" multiple>
<label for="form_files">Attach file</label>
<input type="submit" value="Send form">
</form>
<% if (defined? formdata) and formdata %>
<hr>
<ul>
<% formdata.each do |key, part| %>
<li><%= key %>: <%= part.is_a?(String) ? part : "File: #{part.map do |x| x.filename end.join(',')}" %></li>
<% end %>
</ul>
<% end %>
</body>
</html>

1
examples/form2/lib Symbolic link
View File

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

View File

@ -0,0 +1 @@
Example of handling forms in Hyde

View File

@ -6,7 +6,7 @@ module Hyde
module ProbeConstructors module ProbeConstructors
# Create a new erb template # Create a new erb template
# @see {Hyde::Template#new} # @see {Hyde::Template#new}
def erb(input, vars = nil) def erb(input, vars = {})
Hyde::Templates::ERB.new(input, Hyde::Templates::ERB.new(input,
vars, vars,
parent: @origin) parent: @origin)
@ -16,7 +16,7 @@ module Hyde
# @see {Hyde::Template#new} # @see {Hyde::Template#new}
# @param freeze [Boolean] whether to use frozen string literal # @param freeze [Boolean] whether to use frozen string literal
# @param capture [Boolean] whether to enable output capturing # @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, Hyde::Templates::Erubi.new(input,
vars, vars,
parent: @origin, parent: @origin,