├── .gitignore ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── pacapt ├── run ├── scripts ├── fetch └── generate ├── src ├── Info.plist ├── icon.png ├── index.rb ├── overrides.css └── setup.sql └── tmp ├── icon.png └── icon@2x.png /.gitignore: -------------------------------------------------------------------------------- 1 | _input 2 | _output 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'nokogiri' 4 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | mini_portile2 (2.1.0) 5 | nokogiri (1.7.1) 6 | mini_portile2 (~> 2.1.0) 7 | 8 | PLATFORMS 9 | ruby 10 | 11 | DEPENDENCIES 12 | nokogiri 13 | 14 | BUNDLED WITH 15 | 1.13.7 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Marcel Jackwerth 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kotlin-docset 2 | 3 | *kotlin-docset* is a docset for [Dash.app](http://kapeli.com/dash) 4 | containing the documentation for [Kotlin](http://kotlinlang.org). 5 | 6 | ## Prerequisites 7 | 8 | This docset only builds on *Mac OS X*, since it requires `tiffutil`. 9 | 10 | Install via *Homebrew* (`brew install ...`): 11 | 12 | - `wget` 13 | - `imagemagick` 14 | 15 | Install via *Bundler* (`bundle install`): 16 | 17 | - `nokogiri` 18 | 19 | ## Building the Docset 20 | 21 | The following command generates `Kotlin.docset` in the `_output` folder. 22 | 23 | ``` 24 | ./run 25 | ``` 26 | 27 | ## License 28 | 29 | This project is licensed under the terms of the MIT license. See the LICENSE file. 30 | -------------------------------------------------------------------------------- /pacapt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Purpose: A wrapper for all Unix package managers 4 | # License: Fair license (http://www.opensource.org/licenses/fair) 5 | # Source : http://github.com/icy/pacapt/ 6 | # Version: 2.2.7 7 | # Authors: Anh K. Huynh et al. 8 | 9 | # Copyright (C) 2010 - 2015 \ 10 | # | 10sr 11 | # | Alexander Dupuy 12 | # | Anh K. Huynh 13 | # | Arcterus 14 | # | Cuong Manh Le 15 | # | Daniel YC Lin 16 | # | Danny George 17 | # | Darshit Shah 18 | # | GijsTimmers 19 | # | Hà-Dương Nguyễn 20 | # | Huy Ngô 21 | # | James Pearson 22 | # | Janne Heß 23 | # | Karol Blazewicz 24 | # | Konrad Borowski 25 | # | Somasis 26 | # | Vojtech Letal 27 | # 28 | # Usage of the works is permitted provided that this instrument is 29 | # retained with the works, so that any entity that uses the works is 30 | # notified of this instrument. 31 | # 32 | # DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. 33 | # 34 | 35 | export PACAPT_VERSION='2.2.7' 36 | 37 | _help() { 38 | cat <<'EOF' 39 | NAME 40 | pacapt - An Arch's pacman-like package manager for some Unices. 41 | More details can be found at https://github.com/icy/pacapt . 42 | 43 | SYNTAX 44 | 45 | $ pacapt 46 | 47 | OPERATIONS 48 | 49 | Basic 50 | -h or --help print this help message 51 | -P print supported operations 52 | -V print version information 53 | 54 | Query 55 | -Q list all installed packages 56 | -Qc show package's changelog 57 | -Qi print package status 58 | -Ql list package's files 59 | -Qm list installed packages that aren't available 60 | in any installation source 61 | -Qo query package that provides 62 | -Qp query a package file (don't use package database) 63 | -Qs search for installed package 64 | 65 | Synchronize 66 | -S install package(s) 67 | -Ss search for packages 68 | -Su upgrade the system 69 | -Sy update package database 70 | -Suy update package database, then upgrade the system 71 | 72 | Remove / Clean up 73 | -R remove some packages 74 | -Sc delete old downloaded packages 75 | -Scc delete all downloaded packages 76 | -Sccc clean variant files. 77 | (debian) See also http://dragula.viettug.org/blogs/646 78 | 79 | OPTIONS 80 | 81 | -w download packages but don't install them 82 | 83 | EXAMPLES 84 | 85 | 1. To install a package from Debian's backports repository 86 | $ pacapt -S foobar -t lenny-backports 87 | $ pacapt -S -- -t lenny-backports foobar 88 | 89 | 2. To update package database and then update your system 90 | $ pacapt -Syu 91 | 92 | 3. To download a package without installing it 93 | $ pacapt -Sw foobar 94 | 95 | NOTES 96 | 97 | When being executed on Arch-based system, the tool simply invokes 98 | the system package manager (`/usr/bin/pacman`.) 99 | 100 | Though you can specify option by its own word, for example, 101 | $ pacapt -S -y -u 102 | 103 | it's always the best to combine them 104 | $ pacapt -Syu 105 | EOF 106 | 107 | } 108 | 109 | 110 | 111 | 112 | _error() { 113 | echo >&2 "Error: $*" 114 | return 1 115 | } 116 | 117 | _die() { 118 | echo >&2 "$@" 119 | exit 1 120 | } 121 | 122 | _not_implemented() { 123 | echo >&2 "${_PACMAN}: '${_POPT}:${_SOPT}:${_TOPT}' operation is invalid or not implemented." 124 | return 1 125 | } 126 | 127 | _removing_is_dangerous() { 128 | echo >&2 "${_PACMAN}: removing with '$*' is too dangerous" 129 | return 1 130 | } 131 | 132 | _issue2pacman() { 133 | local _pacman 134 | 135 | _pacman="$1"; shift 136 | 137 | # The following line is added by Daniel YC Lin to support SunOS. 138 | # 139 | # [ `uname` = "$1" ] && _PACMAN="$_pacman" && return 140 | # 141 | # This is quite tricky and fast, however I don't think it works 142 | # on Linux/BSD systems. To avoid extra check, I slightly modify 143 | # the code to make sure it's only applicable on SunOS. 144 | # 145 | [[ "$(uname)" == "SunOS" ]] && _PACMAN="$_pacman" && return 146 | 147 | $GREP -qis "$@" /etc/issue \ 148 | && _PACMAN="$_pacman" && return 149 | 150 | $GREP -qis "$@" /etc/os-release \ 151 | && _PACMAN="$_pacman" && return 152 | } 153 | 154 | _PACMAN_detect() { 155 | _issue2pacman sun_tools "SunOS" && return 156 | _issue2pacman pacman "Arch Linux" && return 157 | _issue2pacman dpkg "Debian GNU/Linux" && return 158 | _issue2pacman dpkg "Ubuntu" && return 159 | _issue2pacman cave "Exherbo Linux" && return 160 | _issue2pacman yum "CentOS" && return 161 | _issue2pacman yum "Red Hat" && return 162 | _issue2pacman yum "Fedora" && return 163 | _issue2pacman zypper "SUSE" && return 164 | _issue2pacman pkg_tools "OpenBSD" && return 165 | _issue2pacman pkg_tools "Bitrig" && return 166 | 167 | [[ -z "$_PACMAN" ]] || return 168 | 169 | # Prevent a loop when this script is installed on non-standard system 170 | if [[ -x "/usr/bin/pacman" ]]; then 171 | $GREP -q "$FUNCNAME" '/usr/bin/pacman' >/dev/null 2>&1 172 | [[ $? -ge 1 ]] && _PACMAN="pacman" \ 173 | && return 174 | fi 175 | 176 | [[ -x "/usr/bin/apt-get" ]] && _PACMAN="dpkg" && return 177 | [[ -x "/usr/bin/cave" ]] && _PACMAN="cave" && return 178 | [[ -x "/usr/bin/yum" ]] && _PACMAN="yum" && return 179 | [[ -x "/opt/local/bin/port" ]] && _PACMAN="macports" && return 180 | [[ -x "/usr/bin/emerge" ]] && _PACMAN="portage" && return 181 | [[ -x "/usr/bin/zypper" ]] && _PACMAN="zypper" && return 182 | [[ -x "/usr/sbin/pkg" ]] && _PACMAN="pkgng" && return 183 | # make sure pkg_add is after pkgng, FreeBSD base comes with it until converted 184 | [[ -x "/usr/sbin/pkg_add" ]] && _PACMAN="pkg_tools" && return 185 | [[ -x "/usr/sbin/pkgadd" ]] && _PACMAN="sun_tools" && return 186 | 187 | command -v brew >/dev/null && _PACMAN="homebrew" && return 188 | 189 | return 1 190 | } 191 | 192 | _translate_w() { 193 | 194 | echo "$_EOPT" | $GREP -q ":w:" || return 0 195 | 196 | local _opt= 197 | local _ret=0 198 | 199 | case "$_PACMAN" in 200 | "dpkg") _opt="-d";; 201 | "cave") _opt="-f";; 202 | "macports") _opt="fetch";; 203 | "portage") _opt="--fetchonly";; 204 | "zypper") _opt="--download-only";; 205 | "pkgng") _opt="fetch";; 206 | "yum") _opt="--downloadonly"; 207 | if ! rpm -q 'yum-downloadonly' >/dev/null 2>&1; then 208 | _error "'yum-downloadonly' package is required when '-w' is used." 209 | _ret=1 210 | fi 211 | ;; 212 | 213 | *) 214 | _opt="" 215 | _ret=1 216 | 217 | _error "$_PACMAN: Option '-w' is not supported/implemented." 218 | ;; 219 | esac 220 | 221 | echo $_opt 222 | return "$_ret" 223 | } 224 | 225 | _translate_debug() { 226 | echo "$_EOPT" | $GREP -q ":v:" || return 0 227 | 228 | echo "-v" 229 | } 230 | 231 | _translate_noconfirm() { 232 | 233 | echo "$_EOPT" | $GREP -q ":noconfirm:" || return 0 234 | 235 | local _opt= 236 | local _ret=0 237 | 238 | case "$_PACMAN" in 239 | # FIXME: Update environment DEBIAN_FRONTEND=noninteractive 240 | # FIXME: There is also --force-yes for a stronger case 241 | "dpkg") _opt="--yes";; 242 | "yum") _opt="--assumeyes";; 243 | # FIXME: pacman has 'assume-yes' and 'assume-no' 244 | # FIXME: zypper has better mode. Similar to dpkg (Debian). 245 | "zypper") _opt="--non-interactive";; 246 | "pkgng") _opt="-y";; 247 | *) 248 | _opt="" 249 | _ret=1 250 | _error "$_PACMAN: Option '--noconfirm' is not supported/implemented." 251 | ;; 252 | esac 253 | 254 | echo $_opt 255 | return $_ret 256 | } 257 | 258 | _translate_all() { 259 | local _args="" 260 | 261 | _args="$(_translate_w)" || return 1 262 | _args="${_args:+$_args }$(_translate_noconfirm)" || return 1 263 | _args="${_args:+$_args }$(_translate_debug)" || return 1 264 | 265 | export _EOPT="$_args" 266 | } 267 | 268 | _print_supported_operations() { 269 | local _pacman="$1" 270 | echo -n "pacapt: available operations:" 271 | $GREP -E "^${_pacman}_[^ \t]+\(\)" "$0" \ 272 | | $AWK -F '(' '{print $1}' \ 273 | | sed -e "s/${_pacman}_//g" \ 274 | | while read O; do 275 | echo -n " $O" 276 | done 277 | echo 278 | } 279 | 280 | _print_pacapt_version() { 281 | cat < Syy). 1664 | # 1665 | # See also 1666 | # 1667 | # * https://github.com/icy/pacapt/issues/13 1668 | # 1669 | # This implementation works, but with a bug. #Rsn works 1670 | # but #Rns is translated to #Rn (incorrectly.) 1671 | # Thanks Huy-Ngo for this nice catch. 1672 | # 1673 | # FIXME: Please check pacman(8) to see if they are really 2nd operation 1674 | # 1675 | s|l|i|p|o|m|n) 1676 | if [[ "$_SOPT" == '' ]]; then 1677 | _SOPT="$_opt" 1678 | continue 1679 | fi 1680 | 1681 | # Understand it: 1682 | # If there is already an option recorded, the incoming option 1683 | # will come and compare itself with known one. 1684 | # We have a table 1685 | # 1686 | # known one vs. incoming ? | result 1687 | # < | one-new 1688 | # = | one-one 1689 | # > | new-one 1690 | # 1691 | # Let's say, after this step, the 3rd option comes (named X), 1692 | # and the current result is "a-b". We have a table 1693 | # 1694 | # a(b) vs. X | result 1695 | # < | aX (b dropped) 1696 | # = | aa (b dropped) 1697 | # > | Xa (b dropped) 1698 | # 1699 | # In any case, the first one matters. 1700 | # 1701 | if [[ "${_SOPT:0:1}" < "$_opt" ]]; then 1702 | _SOPT="${_SOPT:0:1}$_opt" 1703 | elif [[ "${_SOPT:0:1}" == "$_opt" ]]; then 1704 | _SOPT="$_opt$_opt" 1705 | else 1706 | _SOPT="$_opt${_SOPT:0:1}" 1707 | fi 1708 | 1709 | ;; 1710 | 1711 | q) 1712 | _TOPT="$_opt" ;; # Thanks to James Pearson 1713 | 1714 | u) 1715 | if [[ "${_SOPT:0:1}" == "y" ]]; then 1716 | _SOPT="uy" 1717 | else 1718 | _SOPT="u" 1719 | fi 1720 | ;; 1721 | 1722 | y) 1723 | if [[ "${_SOPT:0:1}" == "u" ]]; then 1724 | _SOPT="uy" 1725 | else 1726 | _SOPT="y" 1727 | fi 1728 | ;; 1729 | 1730 | c) 1731 | if [[ "${_SOPT:0:2}" == "cc" ]]; then 1732 | _SOPT="ccc" 1733 | elif [[ "${_SOPT:0:1}" == "c" ]]; then 1734 | _SOPT="cc" 1735 | else 1736 | _SOPT="$_opt" 1737 | fi 1738 | ;; 1739 | 1740 | w|v) 1741 | _EOPT="$_EOPT:$_opt:" 1742 | ;; 1743 | 1744 | *) 1745 | # FIXME: If option is unknown, we will break the loop 1746 | # FIXME: and this option will be used by the native program. 1747 | # FIXME: break 2 1748 | _die "pacapt: Unknown option '$_opt'." 1749 | ;; 1750 | esac 1751 | done 1752 | 1753 | shift 1754 | 1755 | # If the primary option and the secondary are known 1756 | # we would break the argument detection, but for sure we will look 1757 | # forward to see there is anything interesting... 1758 | if [[ -n "$_POPT" && -n "$_SOPT" ]]; then 1759 | case "${1:-}" in 1760 | "-w"|"--noconfirm") ;; 1761 | *) break;; 1762 | esac 1763 | 1764 | # Don't have anything from the **first** argument. Something wrong. 1765 | # FIXME: This means that user must enter at least primary action 1766 | # FIXME: or secondary action in the very first part... 1767 | elif [[ -z "${_POPT}${_SOPT}${_TOPT}" ]]; then 1768 | break 1769 | fi 1770 | done 1771 | 1772 | [[ -n "$_POPT" ]] \ 1773 | || _die "Usage: pacapt # -h for help, -P list supported functions" 1774 | 1775 | _validate_operation "${_PACMAN}_${_POPT}${_SOPT}" \ 1776 | || { 1777 | _not_implemented 1778 | exit 1 1779 | } 1780 | 1781 | _translate_all || exit 1782 | 1783 | if [[ -n "$@" ]]; then 1784 | case "${_POPT}${_SOPT}" in 1785 | "Su"|"Sy"|"Suy") 1786 | echo 1>&2 "WARNING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 1787 | echo 1>&2 " The -Sy/u options refresh and/or upgrade all packages." 1788 | echo 1>&2 " To install packages as well, use separate commands:" 1789 | echo 1>&2 1790 | echo 1>&2 " $0 -S$_SOPT; $0 -S ${*}" 1791 | echo 1>&2 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 1792 | esac 1793 | fi 1794 | 1795 | if [[ -n "$PACAPT_DEBUG" ]]; then 1796 | echo "pacapt: $_PACMAN, p=$_POPT, s=$_SOPT, t=$_TOPT, e=$_EOPT" 1797 | echo "pacapt: execute '${_PACMAN}_${_POPT}${_SOPT} $_EOPT ${*}'" 1798 | declare -f "${_PACMAN}_${_POPT}${_SOPT}" 1799 | else 1800 | "_${_PACMAN}_init" 1801 | "${_PACMAN}_${_POPT}${_SOPT}" $_EOPT "$@" 1802 | fi 1803 | -------------------------------------------------------------------------------- /run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | ask() { 6 | read -p "Install '$1' now? [y/N] " -n 1 -r 7 | echo 8 | 9 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then 10 | echo "Exiting..." 11 | exit 1 12 | fi 13 | } 14 | 15 | install() { 16 | if [[ "$OSTYPE" == "darwin"* ]]; then 17 | if ! hash brew 2>/dev/null; then 18 | echo "Please install homebrew from http://brew.sh/ first" 19 | exit 1 20 | fi 21 | fi 22 | 23 | echo "Installing $1..." 24 | ./pacapt -S $1 25 | } 26 | 27 | check() { 28 | if ! hash $1 2>/dev/null; then 29 | echo "Couldn't find dependency: $1" 30 | ask ${2:-$1} 31 | install ${2:-$1} 32 | fi 33 | } 34 | 35 | install_gem() { 36 | echo "Installing ruby gem '$1'..." 37 | if ! gem install $1; then 38 | echo "Installing ruby gem '$1' failed... Try: sudo gem install $1" 39 | exit 1 40 | fi 41 | } 42 | 43 | check_gem() { 44 | if ! ruby -e "require '$1'" 2>/dev/null; then 45 | echo "Couldn't find ruby gem dependency: $1" 46 | ask ${2:-$1} 47 | install_gem ${2:-$1} 48 | fi 49 | } 50 | 51 | check wget 52 | check convert imagemagick 53 | check_gem bundler 54 | bundle install 55 | 56 | echo "Fetching data..." 57 | ./scripts/fetch 58 | 59 | echo "Generating docset..." 60 | ./scripts/generate 61 | -------------------------------------------------------------------------------- /scripts/fetch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | mkdir -p _input 6 | cd _input 7 | 8 | FILES=( 9 | "_assets/default.js" 10 | "_assets/common.js" 11 | "_assets/common.css" 12 | "_assets/styles.css" 13 | ) 14 | 15 | for f in ${FILES[@]} 16 | do 17 | dir=`dirname $f` 18 | mkdir -p $dir 19 | wget -O $f http://kotlinlang.org/$f 20 | done 21 | 22 | set +e 23 | wget --mirror -k -nH http://kotlinlang.org/docs/reference/ 24 | wget_status=$? 25 | set -e 26 | 27 | if [ $wget_status -eq 8 ]; then 28 | # https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html 29 | echo "wget partially failed (exit status $wget_status)... continuing." 30 | elif [ $wget_status -ne 0 ]; then 31 | echo "wget failed (exit status $wget_status)" 32 | exit 1 33 | fi 34 | 35 | if [ ! -d _javadoc ]; then 36 | wget -O - https://github.com/JetBrains/kotlin/archive/gh-pages.zip | bsdtar -xvf- 37 | mv kotlin-gh-pages _javadoc 38 | fi 39 | -------------------------------------------------------------------------------- /scripts/generate: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | ROOT=_output/Kotlin.docset 6 | RESOURCES=$ROOT/Contents/Resources 7 | 8 | rm -rf $ROOT 9 | mkdir -p $RESOURCES 10 | 11 | cp src/Info.plist $ROOT/Contents/ 12 | cp -r _input $RESOURCES/Documents 13 | cat src/overrides.css >> $RESOURCES/Documents/_assets/styles.css 14 | cat src/overrides.css >> $RESOURCES/Documents/_assets/common.css 15 | 16 | mkdir -p _tmp 17 | 18 | if hash tiffutil 2>/dev/null; then 19 | convert src/icon.png -resize 16x16 _tmp/icon.png 20 | convert src/icon.png -resize 32x32 _tmp/icon@2x.png 21 | tiffutil -cathidpicheck _tmp/icon.png _tmp/icon@2x.png -out $ROOT/icon.tiff 22 | fi 23 | 24 | cat src/setup.sql | sqlite3 $RESOURCES/docSet.dsidx 25 | 26 | pushd _input 27 | find . -name \*\.html | xargs -n1 -P4 ruby ../src/index.rb | sqlite3 ../$RESOURCES/docSet.dsidx 28 | popd 29 | 30 | pushd _output 31 | 32 | rm -f Kotlin.tgz 33 | 34 | tar \ 35 | --exclude 'tutorials.*' \ 36 | --exclude 'apple-touch-*.png' \ 37 | --exclude='.DS_Store' \ 38 | -cvzf Kotlin.tgz \ 39 | Kotlin.docset 40 | popd 41 | 42 | if [ ! -f $ROOT/icon.tiff ]; then 43 | echo "Warning: Couldn't generate icon.tiff for retina display support!" 44 | echo "Do NOT submit this to https://github.com/Kapeli/Dash-User-Contributions" 45 | exit 1 46 | fi 47 | -------------------------------------------------------------------------------- /src/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIdentifier 6 | kotlin 7 | CFBundleName 8 | Kotlin 9 | DocSetPlatformFamily 10 | kotlin 11 | dashIndexFilePath 12 | /docs/reference/index.html 13 | isDashDocset 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrcljx/kotlin-docset/f198b8d9c9fb8a08451abe9c90ca9529602055cb/src/icon.png -------------------------------------------------------------------------------- /src/index.rb: -------------------------------------------------------------------------------- 1 | # rubocop:disable Metrics/AbcSize 2 | # rubocop:disable Metrics/LineLength 3 | # rubocop:disable Metrics/MethodLength 4 | # rubocop:disable Metrics/CyclomaticComplexity 5 | require 'bundler' 6 | Bundler.require 7 | 8 | # Object.try from Rails 9 | class Object 10 | def try(*a, &b) 11 | if a.empty? && block_given? 12 | yield self 13 | elsif !nil? 14 | __send__(*a, &b) 15 | end 16 | end 17 | end 18 | 19 | # Extracts info from page 20 | class Parser 21 | def initialize 22 | @file_name = ARGV.first 23 | end 24 | 25 | attr_reader :file_name 26 | 27 | def doc 28 | @doc ||= Nokogiri::HTML(ARGF.read) 29 | end 30 | 31 | def title 32 | @title ||= (doc.css('article[role=main] h1').first.try(:content) || '').strip 33 | end 34 | 35 | def meta 36 | @meta ||= (doc.css('article[role=main] .signature code').first.try(:content) || '').strip 37 | end 38 | 39 | def type 40 | @type ||= begin 41 | return 'Constructor' if title == '' 42 | case meta 43 | when /\bannotation class\b/ then 'Annotation' 44 | when /\benum class\b/ then 'Enum' 45 | when /\bclass\b/ then meta.end_with?('Exception') ? 'Exception' : 'Class' 46 | when /\binterface\b/ then 'Interface' 47 | when /\bobject\b/ then 'Object' 48 | when /\btypealias\b/ then 'Type' 49 | when /\bfun\b/ then 'Method' 50 | when /\bva[rl]\b/ then 'Property' 51 | else 52 | 'Element' if /^[A-Z0-9_]+$/ =~ title 53 | end 54 | end || 'Guide' 55 | end 56 | 57 | def url 58 | "https://kotlinlang.org/#{file_name[2..-1]}" 59 | end 60 | 61 | def to_sql 62 | if title.empty? 63 | $stderr.puts [url, 'SKIPPED', ' '].join("\n") 64 | else 65 | result = "#{type.upcase} | #{title}" 66 | $stderr.puts [url, meta, result, ' '].join("\n") 67 | "INSERT INTO searchIndex VALUES (NULL, '#{title}', '#{type}', '#{file_name}');" 68 | end 69 | rescue 70 | $stderr.puts "Processing #{url} --> ERROR" 71 | raise 72 | end 73 | end 74 | 75 | parser = Parser.new 76 | puts parser.to_sql 77 | -------------------------------------------------------------------------------- /src/overrides.css: -------------------------------------------------------------------------------- 1 | /* 2 | Dash DocSet Overrides 3 | */ 4 | 5 | article, .g-layout { 6 | width: auto !important; 7 | } 8 | 9 | .g-layout { 10 | padding: 20px !important; 11 | } 12 | 13 | header, footer, aside, nav, .global-layout:after, .page-link-to-github { 14 | display: none !important; 15 | } 16 | -------------------------------------------------------------------------------- /src/setup.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT); 2 | CREATE UNIQUE INDEX IF NOT EXISTS anchor ON searchIndex (name, type, path); 3 | -------------------------------------------------------------------------------- /tmp/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrcljx/kotlin-docset/f198b8d9c9fb8a08451abe9c90ca9529602055cb/tmp/icon.png -------------------------------------------------------------------------------- /tmp/icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrcljx/kotlin-docset/f198b8d9c9fb8a08451abe9c90ca9529602055cb/tmp/icon@2x.png --------------------------------------------------------------------------------