Skip to content

Commit

Permalink
Merge pull request #1386 from Automattic/update/spec-1534879991178
Browse files Browse the repository at this point in the history
Add support for reference points and update spec to file revision 720 (v1534879991178)
  • Loading branch information
westonruter authored Sep 2, 2018
2 parents c3d5c34 + 0a2916d commit c2a297c
Show file tree
Hide file tree
Showing 6 changed files with 824 additions and 87 deletions.
48 changes: 42 additions & 6 deletions bin/amphtml-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def GeneratePHP(out_dir):
logging.info('entering ...')
assert re.match(r'^[a-zA-Z_\-0-9]+$', out_dir), 'bad out_dir: %s' % out_dir

allowed_tags, attr_lists, versions = ParseRules(out_dir)
allowed_tags, attr_lists, reference_points, versions = ParseRules(out_dir)

#Generate the output
out = []
Expand All @@ -109,6 +109,7 @@ def GeneratePHP(out_dir):
GenerateAllowedTagsPHP(out, allowed_tags)
GenerateLayoutAttributesPHP(out, attr_lists)
GenerateGlobalAttributesPHP(out, attr_lists)
GenerateReferencePointsPHP(out, reference_points)
GenerateFooterPHP(out)

# join out array into a single string and remove unneeded whitespace
Expand Down Expand Up @@ -188,6 +189,15 @@ def GenerateGlobalAttributesPHP(out, attr_lists):
out.append('')
logging.info('... done')

def GenerateReferencePointsPHP(out, reference_points):
logging.info('entering ...')

# Output the reference points.
out.append('')
out.append('\tprivate static $reference_points = %s;' % Phpize( reference_points, 1 ).lstrip() )
out.append('')
logging.info('... done')

def GenerateFooterPHP(out):
logging.info('entering ...')

Expand Down Expand Up @@ -219,6 +229,20 @@ def GenerateFooterPHP(out):
return null;
}
/**
* Get reference point spec.
*
* @since 1.0
* @param string $tag_spec_name Tag spec name.
* @return array|null Reference point spec, or null if does not exist.
*/
public static function get_reference_point_spec( $tag_spec_name ) {
if ( isset( self::$reference_points[ $tag_spec_name ] ) ) {
return self::$reference_points[ $tag_spec_name ];
}
return null;
}
/**
* Get list of globally-allowed attributes.
*
Expand Down Expand Up @@ -258,6 +282,7 @@ def ParseRules(out_dir):

allowed_tags = {}
attr_lists = {}
reference_points = {}
versions = {}

specfile='%s/validator.protoascii' % out_dir
Expand Down Expand Up @@ -301,14 +326,15 @@ def ParseRules(out_dir):
if tag_spec.HasField('mandatory_parent') and tag_spec.mandatory_parent in mandatory_parent_blacklist and tag_spec.tag_name != 'HTML':
continue

# Ignore the special $REFERENCE_POINT tag
if '$REFERENCE_POINT' == tag_spec.tag_name:
continue

# Ignore deprecated tags
if tag_spec.HasField('deprecation'):
continue

# Handle the special $REFERENCE_POINT tag
if '$REFERENCE_POINT' == tag_spec.tag_name:
reference_points[ tag_spec.spec_name ] = GetTagSpec(tag_spec, attr_lists)
continue

# If we made it here, then start adding the tag_spec
if tag_spec.tag_name.lower() not in allowed_tags:
tag_list = []
Expand All @@ -322,7 +348,7 @@ def ParseRules(out_dir):
allowed_tags[UnicodeEscape(tag_spec.tag_name).lower()] = tag_list

logging.info('... done')
return allowed_tags, attr_lists, versions
return allowed_tags, attr_lists, reference_points, versions


def GetTagSpec(tag_spec, attr_lists):
Expand Down Expand Up @@ -400,6 +426,16 @@ def GetTagRules(tag_spec):
requires_extension_list.append(requires_extension)
tag_rules['requires_extension'] = requires_extension_list

if hasattr(tag_spec, 'reference_points') and len( tag_spec.reference_points ) != 0:
tag_reference_points = {}
for reference_point_spec in tag_spec.reference_points:
tag_reference_points[ reference_point_spec.tag_spec_name ] = {
"mandatory": reference_point_spec.mandatory,
"unique": reference_point_spec.unique
}
if len( tag_reference_points ) > 0:
tag_rules['reference_points'] = tag_reference_points

if hasattr(tag_spec, 'also_requires_tag_warning') and len( tag_spec.also_requires_tag_warning ) != 0:
also_requires_tag_warning_list = []
for also_requires_tag_warning in tag_spec.also_requires_tag_warning:
Expand Down
Loading

0 comments on commit c2a297c

Please sign in to comment.