rubydown 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90da523f65d454d4aeb48b78fbfa2e2b35378c565a2823aae1a2e0dc07d1cf3d
4
- data.tar.gz: 920bb095fd9c9855bd1dbb15c2a6a86d0d2e54e5d73b7d2d71644ec60709f5a2
3
+ metadata.gz: ce37172e6c98263b0b2c9bbdb3df5d695342183756af350fc6460619fcc11602
4
+ data.tar.gz: 2242d204fec921ef8a3b5c782a28dcf1eaa3d3a9f835218bf5830449fb3f6cfb
5
5
  SHA512:
6
- metadata.gz: 62cde3191b98f6dc8500a76722979bf022a88e83d156391f4362d33406bf80158f52da205e05ba4ec5b95efde689296766ae179a21e0a886b7dcc8784d698481
7
- data.tar.gz: 58b1243ed10666233d24683e0322b3a3b1482452c6bfb1650204df798919bf105a91ac32404261328402183f72d821b2ac8d703dca3e51f2d64cef02a4a8a301
6
+ metadata.gz: 6354f30245f6e34a1a0eb4a9bf5d26383dac2590455bbbb40ab6c51fbf516a132637d9a913e03763159916b2d9492fa746d2c0b61e75b48815b391ea3a56084e
7
+ data.tar.gz: 1ad1c76f3200793b6d5c094d6f93968a1078440174bcdabaf5ab8ddc85eb5e56e99c0477de480b648604c76009c5029a0be5d1744e7e5cf84fa3d551ecbc8849
@@ -7,7 +7,7 @@ jobs:
7
7
  build:
8
8
  docker:
9
9
  - image: ruby
10
-
10
+
11
11
  working_directory: ~/repo
12
12
 
13
13
  steps:
@@ -19,9 +19,9 @@ jobs:
19
19
  apt-get update
20
20
  apt-get install -y gnuplot
21
21
  gem build rubydown.gemspec
22
- gem install rubydown-0.1.0.gem
22
+ gem install rubydown-0.2.0.gem
23
23
  gem install bio
24
-
24
+
25
25
  # run tests!
26
26
  - run:
27
27
  name: run tests
@@ -29,7 +29,7 @@ jobs:
29
29
  rubydown -i examples/bio.md -e templates/template.html.erb -o /tmp/bio.html
30
30
  rubydown -i examples/table.md -e templates/template.html.erb -o /tmp/table.html
31
31
  rubydown -i examples/graph.md -e templates/template.html.erb -o /tmp/graph.html
32
-
32
+
33
33
  # collect reports
34
34
  - store_artifacts:
35
35
  path: /tmp
data/README.md CHANGED
@@ -18,8 +18,7 @@ https://github.com/pystitch/stitch
18
18
 
19
19
  ```
20
20
  apt install gnuplot # When you use numo-gnuplot in your workflow markdown
21
- gem install specific_install
22
- gem specific_install https://github.com/sciruby-jp/rubydown
21
+ gem install rubydown
23
22
  ```
24
23
 
25
24
  ## Usage (example with [rumale](https://github.com/yoshoku/rumale) and [rdatasets](https://github.com/kojix2/rdatasets))
@@ -28,5 +27,5 @@ gem specific_install https://github.com/sciruby-jp/rubydown
28
27
  gem install rumale rdatasets
29
28
  git clone git://github.com/sciruby-jp/rubydown
30
29
  cd rubydown/examples
31
- rubydown -i rumale.md -o rumale.html
30
+ rubydown -i rumale.md
32
31
  ```
@@ -2,7 +2,7 @@
2
2
  install:
3
3
  - set PATH=C:\Ruby25-x64\bin;%PATH%
4
4
  - gem build rubydown.gemspec
5
- - gem install rubydown-0.1.0.gem
5
+ - gem install rubydown-0.2.0.gem
6
6
 
7
7
  build: off
8
8
 
@@ -20,6 +20,6 @@ test_script:
20
20
  - rubydown -i examples\bio.md -e templates\template.html.erb -o bio.html
21
21
  - rubydown -i examples\graph.md -e templates\template.html.erb -o graph.html
22
22
  - rubydown -i examples\table.md -e templates\template.html.erb -o table.html
23
-
23
+
24
24
  artifacts:
25
25
  - path: '*.html'
@@ -3,7 +3,7 @@
3
3
  require 'kramdown'
4
4
  require 'erb'
5
5
  require 'stringio'
6
-
6
+ require 'base64'
7
7
  require 'optparse'
8
8
 
9
9
  require 'rubydown'
@@ -14,16 +14,23 @@ end
14
14
 
15
15
  class EvalDoc < Kramdown::Document
16
16
  attr_accessor :context, :stdout
17
+ attr_reader :javascripts
17
18
 
18
19
  def initialize(text, *opts)
19
20
  super(text, *opts)
20
21
 
22
+ @javascripts = {}
21
23
  self.context = get_context
22
24
  self.root = scan_el(self.root)
23
25
  end
24
26
 
27
+ REQUIREJS_SCRIPT_TAG = '<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>'
28
+ MATHJAX_SCRIPT_TAG = "<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>"
29
+
25
30
  private
26
31
  def scan_el(el)
32
+ @javascripts[:mathjax] ||= MATHJAX_SCRIPT_TAG if el.type == :math
33
+
27
34
  new_children = []
28
35
  el.children.each do |child_el|
29
36
  child_el = scan_el(child_el)
@@ -34,6 +41,7 @@ class EvalDoc < Kramdown::Document
34
41
  if is_code && child_el.options[:lang] == 'ruby'
35
42
  code = child_el.value.gsub(/^ *ruby *\n/, '')
36
43
  new_children << eval_and_elementize(code)
44
+ @javascripts[:requirejs] ||= REQUIREJS_SCRIPT_TAG
37
45
  end
38
46
  end
39
47
 
@@ -54,6 +62,9 @@ class EvalDoc < Kramdown::Document
54
62
  case
55
63
  when eval_result.respond_to?(:to_html)
56
64
  Kramdown::Document.new(eval_result.to_html, input: :html).root
65
+ when eval_result.instance_of?(File) && File.extname(eval_result.path) == ".png"
66
+ img_b64 = Base64.encode64(File.binread(eval_result.path))
67
+ Kramdown::Document.new("<img src='data:image/png;base64,#{img_b64}' />", input: :html).root
57
68
  else
58
69
  text_result_el(stdout_string + "=> #{eval_result}")
59
70
  end
@@ -5,27 +5,41 @@ require 'rbplotly'
5
5
  require 'numo/gnuplot'
6
6
  require 'base64'
7
7
  require 'tempfile'
8
+ require 'charty'
8
9
 
9
10
 
10
11
  class Numo::NArray
11
12
  def to_html
12
- rows = self.to_a.map do |row|
13
- elems = row.map do |elem|
13
+ case ndim
14
+ when 2
15
+ rows = self.to_a.map do |row|
16
+ elems = row.map do |elem|
17
+ "<td>#{elem}</td>"
18
+ end
19
+ "<tr>#{elems.join}</tr>"
20
+ end
21
+ "<table>#{rows.join}</table>"
22
+ when 1
23
+ cols = self.to_a.map do |elem|
14
24
  "<td>#{elem}</td>"
15
25
  end
16
- "<tr>#{elems.join}</tr>"
26
+ "<table><tr>#{cols.join}</tr></table>"
27
+ else
28
+ inspect
17
29
  end
18
- "<table>#{rows.join}</table>"
19
30
  end
20
31
  end
21
32
 
22
- class Numo::Int32
23
- def to_html
24
- <<-HTML
25
- #{self.to_a}
26
- HTML
33
+ Charty::RenderContext.prepend Module.new {
34
+ def render(filename=nil)
35
+ super
36
+ if filename.nil?
37
+ p "The image could not be rendered. In the environment without IRuby, the file name for the charty render method is required."
38
+ else
39
+ File.open(filename)
40
+ end
27
41
  end
28
- end
42
+ }
29
43
 
30
44
  module Rubydown
31
45
  class RbMarkPlot < Numo::Gnuplot
@@ -1,3 +1,3 @@
1
1
  module Rubydown
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -6,8 +6,8 @@ require "rubydown/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "rubydown"
8
8
  spec.version = Rubydown::VERSION
9
- spec.authors = ["Kozo Nishida"]
10
- spec.email = ["knishida@riken.jp"]
9
+ spec.authors = ["Yusuke Sangenya", "Kozo Nishida", "Kazuhiro Nishiyama"]
10
+ spec.email = ["kozo.nishida@gmail.com"]
11
11
  spec.license = 'MIT'
12
12
  spec.summary = "Pure Ruby R Markdown clone."
13
13
  spec.description = "rubydown is R Markdown clone for Rubyists."
@@ -40,6 +40,8 @@ Gem::Specification.new do |spec|
40
40
  spec.add_dependency "numo-narray", "~> 0.9.1"
41
41
  spec.add_dependency "numo-gnuplot", "~> 0.2.4"
42
42
  spec.add_dependency "rbplotly", "~> 0.1.2"
43
+ spec.add_dependency "charty", "0.1.2.dev"
44
+ spec.add_dependency "matplotlib", "~> 1.0.0"
43
45
 
44
46
  spec.add_development_dependency "bundler", "~> 1.17"
45
47
  spec.add_development_dependency "rake", "~> 10.0"
@@ -16,7 +16,7 @@
16
16
  display: none;
17
17
  }
18
18
  </style>
19
- <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
19
+ <%= doc.javascripts.values.join('') %>
20
20
  </head>
21
21
  <body>
22
22
  <article class='markdown-body'>
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Yusuke Sangenya
7
8
  - Kozo Nishida
9
+ - Kazuhiro Nishiyama
8
10
  autorequire:
9
11
  bindir: exe
10
12
  cert_chain: []
11
- date: 2019-03-10 00:00:00.000000000 Z
13
+ date: 2019-04-17 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: kramdown
@@ -80,6 +82,34 @@ dependencies:
80
82
  - - "~>"
81
83
  - !ruby/object:Gem::Version
82
84
  version: 0.1.2
85
+ - !ruby/object:Gem::Dependency
86
+ name: charty
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '='
90
+ - !ruby/object:Gem::Version
91
+ version: 0.1.2.dev
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '='
97
+ - !ruby/object:Gem::Version
98
+ version: 0.1.2.dev
99
+ - !ruby/object:Gem::Dependency
100
+ name: matplotlib
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: 1.0.0
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: 1.0.0
83
113
  - !ruby/object:Gem::Dependency
84
114
  name: bundler
85
115
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +154,7 @@ dependencies:
124
154
  version: '3.3'
125
155
  description: rubydown is R Markdown clone for Rubyists.
126
156
  email:
127
- - knishida@riken.jp
157
+ - kozo.nishida@gmail.com
128
158
  executables:
129
159
  - rubydown
130
160
  extensions: []