Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix API reference page is partly broken #11033

Merged
merged 7 commits into from
Dec 18, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions core/API/DocumentationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public function __construct()
*
* @param bool $outputExampleUrls
* @param string $prefixUrls
* @param bool $displayTitlesAsAngularDirective Set to false for the API ref doc at http://developer.piwik.org/api-reference/reporting-api where we need to display titles without using AngularJS
* @return string
*/
public function getAllInterfaceString($outputExampleUrls = true, $prefixUrls = '')
public function getAllInterfaceString($outputExampleUrls = true, $prefixUrls = '', $displayTitlesAsAngularDirective = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to either have a separate method for this, OR to rename it to something like "embedded or widgetized" and not that specific that will break over time and be misused over time. Ideally it was a separate method though or we would include angular wherever it is embedded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of calling the API directly maybe it could be built a widget maybe? not sure

{
if (!empty($prefixUrls)) {
$prefixUrls = 'http://demo.piwik.org/';
Expand Down Expand Up @@ -86,13 +87,19 @@ public function getAllInterfaceString($outputExampleUrls = true, $prefixUrls = '

foreach ($toDisplay as $moduleName => $methods) {
$toc .= $this->prepareModuleToDisplay($moduleName);
$str .= $this->prepareMethodToDisplay($moduleName, $info, $methods, $class, $outputExampleUrls, $prefixUrls);
$str .= $this->prepareMethodToDisplay($moduleName, $info, $methods, $class, $outputExampleUrls, $prefixUrls, $displayTitlesAsAngularDirective);
}
}

$str = "<div piwik-content-block content-title='Quick access to APIs' id='topApiRef' name='topApiRef'>
if($displayTitlesAsAngularDirective) {
$str = "<div piwik-content-block content-title='Quick access to APIs' id='topApiRef' name='topApiRef'>
$toc</div>
$str";
} else {
$str = "<h2 id='topApiRef' name='topApiRef'>Quick access to APIs</h2>
$toc
$str";
}

return $str;
}
Expand All @@ -102,10 +109,15 @@ public function prepareModuleToDisplay($moduleName)
return "<a href='#$moduleName'>$moduleName</a><br/>";
}

public function prepareMethodToDisplay($moduleName, $info, $methods, $class, $outputExampleUrls, $prefixUrls)
public function prepareMethodToDisplay($moduleName, $info, $methods, $class, $outputExampleUrls, $prefixUrls, $displayTitlesAsAngularDirective)
{
$str = '';
$str .= "\n<a name='$moduleName' id='$moduleName'></a><div piwik-content-block content-title='Module " . $moduleName . "'>";
$str .= "\n<a name='$moduleName' id='$moduleName'></a>";
if($displayTitlesAsAngularDirective) {
$str .= "<div piwik-content-block content-title='Module " . $moduleName . "'>";
} else {
$str .= "<h2>Module " . $moduleName . "</h2>";
}
$info['__documentation'] = $this->checkDocumentation($info['__documentation']);
$str .= "<div class='apiDescription'> " . $info['__documentation'] . " </div>";
foreach ($methods as $methodName) {
Expand All @@ -124,7 +136,11 @@ public function prepareMethodToDisplay($moduleName, $info, $methods, $class, $ou
$str .= "</div>\n";
}

return $str . "</div>";
if($displayTitlesAsAngularDirective) {
$str .= "</div>";
}

return $str;
}

public function prepareModulesAndMethods($info, $moduleName)
Expand Down
2 changes: 1 addition & 1 deletion plugins/API/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function index()
public function listAllMethods()
{
$ApiDocumentation = new DocumentationGenerator();
return $ApiDocumentation->getAllInterfaceString($outputExampleUrls = true, $prefixUrls = Common::getRequestVar('prefixUrl', ''));
return $ApiDocumentation->getAllInterfaceString($outputExampleUrls = true, $prefixUrls = Common::getRequestVar('prefixUrl', ''), $displayTitlesAsAngularDirective = false);
}

public function listAllAPI()
Expand Down