quickfix for template constructors
This commit is contained in:
parent
4312d31268
commit
3300f966a9
|
@ -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
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
../../lib
|
|
@ -0,0 +1 @@
|
||||||
|
Example of handling forms in Hyde
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue