From e649b1a12fe4b43063753e482a47fcda0cbeb9d7 Mon Sep 17 00:00:00 2001
From: Christian Schneider
Date: Thu, 26 Apr 2018 18:32:07 +0200
Subject: Use different global object for htmltype xml to allow mixing
xml/html5 generation
---
it_html.class | 4 ++--
tests/it_html.t | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/it_html.class b/it_html.class
index 58e0b84..e410816 100644
--- a/it_html.class
+++ b/it_html.class
@@ -76,7 +76,7 @@ function __construct($p = array())
'htmltype' => 'html5', # 'html5', 'html' (=old-style), 'xhtml' or 'xhtml-mobile' for xhtml, or 'xml' for plain xml without magic
'lang' => 'de', # Language code to use in tag
'moretags' => '', # Comma-separated list of tag-functions to generate additionally to 'tags'
- 'name' => 'it_html', # Name of global variable $this is assigned to (string), XXX Copy and paste in configure() to keep PHP4 compatibility
+ 'name' => $p['htmltype'] == 'xml' ? 'it_html_xml' : 'it_html', # Name of global variable $this is assigned to (string), XXX Copy and paste in configure()
'nonewlinetags' => 'a,b,em,img,input,label,span,noscript', # tags that do not like newlines after them
'prettyprint' => it::is_devel(), # Should output be prettily indented?
'show_boot_dom' => false, # If true, append invisible
at the end of body
@@ -138,7 +138,7 @@ function __construct($p = array())
*/
static function configure($p)
{
- $ithtml = $GLOBALS[$p['name'] ? $p['name'] : "it_html"];
+ $ithtml = $GLOBALS[$p['name'] ?: ($p['htmltype'] == 'xml' ? 'it_html_xml' : 'it_html')];
$ithtml->p = $p + (array)$ithtml->p;
$ithtml->alltags = array_flip(explode(',', trim($ithtml->p['tags'] . ',' . $ithtml->p['moretags'], ',')));
$ithtml->hasnonewline = array_flip(explode(',', $ithtml->p['nonewlinetags']));
diff --git a/tests/it_html.t b/tests/it_html.t
index 8e529e0..6d55319 100755
--- a/tests/it_html.t
+++ b/tests/it_html.t
@@ -139,7 +139,7 @@ is(
# XML generation
unset($GLOBALS['it_html']);
-new it_html(array('htmltype' => "xml", 'tags' => "xmltest"));
+new it_html(array('htmltype' => "xml", 'name' => 'it_html', 'tags' => "xmltest"));
is(
xmltest(),
--
cgit v1.2.3
From 49cb7482b57046d69c15eea7737716229ba08ef8 Mon Sep 17 00:00:00 2001
From: Christian Schneider
Date: Thu, 3 May 2018 17:48:27 +0200
Subject: Generate it::error when trying to redefine function for a tag
---
it_html.class | 3 +++
tests/it_html.t | 10 +++++-----
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/it_html.class b/it_html.class
index e410816..5828438 100644
--- a/it_html.class
+++ b/it_html.class
@@ -88,6 +88,7 @@ function __construct($p = array())
'title' => '', # HTML title (default: no title added)
'use_it_state' => false, # If true, generate code needed by state.js (aka 'history iframe')
'srclines' => $GLOBALS['debug_srclines'], # append stackdump to each tag
+ 'error_on_redefine' => true, # Generate it::error when trying to redefine function for a tag
);
$this->p['notexported'] = trim($p['notexported'] . ',configure,sanitize,comment', ',');
@@ -111,6 +112,8 @@ function __construct($p = array())
{
if (!function_exists($func) && $func)
$code[$func] = "function $func() { \$args = func_get_args(); return \$GLOBALS['{$this->p['name']}']->_tag('$func', \$args); }";
+ else if ($this->p['error_on_redefine'])
+ it::error("Trying to redefine existing function '$func' in it_html");
}
# Create global functions for it_html methods
diff --git a/tests/it_html.t b/tests/it_html.t
index 6d55319..d18afdc 100755
--- a/tests/it_html.t
+++ b/tests/it_html.t
@@ -7,7 +7,7 @@ it::getopt(""); #handle possible --debug parameter
# Traditional html5 generation
ini_set('default_charset', "utf-8");
-new it_html(array('htmltype' => "html5", 'prettyprint' => false));
+new it_html(array('htmltype' => "html5", 'prettyprint' => false, 'error_on_redefine' => false));
is(
a(array('href' => "&foo", 'true' => true, 'false' => false, 'null' => null, 'empty' => ""), "bar"),
@@ -110,13 +110,13 @@ is(
foreach (array('html5' => "
", 'html' => "
", 'xhtml' => "
", 'xhtml-mobile' => "
") as $type => $value)
{
unset($GLOBALS['it_html']);
- new it_html(array('htmltype' => $type));
+ new it_html(array('htmltype' => $type, 'error_on_redefine' => false));
is (trim(br(array('flag' => true))), $value, "Check empty tag and attribute for $type");
}
# XHTML generation
unset($GLOBALS['it_html']);
-new it_html(array('htmltype' => "xhtml", 'tags' => "script"));
+new it_html(array('htmltype' => "xhtml", 'tags' => "script", 'error_on_redefine' => false));
is(
script(),
@@ -139,7 +139,7 @@ is(
# XML generation
unset($GLOBALS['it_html']);
-new it_html(array('htmltype' => "xml", 'name' => 'it_html', 'tags' => "xmltest"));
+new it_html(array('htmltype' => "xml", 'name' => 'it_html', 'tags' => "xmltest", 'error_on_redefine' => false));
is(
xmltest(),
@@ -194,7 +194,7 @@ function overriddentag($args)
}
unset($GLOBALS['it_html']);
-new myhtml(array('htmltype' => "html"));
+new myhtml(array('htmltype' => "html", 'error_on_redefine' => false));
is(
myimg(['src' => "foo.gif", 'alt' => "foo"]),
--
cgit v1.2.3
From 7f41132b49ab09232a653cc6d2f3b2e14d0a139b Mon Sep 17 00:00:00 2001
From: Christian Schneider
Date: Mon, 7 May 2018 16:31:40 +0200
Subject: Disable the redefine function warning per default, renable it in the
search-specific auto_prepend instead
---
it_html.class | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/it_html.class b/it_html.class
index 5828438..7e24021 100644
--- a/it_html.class
+++ b/it_html.class
@@ -88,7 +88,7 @@ function __construct($p = array())
'title' => '', # HTML title (default: no title added)
'use_it_state' => false, # If true, generate code needed by state.js (aka 'history iframe')
'srclines' => $GLOBALS['debug_srclines'], # append stackdump to each tag
- 'error_on_redefine' => true, # Generate it::error when trying to redefine function for a tag
+ 'error_on_redefine' => false, # Generate it::error when trying to redefine function for a tag
);
$this->p['notexported'] = trim($p['notexported'] . ',configure,sanitize,comment', ',');
--
cgit v1.2.3
From d1195a5f10cdc4e8cb8a3a5e1c58f46fba9e5f3d Mon Sep 17 00:00:00 2001
From: Christian Schneider
Date: Mon, 7 May 2018 17:03:23 +0200
Subject: Hack: Manually copy for new instance without custom value to keep
setting from global auto_prepend instance
---
it_html.class | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/it_html.class b/it_html.class
index 7e24021..f433e14 100644
--- a/it_html.class
+++ b/it_html.class
@@ -101,6 +101,10 @@ function __construct($p = array())
'xml' => ''
);
+ # @@@ Hack: Manually copy for new instance without custom value to keep setting from global auto_prepend instance
+ if (!isset($p['error_on_redefine']) && isset($GLOBALS[$this->p['name']]))
+ $this->p['error_on_redefine'] = $GLOBALS[$this->p['name']]->p['error_on_redefine'];
+
# Since name is given as param, it is our duty to store it, not our caller's.
$GLOBALS[$this->p['name']] =& $this;
--
cgit v1.2.3