datastory 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/datastory.gemspec +2 -1
- data/lib/datastory/eval_context.rb +13 -13
- data/lib/datastory/markdown_renderer.rb +12 -13
- data/lib/datastory/version.rb +1 -1
- data/lib/datastory.rb +19 -0
- data/samples/test.md +14 -13
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08a71919d602181417d23cb9e32cc6ea6db5b234
|
4
|
+
data.tar.gz: 2c9ba177faac33e62bfaae6ec340254289142ebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33cf0f2ca6ce97e2c5f3ca554a69d1a09193a0ff7e4d5d966a79812f4738d573a2068582b52475cceeca91691ae1d3a2b42528b35cdb18fdf188f3e0192b38b7
|
7
|
+
data.tar.gz: 884b128831cc442c95e06beadf575533e99b4d6e673d0aa2aec898e67435166fbbf104277d6584900721ea76f435c1da02db3cf0dce4f24766175758ea4e4a2c
|
data/datastory.gemspec
CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "redcarpet", "~> 3.0.0"
|
22
|
-
|
22
|
+
spec.add_dependency "erubis", "~> 2.7.0"
|
23
|
+
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
+
require "erubis"
|
2
|
+
|
1
3
|
module DataStory
|
2
4
|
class EvalContext
|
3
5
|
|
4
|
-
#
|
6
|
+
# Public: Evaluates the passed code in this context.
|
5
7
|
def self.evaluate(code)
|
6
|
-
@binding ||= binding
|
7
|
-
@append = ""
|
8
|
-
|
9
8
|
prev_stdout = $stdout
|
10
9
|
#prev_stderr = $stderr
|
11
10
|
|
@@ -13,21 +12,22 @@ module DataStory
|
|
13
12
|
$stdout = out
|
14
13
|
#$stderr = out
|
15
14
|
|
16
|
-
eval(code,
|
15
|
+
eval(code, eval_binding)
|
17
16
|
|
18
17
|
$stdout = prev_stdout
|
19
18
|
#$stderr = prev_stderr
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
out.string
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Evaluates some ERb in this context.
|
24
|
+
def self.evaluate_erb(code)
|
25
|
+
erb = Erubis::EscapedEruby.new(code)
|
26
|
+
erb.result(eval_binding)
|
25
27
|
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
@append ||= ""
|
30
|
-
@append << content
|
29
|
+
def self.eval_binding
|
30
|
+
@binding ||= eval("binding")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -3,24 +3,23 @@ require "cgi"
|
|
3
3
|
|
4
4
|
module DataStory
|
5
5
|
class MarkdownRenderer < Redcarpet::Render::HTML
|
6
|
-
def initialize
|
7
|
-
@binding = eval("binding;")
|
8
|
-
super
|
9
|
-
end
|
10
|
-
|
11
6
|
def block_code(code, language)
|
12
|
-
output =
|
13
|
-
|
14
|
-
|
7
|
+
output = ""
|
8
|
+
|
9
|
+
unless language == "ruby-datastory-erb"
|
10
|
+
output += <<-EOF
|
11
|
+
<pre><code class="#{language}">#{CGI.escapeHTML(code)}</code></pre>
|
12
|
+
EOF
|
13
|
+
end
|
15
14
|
|
16
|
-
if language == "ruby-datastory"
|
17
|
-
eval_output
|
15
|
+
if language == "ruby-datastory"
|
16
|
+
eval_output = EvalContext.evaluate(code)
|
18
17
|
|
19
|
-
if eval_output.length > 0
|
18
|
+
if eval_output.length > 0
|
20
19
|
output += "<p>Output:</p><pre>#{CGI.escapeHTML(eval_output)}</pre>"
|
21
20
|
end
|
22
|
-
|
23
|
-
output +=
|
21
|
+
elsif language == "ruby-datastory-erb"
|
22
|
+
output += EvalContext.evaluate_erb(code)
|
24
23
|
end
|
25
24
|
|
26
25
|
output
|
data/lib/datastory/version.rb
CHANGED
data/lib/datastory.rb
CHANGED
@@ -53,6 +53,25 @@ module DataStory
|
|
53
53
|
font-size: .8rem;
|
54
54
|
border-top: 2px solid #eee;
|
55
55
|
}
|
56
|
+
|
57
|
+
table {
|
58
|
+
width: 100%;
|
59
|
+
overflow: scroll;
|
60
|
+
border-collapse: collapse;
|
61
|
+
margin: 1rem 0;
|
62
|
+
font-size: .8rem
|
63
|
+
}
|
64
|
+
table caption {
|
65
|
+
margin-bottom: .5rem;
|
66
|
+
font-size: 1rem;
|
67
|
+
}
|
68
|
+
td, th {
|
69
|
+
border: 1px solid #ccc;
|
70
|
+
padding: 3px;
|
71
|
+
}
|
72
|
+
th {
|
73
|
+
background: #eee;
|
74
|
+
}
|
56
75
|
|
57
76
|
.content {
|
58
77
|
width: 80%;
|
data/samples/test.md
CHANGED
@@ -52,17 +52,18 @@ end
|
|
52
52
|
|
53
53
|
The following code uses the `append` method to append html output to the document.
|
54
54
|
|
55
|
-
``` ruby-datastory
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
55
|
+
``` ruby-datastory-erb
|
56
|
+
<table>
|
57
|
+
<caption>Some random numbers.</caption>
|
58
|
+
<tr>
|
59
|
+
<% 6.times do |i| %>
|
60
|
+
<th><%= i %></th>
|
61
|
+
<% end %>
|
62
|
+
</tr>
|
63
|
+
<tr>
|
64
|
+
<% 6.times do %>
|
65
|
+
<td><%= rand %></td>
|
66
|
+
<% end %>
|
67
|
+
</tr>
|
68
|
+
</table>
|
68
69
|
```
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datastory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Johnson
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: erubis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.7.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.7.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|