rubydown 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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +35 -0
  3. data/.gitignore +3 -0
  4. data/Dockerfile +9 -0
  5. data/Gemfile +8 -0
  6. data/Gemfile.lock +43 -0
  7. data/LICENSE +21 -0
  8. data/README.md +32 -0
  9. data/Rakefile +2 -0
  10. data/_config.yml +1 -0
  11. data/appveyor.yml +25 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/docs/_config.yml +1 -0
  15. data/docs/index.html +20 -0
  16. data/docs/sidebyside.md +1 -0
  17. data/examples/bio.html +129 -0
  18. data/examples/bio.md +73 -0
  19. data/examples/graph.html +160 -0
  20. data/examples/graph.md +11 -0
  21. data/examples/index.html +217 -0
  22. data/examples/index.md +58 -0
  23. data/examples/numo-gnuplot.ipynb +1515 -0
  24. data/examples/rbplotly-bar.html +146 -0
  25. data/examples/rbplotly-bar.md +54 -0
  26. data/examples/rbplotly-basic.html +134 -0
  27. data/examples/rbplotly-basic.md +43 -0
  28. data/examples/rbplotly-boxplot.html +136 -0
  29. data/examples/rbplotly-boxplot.md +60 -0
  30. data/examples/rbplotly-heatmap.html +95 -0
  31. data/examples/rbplotly-heatmap.md +35 -0
  32. data/examples/rbplotly-hist.html +52 -0
  33. data/examples/rbplotly-hist.md +9 -0
  34. data/examples/rbplotly-line.html +62 -0
  35. data/examples/rbplotly-line.md +19 -0
  36. data/examples/rbplotly-pie.html +100 -0
  37. data/examples/rbplotly-pie.md +40 -0
  38. data/examples/rbplotly-scatter.html +148 -0
  39. data/examples/rbplotly-scatter.md +71 -0
  40. data/examples/rumale-kmeans.html +75 -0
  41. data/examples/rumale-kmeans.md +33 -0
  42. data/examples/rumale.html +967 -0
  43. data/examples/rumale.md +31 -0
  44. data/examples/table.html +57 -0
  45. data/examples/table.md +7 -0
  46. data/exe/rubydown +114 -0
  47. data/lib/rubydown.rb +59 -0
  48. data/lib/rubydown/version.rb +3 -0
  49. data/rubydown.gemspec +47 -0
  50. data/templates/template.html.erb +26 -0
  51. metadata +207 -0
@@ -0,0 +1,31 @@
1
+ Rumale machine learning examples
2
+
3
+
4
+ ~~~ruby
5
+ require 'rumale'
6
+ require 'rdatasets'
7
+
8
+ iris = RDatasets.load(:datasets, :iris)
9
+
10
+ iris_labels = iris['Species'].to_a
11
+ encoder = Rumale::Preprocessing::LabelEncoder.new
12
+ labels = encoder.fit_transform(iris_labels)
13
+ p "hoge"
14
+ ~~~
15
+
16
+ ~~~ruby
17
+ samples = Numo::DFloat[*iris[0..3].to_matrix.to_a]
18
+ ~~~
19
+
20
+ ~~~ruby
21
+ model = Rumale::LinearModel::SVC.new(
22
+ reg_param: 0.0001,
23
+ fit_bias: true,
24
+ max_iter: 3000,
25
+ random_seed: 1
26
+ )
27
+
28
+ model.fit(samples, labels)
29
+
30
+ p model.predict(samples).to_a
31
+ ~~~
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1">
5
+ <link href='https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css' rel='stylesheet' type='text/css' />
6
+ <style>
7
+ article.markdown-body {
8
+ box-sizing: border-box;
9
+ min-width: 200px;
10
+ max-width: 980px;
11
+ margin: 0 auto;
12
+ padding: 45px;
13
+ }
14
+
15
+ span.line-numbers {
16
+ display: none;
17
+ }
18
+ </style>
19
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
20
+ </head>
21
+ <body>
22
+ <article class='markdown-body'>
23
+ <h1 id="table-generation-example">Table generation example</h1>
24
+
25
+ <h2 id="with-numonarrayhttpsgithubcomruby-numonumo-narray">With <a href="https://github.com/ruby-numo/numo-narray">Numo::Narray</a></h2>
26
+
27
+ <pre><code class="language-ruby">a = Numo::DFloat.new(3, 5).seq
28
+ </code></pre>
29
+ <table>
30
+ <tbody>
31
+ <tr>
32
+ <td>0.0</td>
33
+ <td>1.0</td>
34
+ <td>2.0</td>
35
+ <td>3.0</td>
36
+ <td>4.0</td>
37
+ </tr>
38
+ <tr>
39
+ <td>5.0</td>
40
+ <td>6.0</td>
41
+ <td>7.0</td>
42
+ <td>8.0</td>
43
+ <td>9.0</td>
44
+ </tr>
45
+ <tr>
46
+ <td>10.0</td>
47
+ <td>11.0</td>
48
+ <td>12.0</td>
49
+ <td>13.0</td>
50
+ <td>14.0</td>
51
+ </tr>
52
+ </tbody>
53
+ </table>
54
+
55
+ </article>
56
+ </body>
57
+ </html>
data/examples/table.md ADDED
@@ -0,0 +1,7 @@
1
+ # Table generation example
2
+
3
+ ## With [Numo::Narray](https://github.com/ruby-numo/numo-narray)
4
+
5
+ ~~~ruby
6
+ a = Numo::DFloat.new(3, 5).seq
7
+ ~~~
data/exe/rubydown ADDED
@@ -0,0 +1,114 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'kramdown'
4
+ require 'erb'
5
+ require 'stringio'
6
+
7
+ require 'optparse'
8
+
9
+ require 'rubydown'
10
+
11
+ def get_context
12
+ binding
13
+ end
14
+
15
+ class EvalDoc < Kramdown::Document
16
+ attr_accessor :context, :stdout
17
+
18
+ def initialize(text, *opts)
19
+ super(text, *opts)
20
+
21
+ self.context = get_context
22
+ self.root = scan_el(self.root)
23
+ end
24
+
25
+ private
26
+ def scan_el(el)
27
+ new_children = []
28
+ el.children.each do |child_el|
29
+ child_el = scan_el(child_el)
30
+ new_children << child_el
31
+
32
+ is_code = child_el.type == :codeblock || child_el.type == :codespan
33
+
34
+ if is_code && child_el.options[:lang] == 'ruby'
35
+ code = child_el.value.gsub(/^ *ruby *\n/, '')
36
+ new_children << eval_and_elementize(code)
37
+ end
38
+ end
39
+
40
+ el.children = new_children
41
+
42
+ return el
43
+ end
44
+
45
+ def eval_and_elementize(code)
46
+ stdout = StringIO.new
47
+
48
+ $stdout = stdout
49
+ eval_result = self.context.eval(code)
50
+ $stdout = STDOUT
51
+
52
+ stdout_string = stdout.string.empty? ? '' : stdout.string + "\n"
53
+
54
+ case
55
+ when eval_result.respond_to?(:to_html)
56
+ Kramdown::Document.new(eval_result.to_html, input: :html).root
57
+ else
58
+ text_result_el(stdout_string + "=> #{eval_result}")
59
+ end
60
+ end
61
+
62
+ def text_result_el(text)
63
+ text_el = Kramdown::Element.new(:codeblock, text)
64
+ p_el = Kramdown::Element.new(:p)
65
+ p_el.children << text_el
66
+ p_el
67
+ end
68
+ end
69
+
70
+ def main # to separate binding
71
+
72
+ options = {}
73
+ options[:erb] = File.expand_path('../../templates/template.html.erb', __FILE__)
74
+ option_parser = OptionParser.new do |opts|
75
+ opts.on("-i INPUT", "Input form the file") do |input|
76
+ options[:input] = input
77
+ end
78
+ opts.on("-e ERB", "Specify template file") do |erb|
79
+ options[:erb] = erb
80
+ end
81
+ opts.on("-o OUTPUT", "Output html to OUTPUT") do |output|
82
+ options[:output] = output
83
+ end
84
+ opts.on("-h", "--help", "Prints this help") do
85
+ puts opts
86
+ exit
87
+ end
88
+ opts.on_tail("--version", "Show version") do
89
+ puts Rubydown::VERSION
90
+ exit
91
+ end
92
+ end
93
+
94
+ option_parser.parse!
95
+ # puts options.inspect
96
+ # puts options[:input]
97
+ # puts options[:erb]
98
+ # puts options[:output]
99
+
100
+ case options[:input]
101
+ when /\.md\z/i
102
+ options[:output] ||= options[:input].sub(/\.md\z/i, '.html')
103
+ when /./
104
+ abort("Input file must be markdown (*.md)")
105
+ else
106
+ abort(option_parser.help)
107
+ end
108
+
109
+ doc = EvalDoc.new(File.read(options[:input], encoding: 'utf-8')) # using in ERB
110
+ File.write(options[:output], ERB.new(File.read(options[:erb])).result(binding))
111
+ # puts ERB.new(File.read(options[:erb])).result(binding)
112
+ end
113
+
114
+ main
data/lib/rubydown.rb ADDED
@@ -0,0 +1,59 @@
1
+ require "rubydown/version"
2
+
3
+ require 'numo/narray'
4
+ require 'rbplotly'
5
+ require 'numo/gnuplot'
6
+ require 'base64'
7
+ require 'tempfile'
8
+
9
+
10
+ class Numo::NArray
11
+ def to_html
12
+ rows = self.to_a.map do |row|
13
+ elems = row.map do |elem|
14
+ "<td>#{elem}</td>"
15
+ end
16
+ "<tr>#{elems.join}</tr>"
17
+ end
18
+ "<table>#{rows.join}</table>"
19
+ end
20
+ end
21
+
22
+ class Numo::Int32
23
+ def to_html
24
+ <<-HTML
25
+ #{self.to_a}
26
+ HTML
27
+ end
28
+ end
29
+
30
+ module Rubydown
31
+ class RbMarkPlot < Numo::Gnuplot
32
+ def plot(*args)
33
+ super(*args)
34
+ self
35
+ end
36
+
37
+ def splot(*args)
38
+ super(*args)
39
+ self
40
+ end
41
+
42
+ def _plot_splot(*args)
43
+ @tempfile = Tempfile.open(['plot', '.png'])
44
+ set terminal: 'png'
45
+ set output: @tempfile.path
46
+ super(*args)
47
+ end
48
+
49
+ def to_html
50
+ img_b64 = Base64.encode64(File.binread(@tempfile))
51
+ <<-HTML
52
+ <img src='data:image/png;base64,#{img_b64}' />
53
+ HTML
54
+ end
55
+ end
56
+
57
+ class Error < StandardError; end
58
+ # Your code goes here...
59
+ end
@@ -0,0 +1,3 @@
1
+ module Rubydown
2
+ VERSION = "0.1.0"
3
+ end
data/rubydown.gemspec ADDED
@@ -0,0 +1,47 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rubydown/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubydown"
8
+ spec.version = Rubydown::VERSION
9
+ spec.authors = ["Kozo Nishida"]
10
+ spec.email = ["knishida@riken.jp"]
11
+ spec.license = 'MIT'
12
+ spec.summary = "Pure Ruby R Markdown clone."
13
+ spec.description = "rubydown is R Markdown clone for Rubyists."
14
+ spec.homepage = "https://github.com/sciruby-jp/rubydown"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/sciruby-jp/rubydown"
23
+ # spec.metadata["changelog_uri"] = "https//github.com/sciruby-jp/rubydown/blob/master/CHANGELOG.md"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_dependency "kramdown", "~> 2.1"
39
+ spec.add_dependency "daru", "~> 0.2"
40
+ spec.add_dependency "numo-narray", "~> 0.9.1"
41
+ spec.add_dependency "numo-gnuplot", "~> 0.2.4"
42
+ spec.add_dependency "rbplotly", "~> 0.1.2"
43
+
44
+ spec.add_development_dependency "bundler", "~> 1.17"
45
+ spec.add_development_dependency "rake", "~> 10.0"
46
+ spec.add_development_dependency "test-unit", "~> 3.3"
47
+ end
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1">
5
+ <link href='https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css' rel='stylesheet' type='text/css' />
6
+ <style>
7
+ article.markdown-body {
8
+ box-sizing: border-box;
9
+ min-width: 200px;
10
+ max-width: 980px;
11
+ margin: 0 auto;
12
+ padding: 45px;
13
+ }
14
+
15
+ span.line-numbers {
16
+ display: none;
17
+ }
18
+ </style>
19
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
20
+ </head>
21
+ <body>
22
+ <article class='markdown-body'>
23
+ <%= doc.to_html %>
24
+ </article>
25
+ </body>
26
+ </html>
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubydown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kozo Nishida
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kramdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: daru
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: numo-narray
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: numo-gnuplot
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: rbplotly
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.17'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.17'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: test-unit
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.3'
125
+ description: rubydown is R Markdown clone for Rubyists.
126
+ email:
127
+ - knishida@riken.jp
128
+ executables:
129
+ - rubydown
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".circleci/config.yml"
134
+ - ".gitignore"
135
+ - Dockerfile
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - _config.yml
142
+ - appveyor.yml
143
+ - bin/console
144
+ - bin/setup
145
+ - docs/_config.yml
146
+ - docs/index.html
147
+ - docs/sidebyside.md
148
+ - examples/bio.html
149
+ - examples/bio.md
150
+ - examples/graph.html
151
+ - examples/graph.md
152
+ - examples/index.html
153
+ - examples/index.md
154
+ - examples/numo-gnuplot.ipynb
155
+ - examples/rbplotly-bar.html
156
+ - examples/rbplotly-bar.md
157
+ - examples/rbplotly-basic.html
158
+ - examples/rbplotly-basic.md
159
+ - examples/rbplotly-boxplot.html
160
+ - examples/rbplotly-boxplot.md
161
+ - examples/rbplotly-heatmap.html
162
+ - examples/rbplotly-heatmap.md
163
+ - examples/rbplotly-hist.html
164
+ - examples/rbplotly-hist.md
165
+ - examples/rbplotly-line.html
166
+ - examples/rbplotly-line.md
167
+ - examples/rbplotly-pie.html
168
+ - examples/rbplotly-pie.md
169
+ - examples/rbplotly-scatter.html
170
+ - examples/rbplotly-scatter.md
171
+ - examples/rumale-kmeans.html
172
+ - examples/rumale-kmeans.md
173
+ - examples/rumale.html
174
+ - examples/rumale.md
175
+ - examples/table.html
176
+ - examples/table.md
177
+ - exe/rubydown
178
+ - lib/rubydown.rb
179
+ - lib/rubydown/version.rb
180
+ - rubydown.gemspec
181
+ - templates/template.html.erb
182
+ homepage: https://github.com/sciruby-jp/rubydown
183
+ licenses:
184
+ - MIT
185
+ metadata:
186
+ homepage_uri: https://github.com/sciruby-jp/rubydown
187
+ source_code_uri: https://github.com/sciruby-jp/rubydown
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubygems_version: 3.0.3
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Pure Ruby R Markdown clone.
207
+ test_files: []