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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa61e11b6d796a4492f4a3245328a44504080358
4
- data.tar.gz: 7c8d49b6fb6c6297aa5017ce1e6ee0d72438a24c
3
+ metadata.gz: 08a71919d602181417d23cb9e32cc6ea6db5b234
4
+ data.tar.gz: 2c9ba177faac33e62bfaae6ec340254289142ebe
5
5
  SHA512:
6
- metadata.gz: 9bcb0fffae195e371304c45fd36f6115d7dda2665d6b892d5a5efd985a3b9e982abaaa30f5632d1ffa8fda724311a0867a263994d915dc70abf698abb1f012d1
7
- data.tar.gz: d0011f9eaaafe5fafe43e956b0ba5bcd67114f38647bf15d9ca0b98c9e5580cdd094ed61757030142a441e135e3a44b7ed378bd1e44db31c6e6455ad146be592
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
- # Returns the binding for this context.
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, @binding)
15
+ eval(code, eval_binding)
17
16
 
18
17
  $stdout = prev_stdout
19
18
  #$stderr = prev_stderr
20
19
 
21
- to_return = [out.string, @append.clone]
22
- @append = nil
23
-
24
- to_return
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
- # Public: Appends html to the document.
28
- def self.append(content)
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 = <<-EOF
13
- <pre><code class="#{language}">#{CGI.escapeHTML(code)}</code></pre>
14
- EOF
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" || language == "ruby-datastory-silent"
17
- eval_output, append = EvalContext.evaluate(code)
15
+ if language == "ruby-datastory"
16
+ eval_output = EvalContext.evaluate(code)
18
17
 
19
- if eval_output.length > 0 && language != "ruby-datastory-silent"
18
+ if eval_output.length > 0
20
19
  output += "<p>Output:</p><pre>#{CGI.escapeHTML(eval_output)}</pre>"
21
20
  end
22
-
23
- output += append
21
+ elsif language == "ruby-datastory-erb"
22
+ output += EvalContext.evaluate_erb(code)
24
23
  end
25
24
 
26
25
  output
@@ -1,3 +1,3 @@
1
1
  module DataStory
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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
- append "<table>"
57
- append "<tr>"
58
- 12.times do |i|
59
- append "<td>#{i}</td>"
60
- end
61
- append "</tr>"
62
- append "<tr>"
63
- 12.times do
64
- append "<td>#{rand}</td>"
65
- end
66
- append "</tr>"
67
- append "</table>"
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.2
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