Skip to content

Commit

Permalink
Fix a few 11ty errors and formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough committed Jan 21, 2024
1 parent e0097ba commit fe25a0e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .eleventyignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**/README.md
**/_readme.md
**/_shared
**/_*
56 changes: 23 additions & 33 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import * as sass from 'sass';
* @param {EleventyConfig} eleventyConfig
*/
export default function (eleventyConfig) {
const isProduction = process.env.PRODUCTION === 'true';

eleventyConfig.on('eleventy.before', async () => {
await configureHighlighting(markdown);
});

eleventyConfig.addGlobalData('isProduction', _isProduction());
eleventyConfig.addGlobalData('isProduction', isProduction);

eleventyConfig.setLibrary('md', markdown);

Expand All @@ -39,8 +41,6 @@ export default function (eleventyConfig) {
lenientIf: true
});

eleventyConfig.addTemplateFormats('scss');

eleventyConfig.addFilter('regex_replace', regexReplace);
eleventyConfig.addFilter('toISOString', toISOString);
eleventyConfig.addFilter('active_nav_entry_index_array', activeNavEntryIndexArray);
Expand All @@ -50,35 +50,29 @@ export default function (eleventyConfig) {
eleventyConfig.addAsyncFilter('generate_toc', generateToc);
eleventyConfig.addFilter('breadcrumbsForPage', breadcrumbsForPage);

eleventyConfig.addTemplateFormats('scss');
eleventyConfig.addExtension('scss', {
read: false,
getData: async function (inputPath) {
const data = {
eleventyExcludeFromCollections: true
};

if (path.basename(inputPath).startsWith('_')) {
return data;
outputFileExtension: 'css',
compile: function (inputContent, inputPath) {
const parsedPath = path.parse(inputPath);
if (parsedPath.name.startsWith('_')) {
return;
}
const { css } = sass.compile(inputPath, {
style: _isProduction() ? 'compressed' : 'expanded',
sourceMap: !_isProduction(),

const result = sass.compileString(inputContent, {
style: isProduction ? 'compressed' : 'expanded',
quietDeps: true,
loadPaths: [parsedPath.dir, '_sass'],
});
data._content = css;
return data;
},
compileOptions: {
cache: !_isProduction(),
permalink: function (permalink, inputPath) {
if (path.basename(inputPath).startsWith('_')) {
return false;
}

return data => `${data.page.filePathStem}.css`;
}

const dependencies = result.loadedUrls
.filter(loadedUrl => loadedUrl.protocol === 'file:' && loadedUrl.pathname !== '')
.map(url => path.relative('.', url.pathname));

this.addDependencies(inputPath, dependencies);

return () => result.css;
},
compile: () => data => data._content
});

eleventyConfig.addPassthroughCopy('src/assets/dash');
Expand All @@ -88,7 +82,7 @@ export default function (eleventyConfig) {
eleventyConfig.addPassthroughCopy('src/f', {expand: true, filter: /^(?!_).+/});
eleventyConfig.addPassthroughCopy('src/guides/language/specifications');

if (_isProduction()) {
if (isProduction) {
// If building for production, minify/optimize the HTML output.
// Doing so during serving isn't worth the extra build time.
eleventyConfig.addTransform('minify-html', async function (content) {
Expand All @@ -108,7 +102,7 @@ export default function (eleventyConfig) {
}

eleventyConfig.setQuietMode(true);

eleventyConfig.setServerOptions({
port: 4000,
});
Expand All @@ -122,7 +116,3 @@ export default function (eleventyConfig) {
}
}
};

function _isProduction() {
return process.env.PRODUCTION === 'true'
}
1 change: 1 addition & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
{ "source": "/guides/language/library-tour", "destination": "/libraries", "type": 301 },
{ "source": "/guides/language/sound-dart", "destination": "/language/type-system", "type": 301 },
{ "source": "/guides/language/sound-faq", "destination": "/language/type-system", "type": 301 },
{ "source": "/guides/language/specifications/DartLangSpec-v2.2.pdf", "destination": "https://github.com/dart-lang/site-www/blob/a7f170389e210adc2aef810cc9a6fdbfa78059a5/src/guides/language/specifications/DartLangSpec-v2.2.pdf", "type": 301 },
{ "source": "/guides/language/type-system", "destination": "/language/type-system", "type": 301 },
{ "source": "/guides/libraries", "destination": "/libraries", "type": 301 },
{ "source": "/guides/libraries/create-library-packages", "destination": "/guides/libraries/create-packages", "type": 301 },
Expand Down
4 changes: 4 additions & 0 deletions src/assets/css/main.scss
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
---
layout: none
---

@forward '../../_sass/site';
Binary file not shown.
120 changes: 64 additions & 56 deletions src/interop/c-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,62 +102,70 @@ illustrates the steps for using `dart:ffi` to call a C function:

Here's the code for each step.

1. Import `dart:ffi`.
```dart
import 'dart:ffi' as ffi;
```

2. Import the path library that you'll use to store the path of dynamic library.
```dart
import 'dart:io' show Platform, Directory;
import 'package:path/path.dart' as path;
```

3. Create a typedef with the FFI type signature of the C function. <br>
See [Interfacing with native types](#interfacing-with-native-types)
for commonly used types defined by `dart:ffi` library.
```dart
typedef hello_world_func = ffi.Void Function();
```

4. Create a typedef for the variable that you'll use
when calling the C function.
```dart
typedef HelloWorld = void Function();
```

5. Create a variable to store the path of the dynamic library.
```dart
var libraryPath = path.join(Directory.current.path, 'hello_library',
'libhello.so');
if (Platform.isMacOS) {
libraryPath = path.join(Directory.current.path, 'hello_library',
'libhello.dylib');
} else if (Platform.isWindows) {
libraryPath = path.join(Directory.current.path, 'hello_library',
'Debug', 'hello.dll');
}
```

6. Open the dynamic library that contains the C function.
```dart
final dylib = ffi.DynamicLibrary.open(libraryPath);
```

7. Get a reference to the C function,
and put it into a variable.
This code uses the typedefs defined in steps 2 and 3,
along with the dynamic library variable from step 4.
```dart
final HelloWorld hello = dylib
.lookup<ffi.NativeFunction<hello_world_func>>('hello_world')
.asFunction();
```

8. Call the C function.
```dart
hello();
```
1. Import `dart:ffi`.

```dart
import 'dart:ffi' as ffi;
```
2. Import the path library that you'll use to store the path of dynamic library.
```dart
import 'dart:io' show Platform, Directory;
import 'package:path/path.dart' as path;
```
3. Create a typedef with the FFI type signature of the C function. <br>
See [Interfacing with native types](#interfacing-with-native-types)
for commonly used types defined by `dart:ffi` library.
```dart
typedef hello_world_func = ffi.Void Function();
```
4. Create a typedef for the variable that you'll use
when calling the C function.
```dart
typedef HelloWorld = void Function();
```
5. Create a variable to store the path of the dynamic library.
```dart
var libraryPath = path.join(Directory.current.path, 'hello_library',
'libhello.so');
if (Platform.isMacOS) {
libraryPath = path.join(Directory.current.path, 'hello_library',
'libhello.dylib');
} else if (Platform.isWindows) {
libraryPath = path.join(Directory.current.path, 'hello_library',
'Debug', 'hello.dll');
}
```
6. Open the dynamic library that contains the C function.
```dart
final dylib = ffi.DynamicLibrary.open(libraryPath);
```
7. Get a reference to the C function,
and put it into a variable.
This code uses the typedefs defined in steps 2 and 3,
along with the dynamic library variable from step 4.
```dart
final HelloWorld hello = dylib
.lookup<ffi.NativeFunction<hello_world_func>>('hello_world')
.asFunction();
```
8. Call the C function.
```dart
hello();
```
Once you understand the hello_world example,
you should be ready to look at the
Expand Down

0 comments on commit fe25a0e

Please sign in to comment.