jekyll-jupyter-notebook 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2d8a308475c3bbced91a8f917dd2269cd5841f2f
4
- data.tar.gz: 7bfd27ff41148e95d335eb16a53ef5649227156d
2
+ SHA256:
3
+ metadata.gz: 6c466c7ee83b97759654b140f971cf5767b326f81bfed119c01fdf8d02bb2af8
4
+ data.tar.gz: 33243d1e14cb04552dc2ec8351403deee428ab25a529de95e943903b65eddd1a
5
5
  SHA512:
6
- metadata.gz: 3cdf4e001557890333f746d30ce5c4b6b790ccd61215b0c1fe0a0a5167a16de48436e93040ebc266b8170901b5c64f8709705e9b5ad8aba8d3f193454d17bd43
7
- data.tar.gz: 774011d293718da25e201b8348dda74c597e470fc3c9e8e4e5de473accfda7258eda13bf8ffb79aaa04b98be9b607f521cbe3e65648e5655f0daec281a35516d
6
+ metadata.gz: d5b9a7c0f95059b609eea6e9389b4dc9b231de0e87dd384a9f0f219a165ae6d7e18beba5df8fb46813e860f94793e6b5d4f65aa3b39c4704a427c92eefe9433d
7
+ data.tar.gz: b2eef64b0124162eaf4608a50502d1ae005042b8c38f38e9e70336fad47c44dc9b7758a5314326a3712bff44c299422f9d9cfd9289f1f180ca5bfc599e770191
data/README.md CHANGED
@@ -16,10 +16,16 @@ Add the following line to your site's `Gemfile`:
16
16
  gem "jekyll-jupyter-notebook"
17
17
  ```
18
18
 
19
+ Run the following command line to make the gem available:
20
+
21
+ ```console
22
+ % bundle install
23
+ ```
24
+
19
25
  Add the following line to your site's `_config.yml`:
20
26
 
21
27
  ```yaml
22
- gems:
28
+ plugins:
23
29
  - jekyll-jupyter-notebook
24
30
  ```
25
31
 
@@ -36,14 +42,14 @@ Put a Jupyter Notebook (`sample.ipynb`) to the directory that has the target tex
36
42
  Put the following tag into the target text:
37
43
 
38
44
  ```markdown
39
- {% jupyter_notebook sample.ipynb %}
45
+ {% jupyter_notebook "sample.ipynb" %}
40
46
  ```
41
47
 
42
48
  If you use kramdown as Markdown parser and get strange result, try to surround `{% jupyter_notebook ...%}` with `{::nomarkdown}` and `{:/nomarkdown}` like the following:
43
49
 
44
50
  ```markdown
45
51
  {::nomarkdown}
46
- {% jupyter_notebook sample.ipynb %}
52
+ {% jupyter_notebook "sample.ipynb" %}
47
53
  {:/nomarkdown}
48
54
  ```
49
55
 
data/doc/text/news.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # News
2
2
 
3
+ ## 0.0.5 - 2022-08-20
4
+
5
+ ### Improvements
6
+
7
+ * Added support for collection.
8
+ [GitHub#8][Reported by Jeremy Lloyd Conlin]
9
+
10
+ ### Thanks
11
+
12
+ * Jeremy Lloyd Conlin
13
+
14
+ ## 0.0.4 - 2018-08-08
15
+
16
+ ### Improvements
17
+
18
+ * Added support for variable for notebook path. Now, notebook path
19
+ must be string literal such as `"sample.ipynb"` not
20
+ `sample.ipynb`. `sample.ipynb` is still supported for backward
21
+ compatibility but it's obsoleted.
22
+ [GitHub#7][Patch by Josh Hills]
23
+
24
+ ### Thanks
25
+
26
+ * Josh Hills
27
+
28
+ ## 0.0.3 - 2018-03-31
29
+
30
+ ### Improvements
31
+
32
+ * Improved install document.
33
+ [GitHub#5][Patch by Jake VanCampen]
34
+
35
+ * Changed to use `iframe` instead of embedding `nbconvert`-ed HTML directory.
36
+ It required JavaScript.
37
+
38
+ ### Thanks
39
+
40
+ * Jake VanCampen
41
+
3
42
  ## 0.0.2 - 2017-09-03
4
43
 
5
44
  ### Improvements
@@ -0,0 +1,70 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require "tempfile"
14
+
15
+ module JekyllJupyterNotebook
16
+ class Converter < Jekyll::Converter
17
+ def matches(ext)
18
+ ext == ".ipynb"
19
+ end
20
+
21
+ def output_ext(ext)
22
+ ".html"
23
+ end
24
+
25
+ def convert(content)
26
+ config = @config["jupyter_notebook"] || {}
27
+
28
+ html = convert_notebook(content)
29
+ html.sub!(/<link.+?href="custom.css">/, "")
30
+ case config["content"] || "html"
31
+ when "html"
32
+ when "body"
33
+ html.sub!(/\A.*?<\/title>/m, "")
34
+ html.sub!(/<\/head>/, "")
35
+ html.sub!(/<body>/, "")
36
+ html.sub!(/<\/body>.*?\z/m, "")
37
+ when "body-without-style"
38
+ html.sub!(/\A.*?<body>/m, "")
39
+ html.sub!(/<\/body>.*?\z/m, "")
40
+ end
41
+ html
42
+ end
43
+
44
+ private
45
+ def convert_notebook(content)
46
+ notebook = Tempfile.new(["jekyll-jupyter-notebook", ".ipynb"])
47
+ notebook.print(content)
48
+ notebook.close
49
+ IO.pipe do |input, output|
50
+ pid = spawn("jupyter",
51
+ "nbconvert",
52
+ "--to", "html",
53
+ "--stdout",
54
+ notebook.path,
55
+ :out => output)
56
+ begin
57
+ output.close
58
+ html = nil
59
+ read_thread = Thread.new do
60
+ html = input.read
61
+ end
62
+ read_thread.join
63
+ html
64
+ ensure
65
+ Process.waitpid(pid)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,59 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ module JekyllJupyterNotebook
14
+ module IFramable
15
+ def output_ext
16
+ extname + super
17
+ end
18
+ end
19
+
20
+ class Generator < Jekyll::Generator
21
+ def generate(site)
22
+ generate_site_static_files(site)
23
+ site.collections.each_value do |collection|
24
+ generate_collection_filtered_entries(collection)
25
+ end
26
+ end
27
+
28
+ private
29
+ def generate_site_static_files(site)
30
+ site.static_files.reject! do |static_file|
31
+ next false unless static_file.extname == ".ipynb"
32
+
33
+ base = static_file.instance_variable_get(:@base)
34
+ dir = static_file.instance_variable_get(:@dir)
35
+ name = static_file.name
36
+ page = Jekyll::Page.new(site, base, dir, name)
37
+ page.extend(IFramable)
38
+ site.pages << page
39
+ true
40
+ end
41
+ end
42
+
43
+ def generate_collection_filtered_entries(collection)
44
+ collection.filtered_entries.reject! do |file_path|
45
+ full_path = collection.collection_dir(file_path)
46
+ next false unless File.extname(file_path) == ".ipynb"
47
+ next false if Jekyll::Utils.has_yaml_header?(full_path)
48
+
49
+ document = Jekyll::Document.new(full_path,
50
+ site: collection.site,
51
+ collection: collection)
52
+ document.extend(IFramable)
53
+ document.read
54
+ collection.docs << document
55
+ true
56
+ end
57
+ end
58
+ end
59
+ end
@@ -16,37 +16,38 @@ module JekyllJupyterNotebook
16
16
  class Tag < Liquid::Tag
17
17
  Liquid::Template.register_tag("jupyter_notebook", self)
18
18
 
19
- def initialize(tag_name, markup, tokens)
19
+ def initialize(tag_name, markup, parse_context)
20
20
  super
21
- @notebook_path = markup.strip
22
21
  end
23
22
 
24
23
  def syntax_example
25
- "{% #{@tag_name} filename.ipynb %}"
24
+ "{% #{@tag_name} \"filename.ipynb\" %}"
26
25
  end
27
26
 
28
27
  def render(context)
29
- dir = context["page"]["dir"] || File.dirname(context["page"]["path"])
30
- notebook_path = File.join(context["site"]["source"],
31
- dir,
32
- @notebook_path)
33
- Dir.mktmpdir do |output|
34
- system("jupyter",
35
- "nbconvert",
36
- "--to", "html",
37
- "--output-dir", output,
38
- notebook_path)
39
- html_path = Dir.glob("#{output}/*.html").first
40
- html = File.read(html_path)
41
- html.sub!(/\A.*?<\/title>/m, "")
42
- html.sub!(/<link.+?href="custom.css">/, "")
43
- html.sub!(/<\/head>/, "")
44
- html.sub!(/<body>/, "")
45
- html.sub!(/<\/body>.*?\z/m, "")
46
- <<-HTML
47
- <div class="jupyter-notebook">#{html}</div>
48
- HTML
28
+ variable = Liquid::Variable.new(@markup, @parse_context)
29
+ notebook_path = variable.render(context)
30
+ if notebook_path.nil?
31
+ Jekyll.logger.warn("Warning:",
32
+ "Jupyter Notebook path be string literal: " +
33
+ "<#{@markup.strip.inspect}>")
34
+ notebook_path = @markup.strip # For backward compatibility
49
35
  end
36
+ notebook_html_path = "#{notebook_path}.html"
37
+ <<-HTML
38
+ <div
39
+ class="jupyter-notebook"
40
+ style="position: relative; width: 100%; margin: 0 auto;">
41
+ <div class="jupyter-notebook-iframe-container">
42
+ <iframe
43
+ src="#{CGI.escapeHTML(notebook_html_path)}"
44
+ style="position: absolute; top: 0; left: 0; border-style: none;"
45
+ width="100%"
46
+ height="100%"
47
+ onload="this.parentElement.style.paddingBottom = (this.contentWindow.document.documentElement.scrollHeight + 10) + 'px'"></iframe>
48
+ </div>
49
+ </div>
50
+ HTML
50
51
  end
51
52
  end
52
53
  end
@@ -11,5 +11,5 @@
11
11
  # limitations under the License.
12
12
 
13
13
  module JekyllJupyterNotebook
14
- VERSION = "0.0.2"
14
+ VERSION = "0.0.5"
15
15
  end
@@ -12,4 +12,6 @@
12
12
 
13
13
  require "jekyll-jupyter-notebook/version"
14
14
 
15
+ require "jekyll-jupyter-notebook/converter"
16
+ require "jekyll-jupyter-notebook/generator"
15
17
  require "jekyll-jupyter-notebook/tag"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-jupyter-notebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-03 00:00:00.000000000 Z
11
+ date: 2022-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -109,6 +109,8 @@ files:
109
109
  - doc/text/news.md
110
110
  - jekyll-jupyter-notebook.gemspec
111
111
  - lib/jekyll-jupyter-notebook.rb
112
+ - lib/jekyll-jupyter-notebook/converter.rb
113
+ - lib/jekyll-jupyter-notebook/generator.rb
112
114
  - lib/jekyll-jupyter-notebook/tag.rb
113
115
  - lib/jekyll-jupyter-notebook/version.rb
114
116
  homepage: https://github.com/red-data-tools/jekyll-jupyter-notebook
@@ -130,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
132
  - !ruby/object:Gem::Version
131
133
  version: '0'
132
134
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 2.5.2
135
+ rubygems_version: 3.4.0.dev
135
136
  signing_key:
136
137
  specification_version: 4
137
138
  summary: Jekyll Jupyter Notebook plugin adds [Jupyter](http://jupyter.org/) Notebook