mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Hack is Facebook's dialect of PHP: http://hacklang.org/. This adds support for detecting it via the ".hh" file extension; although that extension techincally conflicts with C++ headers, the files look different enough that the existing classifier based on sample code has no trouble distinguising them. This diff deliberately does not deal with detecting ".php" as another valid extension for Hack code. That's much trickier since the code looks basically identical to PHP to the classifier, and needs a different approach.
105 lines
2.6 KiB
C++
105 lines
2.6 KiB
C++
<?hh // strict
|
|
/**
|
|
* Copyright (c) 2014, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/hhvm/xhp/src/init.php';
|
|
|
|
type NavItem = shape(
|
|
'name' => string,
|
|
'location' => string,
|
|
);
|
|
|
|
type NavSection = shape(
|
|
'name' => string,
|
|
'location' => ?string,
|
|
'items' => Vector<NavItem>,
|
|
);
|
|
|
|
final class :hack:nav extends :x:element {
|
|
private function getNavSections(): Vector<NavSection> {
|
|
return Vector{
|
|
shape(
|
|
'name' => 'Home',
|
|
'location' => '/',
|
|
'items' => Vector {},
|
|
),
|
|
shape(
|
|
'name' => 'GitHub',
|
|
'location' => 'http://github.com/facebook/hack-example-site',
|
|
'items' => Vector {},
|
|
),
|
|
shape(
|
|
'name' => 'Recipes',
|
|
'location' => null,
|
|
'items' => Vector {
|
|
shape(
|
|
'name' => '$_GET and $_POST',
|
|
'location' => '/recipes/get-and-post/',
|
|
),
|
|
shape(
|
|
'name' => 'Assert',
|
|
'location' => '/recipes/assert/',
|
|
),
|
|
shape(
|
|
'name' => 'DB Result',
|
|
'location' => '/recipes/db-result/',
|
|
),
|
|
shape(
|
|
'name' => 'Unescaped String',
|
|
'location' => '/recipes/unescaped-string/',
|
|
),
|
|
shape(
|
|
'name' => 'User ID',
|
|
'location' => '/recipes/user-id/',
|
|
),
|
|
},
|
|
),
|
|
};
|
|
}
|
|
|
|
private function renderNavItems(Vector<NavItem> $items): :xhp {
|
|
$render_item = $item ==>
|
|
<li>
|
|
<a class="navItem" href={$item['location']}>
|
|
{$item['name']}
|
|
</a>
|
|
</li>;
|
|
return
|
|
<x:frag>
|
|
{$items->map($render_item)->toArray()}
|
|
</x:frag>;
|
|
}
|
|
|
|
private function renderNavSection(NavSection $section): :xhp {
|
|
$section_item = <h3 class="navItem">{$section['name']}</h3>;
|
|
if ($section['location'] !== null) {
|
|
$section_item = <a href={$section['location']}>{$section_item}</a>;
|
|
}
|
|
return
|
|
<li class="navSectionItem">
|
|
{$section_item}
|
|
<ul class="navItems">
|
|
{$this->renderNavItems($section['items'])}
|
|
</ul>
|
|
</li>;
|
|
}
|
|
|
|
public function render(): :xhp {
|
|
$sections = $this->getNavSections()
|
|
->map($section ==> $this->renderNavSection($section));
|
|
return
|
|
<div class="nav">
|
|
<ul class="navSections">
|
|
{$sections->toArray()}
|
|
</ul>
|
|
</div>;
|
|
}
|
|
}
|