Skip to content

Commit

Permalink
⬆️ Add support for Django v5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Dec 27, 2023
1 parent eca6df3 commit 6bc9cab
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 36 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
APP_VERSION=
GITHUB_REPOSITORY_URL=
SUPPORTED_VERSIONS=v1.8,v1.10,v1.11,v2,v2.1,v2.2,v3,v3.1,v3.2,v4,v4.1,v4.2
ALGOLIA_SEARCH_INDEX=
ALGOLIA_APPLICATION_ID=
ALGOLIA_SEARCH_ONLY_API_KEY=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ bin/*_cache/
sign.sh

.env

prefs.plist
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ Either press `⌘Y` to Quick Look the result, or press `<enter>` to open it in y
## Changing Branches

The workflow supports searching the documentation of all the currently officially supported branches.
By default, it searches the latest stable branch. To search branch `3.2` or `2.2` simply type `v3.2` or `v2.2` anywhere in your query, like so:
By default, it searches the latest stable branch. To search branch `4.2` or `3.2` simply type `v4.2` or `v3.2` anywhere in your query, like so:

```
dj v3.2 as_p
dj v4.2 as_p
```

### Note
Expand Down
26 changes: 17 additions & 9 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import 'package:alfred_workflow/alfred_workflow.dart'
AlfredItemText,
AlfredItems,
AlfredUpdater,
AlfredWorkflow;
AlfredUserConfigurationSelect,
AlfredWorkflow,
UserDefaults;
import 'package:alfred_workflow/src/models/alfred_user_configuration.dart';
import 'package:alfred_workflow/src/models/alfred_user_configuration_config.dart';
import 'package:algoliasearch/src/model/hit.dart';
import 'package:algoliasearch/src/model/search_response.dart';
import 'package:args/args.dart' show ArgParser, ArgResults;
import 'package:cli_script/cli_script.dart';
import 'package:collection/collection.dart' show IterableExtension;

import 'src/env/env.dart';
import 'src/extensions/string_helpers.dart';
Expand Down Expand Up @@ -46,15 +49,20 @@ void main(List<String> arguments) {

_verbose = args['verbose'];

final Map<String, AlfredUserConfiguration<AlfredUserConfigurationConfig>>?
userDefaults = await _workflow.getUserDefaults();

final AlfredUserConfigurationSelect? djangoVersion =
userDefaults?['django_version'] as AlfredUserConfigurationSelect?;

if (djangoVersion == null) {
throw Exception('django_version not set!');
}

List<String> query =
args['query'].replaceAll(RegExp(r'\s+'), ' ').trim().split(' ');
String? version =
query.firstWhereOrNull((el) => Env.supportedVersions.contains(el));
if (version != null) {
query.removeWhere((str) => str == version);
} else {
version = Env.supportedVersions.last;
}
final String version = djangoVersion.config.value;
query.removeWhere((str) => str == version);
final String queryString = query.join(' ').trim().toLowerCase();

if (_verbose) stdout.writeln('Query: "$queryString"');
Expand Down
2 changes: 1 addition & 1 deletion bin/main_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void _showPlaceholder() {
);
}

Future<void> _performSearch(String query, {String? version}) async {
Future<void> _performSearch(String query, {required String version}) async {
try {
final SearchResponse searchResponse = await AlgoliaSearch.query(
query,
Expand Down
5 changes: 0 additions & 5 deletions bin/src/env/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,4 @@ abstract class Env {

@EnviedField(varName: 'ALGOLIA_SEARCH_INDEX', obfuscate: true)
static final String algoliaSearchIndex = _Env.algoliaSearchIndex;

@EnviedField(varName: 'SUPPORTED_VERSIONS')
static const String _supportedVersions = _Env._supportedVersions;

static final List<String> supportedVersions = _supportedVersions.split(',');
}
4 changes: 2 additions & 2 deletions bin/src/services/algolia_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class AlgoliaSearch {

static Future<SearchResponse> query(
String queryString, {
String? version,
required String version,
}) =>
_client.searchIndex(
request: SearchForHits(
indexName: Env.algoliaSearchIndex,
query: queryString,
facetFilters: [
'version:${(version ?? Env.supportedVersions.last).replaceAll('v', '')}',
'version:${version.replaceAll('v', '')}',
],
attributesToRetrieve: SearchResult.attributesToRetrieve,
page: 0,
Expand Down
77 changes: 73 additions & 4 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>bundleid</key>
<string>org.techouse.alfred-django-docs</string>
<key>category</key>
<string>Internet</string>
<string>Tools</string>
<key>connections</key>
<dict>
<key>1B414F90-9594-4F84-8154-9FD8300D2FDB</key>
Expand Down Expand Up @@ -217,9 +217,78 @@
</dict>
</dict>
<key>userconfigurationconfig</key>
<array/>
<key>variablesdontexport</key>
<array/>
<array>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>v5</string>
<key>pairs</key>
<array>
<array>
<string>5.0</string>
<string>v5</string>
</array>
<array>
<string>4.2</string>
<string>v4.2</string>
</array>
<array>
<string>4.1</string>
<string>v4.1</string>
</array>
<array>
<string>4.0</string>
<string>v4</string>
</array>
<array>
<string>3.2</string>
<string>v3.2</string>
</array>
<array>
<string>3.1</string>
<string>v3.1</string>
</array>
<array>
<string>3.0</string>
<string>v3</string>
</array>
<array>
<string>2.2</string>
<string>v2.2</string>
</array>
<array>
<string>2.1</string>
<string>v2.1</string>
</array>
<array>
<string>2.0</string>
<string>v2</string>
</array>
<array>
<string>1.11</string>
<string>v1.11</string>
</array>
<array>
<string>1.10</string>
<string>v1.10</string>
</array>
<array>
<string>1.8</string>
<string>v1.8</string>
</array>
</array>
</dict>
<key>description</key>
<string>Searching the documentation of this Django version</string>
<key>label</key>
<string>Django version</string>
<key>type</key>
<string>popupbutton</string>
<key>variable</key>
<string>django_version</string>
</dict>
</array>
<key>version</key>
<string></string>
<key>webaddress</key>
Expand Down
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ packages:
dependency: "direct main"
description:
name: alfred_workflow
sha256: af5fdb2d4111cacc99023a44152db24e8c6f443c59a0b6ac034fc6c29c09f0ad
sha256: ab87f6d5ab708b73efd3f7fcb5376ade843725920b6d17ac4052a0b147fafc62
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.0"
algolia_client_core:
dependency: transitive
description:
Expand Down Expand Up @@ -525,18 +525,18 @@ packages:
dependency: transitive
description:
name: stash
sha256: "70a516b6d791fa760a9e58c4f01ac0230ca3be8d71d57fcec637996c7d4e463f"
sha256: "4858c547ba49cfd9a1964ff19cc087c682f20537147bad59ec54932d01de6a49"
url: "https://pub.dev"
source: hosted
version: "5.0.2"
version: "5.0.3"
stash_file:
dependency: transitive
description:
name: stash_file
sha256: dc90f076cef14d486e473e0156d6e256503e9193e8681b650d0e4e70c33210bd
sha256: "883314e8881f577acd0997fdb2982ae80df487698f3d5325e2d793124083381a"
url: "https://pub.dev"
source: hosted
version: "5.0.2"
version: "5.0.3"
stream_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -629,10 +629,10 @@ packages:
dependency: transitive
description:
name: web_socket_channel
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
sha256: "045ec2137c27bf1a32e6ffa0e734d532a6677bf9016a0d1a406c54e499ff945b"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
version: "2.4.1"
xml:
dependency: transitive
description:
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ description: Search the Django documentation using Alfred
# Prevent accidental publishing to pub.dev.
publish_to: 'none'

version: 2.1.11
version: 2.2.0

environment:
sdk: '>=3.2.0 <4.0.0'

dependencies:
algoliasearch: ^1.2.0
args: ^2.4.2
alfred_workflow: ^0.5.0
alfred_workflow: ^0.6.0
cli_script: ^1.0.0
envied: ^0.5.2
collection: ^1.18.0
json_annotation: ^4.8.1

dev_dependencies:
build_runner: ^2.4.6
build_runner: ^2.4.7
envied_generator: ^0.5.2
json_serializable: ^6.7.1
lints: ^3.0.0

0 comments on commit 6bc9cab

Please sign in to comment.