Skip to content

Commit

Permalink
Add partial support for sass
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck authored and josephfrazier committed Mar 21, 2017
1 parent 647f409 commit 5348299
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ OctoLinker is the easiest and best way to navigate between files and projects on
### CSS
- `@import`

### Sass
- `@import`

### HTML
- `<link rel="import" href="...">`

Expand Down Expand Up @@ -125,7 +128,7 @@ Show your support to our open source project. Your donation will help us to cove

- [Buy OctoLinker stickers](https://www.stickermule.com/marketplace/16611-the-official-logo)
- [Donate with PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WSXA9GCDRMX7W)
- [Become a backer or sponsor](https://opencollective.com/octolinker)
- [Become a backer or sponsor](https://opencollective.com/octolinker)

# Legal and License

Expand Down
8 changes: 8 additions & 0 deletions lib/pattern-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export const presets = {
],
},

sass: {
pathSubstrings: ['.scss', '.sass'],
githubClasses: [
'type-sass',
'highlight-source-sass',
],
},

html: {
pathSubstrings: [
'.html',
Expand Down
31 changes: 31 additions & 0 deletions lib/plugins/sass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { join } from 'path';
import pathParse from 'path-parse';
import { CSS_IMPORT } from '../../packages/helper-grammar-regex-collection/index.js';
import insertLink from '../insert-link';
import preset from '../pattern-preset';
import relativeFile from '../resolver/relative-file.js';

export default class Sass {

static resolve({ path, target }) {
const { dir, name } = pathParse(target);
const prefixedTarget = join(dir, `_${name}`);

return [
relativeFile({ path, target: `${prefixedTarget}.scss` }),
relativeFile({ path, target: `${prefixedTarget}.sass` }),
];
}

getPattern() {
return preset('sass');
}

parseBlob(blob) {
insertLink(blob.el, CSS_IMPORT, {
pluginName: this.constructor.name,
target: '$1',
path: blob.path,
});
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"github-url-from-username-repo": "^1.0.2",
"giturl": "^1.0.0",
"jquery": "^3.1.1",
"path-parse": "^1.0.5",
"pop-zip": "^1.0.0",
"querystring": "^0.2.0",
"semver": "^5.3.0",
Expand Down
26 changes: 26 additions & 0 deletions test/plugins/sass.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from 'assert';
import Sass from '../../lib/plugins/sass';

describe('Sass', () => {
const path = '/octo/dog.scss';

it('resolves link when target does not have a file extension', () => {
assert.deepEqual(
Sass.resolve({ path, target: 'foo' }),
[
'{BASE_URL}/octo/_foo.scss',
'{BASE_URL}/octo/_foo.sass',
],
);
});

it('resolves link when target has a file extension', () => {
assert.deepEqual(
Sass.resolve({ path, target: 'foo.scss' }),
[
'{BASE_URL}/octo/_foo.scss',
'{BASE_URL}/octo/_foo.sass',
],
);
});
});

0 comments on commit 5348299

Please sign in to comment.