Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
f8458256
Commit
f8458256
authored
Jun 19, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #558 from creocoder/html5
Html helper pure HTML 5 mode without support old standarts
parents
11c14a20
ef9ceafd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
52 deletions
+16
-52
Html.php
framework/yii/helpers/base/Html.php
+15
-51
FormatterTest.php
tests/unit/framework/base/FormatterTest.php
+1
-1
HtmlTest.php
tests/unit/framework/helpers/HtmlTest.php
+0
-0
No files found.
framework/yii/helpers/base/Html.php
View file @
f8458256
...
@@ -21,13 +21,7 @@ use yii\base\Model;
...
@@ -21,13 +21,7 @@ use yii\base\Model;
class
Html
class
Html
{
{
/**
/**
* @var boolean whether to close void (empty) elements. Defaults to true.
* @see voidElements
*/
public
static
$closeVoidElements
=
true
;
/**
* @var array list of void elements (element name => 1)
* @var array list of void elements (element name => 1)
* @see closeVoidElements
* @see http://www.w3.org/TR/html-markup/syntax.html#void-element
* @see http://www.w3.org/TR/html-markup/syntax.html#void-element
*/
*/
public
static
$voidElements
=
array
(
public
static
$voidElements
=
array
(
...
@@ -49,15 +43,8 @@ class Html
...
@@ -49,15 +43,8 @@ class Html
'wbr'
=>
1
,
'wbr'
=>
1
,
);
);
/**
/**
* @var boolean whether to show the values of boolean attributes in element tags.
* If false, only the attribute names will be generated.
* @see booleanAttributes
*/
public
static
$showBooleanAttributeValues
=
true
;
/**
* @var array list of boolean attributes. The presence of a boolean attribute on
* @var array list of boolean attributes. The presence of a boolean attribute on
* an element represents the true value, and the absence of the attribute represents the false value.
* an element represents the true value, and the absence of the attribute represents the false value.
* @see showBooleanAttributeValues
* @see http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes
* @see http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes
*/
*/
public
static
$booleanAttributes
=
array
(
public
static
$booleanAttributes
=
array
(
...
@@ -165,12 +152,8 @@ class Html
...
@@ -165,12 +152,8 @@ class Html
*/
*/
public
static
function
tag
(
$name
,
$content
=
''
,
$options
=
array
())
public
static
function
tag
(
$name
,
$content
=
''
,
$options
=
array
())
{
{
$html
=
'<'
.
$name
.
static
::
renderTagAttributes
(
$options
);
$html
=
"<
$name
"
.
static
::
renderTagAttributes
(
$options
)
.
'>'
;
if
(
isset
(
static
::
$voidElements
[
strtolower
(
$name
)]))
{
return
isset
(
static
::
$voidElements
[
strtolower
(
$name
)])
?
$html
:
"
$html$content
</
$name
>"
;
return
$html
.
(
static
::
$closeVoidElements
?
' />'
:
'>'
);
}
else
{
return
$html
.
">
$content
</
$name
>"
;
}
}
}
/**
/**
...
@@ -185,7 +168,7 @@ class Html
...
@@ -185,7 +168,7 @@ class Html
*/
*/
public
static
function
beginTag
(
$name
,
$options
=
array
())
public
static
function
beginTag
(
$name
,
$options
=
array
())
{
{
return
'<'
.
$name
.
static
::
renderTagAttributes
(
$options
)
.
'>'
;
return
"<
$name
"
.
static
::
renderTagAttributes
(
$options
)
.
'>'
;
}
}
/**
/**
...
@@ -201,16 +184,6 @@ class Html
...
@@ -201,16 +184,6 @@ class Html
}
}
/**
/**
* Encloses the given content within a CDATA tag.
* @param string $content the content to be enclosed within the CDATA tag
* @return string the CDATA tag with the enclosed content.
*/
public
static
function
cdata
(
$content
)
{
return
'<![CDATA['
.
$content
.
']]>'
;
}
/**
* Generates a style tag.
* Generates a style tag.
* @param string $content the style content
* @param string $content the style content
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
...
@@ -221,10 +194,7 @@ class Html
...
@@ -221,10 +194,7 @@ class Html
*/
*/
public
static
function
style
(
$content
,
$options
=
array
())
public
static
function
style
(
$content
,
$options
=
array
())
{
{
if
(
!
isset
(
$options
[
'type'
]))
{
return
static
::
tag
(
'style'
,
$content
,
$options
);
$options
[
'type'
]
=
'text/css'
;
}
return
static
::
tag
(
'style'
,
"/*<![CDATA[*/
\n
{
$content
}
\n
/*]]>*/"
,
$options
);
}
}
/**
/**
...
@@ -238,10 +208,7 @@ class Html
...
@@ -238,10 +208,7 @@ class Html
*/
*/
public
static
function
script
(
$content
,
$options
=
array
())
public
static
function
script
(
$content
,
$options
=
array
())
{
{
if
(
!
isset
(
$options
[
'type'
]))
{
return
static
::
tag
(
'script'
,
$content
,
$options
);
$options
[
'type'
]
=
'text/javascript'
;
}
return
static
::
tag
(
'script'
,
"/*<![CDATA[*/
\n
{
$content
}
\n
/*]]>*/"
,
$options
);
}
}
/**
/**
...
@@ -256,7 +223,6 @@ class Html
...
@@ -256,7 +223,6 @@ class Html
public
static
function
cssFile
(
$url
,
$options
=
array
())
public
static
function
cssFile
(
$url
,
$options
=
array
())
{
{
$options
[
'rel'
]
=
'stylesheet'
;
$options
[
'rel'
]
=
'stylesheet'
;
$options
[
'type'
]
=
'text/css'
;
$options
[
'href'
]
=
static
::
url
(
$url
);
$options
[
'href'
]
=
static
::
url
(
$url
);
return
static
::
tag
(
'link'
,
''
,
$options
);
return
static
::
tag
(
'link'
,
''
,
$options
);
}
}
...
@@ -272,7 +238,6 @@ class Html
...
@@ -272,7 +238,6 @@ class Html
*/
*/
public
static
function
jsFile
(
$url
,
$options
=
array
())
public
static
function
jsFile
(
$url
,
$options
=
array
())
{
{
$options
[
'type'
]
=
'text/javascript'
;
$options
[
'src'
]
=
static
::
url
(
$url
);
$options
[
'src'
]
=
static
::
url
(
$url
);
return
static
::
tag
(
'script'
,
''
,
$options
);
return
static
::
tag
(
'script'
,
''
,
$options
);
}
}
...
@@ -313,7 +278,10 @@ class Html
...
@@ -313,7 +278,10 @@ class Html
// we use hidden fields to add them back
// we use hidden fields to add them back
foreach
(
explode
(
'&'
,
substr
(
$action
,
$pos
+
1
))
as
$pair
)
{
foreach
(
explode
(
'&'
,
substr
(
$action
,
$pos
+
1
))
as
$pair
)
{
if
((
$pos1
=
strpos
(
$pair
,
'='
))
!==
false
)
{
if
((
$pos1
=
strpos
(
$pair
,
'='
))
!==
false
)
{
$hiddenInputs
[]
=
static
::
hiddenInput
(
urldecode
(
substr
(
$pair
,
0
,
$pos1
)),
urldecode
(
substr
(
$pair
,
$pos1
+
1
)));
$hiddenInputs
[]
=
static
::
hiddenInput
(
urldecode
(
substr
(
$pair
,
0
,
$pos1
)),
urldecode
(
substr
(
$pair
,
$pos1
+
1
))
);
}
else
{
}
else
{
$hiddenInputs
[]
=
static
::
hiddenInput
(
urldecode
(
$pair
),
''
);
$hiddenInputs
[]
=
static
::
hiddenInput
(
urldecode
(
$pair
),
''
);
}
}
...
@@ -395,7 +363,7 @@ class Html
...
@@ -395,7 +363,7 @@ class Html
if
(
!
isset
(
$options
[
'alt'
]))
{
if
(
!
isset
(
$options
[
'alt'
]))
{
$options
[
'alt'
]
=
''
;
$options
[
'alt'
]
=
''
;
}
}
return
static
::
tag
(
'img'
,
null
,
$options
);
return
static
::
tag
(
'img'
,
''
,
$options
);
}
}
/**
/**
...
@@ -424,14 +392,10 @@ class Html
...
@@ -424,14 +392,10 @@ class Html
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* If a value is null, the corresponding attribute will not be rendered.
* If the options does not contain "type", a "type" attribute with value "button" will be rendered.
* @return string the generated button tag
* @return string the generated button tag
*/
*/
public
static
function
button
(
$content
=
'Button'
,
$options
=
array
())
public
static
function
button
(
$content
=
'Button'
,
$options
=
array
())
{
{
if
(
!
isset
(
$options
[
'type'
]))
{
$options
[
'type'
]
=
'button'
;
}
return
static
::
tag
(
'button'
,
$content
,
$options
);
return
static
::
tag
(
'button'
,
$content
,
$options
);
}
}
...
@@ -482,7 +446,7 @@ class Html
...
@@ -482,7 +446,7 @@ class Html
$options
[
'type'
]
=
$type
;
$options
[
'type'
]
=
$type
;
$options
[
'name'
]
=
$name
;
$options
[
'name'
]
=
$name
;
$options
[
'value'
]
=
$value
;
$options
[
'value'
]
=
$value
;
return
static
::
tag
(
'input'
,
null
,
$options
);
return
static
::
tag
(
'input'
,
''
,
$options
);
}
}
/**
/**
...
@@ -497,7 +461,7 @@ class Html
...
@@ -497,7 +461,7 @@ class Html
{
{
$options
[
'type'
]
=
'button'
;
$options
[
'type'
]
=
'button'
;
$options
[
'value'
]
=
$label
;
$options
[
'value'
]
=
$label
;
return
static
::
tag
(
'input'
,
null
,
$options
);
return
static
::
tag
(
'input'
,
''
,
$options
);
}
}
/**
/**
...
@@ -512,7 +476,7 @@ class Html
...
@@ -512,7 +476,7 @@ class Html
{
{
$options
[
'type'
]
=
'submit'
;
$options
[
'type'
]
=
'submit'
;
$options
[
'value'
]
=
$label
;
$options
[
'value'
]
=
$label
;
return
static
::
tag
(
'input'
,
null
,
$options
);
return
static
::
tag
(
'input'
,
''
,
$options
);
}
}
/**
/**
...
@@ -526,7 +490,7 @@ class Html
...
@@ -526,7 +490,7 @@ class Html
{
{
$options
[
'type'
]
=
'reset'
;
$options
[
'type'
]
=
'reset'
;
$options
[
'value'
]
=
$label
;
$options
[
'value'
]
=
$label
;
return
static
::
tag
(
'input'
,
null
,
$options
);
return
static
::
tag
(
'input'
,
''
,
$options
);
}
}
/**
/**
...
@@ -1315,7 +1279,7 @@ class Html
...
@@ -1315,7 +1279,7 @@ class Html
foreach
(
$attributes
as
$name
=>
$value
)
{
foreach
(
$attributes
as
$name
=>
$value
)
{
if
(
isset
(
static
::
$booleanAttributes
[
strtolower
(
$name
)]))
{
if
(
isset
(
static
::
$booleanAttributes
[
strtolower
(
$name
)]))
{
if
(
$value
||
strcasecmp
(
$name
,
$value
)
===
0
)
{
if
(
$value
||
strcasecmp
(
$name
,
$value
)
===
0
)
{
$html
.=
static
::
$showBooleanAttributeValues
?
"
$name
=
\"
$name
\"
"
:
"
$name
"
;
$html
.=
"
$name
"
;
}
}
}
elseif
(
$value
!==
null
)
{
}
elseif
(
$value
!==
null
)
{
$html
.=
"
$name
=
\"
"
.
static
::
encode
(
$value
)
.
'"'
;
$html
.=
"
$name
=
\"
"
.
static
::
encode
(
$value
)
.
'"'
;
...
...
tests/unit/framework/base/FormatterTest.php
View file @
f8458256
...
@@ -96,7 +96,7 @@ class FormatterTest extends TestCase
...
@@ -96,7 +96,7 @@ class FormatterTest extends TestCase
public
function
testAsImage
()
public
function
testAsImage
()
{
{
$value
=
'http://sample.com/img.jpg'
;
$value
=
'http://sample.com/img.jpg'
;
$this
->
assertSame
(
"<img src=
\"
$value
\"
alt=
\"\"
/
>"
,
$this
->
formatter
->
asImage
(
$value
));
$this
->
assertSame
(
"<img src=
\"
$value
\"
alt=
\"\"
>"
,
$this
->
formatter
->
asImage
(
$value
));
}
}
public
function
testAsBoolean
()
public
function
testAsBoolean
()
...
...
tests/unit/framework/helpers/HtmlTest.php
View file @
f8458256
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment