Merge branch 'master' into v1

This commit is contained in:
2015-06-08 10:10:51 +02:00
73 changed files with 5913 additions and 82 deletions

View File

@@ -191,7 +191,8 @@ feature -- Execution
local
l_remote_info: detachable like remote_info
l_socket: like client_socket
l_ready_for_reading: BOOLEAN
l_is_ready: BOOLEAN
i: INTEGER
do
l_socket := client_socket
check
@@ -214,14 +215,14 @@ feature -- Execution
from
i := persistent_connection_timeout -- * 1 sec
until
l_ready_for_reading or i <= 0 or has_error
l_is_ready or i <= 0 or has_error
loop
l_ready_for_reading := l_socket.ready_for_reading
l_is_ready := l_socket.ready_for_reading
check not l_socket.is_closed end
i := i - 1
end
if l_ready_for_reading then
if l_is_ready then
create l_remote_info
if attached l_socket.peer_address as l_addr then
l_remote_info.addr := l_addr.host_address.host_address
@@ -238,7 +239,7 @@ feature -- Execution
end
if has_error then
if l_ready_for_reading then
if l_is_ready then
-- check catch_bad_incoming_connection: False end
if is_verbose then
log ("ERROR: invalid HTTP incoming request")

View File

@@ -147,7 +147,7 @@ feature -- Status report
launchable: BOOLEAN
do
Result := Precursor and port_number >= 0
Result := Precursor and 0 <= port_number and port_number <= {NATURAL_16}.max_value
end
;note

View File

@@ -47,26 +47,22 @@ feature -- Documentation
feature -- Status
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
-- <Precursor>
local
p: READABLE_STRING_8
s: like based_uri
do
p := path_from_request (req)
s := based_uri (uri, a_router)
Result := p.starts_with (s)
Result := a_path.starts_with (s)
end
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
-- <Precursor>
local
p: READABLE_STRING_8
s: like based_uri
do
p := path_from_request (req)
s := based_uri (uri, a_router)
if p.starts_with (s) then
if a_path.starts_with (s) then
sess.set_dispatched_handler (handler)
a_router.execute_before (Current)
execute_handler (handler, s, req, res)
@@ -113,7 +109,7 @@ invariant
uri_attached: uri /= Void
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -50,13 +50,13 @@ feature -- Documentation
feature -- Status
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
-- <Precursor>
local
p: READABLE_STRING_8
l_uri: like uri
do
p := path_from_request (req)
p := a_path
l_uri := based_uri (uri, a_router)
if l_uri.ends_with ("/") then
if not p.ends_with ("/") then
@@ -72,10 +72,10 @@ feature -- Status
end
end
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
-- <Precursor>
do
if is_mapping (req, a_router) then
if is_mapping (a_path, req, a_router) then
sess.set_dispatched_handler (handler)
a_router.execute_before (Current)
execute_handler (handler, req, res)
@@ -106,7 +106,7 @@ feature {NONE} -- Implementation
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -57,36 +57,32 @@ feature -- Documentation
feature -- Status
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
-- <Precursor>
local
tpl: URI_TEMPLATE
p: READABLE_STRING_8
do
p := path_from_request (req)
tpl := based_uri_template (template, a_router)
Result := tpl.match (p) /= Void
Result := tpl.match (a_path) /= Void
end
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
-- <Precursor>
local
tpl: URI_TEMPLATE
p: READABLE_STRING_8
new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER
do
p := path_from_request (req)
tpl := based_uri_template (template, a_router)
if attached tpl.match (p) as tpl_res then
if attached tpl.match (a_path) as tpl_res then
sess.set_dispatched_handler (handler)
a_router.execute_before (Current)
--| Applied the context to the request
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
--| Applied the context to the request
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
create new_src.make (tpl_res.path_variables.count, tpl_res.path_variables)
new_src.apply (req)
execute_handler (handler, req, res)
--| Revert {WSF_REQUEST}.path_parameters_source to former value
--| In case the request object passed by other handler that alters its values.
--| Revert {WSF_REQUEST}.path_parameters_source to former value
--| In case the request object passed by other handler that alters its values.
new_src.revert (req)
a_router.execute_after (Current)
end
@@ -126,7 +122,7 @@ feature {NONE} -- Implementation
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -170,6 +170,20 @@ feature -- Basic operations
Result := sess.dispatched_handler
end
feature {WSF_ROUTER_MAPPING} -- Dispatch helper
path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8
-- Path used by the router, to apply url dispatching of request `req'.
-- This can be redefined in descendant, to apply various url mapping, or aliasing
-- if needed, or for other purpose.
require
req_attached: req /= Void
do
Result := req.percent_encoded_path_info
ensure
path_from_request_attached: Result /= Void
end
feature {NONE} -- Dispatch implementation
router_dispatch (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION)
@@ -203,7 +217,9 @@ feature {NONE} -- Dispatch implementation
a_request_method_attached: a_request_method /= Void
local
m: WSF_ROUTER_MAPPING
p: like path_to_dispatch
do
p := path_to_dispatch (req)
across
mappings as c
until
@@ -212,7 +228,7 @@ feature {NONE} -- Dispatch implementation
if attached c.item as l_info then
if is_matching_request_methods (a_request_method, l_info.request_methods) then
m := l_info.mapping
m.try (req, res, sess, Current)
m.try (p, req, res, sess, Current)
end
end
end
@@ -320,16 +336,17 @@ feature -- Status report
local
m: WSF_ROUTER_MAPPING
l_rqsmethods: detachable WSF_REQUEST_METHODS
p: like path_to_dispatch
do
create Result
p := path_to_dispatch (req)
across
mappings as c
loop
m := c.item.mapping
if attached {WSF_ROUTING_HANDLER} m.handler as l_routing then
l_rqsmethods := l_routing.router.allowed_methods_for_request (req)
elseif m.is_mapping (req, Current) then
elseif m.is_mapping (p, req, Current) then
l_rqsmethods := c.item.request_methods
else
l_rqsmethods := Void
@@ -576,7 +593,7 @@ invariant
pre_execution_actions_attached: pre_execution_actions /= Void
note
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -56,18 +56,20 @@ feature -- Status report
feature -- Status
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
-- Does `Current' accept `req' when using `a_router'?
is_mapping (a_path: READABLE_STRING_8; req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
-- Does `Current' accept path `a_path' and request `req' when using `a_router'?
require
a_path_attached: a_path /= Void
req_attached: req /= Void
a_router_attached: a_router /= Void
deferred
end
try (req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
-- Try using `Current' mapping and if it matches request `req'
try (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE; sess: WSF_ROUTER_SESSION; a_router: WSF_ROUTER)
-- Try using `Current' mapping and if it matches path `a_path' and request `req'
-- execute associated handler and set this handler in session `sess'.
require
a_path_attached: a_path /= Void
req_attached: req /= Void
res_attached: res /= Void
sess_attached: sess /= Void
@@ -75,20 +77,8 @@ feature -- Status
deferred
end
feature -- Helper
path_from_request (req: WSF_REQUEST): READABLE_STRING_8
-- Path used by `Current' to check that mapping matches request `req'
require
req_attached: req /= Void
do
Result := req.percent_encoded_path_info
ensure
path_from_request_attached: Result /= Void
end
note
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -1,7 +1,9 @@
note
description: "[
This class is used to get a safe temporary file
in a specific directory, for an optional prefix, and an optional expected filename.
Collection of file system utilities.
Such as getting safe temporary file in a specific directory,
for an optional prefix, and an optional expected filename.
]"
date: "$Date$"
revision: "$Revision$"
@@ -11,32 +13,15 @@ class
feature -- Factory
new_temporary_file (d: DIRECTORY; a_prefix: detachable READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable G
-- New temporary file open for writing inside directory `d', with prefix `a_prefix' is set, and based on name `a_name' is set.
-- If it is unable to create such file opened for writing, then return Void.
require
d_valid: d.exists and then d.is_writable
new_file (p: PATH): detachable G
-- New temporary file open for writing at location `p' or appended with integer suffix if already exists.
local
f: G
fn: PATH
bn, tmp: STRING_32
dn: PATH
bn: STRING_32
n: INTEGER
do
from
if a_prefix /= Void then
create tmp.make_from_string_general (a_prefix)
else
create tmp.make_from_string_general ("tmp")
end
dn := d.path
if a_name /= Void then
tmp.append_character ('-')
tmp.append_string_general (safe_filename (a_name))
end
fn := dn.extended (tmp)
create f.make_with_path (fn)
create f.make_with_path (p)
Result := new_file_opened_for_writing (f)
n := 0
until
@@ -44,17 +29,43 @@ feature -- Factory
or else n > 1_000
loop
n := n + 1
create bn.make_from_string (tmp)
create bn.make (2 + n // 10)
bn.append_character ('-')
bn.append_integer (n)
fn := dn.extended (bn)
f.make_with_path (fn)
f.make_with_path (p.appended (bn))
Result := new_file_opened_for_writing (f)
end
ensure
result_opened_for_writing_if_set: Result /= Void implies Result.is_open_write
end
new_temporary_file (d: DIRECTORY; a_prefix: detachable READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable G
-- New temporary file open for writing inside directory `d', with prefix `a_prefix' is set, and based on name `a_name' is set.
-- If it is unable to create such file opened for writing, then return Void.
require
d_valid: d.exists and then d.is_writable
local
fn: PATH
tmp: STRING_32
dn: PATH
do
if a_prefix /= Void then
create tmp.make_from_string_general (a_prefix)
else
create tmp.make_from_string_general ("tmp")
end
dn := d.path
if a_name /= Void then
tmp.append_character ('-')
tmp.append_string_general (safe_filename (a_name))
end
fn := dn.extended (tmp)
Result := new_file (fn)
ensure
result_opened_for_writing_if_set: Result /= Void implies Result.is_open_write
end
safe_filename (fn: READABLE_STRING_GENERAL): STRING
-- Safe filename that avoid impossible filename, or dangerous one.
local
@@ -162,7 +173,7 @@ feature {NONE} -- Implementation
end
note
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -0,0 +1,24 @@
note
description: "[
Represent an input type color
Example
<input id="color" name="color" type="color">
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=color", "src=https://html.spec.whatwg.org/multipage/forms.html#color-state-(type=color)"
class
WSF_FORM_COLOR_INPUT
inherit
WSF_FORM_INPUT
create
make,
make_with_text
feature -- Access
input_type: STRING = "color"
end

View File

@@ -0,0 +1,39 @@
note
description: "[
Example:
<name="startdate" min="2012-01-01" max="2013-01-01" type="date">
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=date", "src=https://html.spec.whatwg.org/multipage/forms.html#date-state-(type=date)"
class
WSF_FORM_DATE_INPUT
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
create
make,
make_with_text
feature -- Access
input_type: STRING = "date"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
create Result.make_empty
append_numeric_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,42 @@
note
description: "[
Represent an input type datetime
Example
<input id="entry-day-time" name="entry-day-time" type="datetime">
]"
author: ""
date: "$Date$"
revision: "$Revision$"
EIS: "name=datetime", "src=https://html.spec.whatwg.org/multipage/forms.html#date-and-time-state-(type=datetime)"
class
WSF_FORM_DATETIME_INPUT
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
create
make,
make_with_text
feature -- Access
input_type: STRING = "datetime"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
create Result.make_empty
append_numeric_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,41 @@
note
description: "[
Represent an input type datetime-local
Example:
<input id="arrival-time" name="arrival-time " type="datetime-local">
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=datetime-local", "src=https://html.spec.whatwg.org/multipage/forms.html#local-date-and-time-state-(type=datetime-local)"
class
WSF_FORM_DATETIME_LOCAL_INPUT
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
create
make,
make_with_text
feature -- Access
input_type: STRING = "datetime-local"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
-- TODO find a way to validte differnet types of
-- values to (min, max and step).
create Result.make_empty
append_numeric_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,26 @@
note
description: "[
Represent the intput type email
Example:
<input type="email" name="email" required>
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=email", "src=https://html.spec.whatwg.org/multipage/forms.html#e-mail-state-(type=email)"
class
WSF_FORM_EMAIL_INPUT
inherit
WSF_FORM_INPUT
create
make,
make_with_text
feature -- Access
input_type: STRING = "email"
end

View File

@@ -0,0 +1,125 @@
note
description: "[
Represent attributes applicable to input type type=[number, range, date]
The attributes: min, max, step.
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=numeric attributes", "src=https://html.spec.whatwg.org/multipage/forms.html#common-input-element-attributes"
class
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
inherit
SHARED_HTML_ENCODER
feature -- Access
min: detachable READABLE_STRING_8
-- minimun value accepted by Current field.
max: detachable READABLE_STRING_8
-- maximun value accepted by Current field.
step: detachable READABLE_STRING_8
-- step is the increment that the value should adjust up or down, with the default step value being 1.
feature -- Element Change
set_min (a_val: INTEGER)
-- Set `min' with `a_val'.
do
set_min_string (a_val.out)
ensure
min_set: attached min as l_min implies l_min.same_string (a_val.out)
end
set_max (a_val: INTEGER)
-- Set `max' with `a_val'.
do
set_max_string(a_val.out)
ensure
max_set: attached max as l_max implies l_max.same_string (a_val.out)
end
set_step (a_val: REAL)
-- Set `step' with `a_val'.
do
set_step_string (a_val.out)
ensure
step_set: attached step as l_step implies l_step.same_string (a_val.out)
end
set_min_string (a_val: READABLE_STRING_GENERAL)
-- Set `min' with `a_val'.
require
is_valid_number: a_val.is_integer
do
if a_val.is_string_32 then
min := html_encoder.encoded_string (a_val.as_string_32)
elseif a_val.is_string_8 then
min := a_val.as_string_8
end
ensure
min_set: attached min as l_min implies l_min.same_string_general (a_val)
end
set_max_string (a_val: READABLE_STRING_GENERAL)
-- Set `max' with `a_val'.
require
is_valid_number: a_val.is_integer
do
if a_val.is_string_32 then
max := html_encoder.encoded_string (a_val.as_string_32)
elseif a_val.is_string_8 then
max := a_val.as_string_8
end
ensure
max_set: attached max as l_max implies l_max.same_string_general (a_val)
end
set_step_string (a_val: READABLE_STRING_GENERAL)
-- Set `step' with `a_val'.
require
is_valid_sequence: a_val.is_number_sequence or else a_val.is_real_sequence
do
if a_val.is_string_32 then
step := html_encoder.encoded_string (a_val.as_string_32)
elseif a_val.is_string_8 then
step := a_val.as_string_8
end
ensure
step_set: attached step as l_step implies l_step.same_string_general (a_val)
end
feature {NONE} -- Conversion
append_numeric_input_attributes_to (a_target: STRING)
-- append numeric attributes to a_target, if any.
do
--min
if attached min as l_min then
a_target.append (" min=%"")
a_target.append(l_min)
a_target.append_character ('%"')
end
--max
if attached max as l_max then
a_target.append (" max=%"")
a_target.append (l_max)
a_target.append_character ('%"')
end
--step
if attached step as l_step then
a_target.append (" step=%"")
a_target.append (l_step)
a_target.append_character ('%"')
end
end
end

View File

@@ -12,6 +12,8 @@ inherit
redefine
specific_input_attributes_string
end
WSF_FORM_WITH_ALTERNATIVE_ACTIONS
create
make
@@ -51,6 +53,7 @@ feature {NONE} -- Implementation
if attached alt as l_alt then
Result.append (" alt=%"" + l_alt + "%"")
end
append_submit_image_input_attributes_to (Result)
end
invariant

View File

@@ -10,6 +10,8 @@ deferred class
inherit
WSF_FORM_FIELD
WSF_FORM_INPUT_WITH_HTML5
feature {NONE} -- Initialization
make (a_name: like name)
@@ -86,6 +88,7 @@ feature -- Conversion
append_css_class_to (a_html, Void)
append_css_id_to (a_html)
append_css_style_to (a_html)
append_html5_input_attributes_to (a_theme, a_html)
if is_readonly then
a_html.append (" readonly=%"readonly%"")
@@ -131,6 +134,7 @@ feature {NONE} -- Implementation
-- Specific input attributes if any.
--| To redefine if needed
do
-- TODO: should we consider to use theme?
end
end

View File

@@ -0,0 +1,181 @@
note
description: "Represent the improvement HTML5 brings to web forms"
date: "$Date$"
revision: "$Revision$"
EIS: "name=HTML5 forms", "src=https://html.spec.whatwg.org/multipage/forms.html#forms"
deferred class
WSF_FORM_INPUT_WITH_HTML5
inherit
SHARED_HTML_ENCODER
feature -- Access
placeholder: detachable READABLE_STRING_32
-- short hint intended to aid the user with data entry when the control has no value.
-- EIS:"name=placeholder", "src=https://html.spec.whatwg.org/multipage/forms.html#attr-input-placeholder
autofocus: BOOLEAN
-- moves the input focus to a particular input field.
autocomplete: BOOLEAN
-- helps users complete forms based on earlier input.
-- The default state is set to on.
-- call set_autocomplete to turn it off.
required: BOOLEAN
-- The browser requires the user to enter data into that field before submitting the form.
pattern: detachable READABLE_STRING_32
-- specifies a JavaScript regular expression for the fields value to be checked against.
-- pattern makes it easy for us to implement specific validation for product codes, invoice numbers, and so on.
--! This pattern is not validated, at the moment.
feature -- Change element
set_placeholder (a_placeholder: READABLE_STRING_32)
-- Set `placeholder' with `a_placeholder'.
do
placeholder := a_placeholder
ensure
placeholder_set: attached placeholder as l_placeholder implies l_placeholder = a_placeholder
end
enable_autofocus
-- Set autofocus in True.
do
autofocus := True
ensure
autofocus_true: autofocus
end
disable_autofocus
-- Set autofocus in False
do
autofocus := False
ensure
autofocus_false: not autofocus
end
disable_autocomplete
-- Turn off the autocomplete. The default behavior is on.
do
autocomplete := True
ensure
autocomplete_true: autocomplete
end
enable_autocomplete
-- Set autocomplete in False, Set default behavior.
do
autocomplete := False
ensure
autocomplete_false: not autocomplete
end
enable_required
-- Set required to True.
do
required := True
ensure
required_true: required
end
disable_required
-- Set rquired to False.
do
required := False
ensure
required_flase: not required
end
set_pattern (a_pattern: READABLE_STRING_32)
-- Set `pattern' with `a_pattern'.
-- Example:[0-9][A-Z]{3}
-- Check HTML5 patterns site.
note
EIS: "name=HTML5 Patterns", "src=http://html5pattern.com/"
do
pattern := a_pattern
ensure
pattern_set: attached pattern as l_pattern implies l_pattern = a_pattern
end
-- The attribues `form',`list', and `multiple' are not supported yet.
-- For example the list attribute need datalist support.
-- list: detachable READABLE_STRING_32
-- The list attribute enables the user to associate a list of options with a particular field.
-- The value of the list attribute must be the same as the ID of a datalist element that resides in the same document.
-- The datalist element is new in HTML5 and represents a predefined list of options for form controls.
--
-- Example
--
-- <label>Your favorite fruit:
-- <datalist id="fruits">
-- <option value="Blackberry">Blackberry</option>
-- <option value="Blackcurrant">Blackcurrant</option>
-- <option value="Blueberry">Blueberry</option>
-- <!-- … -->
-- </datalist>
-- If other, please specify:
-- <input type="text" name="fruit" list="fruits">
-- </label>
-- multiple: BOOLEAN
--We can take our lists and datalists one step further by applying the Boolean attribute multiple to allow more than one value to be entered from the datalist.
-- Here is an example.
--<label>Your favorite fruit:
--<datalist id="fruits">
-- <select name="fruits">
-- <option value="Blackberry">Blackberry</option>
-- <option value="Blackcurrant">Blackcurrant</option>
-- <option value="Blueberry">Blueberry</option>
-- <!-- … -->
-- </select>
--If other, please specify:
--</datalist>
-- <input type="text" name="fruit" list="fruits" multiple>
--</label>
feature -- Conversion
append_html5_input_attributes_to (a_theme: WSF_THEME; a_target: STRING)
-- Append html5 attributes to target `a_target'.
--!Note: Several new HTML5 form attributes are Boolean attributes.
--This just means theyre set if theyre present and not set if theyre absent. They can be written several ways in HTML5.
--autofocus
--autofocus=""
--autofocus="autofocus"
--However, if you are writing XHTML5, you have to use the autofocus="autofocus" style.
do
if attached placeholder as l_placeholder then
a_target.append (" placeholder=%"")
a_target.append (html_encoder.encoded_string (l_placeholder))
a_target.append_character ('%"')
end
--TODO check how we can add xhtml5 support
-- if a_theme.has_xhtml5_support then
-- ....
if autofocus then
a_target.append (" autofocus")
end
if autocomplete then
a_target.append (" autocomplete=%"")
a_target.append ("off")
a_target.append_character ('%"')
end
if required then
a_target.append (" required")
end
if attached pattern as l_pattern then
a_target.append (" pattern=%"")
a_target.append ( html_encoder.encoded_string (l_pattern))
a_target.append_character ('%"')
end
end
end

View File

@@ -0,0 +1,41 @@
note
description: "[
Represent an input type Month
Example:
<input id="expiry" name="expiry" type="month" required>
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=month", "src=https://html.spec.whatwg.org/multipage/forms.html#month-state-(type=month)"
class
WSF_FORM_MONTH_INPUT
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
create
make,
make_with_text
feature -- Access
input_type: STRING = "month"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
create Result.make_empty
append_numeric_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,40 @@
note
description: "[
Represent the input type number.
Example:
<input type="number" min="5" max="18" step="0.5" value="9" name="shoe-size">
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name= Number", "src=https://html.spec.whatwg.org/multipage/forms.html#number-state-(type=number)"
class
WSF_FORM_NUMBER_INPUT
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
create
make,
make_with_text
feature -- Access
input_type: STRING = "number"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
create Result.make_empty
append_numeric_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,40 @@
note
description: "[
Represent an input type range
Example
<input type="range" min=0 max=100 step=20 value=50>
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_FORM_RANGE_INPUT
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
create
make,
make_with_text
feature -- Access
input_type: STRING = "range"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
create Result.make_empty
append_numeric_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,23 @@
note
description: "[
Represent the intput type search
Example
<input type="search" name="Search">
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=search", "src=https://html.spec.whatwg.org/multipage/forms.html#text-(type=text)-state-and-search-state-(type=search)"
class
WSF_FORM_SEARCH_INPUT
inherit
WSF_FORM_INPUT
create
make,
make_with_text
feature -- Access
input_type: STRING = "search"
end

View File

@@ -9,7 +9,11 @@ class
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_WITH_ALTERNATIVE_ACTIONS
create
make,
make_with_text
@@ -18,4 +22,14 @@ feature -- Access
input_type: STRING = "submit"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
create Result.make_empty
append_submit_image_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,24 @@
note
description: "[
Represent an input type tel
Example
<input type="tel" name="tel" id="tel" required>
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=tel", "src=https://html.spec.whatwg.org/multipage/forms.html#telephone-state-(type=tel)"
class
WSF_FORM_TEL_INPUT
inherit
WSF_FORM_INPUT
create
make,
make_with_text
feature -- Access
input_type: STRING = "tel"
end

View File

@@ -0,0 +1,36 @@
note
description: "Summary description for {WSF_FORM_TIME_INPUT}."
date: "$Date$"
revision: "$Revision$"
EIS: "name=time", "src=https://html.spec.whatwg.org/multipage/forms.html#time-state-(type=time)"
class
WSF_FORM_TIME_INPUT
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
create
make,
make_with_text
feature -- Access
input_type: STRING = "time"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
create Result.make_empty
append_numeric_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,24 @@
note
description: "[
Represent the input type url
Example
<input type="url" name="url" required>
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=url", "src=https://html.spec.whatwg.org/multipage/forms.html#url-state-(type=url)"
class
WSF_FORM_URL_INPUT
inherit
WSF_FORM_INPUT
create
make,
make_with_text
feature -- Access
input_type: STRING = "url"
end

View File

@@ -0,0 +1,43 @@
note
description: "[
Represent an input type week
Example
<input id="vacation" name="vacation" type="week">
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=week", "src=https://html.spec.whatwg.org/multipage/forms.html#week-state-(type=week)"
class
WSF_FORM_WEEK_INPUT
inherit
WSF_FORM_INPUT
redefine
specific_input_attributes_string
end
WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE
create
make,
make_with_text
feature -- Access
input_type: STRING = "week"
feature {NONE} -- Conversion
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
create Result.make_empty
append_numeric_input_attributes_to (Result)
end
end

View File

@@ -0,0 +1,137 @@
note
description: "[
Represent alternative actions for forms
The formaction, formenctype, formmethod, and formtarget attributes.
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=form submission", "src=https://html.spec.whatwg.org/multipage/forms.html#form-submission"
class
WSF_FORM_WITH_ALTERNATIVE_ACTIONS
feature -- Access
formnovalidate: BOOLEAN
-- indicate that the form shouldnt be validated when submitted.
-- it's only applicable to input type=submit or image.
formaction: detachable READABLE_STRING_32
-- formaction specifies the file or application that will submit the form.
-- It has the same effect as the action attribute on the form element and
-- can only be used with a submit or image button (type="submit" or type="image").
-- When the form is submitted, the browser first checks for a formaction attribute;
-- if that isnt present, it proceeds to look for an action attribute on the form.
formenctype: detachable READABLE_STRING_32
-- formenctype details how the form data is encoded with the POST method type.
-- It has the same effect as the enctype attribute on the form element and
-- can only be used with a submit or image button (type="submit" or type="image").
-- The default value if not included is application/x-www-formurlencoded.
--! At the moment the value is not validated.
formmethod: detachable READABLE_STRING_32
-- formmethod specifies which HTTP method (GET, POST, PUT, DELETE) will be used to submit the form data.
-- It has the same effect as the method attribute on the form element and can only be used with a
-- submit or image button (type="submit" or type="image").
--!At the moment the value is not validated.
formtarget: detachable READABLE_STRING_32
-- formtarget specifies the target window for the form results.
-- It has the same effect as the target attribute on the form element and can only be used with a submit or image button (type="submit" or type="image").
feature -- Element Change
set_formnovalidate
-- Set formnovalidate to True.
do
formnovalidate := True
ensure
formnovalidate_true: formnovalidate
end
unset_formnovalidate
-- Set formnovalidate to False.
do
formnovalidate := False
ensure
formnovalidate_false: not formnovalidate
end
set_formaction (a_action: READABLE_STRING_32)
-- Set `formaction' with `a_action'.
-- Example:<input type="submit" value="Submit" formaction="/users">
do
formaction := a_action
ensure
formaction_set: attached formaction as l_action implies l_action = a_action
end
set_formenctype (a_enctype: READABLE_STRING_32)
-- Set `formenctype' with `a_enctype'.
-- Example: <input type="submit" value="Submit" formenctype="application/x-www-form-urlencoded">
do
formenctype := a_enctype
ensure
formenctype_set: attached formenctype as l_enctype implies l_enctype = a_enctype
end
set_formmethod (a_method: READABLE_STRING_32)
-- Set `formmethod' with `a_method'.
-- Example: <input type="submit" value="Submit" formmethod="POST">
--! require is_valid_method: [PUT, POST, DELETE, GET, ...]
do
formmethod := a_method
ensure
formmethod_set: attached formmethod as l_method implies l_method = a_method
end
set_formtarget (a_target: READABLE_STRING_32)
-- Set `formtarget' with `a_target'.
-- Example: <input type="submit" value="Submit" formtarget="_self">
do
formtarget := a_target
ensure
formtarget_set: attached formtarget as l_target implies l_target = a_target
end
feature {NONE} -- Conversion
append_submit_image_input_attributes_to (a_target: STRING_8)
-- Append specific input attributes for submit/image to a_target,
do
--formnovalidate
if formnovalidate then
a_target.append (" formnovalidate")
end
--formaction
if attached formaction as l_formaction then
a_target.append (" formaction=%"")
a_target.append (l_formaction)
a_target.append_character ('%"')
end
--formenctype
if attached formenctype as l_enctype then
a_target.append (" formenctype=%"")
a_target.append (l_enctype)
a_target.append_character ('%"')
end
-- formmethod
if attached formmethod as l_method then
a_target.append (" formmethod=%"")
a_target.append (l_method)
a_target.append_character ('%"')
end
-- formmethod
if attached formtarget as l_target then
a_target.append (" formtarget=%"")
a_target.append (l_target)
a_target.append_character ('%"')
end
end
end