Skip to content

Commit

Permalink
feat(syntax): add support for liquid_tags.include_code plugin
Browse files Browse the repository at this point in the history
fix #518
  • Loading branch information
talha131 committed Feb 2, 2020
1 parent edba54f commit 0550a3a
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
Title: Code Snippets -- Include code from file
Tags: code-snippets, plugins, liquid-tags
Date: 2020-02-02 20:53
comments: false
Slug: code-snippets-include-code-from-file
authors: Talha Mansoor
Category: Supported Plugins
---

Elegant supports [`liquid_tags.include_code` plugin](https://github.com/getpelican/pelican-plugins/tree/master/liquid_tags#include-code).

<!-- TODO: remove this warning after https://github.com/getpelican/pelican-plugins/pull/1243 is merged -->

!!! Warning "Pending Pull Request"

The demo you see here is dependent on [this
patch](https://github.com/getpelican/pelican-plugins/pull/1243).

Until Pelican team merges the patch into plugins repository, you will have
apply this patch manually to your copy of plugins.

## Example 1

{% include_code square-root.py lang:python Calculate square root of 8 %}

## Example 2 -- Without Filename

{% include_code alias-sed.fish :hidefilename: Fish Shell alias for sed %}

## Example 3 -- Without Download Link

{% include_code alias-sed.fish :hidelink: Fish Shell alias for sed %}

## Example 4 -- Without Filename and Download Link

{% include_code alias-sed.fish :hidefilename: :hidelink: Fish Shell alias for sed %}

## Example 3 -- Without Metadata

{% include_code square-root.js lang:js :hideall: Compute square-root %}
3 changes: 3 additions & 0 deletions documentation/content/code/alias-sed.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function sed -d 'alias sed to gsed'
command gsed $argv;
end
23 changes: 23 additions & 0 deletions documentation/content/code/square-root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// From https://gist.github.com/joelpt/3824024
//
// The Babylonian Method
// http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
// @param n - the number to compute the square root of
// @param g - the best guess so far (can omit from initial call)
function squirt(n, g) {
if (!g) {
// Take an initial guess at the square root
g = n / 2.0;
}
var d = n / g; // Divide our guess into the number
var ng = (d + g) / 2.0; // Use average of g and d as our new guess
if (g == ng) {
// The new guess is the same as the old guess; further guesses
// can get no more accurate so we return this guess
return g;
}
// Recursively solve for closer and closer approximations of the square root
return squirt(n, ng);
}

console.log(squirt(42)); // 6.48074069840786
8 changes: 8 additions & 0 deletions documentation/content/code/square-root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# Python Program to calculate the square root
# Note: change this value for a different result
num = 8
# To take the input from the user
# num = float(input('Enter a number: '))
num_sqrt = num ** 0.5
print("The square root of %0.3f is %0.3f" % (num, num_sqrt))
3 changes: 2 additions & 1 deletion documentation/pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
PLUGINS = [
"extract_toc",
"liquid_tags.img",
"liquid_tags.include_code",
"neighbors",
"related_posts",
"render_math",
Expand Down Expand Up @@ -76,7 +77,7 @@
)

# Elegant theme
STATIC_PATHS = ["theme/images", "images", "extra/_redirects"]
STATIC_PATHS = ["theme/images", "images", "extra/_redirects", "code"]
EXTRA_PATH_METADATA = {"extra/_redirects": {"path": "_redirects"}}

if os.environ.get("CONTEXT") == "production":
Expand Down
5 changes: 4 additions & 1 deletion documentation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ def plugins_sync(c):
# For now we don't need submodules plugins. When we do, use
# --recurse-submodules and --shallow-submodules switches
# Do specify path in --recurse-submodules so that only relevant plugin is downloaded
# TODO: switch back to getpelican repository after PR is merged
# https://github.com/getpelican/pelican-plugins/pull/1243
# "git clone --jobs 8 --depth 1 --shallow-submodules https://github.com/getpelican/pelican-plugins.git plugins"
c.run(
"git clone --jobs 8 --depth 1 --shallow-submodules https://github.com/getpelican/pelican-plugins.git plugins"
"git clone --jobs 8 --depth 1 --shallow-submodules --single-branch --branch feat-liquid-tags-include-code https://github.com/talha131/pelican-plugins.git plugins"
)


Expand Down
46 changes: 46 additions & 0 deletions static/css/code.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,52 @@ pre {
word-wrap: normal;
color: #ebdbb2; /* This is needed due to bug in Pygments. It does not wraps some part of the code of some lagauges, like reST. This is for fallback. */
}
/* liquid_tags.include_code */
figure.code {
margin: 0;
padding: 0;
& figcaption {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
border-radius: var(--borderRadius) var(--borderRadius) 0 0;
background-color: #544c50;
color: #ebdbb2;
padding: 2px 9.5px;
font-family: var(--sansFontFamily);
& span.liquid-tags-code-title {
flex-grow: 1;
}
& span.liquid-tags-code-filename {
font-family: var(--monoFontFamily);
color: #fe8019;
}
/* Download Link */
& a {
color: #b8bb26;
text-transform: capitalize;
position: relative;
margin-left: 30px;
&:before {
display: inline-block;
height: 18px;
width: 18px;
content: url("data:image/svg+xml,%3Csvg%20image-rendering%3D%22optimizeQuality%22%20shape-rendering%3D%22geometricPrecision%22%20text-rendering%3D%22geometricPrecision%22%20viewBox%3D%220%200%20294%20452.5%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20fill%3D%22%23b8bb26%22%3E%3Cpath%20d%3D%22m126%200h42v185h62l-83%20111-83-111h62z%22%2F%3E%3Cpath%20d%3D%22m294%20257v105c-98%200-196%200-294%200v-105h34v71h226v-71z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E%0A");
margin: 0;
padding: 0 4px 0 0;
top: 4px;
right: 100%;
position: absolute;
}
}
}
& div.highlight:not(:first-child) {
border-radius: 0 0 var(--borderRadius) var(--borderRadius);
}
}

table {
table-layout: fixed;
width: 100%;
Expand Down

0 comments on commit 0550a3a

Please sign in to comment.