Skip to content

Commit 9b1f29b

Browse files
Merge pull request #406 from ashmaroli/static-gem-sticker
Tag static files from a theme-gem with a sticker
2 parents 7e29088 + 327ea95 commit 9b1f29b

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

lib/jekyll-admin/apiable.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def to_api(include_content: false)
4747
output["name"] = basename
4848
end
4949

50+
if is_a?(Jekyll::StaticFile)
51+
output["from_theme"] = from_theme_gem?
52+
end
53+
5054
output
5155
end
5256

@@ -61,6 +65,10 @@ def file_path
6165
end
6266
end
6367

68+
def from_theme_gem?
69+
@base == site.in_theme_dir
70+
end
71+
6472
# StaticFiles don't have `attr_accesor` set for @site or @name
6573
def site
6674
@site

src/components/FilePreview.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,25 @@ export default class FilePreview extends Component {
3030
} else {
3131
nodeLink = <a href={file.http_url} target="_blank">{node}</a>;
3232
}
33+
34+
let overlay;
35+
if (file.from_theme) {
36+
overlay = (
37+
<span className="theme-indicator">
38+
<i className="fa fa-diamond" aria-hidden="true" title="Theme Asset" />
39+
</span>
40+
);
41+
} else {
42+
overlay = (
43+
<button onClick={() => this.handleClickDelete(file.path)} className="delete" title="Delete file">x</button>
44+
);
45+
}
46+
3347
return (
3448
<div className="file-preview">
49+
{overlay}
3550
{nodeLink}
3651
<span className="filename">{file.path}</span>
37-
<button onClick={() => this.handleClickDelete(file.path)} className="delete" title="Delete file">x</button>
3852
</div>
3953
);
4054
}

src/components/tests/filepreview.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function setup(file=staticfile) {
1919
filename: component.find('.filename'),
2020
image: component.find('img'),
2121
div: component.find('.file-preview a div'),
22+
indicator: component.find('.file-preview .theme-indicator'),
23+
delete_btn: component.find('.file-preview .delete'),
2224
actions: actions
2325
};
2426
}
@@ -29,9 +31,20 @@ describe('Components::FilePreview', () => {
2931
expect(image.node).toBeTruthy();
3032
expect(div.node).toBeFalsy();
3133
});
34+
3235
it('should render a div if the file does not have an image extension', () => {
3336
const { image, div } = setup({...staticfile, extname: 'html'});
3437
expect(image.node).toBeFalsy();
3538
expect(div.node).toBeTruthy();
3639
});
40+
41+
it('should render an indicator if file is from theme-gem', () => {
42+
const { indicator } = setup({...staticfile, from_theme: true});
43+
expect(indicator.node).toBeTruthy();
44+
});
45+
46+
it('should not render a delete-button if file is from theme-gem', () => {
47+
const { delete_btn } = setup({...staticfile, from_theme: true});
48+
expect(delete_btn.node).toBeFalsy();
49+
});
3750
});

src/styles/staticfiles.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@
4848
display: inline-table;
4949
}
5050
}
51+
span.theme-indicator {
52+
position: absolute;
53+
bottom: 40px;
54+
left: 0;
55+
width: 32px;
56+
height: 32px;
57+
text-align: left;
58+
background: $dark-red;
59+
i {
60+
margin: 0;
61+
padding: 8px 7px 7px;
62+
color: white;
63+
font-size: 16px;
64+
}
65+
}
5166
span.filename {
5267
font-size: 14px;
5368
line-height: 2;

0 commit comments

Comments
 (0)