Showing the changes to docs/Filter-Reference.md (1 of 7 files). Show all
Unified · Split
| @@ -1,13 +1,11 @@ | ||
| 1 | −--- | |
| 2 | − | |
| 3 | 1 | **Table of contents:** |
| 4 | 2 | |
| 5 | −* [Overview](https://github.com/Thibaut/devdocs/wiki/Filter-Reference#overview) | |
| 6 | −* [Instance methods](https://github.com/Thibaut/devdocs/wiki/Filter-Reference#instance-methods) | |
| 7 | −* [Core filters](https://github.com/Thibaut/devdocs/wiki/Filter-Reference#core-filters) | |
| 8 | −* [Custom filters](https://github.com/Thibaut/devdocs/wiki/Filter-Reference#custom-filters) | |
| 9 | − - [CleanHtmlFilter](https://github.com/Thibaut/devdocs/wiki/Filter-Reference#cleanhtmlfilter) | |
| 10 | − - [EntriesFilter](https://github.com/Thibaut/devdocs/wiki/Filter-Reference#entriesfilter) | |
| 3 | +* [Overview](#overview) | |
| 4 | +* [Instance methods](#instance-methods) | |
| 5 | +* [Core filters](#core-filters) | |
| 6 | +* [Custom filters](#custom-filters) | |
| 7 | + - [CleanHtmlFilter](#cleanhtmlfilter) | |
| 8 | + - [EntriesFilter](#entriesfilter) | |
| 11 | 9 | |
| 12 | 10 | ## Overview |
| 13 | 11 | |
| @@ -25,52 +23,52 @@ module Docs · 11 unmodified lines | ||
| 25 | 23 | end |
| 26 | 24 | ``` |
| 27 | 25 | |
| 28 | −Filters which manipulate the Nokogiri node object (`doc` and related methods) are _HTML filters_ and must not manipulate the HTML string (`html`). Vice-versa, filters which manipulate the string representation of the document are _text filters_ and must not manipulate the Nokogiri node object. The two types are divided into two stacks within the scrapers. These stacks are then combined into a pipeline that calls the HTML filters before the text filters (more details [here](https://github.com/Thibaut/devdocs/wiki/Scraper-Reference#filter-stacks)). This is to avoid parsing the document multiple times. | |
| 26 | +Filters which manipulate the Nokogiri node object (`doc` and related methods) are _HTML filters_ and must not manipulate the HTML string (`html`). Vice-versa, filters which manipulate the string representation of the document are _text filters_ and must not manipulate the Nokogiri node object. The two types are divided into two stacks within the scrapers. These stacks are then combined into a pipeline that calls the HTML filters before the text filters (more details [here](./scraper-reference.md#filter-stacks)). This is to avoid parsing the document multiple times. | |
| 29 | 27 | |
| 30 | 28 | The `call` method must return either `doc` or `html`, depending on the type of filter. |
| 31 | 29 | |
| 32 | 30 | ## Instance methods |
| 33 | 31 | |
| 34 | −* `doc` [Nokogiri::XML::Node] | |
| 35 | − The Nokogiri representation of the container element. | |
| 32 | +* `doc` [Nokogiri::XML::Node] | |
| 33 | + The Nokogiri representation of the container element. | |
| 36 | 34 | See [Nokogiri's API docs](http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Node) for the list of available methods. |
| 37 | 35 | |
| 38 | −* `html` [String] | |
| 36 | +* `html` [String] | |
| 39 | 37 | The string representation of the container element. |
| 40 | − | |
| 41 | −* `context` [Hash] **(frozen)** | |
| 38 | + | |
| 39 | +* `context` [Hash] **(frozen)** | |
| 42 | 40 | The scraper's `options` along with a few additional keys: `:base_url`, `:root_url`, `:root_page` and `:url`. |
| 43 | 41 | |
| 44 | −* `result` [Hash] | |
| 45 | − Used to store the page's metadata and pass back information to the scraper. | |
| 42 | +* `result` [Hash] | |
| 43 | + Used to store the page's metadata and pass back information to the scraper. | |
| 46 | 44 | Possible keys: |
| 47 | − | |
| 45 | + | |
| 48 | 46 | - `:path` — the page's normalized path |
| 49 | 47 | - `:store_path` — the path where the page will be stored (equal to `:path` with `.html` at the end) |
| 50 | 48 | - `:internal_urls` — the list of distinct internal URLs found within the page |
| 51 | 49 | - `:entries` — the [`Entry`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/core/models/entry.rb) objects to add to the index |
| 52 | 50 | |
| 53 | −* `css`, `at_css`, `xpath`, `at_xpath` | |
| 51 | +* `css`, `at_css`, `xpath`, `at_xpath` | |
| 54 | 52 | Shortcuts for `doc.css`, `doc.xpath`, etc. |
| 55 | 53 | |
| 56 | −* `base_url`, `current_url`, `root_url` [Docs::URL] | |
| 54 | +* `base_url`, `current_url`, `root_url` [Docs::URL] | |
| 57 | 55 | Shortcuts for `context[:base_url]`, `context[:url]`, and `context[:root_url]` respectively. |
| 58 | − | |
| 59 | −* `root_path` [String] | |
| 56 | + | |
| 57 | +* `root_path` [String] | |
| 60 | 58 | Shortcut for `context[:root_path]`. |
| 61 | 59 | |
| 62 | −* `subpath` [String] | |
| 63 | − The sub-path from the base URL of the current URL. | |
| 60 | +* `subpath` [String] | |
| 61 | + The sub-path from the base URL of the current URL. | |
| 64 | 62 | _Example: if `base_url` equals `example.com/docs` and `current_url` equals `example.com/docs/file?raw`, the returned value is `/file`._ |
| 65 | 63 | |
| 66 | −* `slug` [String] | |
| 67 | − The `subpath` removed of any leading slash or `.html` extension. | |
| 64 | +* `slug` [String] | |
| 65 | + The `subpath` removed of any leading slash or `.html` extension. | |
| 68 | 66 | _Example: if `subpath` equals `/dir/file.html`, the returned value is `dir/file`._ |
| 69 | 67 | |
| 70 | −* `root_page?` [Boolean] | |
| 68 | +* `root_page?` [Boolean] | |
| 71 | 69 | Returns `true` if the current page is the root page. |
| 72 | 70 | |
| 73 | −* `initial_page?` [Boolean] | |
| 71 | +* `initial_page?` [Boolean] | |
| 74 | 72 | Returns `true` if the current page is the root page or its subpath is one of the scraper's `initial_paths`. |
| 75 | 73 | |
| 76 | 74 | ## Core filters |
| @@ -148,34 +146,34 @@ The following two models are used under the hood to represent the metadata: · 71 unmodified lines | ||
| 148 | 146 | |
| 149 | 147 | Each scraper must implement its own `EntriesFilter` by subclassing the [`Docs::EntriesFilter`](https://github.com/Thibaut/devdocs/blob/master/lib/docs/filters/core/entries.rb) class. The base class already implements the `call` method and includes four methods which the subclasses can override: |
| 150 | 148 | |
| 151 | −* `get_name` [String] | |
| 152 | − The name of the default entry (aka. the page's name). | |
| 153 | − It is usually guessed from the `slug` (documented above) or by searching the HTML markup. | |
| 149 | +* `get_name` [String] | |
| 150 | + The name of the default entry (aka. the page's name). | |
| 151 | + It is usually guessed from the `slug` (documented above) or by searching the HTML markup. | |
| 154 | 152 | **Default:** modified version of `slug` (underscores are replaced with spaces and forward slashes with dots) |
| 155 | 153 | |
| 156 | −* `get_type` [String] | |
| 157 | − The type of the default entry (aka. the page's type). | |
| 158 | − Entries without a type can be searched for but won't be listed in the app's sidebar (unless no other entries have a type). | |
| 154 | +* `get_type` [String] | |
| 155 | + The type of the default entry (aka. the page's type). | |
| 156 | + Entries without a type can be searched for but won't be listed in the app's sidebar (unless no other entries have a type). | |
| 159 | 157 | **Default:** `nil` |
| 160 | 158 | |
| 161 | −* `include_default_entry?` [Boolean] | |
| 162 | − Whether to include the default entry. | |
| 163 | − Used when a page consists of multiple entries (returned by `additional_entries`) but doesn't have a name/type of its own, or to remove a page from the index (if it has no additional entries), in which case it won't be copied on the local filesystem and any link to it in the other pages will be broken (as explained on the [Scraper Reference](https://github.com/Thibaut/devdocs/wiki/Scraper-Reference) page, this is used to keep the `:skip` / `:skip_patterns` options to a maintainable size, or if the page includes links that can't reached from anywhere else). | |
| 159 | +* `include_default_entry?` [Boolean] | |
| 160 | + Whether to include the default entry. | |
| 161 | + Used when a page consists of multiple entries (returned by `additional_entries`) but doesn't have a name/type of its own, or to remove a page from the index (if it has no additional entries), in which case it won't be copied on the local filesystem and any link to it in the other pages will be broken (as explained on the [Scraper Reference](./scraper-reference.md) page, this is used to keep the `:skip` / `:skip_patterns` options to a maintainable size, or if the page includes links that can't reached from anywhere else). | |
| 164 | 162 | **Default:** `true` |
| 165 | 163 | |
| 166 | −* `additional_entries` [Array] | |
| 167 | − The list of additional entries. | |
| 168 | − Each entry is represented by an Array of three attributes: its name, fragment identifier, and type. The fragment identifier refers to the `id` attribute of the HTML element (usually a heading) that the entry relates to. It is combined with the page's path to become the entry's path. If absent or `nil`, the page's path is used. If the type is absent or `nil`, the default `type` is used. | |
| 169 | − Example: `[ ['One'], ['Two', 'id'], ['Three', nil, 'type'] ]` adds three additional entries, the first one named "One" with the default path and type, the second one named "Two" with the URL fragment "#id" and the default type, and the third one named "Three" with the default path and the type "type". | |
| 170 | − The list is usually constructed by running through the markup. Exceptions can also be hard-coded for specific pages. | |
| 164 | +* `additional_entries` [Array] | |
| 165 | + The list of additional entries. | |
| 166 | + Each entry is represented by an Array of three attributes: its name, fragment identifier, and type. The fragment identifier refers to the `id` attribute of the HTML element (usually a heading) that the entry relates to. It is combined with the page's path to become the entry's path. If absent or `nil`, the page's path is used. If the type is absent or `nil`, the default `type` is used. | |
| 167 | + Example: `[ ['One'], ['Two', 'id'], ['Three', nil, 'type'] ]` adds three additional entries, the first one named "One" with the default path and type, the second one named "Two" with the URL fragment "#id" and the default type, and the third one named "Three" with the default path and the type "type". | |
| 168 | + The list is usually constructed by running through the markup. Exceptions can also be hard-coded for specific pages. | |
| 171 | 169 | **Default:** `[]` |
| 172 | 170 | |
| 173 | 171 | The following accessors are also available, but must not be overridden: |
| 174 | 172 | |
| 175 | −* `name` [String] | |
| 173 | +* `name` [String] | |
| 176 | 174 | Memoized version of `get_name` (`nil` for the root page). |
| 177 | 175 | |
| 178 | −* `type` [String] | |
| 176 | +* `type` [String] | |
| 179 | 177 | Memoized version of `get_type` (`nil` for the root page). |
| 180 | 178 | |
| 181 | 179 | **Notes:** |
| @@ -223,4 +221,4 @@ end · 41 unmodified lines | ||
| 223 | 221 | ``` |
| 224 | 222 | |
| 225 | 223 | |
| 226 | −return [[Home]] | |
| 224 | +return [[Home]] | |