datastory 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87dea24700cc2bdc46984ddd4cf9a7567b0b3ebb
4
+ data.tar.gz: 69aa1f62365fab941aa2c284856f6b5d5f71d74a
5
+ SHA512:
6
+ metadata.gz: c314b77af442cbe21b47dec8a654e83eab5e70e60cf977d3d3950621b18aaea1330da3abc2aa0fcf6910f59e37392cc6143f55df81046eee2d9b32a012c74b9e
7
+ data.tar.gz: b261f9dd9db34c7e2b0444701284115d169fe74c9419210f79ed28c2a91282d949319d04cafae7c4fc3384fa0819a8e79e402d0ff235d30dfadab7dde323e406
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in datastory.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alan Johnson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Datastory
2
+
3
+ DataStory is an extension on Markdown that helps you script documents that
4
+ tell a data story and show your work. DataStory is inspired by
5
+ [RMarkdown](http://www.rstudio.com/ide/docs/r_markdown).
6
+
7
+ DataStory attempts to go the extra mile and create a portable HTML output file that is self-contained,
8
+ using data uris, so any included images or filesare attached to the html file itself, including
9
+ the original source file.
10
+
11
+ ## Use with Caution
12
+
13
+ DataStory is in active dev right now, but isn't quite ready for prime time. Feel free to install it
14
+ and play around, but it's got a ways to go. Do report any problems you run into.
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'datastory'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install datastory
29
+
30
+ ## Usage
31
+
32
+ DataStory includes the DataStory command, which takes two arguments, input and output.
33
+
34
+ ```
35
+ datastory analysis.md analysis.html
36
+ ```
37
+
38
+ The input file should be a valid DataStory Markdown file. The output file should be a valid path
39
+ where a new html file can be created.
40
+
41
+ ## Syntax
42
+
43
+ At its core, DataStory converts Markdown to HTML. See the core
44
+ [Markdown reference](http://daringfireball.net/projects/markdown/syntax) to get familiar with
45
+ Markdown.
46
+
47
+ DataStory allows the use of code fences, using 3 backticks (```) to represent blocks of code. Adding
48
+ a language definition of ruby-datastory causes the code in the code fenced area to be both displayed
49
+ and executed, with its output displayed below the original code.
50
+
51
+ Using a language definition of ruby-datastory-silent will display the code and execute it, but not
52
+ display any output.
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/datastory ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/datastory"
4
+
5
+ puts "Processing #{ARGV[0]}..."
6
+ DataStory::Renderer.new(ARGV[0]).render_to(ARGV[1])
7
+ puts "Wrote to #{ARGV[1]}"
8
+ puts
data/datastory.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'datastory/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "datastory"
8
+ spec.version = DataStory::VERSION
9
+ spec.authors = ["Alan Johnson"]
10
+ spec.email = ["alan@commondream.com"]
11
+ spec.description = %q{Tell stories about data and share your work.}
12
+ spec.summary = %q{Tell stories about data and share your work.}
13
+ spec.homepage = "http://github.com/commondream/datastory"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "redcarpet", "~> 3.0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,24 @@
1
+ require "base64"
2
+
3
+ module DataStory
4
+ class DataURI
5
+
6
+ # Public: Generates a data uri from a file type and data.
7
+ def self.from_data(file_type, data)
8
+ encoded_data = Base64.strict_encode64(data)
9
+ "data:#{file_type};base64,%s" % encoded_data
10
+ end
11
+
12
+ # Public: Loads the file at file_path and converts it to a data uri.
13
+ def self.from_file(path)
14
+ file_type = `file --mime -b #{path}`
15
+
16
+ data = nil
17
+ File.open(path, "rb") do |file|
18
+ data = file.read
19
+ end
20
+
21
+ from_data(file_type, data)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,52 @@
1
+ require "redcarpet"
2
+
3
+ module DataStory
4
+ class MarkdownRenderer < Redcarpet::Render::HTML
5
+ def initialize
6
+ @binding = eval("binding;")
7
+ super
8
+ end
9
+
10
+ def block_code(code, language)
11
+ output = <<-EOF
12
+ <pre><code class="#{language}">#{code}</code></pre>
13
+ EOF
14
+
15
+ if language == "ruby-datastory" || language == "ruby-datastory-silent"
16
+ prev_stdout = $stdout
17
+ #prev_stderr = $stderr
18
+
19
+ out = StringIO.new
20
+ $stdout = out
21
+ #$stderr = out
22
+
23
+ eval(code, @binding)
24
+
25
+ $stdout = prev_stdout
26
+ #$stderr = prev_stderr
27
+
28
+ if out.string.length > 0 && language != "ruby-datastory-silent"
29
+ output += "<p>Output:</p><pre>#{out.string}</pre>"
30
+ end
31
+ end
32
+
33
+ output
34
+ end
35
+
36
+
37
+ # Inserts an image. If the image is relative to the current path it'll load it as a data
38
+ # URI to make the resulting report self contained.
39
+ def image(link, title, alt_text)
40
+ if link.start_with?("http")
41
+ <<-EOF
42
+ <img src="#{link}" alt="#{alt_text}" title="#{title}">
43
+ EOF
44
+ else
45
+ src = DataURI.from_file(link)
46
+ <<-EOF
47
+ <img src="#{src}" alt="#{alt_text}" title="#{title}">
48
+ EOF
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module DataStory
2
+ VERSION = "0.0.1"
3
+ end
data/lib/datastory.rb ADDED
@@ -0,0 +1,82 @@
1
+ require_relative "datastory/version"
2
+ require_relative "datastory/markdown_renderer"
3
+ require_relative "datastory/data_uri"
4
+
5
+ module DataStory
6
+ class Renderer
7
+ def initialize(path)
8
+ @path = path
9
+ @markdown = Redcarpet::Markdown.new(DataStory::MarkdownRenderer,
10
+ no_intra_emphasis: true,
11
+ fenced_code_blocks: true,
12
+ autolink: true,
13
+ disable_indented_code_blocks: true,
14
+ strikethrough: true,
15
+ lax_spacing: true,
16
+ space_after_headers: true,
17
+ superscript: true,
18
+ underline: true,
19
+ highlight: true,
20
+ footnotes: true)
21
+ end
22
+
23
+ def render_to(output_path)
24
+ markdown_data = File.read(@path)
25
+
26
+ output = @markdown.render(markdown_data)
27
+
28
+ doc = <<-EOF
29
+ <!DOCTYPE html>
30
+ <html>
31
+ <head>
32
+ <title>DataStory</title>
33
+ <style>
34
+ body {
35
+ font-family: Helvetica, Arial, sans-serif;
36
+ font-size: 100%;
37
+ }
38
+
39
+ h1,h2,h3,h4,h5,h6 {
40
+ font-family: "Times", "Times New Roman", serif;
41
+ }
42
+ h1 {
43
+ font-size: 2.5rem;
44
+ }
45
+
46
+ pre {
47
+ background: #eee;
48
+ padding: 8px;
49
+ }
50
+
51
+ footer {
52
+ font-size: .8rem;
53
+ border-top: 2px solid #eee;
54
+ }
55
+
56
+ .content {
57
+ width: 80%;
58
+ margin: 0 auto;
59
+ }
60
+ </style>
61
+ </head>
62
+ <body>
63
+ <div class="content">
64
+ #{output}
65
+
66
+ <footer>
67
+ <p>
68
+ <em>Generated by <a href="http://github.com/commondream/datastory">DataStory</a> on
69
+ #{Time.now}</em>. <a href="#{DataURI.from_file(@path)}">Original Source</a>
70
+ </p>
71
+ </footer>
72
+ </div>
73
+ </body>
74
+ </html>
75
+ EOF
76
+
77
+ File.open(output_path, "wb") do |file|
78
+ file.write(doc)
79
+ end
80
+ end
81
+ end
82
+ end
data/samples/test.md ADDED
@@ -0,0 +1,51 @@
1
+ # Test Story
2
+
3
+ The idea behind DataStory is that it's hard to tell stories with data sometimes, so we all need
4
+ tools that help us do that as easily as possible. DataStory uses markdown to convert scripts and
5
+ content into great looking output that tells a story.
6
+
7
+ ``` ruby-datastory
8
+ require 'gnuplot'
9
+ ```
10
+
11
+ ``` ruby-datastory
12
+ puts "This is a test"
13
+ output = 5 + 5
14
+ puts output
15
+ ```
16
+
17
+ Here's some code with no output. It shouldn't have an output section under it.
18
+
19
+ ``` ruby-datastory
20
+ output += 2
21
+ ```
22
+
23
+ And then another output.
24
+ ``` ruby-datastory
25
+ puts output
26
+ ```
27
+
28
+ Now let's output a graph:
29
+
30
+ ``` ruby-datastory
31
+ Gnuplot.open do |gp|
32
+ Gnuplot::Plot.new(gp) do |plot|
33
+ plot.terminal "gif"
34
+ plot.output "tmp/sin_wave.gif"
35
+
36
+ # see sin_wave.rb
37
+ plot.xrange "[-10:10]"
38
+ plot.title "Sin Wave Example"
39
+ plot.ylabel "sin(x)"
40
+ plot.xlabel "x"
41
+
42
+ plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds|
43
+ ds.with = "lines"
44
+ ds.linewidth = 4
45
+ end
46
+
47
+ end
48
+ end
49
+ ```
50
+
51
+ ![Graph of Stuff](tmp/sin_wave.gif)
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datastory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alan Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.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: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Tell stories about data and share your work.
56
+ email:
57
+ - alan@commondream.com
58
+ executables:
59
+ - datastory
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/datastory
69
+ - datastory.gemspec
70
+ - lib/datastory.rb
71
+ - lib/datastory/data_uri.rb
72
+ - lib/datastory/markdown_renderer.rb
73
+ - lib/datastory/version.rb
74
+ - samples/test.md
75
+ homepage: http://github.com/commondream/datastory
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.6
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Tell stories about data and share your work.
99
+ test_files: []
100
+ has_rdoc: