Skip to content

Commit

Permalink
first commit, moved from dash-docsets repo
Browse files Browse the repository at this point in the history
  • Loading branch information
godbout committed Jul 23, 2020
0 parents commit 100b627
Show file tree
Hide file tree
Showing 499 changed files with 42,332 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/vendor

.DS_Store

.phpunit.result.cache
.php_cs.cache

/storage/*/*.docset
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Guillaume Leclerc <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h1 align="center">Alfred Dash Docset</h1>

<p align="center">
<a href="https://travis-ci.com/godbout/alfred-dash-docset"><img src="https://img.shields.io/travis/com/godbout/alfred-dash-docset/master.svg?style=flat-square" alt="Build Status"></a>
<a href="https://scrutinizer-ci.com/g/godbout/alfred-dash-docset"><img src="https://img.shields.io/scrutinizer/g/godbout/alfred-dash-docset.svg?style=flat-square" alt="Quality Score"></a>
<a href="https://scrutinizer-ci.com/g/godbout/alfred-dash-docset"><img src="https://scrutinizer-ci.com/g/godbout/alfred-dash-docset/badges/coverage.png?b=master" alt="Code Coverage"></a>
</p>

<p align="center">
<a href="https://kapeli.com/dash">Dash</a> <a href="https://kapeli.com/docsets">Docsets</a> created with the lovely—not biased here—<a href="https://github.com/godbout/dash-docset-builder">Dash Docset Builder</a> in PHP.
</p>

___

## Docsets born here, sorted by eldest first

* [Laravel-Zero](https://laravel-zero.com/docs/introduction/)
* [Jigsaw by Tighten](https://jigsaw.tighten.co/docs/installation/)
* [Tailwind CSS](https://tailwindcss.com/docs/installation/)
* [Tiki](https://doc.tiki.org/All-the-Documentation)
* ~~[Stripe](https://stripe.com/docs)~~[DECEASED](https://github.com/godbout/dash-docset-builder/tree/stripe/storage/stripe)
* ~~[Stripe API](https://stripe.com/docs/api)~~[DECEASED](https://github.com/godbout/dash-docset-builder/tree/stripe-api/storage/stripe-api)
* [Ploi API](https://developers.ploi.io/)
* [Bulma](https://https://bulma.io/)
* [Alfred 4](https://www.alfredapp.com/)
173 changes: 173 additions & 0 deletions app/Docsets/Alfred4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php

namespace App\Docsets;

use Godbout\DashDocsetBuilder\Docsets\BaseDocset;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Wa72\HtmlPageDom\HtmlPageCrawler;

class Alfred4 extends BaseDocset
{
public const CODE = 'alfred-4';
public const NAME = 'Alfred 4';
public const URL = 'www.alfredapp.com';
public const INDEX = 'help/index.html';
public const PLAYGROUND = '';
public const ICON_16 = '../../icons/icon.png';
public const ICON_32 = '../../icons/[email protected]';
public const EXTERNAL_DOMAINS = [
'fonts.googleapis.com',
];


public function grab(): bool
{
$toGet = implode('|', [
'\.css',
'\.ico',
'\.js',
'\.png',
'\.svg',
'/css',
'/help'
]);

system(
"echo; wget www.alfredapp.com/help \
--mirror \
--trust-server-names \
--accept-regex='{$toGet}' \
--ignore-case \
--page-requisites \
--adjust-extension \
--convert-links \
--span-hosts \
--domains={$this->externalDomains()} \
--directory-prefix=storage/{$this->downloadedDirectory()} \
-e robots=off \
--quiet \
--show-progress",
$result
);

return $result === 0;
}

public function entries(string $file): Collection
{
$crawler = HtmlPageCrawler::create(Storage::get($file));

$entries = collect();
$entries = $entries->merge($this->guideEntries($crawler, $file));
$entries = $entries->merge($this->sectionEntries($crawler, $file));

return $entries;
}

protected function guideEntries(HtmlPageCrawler $crawler, string $file)
{
$entries = collect();

if (Str::contains($file, $this->index())) {
$crawler->filter('#helpmenu a')->each(function (HtmlPageCrawler $node) use ($entries) {
$entries->push([
'name' => trim($node->text()),
'type' => 'Guide',
'path' => $this->url() . '/help/' . $node->attr('href'),
]);
});
}

return $entries;
}

protected function sectionEntries(HtmlPageCrawler $crawler, string $file)
{
$entries = collect();

$crawler->filter('h1:not(:first-child), h2')->each(function (HtmlPageCrawler $node) use ($entries, $file) {
$entries->push([
'name' => trim($node->text()),
'type' => 'Section',
'path' => Str::after($file, $this->innerDirectory())
]);
});

return $entries;
}

public function format(string $file): string
{
$crawler = HtmlPageCrawler::create(Storage::get($file));

$this->removeMainNav($crawler);
$this->removeSubNav($crawler);
$this->removeHelpMenu($crawler);
$this->removeLatestBlogPostBanner($crawler);
$this->removeFooter($crawler);
$this->removeFooterMeta($crawler);

$this->removeUnwantedJavaScript($crawler);

$this->insertOnlineRedirection($crawler, $file);
$this->insertDashTableOfContents($crawler);

return $crawler->saveHTML();
}

protected function removeMainNav(HtmlPageCrawler $crawler)
{
$crawler->filter('#mainnav')->remove();
}

protected function removeSubNav(HtmlPageCrawler $crawler)
{
$crawler->filter('#subnav')->remove();
}

protected function removeHelpMenu(HtmlPageCrawler $crawler)
{
$crawler->filter('#helpmenu')->remove();
}

protected function removeLatestBlogPostBanner(HtmlPageCrawler $crawler)
{
$crawler->filter('#latestblogpost')->remove();
}

protected function removeFooter(HtmlPageCrawler $crawler)
{
$crawler->filter('#footer')->remove();
}

protected function removeFooterMeta(HtmlPageCrawler $crawler)
{
$crawler->filter('#footermeta')->remove();
}

protected function removeUnwantedJavaScript(HtmlPageCrawler $crawler)
{
$crawler->filterXPath("//script[text()[contains(.,'google-analytics.com')]]")->remove();
}

protected function insertOnlineRedirection(HtmlPageCrawler $crawler, string $file)
{
$onlineUrl = Str::substr(Str::after($file, $this->innerDirectory()), 1, -11);

$crawler->filter('html')->prepend("<!-- Online page at $onlineUrl -->");
}

protected function insertDashTableOfContents($crawler)
{
$crawler->filter('head')
->before('<a name="//apple_ref/cpp/Section/Top" class="dashAnchor"></a>');

$crawler->filter('h1:not(:first-child), h2, h3')->each(static function (HtmlPageCrawler $node) {
$node->before(
'<a id="' . Str::slug($node->text()) . '" name="//apple_ref/cpp/Section/' . rawurlencode($node->text()) . '" class="dashAnchor"></a>'
);
});
}
}
57 changes: 57 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "godbout/dash-docsets",
"description": "Dash Docsets built with Dash Docset Builder.",
"keywords": [
"dash",
"docset",
"docsets",
"builder",
"build",
"offline",
"documentation",
"PHP",
"love"
],
"homepage": "https://github.com/godbout/dash-docsets",
"type": "project",
"license": "MIT",
"support": {
"issues": "https://github.com/godbout/dash-docset/issues",
"source": "https://github.com/godbout/dash-docset"
},
"authors": [
{
"name": "Guillaume Leclerc",
"email": "[email protected]"
}
],
"require": {
"godbout/dash-docset-builder": "^1.0"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"require-dev": {
"codedungeon/phpunit-result-printer": "^0.27",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^8"
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"scripts": {
"test": "phpunit --group=default,download,tailwindcss,laravel-zero,jigsaw,tiki,ploi,bulma,alfred4 --color=always",
"format": "php-cs-fixer fix -vvv --config=.php_cs.dist --ansi"
},
"minimum-stability": "dev",
"prefer-stable": true
}
Loading

0 comments on commit 100b627

Please sign in to comment.