nanoc-nbconvert 0.1.0

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWFiZGEzMzExODJhYjUyY2I2MjhhYzhiYjY5MGNiMmI4NGQ1ZWUyZQ==
5
+ data.tar.gz: !binary |-
6
+ NmZmYTZiOGM5MzRhMzUzYjVhYjY5ZTg1Mjk0MWFkZTFjYjQ1NDU4Yg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTY5ZTFmYjAyZThhNDI4NmNjNTc0MGIzOThmZjkyOTkwYjYzM2IyYjMxYzM3
10
+ ODBmYjJkNDhmMzM0NjY5MjJkODBkNWExZWI1MTdmMGRmYzBlYjYzMzUwMDkw
11
+ ZDg4MmFmZWQzMTQ1NjI4NzZiNGUwNjQ5YzQ3MzFmZjU3ZjA0ZjI=
12
+ data.tar.gz: !binary |-
13
+ YmUxY2MwOGUzNmVhMWEyMDYxNTMwNGMxNjY1ZDY2MTUwMTExMGYwMmQ5Y2Zh
14
+ MzU5MTNiN2MyYWVlMDE4YTFkYjIxNDUwYjgwZjc1ODAzYzA5ZDJhNzAxMmNm
15
+ NGY5ZDBmNjUxMjI4ZWY0Mjc3NDQ5MTk1ZGIxZWIzZWMxNDk0ZjY=
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'minitest'
6
+ gem 'rake'
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nanoc-nbconvert (0.0.1.0)
5
+ nanoc
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ colored (1.2)
11
+ cri (2.5.0)
12
+ colored (~> 1.2)
13
+ minitest (5.3.0)
14
+ nanoc (3.6.7)
15
+ cri (~> 2.3)
16
+ rake (10.1.1)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler
23
+ minitest
24
+ nanoc-nbconvert!
25
+ rake
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Kun Xi and contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/NEWS.md ADDED
@@ -0,0 +1,5 @@
1
+ # nanoc-nbconvert news
2
+
3
+ ## 1.0.0
4
+
5
+ Initial release.
@@ -0,0 +1,15 @@
1
+ [![Build Status](https://travis-ci.org/kunxi/nanoc-nbconvert.png)](https://travis-ci.org/kunxi/nanoc-nbconvert)
2
+
3
+ # nanoc-nbconvert
4
+
5
+ This provides a [IPython notebook](http://ipython.org/notebook) filter for [nanoc](http://nanoc.ws) using [nbconvert](http://ipython.org/ipython-doc/rel-1.0.0/interactive/nbconvert.html).
6
+
7
+ ## Installation
8
+
9
+ `gem install nanoc-nbconvert`
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ filter :nbconvert
15
+ ```
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs = %w( lib test )
7
+ t.test_files = FileList['test/**/test_*.rb', 'test/**/*_spec.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require "open3"
4
+
5
+ module Nanoc::Filters
6
+
7
+ class NBConvert < Nanoc::Filter
8
+
9
+ identifier :nbconvert
10
+
11
+ def run(content, params={})
12
+ nbconvert = <<'END'
13
+ import sys
14
+
15
+ from IPython.nbconvert import HTMLExporter
16
+ exportor = HTMLExporter(template_file="basic")
17
+ body, _ = exportor.from_file(sys.stdin)
18
+ sys.stdout.write(body)
19
+ END
20
+ python_bin = params[:python_bin] || 'python'
21
+ o, e, s = Open3.capture3("#{python_bin} -c '#{nbconvert}'",
22
+ :stdin_data=>content.to_s)
23
+ if !s.success?
24
+ raise "nbconvert fails: #{e}"
25
+ end
26
+ o
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'nanoc-nbconvert'
5
+ s.version = '0.1.0'
6
+ s.homepage = 'http://github.com/kunxi/nanoc-nbconvert'
7
+ s.summary = %q{A nanoc filter to convert IPython notebook}
8
+ s.description = %q{A nanoc filter to convert IPython notebook}
9
+
10
+ s.author = 'Kun Xi'
11
+ s.email = 'kunxi@kunxi.org'
12
+ s.license = 'MIT'
13
+
14
+ s.files = Dir['[A-Z]*'] +
15
+ Dir['{lib,test}/**/*'] +
16
+ [ 'nanoc-nbconvert.gemspec' ]
17
+ s.test_files = Dir['{test,spec,features}/**/*']
18
+ s.require_paths = [ 'lib' ]
19
+
20
+ s.rdoc_options = [ '--main', 'README.md' ]
21
+ s.extra_rdoc_files = [ 'LICENSE', 'README.md', 'NEWS.md' ]
22
+
23
+ s.add_runtime_dependency('nanoc')
24
+ s.add_development_dependency('bundler')
25
+ end
@@ -0,0 +1,134 @@
1
+
2
+ <div class="cell border-box-sizing text_cell rendered">
3
+ <div class="prompt input_prompt">
4
+ </div>
5
+ <div class="inner_cell">
6
+ <div class="text_cell_render border-box-sizing rendered_html">
7
+ <h1 id="an-h1-header">An h1 header</h1>
8
+ <p>Paragraphs are separated by a blank line.</p>
9
+ <p>2nd paragraph. <em>Italic</em>, <strong>bold</strong>, <code>monospace</code>. Itemized lists
10
+ look like:</p>
11
+ <ul>
12
+ <li>this one</li>
13
+ <li>that one</li>
14
+ <li>the other one</li>
15
+ </ul>
16
+ <p>Note that --- not considering the asterisk --- the actual text
17
+ content starts at 4-columns in.</p>
18
+ <blockquote>
19
+ <p>Block quotes are
20
+ written like so.</p>
21
+ <p>They can span multiple paragraphs,
22
+ if you like.</p>
23
+ </blockquote>
24
+ <p>Use 3 dashes for an em-dash. Use 2 dashes for ranges (ex. &quot;it&#39;s all in
25
+ chapters 12--14&quot;). Three dots ... will be converted to an ellipsis.</p>
26
+ <h2 id="an-h2-header">An h2 header</h2>
27
+ <p>Here&#39;s a numbered list:</p>
28
+ <ol>
29
+ <li>first item</li>
30
+ <li>second item</li>
31
+ <li>third item</li>
32
+ </ol>
33
+ <p>Note again how the actual text starts at 4 columns in (4 characters
34
+ from the left side). Here&#39;s a code sample:</p>
35
+ <pre><code># Let me re-iterate ...
36
+ for i in 1 .. 10 { do-something(i) }
37
+ </code></pre><p>As you probably guessed, indented 4 spaces. By the way, instead of
38
+ indenting the block, you can use delimited blocks, if you like:</p>
39
+ <pre><code>define foobar() {
40
+ print &quot;Welcome to flavor country!&quot;;
41
+ }
42
+ </code></pre><p>(which makes copying &amp; pasting easier). You can optionally mark the
43
+ delimited block for Pandoc to syntax highlight it:</p>
44
+ <pre><code class="language-python"><span class="keyword">import</span> time
45
+ <span class="comment"># Quick, count to ten!</span>
46
+ <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">10</span>):
47
+ <span class="comment"># (but not *too* quick)</span>
48
+ time.sleep(<span class="number">0.5</span>)
49
+ <span class="keyword">print</span> i
50
+ </code></pre>
51
+ <h3 id="an-h3-header">An h3 header</h3>
52
+ <p>Now a nested list:</p>
53
+ <ol>
54
+ <li><p>First, get these ingredients:</p>
55
+ <ul>
56
+ <li>carrots</li>
57
+ <li>celery</li>
58
+ <li>lentils</li>
59
+ </ul>
60
+ </li>
61
+ <li><p>Boil some water.</p>
62
+ </li>
63
+ <li><p>Dump everything in the pot and follow
64
+ this algorithm:</p>
65
+ <pre><code>find wooden spoon
66
+ uncover pot
67
+ stir
68
+ cover pot
69
+ balance wooden spoon precariously on pot handle
70
+ wait 10 minutes
71
+ goto first step (or shut off burner when done)
72
+ </code></pre><p>Do not bump wooden spoon or it will fall.</p>
73
+ </li>
74
+ </ol>
75
+ <p>Notice again how text always lines up on 4-space indents (including
76
+ that last line which continues item 3 above). Here&#39;s a link to <a href="http://foo.bar">a
77
+ website</a>. Here&#39;s a link to a <a href="local-doc.html">local
78
+ doc</a>. Here&#39;s a footnote [^1].</p>
79
+ <p>[^1]: Footnote text goes here.</p>
80
+ <p>Tables can look like this:</p>
81
+ <p>size material color</p>
82
+ <hr>
83
+ <p>9 leather brown
84
+ 10 hemp canvas natural
85
+ 11 glass transparent</p>
86
+ <p>Table: Shoes, their sizes, and what they&#39;re made of</p>
87
+ <p>(The above is the caption for the table.) Here&#39;s a definition list:</p>
88
+ <p>apples
89
+ : Good for making applesauce.
90
+ oranges
91
+ : Citrus!
92
+ tomatoes
93
+ : There&#39;s no &quot;e&quot; in tomatoe.</p>
94
+ <p>Again, text is indented 4 spaces. (Alternately, put blank lines in
95
+ between each of the above definition list lines to spread things
96
+ out more.)</p>
97
+ <p>Inline math equations go in like so: $\omega = d\phi / dt$. Display
98
+ math should get its own line and be put in in double-dollarsigns:</p>
99
+ <p>$$I = \int \rho R^{2} dV$$</p>
100
+ <p>Done.</p>
101
+ </div>
102
+ </div>
103
+ </div>
104
+ <div class="cell border-box-sizing code_cell rendered">
105
+ <div class="input">
106
+ <div class="prompt input_prompt">
107
+ In&nbsp;[1]:
108
+ </div>
109
+ <div class="inner_cell">
110
+ <div class="input_area">
111
+ <div class="highlight"><pre><span class="k">print</span> <span class="s">&quot;Hello world&quot;</span>
112
+ </pre></div>
113
+
114
+ </div>
115
+ </div>
116
+ </div>
117
+
118
+ <div class="output_wrapper">
119
+ <div class="output">
120
+
121
+
122
+ <div class="output_area"><div class="prompt"></div>
123
+ <div class="output_subarea output_stream output_stdout output_text">
124
+ <pre>
125
+ Hello world
126
+
127
+ </pre>
128
+ </div>
129
+ </div>
130
+
131
+ </div>
132
+ </div>
133
+
134
+ </div>
@@ -0,0 +1,165 @@
1
+ {
2
+ "metadata": {
3
+ "name": "",
4
+ "signature": "sha256:013ede031909463ecfa3223c2666fff0ef08ef47e5cb6f875f8004a36bfe1b47"
5
+ },
6
+ "nbformat": 3,
7
+ "nbformat_minor": 0,
8
+ "worksheets": [
9
+ {
10
+ "cells": [
11
+ {
12
+ "cell_type": "markdown",
13
+ "metadata": {},
14
+ "source": [
15
+ "An h1 header\n",
16
+ "============\n",
17
+ "\n",
18
+ "Paragraphs are separated by a blank line.\n",
19
+ "\n",
20
+ "2nd paragraph. *Italic*, **bold**, `monospace`. Itemized lists\n",
21
+ "look like:\n",
22
+ "\n",
23
+ " * this one\n",
24
+ " * that one\n",
25
+ " * the other one\n",
26
+ "\n",
27
+ "Note that --- not considering the asterisk --- the actual text\n",
28
+ "content starts at 4-columns in.\n",
29
+ "\n",
30
+ "> Block quotes are\n",
31
+ "> written like so.\n",
32
+ ">\n",
33
+ "> They can span multiple paragraphs,\n",
34
+ "> if you like.\n",
35
+ "\n",
36
+ "Use 3 dashes for an em-dash. Use 2 dashes for ranges (ex. \"it's all in\n",
37
+ "chapters 12--14\"). Three dots ... will be converted to an ellipsis.\n",
38
+ "\n",
39
+ "\n",
40
+ "\n",
41
+ "An h2 header\n",
42
+ "------------\n",
43
+ "\n",
44
+ "Here's a numbered list:\n",
45
+ "\n",
46
+ " 1. first item\n",
47
+ " 2. second item\n",
48
+ " 3. third item\n",
49
+ "\n",
50
+ "Note again how the actual text starts at 4 columns in (4 characters\n",
51
+ "from the left side). Here's a code sample:\n",
52
+ "\n",
53
+ " # Let me re-iterate ...\n",
54
+ " for i in 1 .. 10 { do-something(i) }\n",
55
+ "\n",
56
+ "As you probably guessed, indented 4 spaces. By the way, instead of\n",
57
+ "indenting the block, you can use delimited blocks, if you like:\n",
58
+ "\n",
59
+ "~~~\n",
60
+ "define foobar() {\n",
61
+ " print \"Welcome to flavor country!\";\n",
62
+ "}\n",
63
+ "~~~\n",
64
+ "\n",
65
+ "(which makes copying & pasting easier). You can optionally mark the\n",
66
+ "delimited block for Pandoc to syntax highlight it:\n",
67
+ "\n",
68
+ "~~~python\n",
69
+ "import time\n",
70
+ "# Quick, count to ten!\n",
71
+ "for i in range(10):\n",
72
+ " # (but not *too* quick)\n",
73
+ " time.sleep(0.5)\n",
74
+ " print i\n",
75
+ "~~~\n",
76
+ "\n",
77
+ "\n",
78
+ "\n",
79
+ "### An h3 header ###\n",
80
+ "\n",
81
+ "Now a nested list:\n",
82
+ "\n",
83
+ " 1. First, get these ingredients:\n",
84
+ "\n",
85
+ " * carrots\n",
86
+ " * celery\n",
87
+ " * lentils\n",
88
+ "\n",
89
+ " 2. Boil some water.\n",
90
+ "\n",
91
+ " 3. Dump everything in the pot and follow\n",
92
+ " this algorithm:\n",
93
+ "\n",
94
+ " find wooden spoon\n",
95
+ " uncover pot\n",
96
+ " stir\n",
97
+ " cover pot\n",
98
+ " balance wooden spoon precariously on pot handle\n",
99
+ " wait 10 minutes\n",
100
+ " goto first step (or shut off burner when done)\n",
101
+ "\n",
102
+ " Do not bump wooden spoon or it will fall.\n",
103
+ "\n",
104
+ "Notice again how text always lines up on 4-space indents (including\n",
105
+ "that last line which continues item 3 above). Here's a link to [a\n",
106
+ "website](http://foo.bar). Here's a link to a [local\n",
107
+ "doc](local-doc.html). Here's a footnote [^1].\n",
108
+ "\n",
109
+ "[^1]: Footnote text goes here.\n",
110
+ "\n",
111
+ "Tables can look like this:\n",
112
+ "\n",
113
+ "size material color\n",
114
+ "---- ------------ ------------\n",
115
+ "9 leather brown\n",
116
+ "10 hemp canvas natural\n",
117
+ "11 glass transparent\n",
118
+ "\n",
119
+ "Table: Shoes, their sizes, and what they're made of\n",
120
+ "\n",
121
+ "(The above is the caption for the table.) Here's a definition list:\n",
122
+ "\n",
123
+ "apples\n",
124
+ " : Good for making applesauce.\n",
125
+ "oranges\n",
126
+ " : Citrus!\n",
127
+ "tomatoes\n",
128
+ " : There's no \"e\" in tomatoe.\n",
129
+ "\n",
130
+ "Again, text is indented 4 spaces. (Alternately, put blank lines in\n",
131
+ "between each of the above definition list lines to spread things\n",
132
+ "out more.)\n",
133
+ "\n",
134
+ "Inline math equations go in like so: $\\omega = d\\phi / dt$. Display\n",
135
+ "math should get its own line and be put in in double-dollarsigns:\n",
136
+ "\n",
137
+ "$$I = \\int \\rho R^{2} dV$$\n",
138
+ "\n",
139
+ "Done."
140
+ ]
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "collapsed": false,
145
+ "input": [
146
+ "print \"Hello world\""
147
+ ],
148
+ "language": "python",
149
+ "metadata": {},
150
+ "outputs": [
151
+ {
152
+ "output_type": "stream",
153
+ "stream": "stdout",
154
+ "text": [
155
+ "Hello world\n"
156
+ ]
157
+ }
158
+ ],
159
+ "prompt_number": 1
160
+ }
161
+ ],
162
+ "metadata": {}
163
+ }
164
+ ]
165
+ }
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+
5
+ class Nanoc::Filters::NBConvertTest < Minitest::Test
6
+
7
+ def test_filter
8
+ # Create filter
9
+ filter = ::Nanoc::Filters::NBConvert.new
10
+
11
+ # Run filter
12
+ fh = File.open(File.expand_path("../../data/example.html", __FILE__))
13
+ expected = fh.read
14
+
15
+ File.open(File.expand_path("../../data/example.ipynb", __FILE__)) {|f|
16
+ content = f.read
17
+ assert_match(expected.strip, filter.run(content).strip)
18
+ }
19
+ end
20
+
21
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest'
4
+ require 'minitest/autorun'
5
+ require 'nanoc'
6
+ require 'nanoc/filters/nbconvert'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-nbconvert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kun Xi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nanoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A nanoc filter to convert IPython notebook
42
+ email: kunxi@kunxi.org
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files:
46
+ - LICENSE
47
+ - README.md
48
+ - NEWS.md
49
+ files:
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - NEWS.md
54
+ - Rakefile
55
+ - README.md
56
+ - lib/nanoc/filters/nbconvert.rb
57
+ - test/data/example.html
58
+ - test/data/example.ipynb
59
+ - test/filters/test_nbconvert.rb
60
+ - test/helper.rb
61
+ - nanoc-nbconvert.gemspec
62
+ homepage: http://github.com/kunxi/nanoc-nbconvert
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --main
69
+ - README.md
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.1.11
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A nanoc filter to convert IPython notebook
88
+ test_files:
89
+ - test/data/example.html
90
+ - test/data/example.ipynb
91
+ - test/filters/test_nbconvert.rb
92
+ - test/helper.rb