forked from ampproject/amp-wp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include requires_extension from spec in AMP_Allowed_Tags_Generated
* Use spec to determine which script components get enqueued * Use the latest component instead of 0.1 * Reduce duplicated logic by defining get_scripts() method on base sanitizer * Add get_allowed_tag_data method on AMP_Allowed_Tags_Generated to reduce size of array passing. * Define sanitized_tag class variable on sanitizer classes
- Loading branch information
1 parent
2447165
commit 26c53c1
Showing
13 changed files
with
407 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
Follow the steps below to generate a new version of the allowed tags class: | ||
- Download a copy of the latet AMPHTML repository from github: | ||
git clone [email protected]:ampproject/amphtml.git | ||
- Copy this file into the repo's validator subdirectory: | ||
|
@@ -149,6 +149,8 @@ def GenerateHeaderPHP(out): | |
out.append(' * Note: This file only contains tags that are relevant to the `body` of') | ||
out.append(' * an AMP page. To include additional elements modify the variable') | ||
out.append(' * `mandatory_parent_blacklist` in the amp_wp_build.py script.') | ||
out.append(' *') | ||
out.append(' * phpcs:ignoreFile') | ||
out.append(' */') | ||
out.append('class AMP_Allowed_Tags_Generated {') | ||
out.append('') | ||
|
@@ -223,15 +225,15 @@ def GenerateAttributesPHP(out, attributes, indent_level = 4): | |
indent = '' | ||
for i in range(0,indent_level): | ||
indent += '\t' | ||
|
||
sorted_attributes = sorted(attributes.items()) | ||
for (attribute, values) in collections.OrderedDict(sorted_attributes).iteritems(): | ||
logging.info('generating php for attribute: %s...' % attribute.lower()) | ||
out.append('%s\'%s\' => array(' % (indent, attribute.lower())) | ||
GeneratePropertiesPHP(out, values) | ||
out.append('%s),' % indent) | ||
logging.info('...done with: %s' % attribute.lower()) | ||
|
||
out.append('') | ||
logging.info('... done') | ||
|
||
|
@@ -305,26 +307,56 @@ def GenerateFooterPHP(out): | |
logging.info('entering ...') | ||
|
||
# Output the footer. | ||
out.append('\tpublic static function get_allowed_tags() {') | ||
out.append('\t\treturn self::$allowed_tags;') | ||
out.append('\t}') | ||
out.append('') | ||
out.append(''' | ||
/** | ||
* Get allowed tags. | ||
* | ||
* @since 0.5 | ||
* @return array Allowed tags. | ||
*/ | ||
public static function get_allowed_tags() { | ||
return self::$allowed_tags; | ||
} | ||
/** | ||
* Get allowed tag data. | ||
* | ||
* @since 0.7 | ||
* @param string $tag_name Tag name. | ||
* @return array|null Allowed tag data. | ||
*/ | ||
public static function get_allowed_tag_data( $tag_name ) { | ||
if ( isset( self::$allowed_tags[ $tag_name ] ) ) { | ||
return self::$allowed_tags[ $tag_name ]; | ||
} | ||
return null; | ||
} | ||
/** | ||
* Get list of globally-allowed attributes. | ||
* | ||
* @since 0.5 | ||
* @return array Allowed tag. | ||
*/ | ||
public static function get_allowed_attributes() { | ||
return self::$globally_allowed_attrs; | ||
} | ||
/** | ||
* Get layout attributes. | ||
* | ||
* @since 0.5 | ||
* @return array Allowed tag. | ||
*/ | ||
public static function get_layout_attributes() { | ||
return self::$layout_allowed_attrs; | ||
}''') | ||
|
||
out.append('\tpublic static function get_allowed_attributes() {') | ||
out.append('\t\treturn self::$globally_allowed_attrs;') | ||
out.append('\t}') | ||
out.append('') | ||
|
||
out.append('\tpublic static function get_layout_attributes() {') | ||
out.append('\t\treturn self::$layout_allowed_attrs;') | ||
out.append('\t}') | ||
out.append('') | ||
|
||
out.append('}') | ||
out.append('') | ||
|
||
out.append('?>') | ||
out.append('') | ||
logging.info('... done') | ||
|
||
|
||
|
@@ -434,6 +466,12 @@ def GetTagRules(tag_spec): | |
also_requires_tag_list.append(UnicodeEscape(also_requires_tag)) | ||
tag_rules['also_requires_tag'] = {'also_requires_tag': also_requires_tag_list} | ||
|
||
if hasattr(tag_spec, 'requires_extension') and len( tag_spec.requires_extension ) != 0: | ||
requires_extension_list = [] | ||
for requires_extension in tag_spec.requires_extension: | ||
requires_extension_list.append(requires_extension) | ||
tag_rules['requires_extension'] = {'requires_extension': requires_extension_list} | ||
|
||
if tag_spec.disallowed_ancestor: | ||
disallowed_ancestor_list = [] | ||
for disallowed_ancestor in tag_spec.disallowed_ancestor: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.