graphdown 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: 7b329ba5609ea9ef8ce2ac37f20d4281f03da537
4
+ data.tar.gz: ef617d20ca0ccac07840e32b55d15544b6a0eba2
5
+ SHA512:
6
+ metadata.gz: fbc79e190bde04380d98dd47db187e384c88ac38dc9d656f440283dfb3c09b74cca17dd7e3f4e2c4c7d42a6a07856e0e4a7a7b06b891815b136a3ce2e04a47fd
7
+ data.tar.gz: 1fee7608cea1f178ec37a8cf6f592d3846be1718b1e26abba75d468acdb095401b17098ce1ec2f2ff51ab0e9f5f3e282c98011812f9ec713fae76ca4923d1146
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .rspec
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in graphdown.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Naoto Kaneko
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,53 @@
1
+ # Graphdown
2
+
3
+ Markdown extension for embedding graphs.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ $ gem install graphdown
9
+ ```
10
+
11
+ ## Requirements
12
+
13
+ - [Graphviz](http://www.graphviz.org/)
14
+
15
+ ## Usage
16
+
17
+ ```rb
18
+ require "redcarpet"
19
+ require "graphdown"
20
+
21
+ class BaseRenderer < Redcarpet::Render::HTML
22
+ include Graphdown::Renderable
23
+ # include other extensions
24
+ end
25
+
26
+ markdown = Redcarpet::Markdown.new(BaseRenderer, fenced_code_blocks: true)
27
+ markdown.render(content)
28
+ ```
29
+
30
+ ## Example
31
+
32
+ ```md
33
+ # Views transition
34
+
35
+ \```dot
36
+ digraph sample {
37
+ A [label = "index.html"];
38
+ B [label = "show.html"];
39
+ C [label = "new.html"];
40
+
41
+ A -> B [dir = both];
42
+ A -> C;
43
+ C -> A [label = "redirect"];
44
+ }
45
+ \```
46
+
47
+ - Users visit show.html from index.html.
48
+ - Users visit index.html from show.html.
49
+ - Users visit new.html from index.html.
50
+ - Users are redirected to index.html from new.html.
51
+ ```
52
+
53
+ Graphdown parses block codes which language is 'dot' into img tags, which load graph PNG image. The image is generated by Graphviz.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ require "redcarpet"
2
+ require "graphdown"
3
+
4
+ class BaseRenderer < Redcarpet::Render::HTML
5
+ include Graphdown::Renderable
6
+ end
7
+
8
+ markdown = Redcarpet::Markdown.new(BaseRenderer, fenced_code_blocks: true)
9
+ File.open("sample.md", "rb") do |file|
10
+ content = file.read
11
+ html = markdown.render(content)
12
+ File.open("sample.html", "wb") { |file| file.write(html) }
13
+ end
@@ -0,0 +1,8 @@
1
+ <h1>Views transition</h1>
2
+ <img src="/Users/naoty/workspace/ruby/graphdown/examples/sample.png"/>
3
+ <ul>
4
+ <li>Users visit show.html from index.html.</li>
5
+ <li>Users visit index.html from show.html.</li>
6
+ <li>Users visit new.html from index.html.</li>
7
+ <li>Users are redirected to index.html from new.html.</li>
8
+ </ul>
@@ -0,0 +1,18 @@
1
+ # Views transition
2
+
3
+ ```dot
4
+ digraph sample {
5
+ A [label = "index.html"];
6
+ B [label = "show.html"];
7
+ C [label = "new.html"];
8
+
9
+ A -> B [dir = both];
10
+ A -> C;
11
+ C -> A [label = "redirect"];
12
+ }
13
+ ```
14
+
15
+ - Users visit show.html from index.html.
16
+ - Users visit index.html from show.html.
17
+ - Users visit new.html from index.html.
18
+ - Users are redirected to index.html from new.html.
Binary file
data/graphdown.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "graphdown"
6
+ spec.version = "0.0.1"
7
+ spec.authors = ["Naoto Kaneko"]
8
+ spec.email = ["naoty.k@gmail.com"]
9
+ spec.summary = %q{Markdown extension for embedding graphs.}
10
+ spec.homepage = "https://github.com/naoty/graphdown"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "redcarpet", "~> 3.0.0"
19
+ spec.add_development_dependency "bundler", "~> 1.5"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rspec", "~> 2.14.1"
22
+ end
@@ -0,0 +1,38 @@
1
+ require "pathname"
2
+ require "pry"
3
+
4
+ module Graphdown
5
+ module Renderable
6
+ if defined?(block_code)
7
+ alias block_code_without_graphdown block_code
8
+ else
9
+ def block_code_without_graphdown(code, language)
10
+ %(<p><code>#{code}</code></p>)
11
+ end
12
+ end
13
+
14
+ def block_code_with_graphdown(code, language)
15
+ if language == "dot"
16
+ if code =~ /digraph\s+(\w+)\s+{/
17
+ dot_path = Pathname.pwd.join("#{$1}.dot")
18
+ dot_path.open("wb") { |f| f.write(code) }
19
+ graph_path = Pathname.pwd.join("#{$1}.png")
20
+ generate_graph(dot_path.to_s, graph_path.to_s)
21
+ dot_path.delete
22
+ %(<img src="#{graph_path.to_s}"/>)
23
+ else
24
+ %(<img src="#"/>)
25
+ end
26
+ else
27
+ block_code_without_graphdown(code, language)
28
+ end
29
+ end
30
+ alias block_code block_code_with_graphdown
31
+
32
+ private
33
+
34
+ def generate_graph(source, output)
35
+ system %(dot -Tpng -o #{output} #{source})
36
+ end
37
+ end
38
+ end
data/lib/graphdown.rb ADDED
@@ -0,0 +1,5 @@
1
+ lib = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require "redcarpet"
5
+ require "graphdown/renderable"
@@ -0,0 +1,18 @@
1
+ # Views transition
2
+
3
+ ```dot
4
+ digraph sample {
5
+ A [label = "index.html"];
6
+ B [label = "show.html"];
7
+ C [label = "new.html"];
8
+
9
+ A -> B [dir = both];
10
+ A -> C;
11
+ C -> A [label = "redirect"];
12
+ }
13
+ ```
14
+
15
+ - Users visit show.html from index.html.
16
+ - Users visit index.html from show.html.
17
+ - Users visit new.html from index.html.
18
+ - Users are redirected to index.html from new.html.
@@ -0,0 +1,7 @@
1
+ # Routing
2
+
3
+ ```rb
4
+ SampleApp::Application.routes.draw do
5
+ resources :contents
6
+ end
7
+ ```
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ class BaseRenderer < Redcarpet::Render::HTML
4
+ include Graphdown::Renderable
5
+ end
6
+
7
+ describe Graphdown::Renderable do
8
+ let(:markdown) { Redcarpet::Markdown.new(BaseRenderer, fenced_code_blocks: true) }
9
+ let(:fixtures_path) { Pathname.new("spec/fixtures") }
10
+ let(:dot_path) { Pathname.pwd.join("sample.dot") }
11
+ let(:graph_path) { Pathname.pwd.join("sample.png") }
12
+
13
+ context "when the language of block code is dot" do
14
+ let(:content) { fixtures_path.join("sample.md").read }
15
+ after do
16
+ graph_path.delete if graph_path.exist?
17
+ end
18
+
19
+ it "generates img tag" do
20
+ html = markdown.render(content)
21
+ expect(html).to match /<img src="#{graph_path.to_s}"\/>/
22
+ end
23
+
24
+ it "generates graph image file" do
25
+ markdown.render(content)
26
+ expect(graph_path).to be_exist
27
+ end
28
+ end
29
+
30
+ context "when the language of block code isn't dot" do
31
+ let(:content) { fixtures_path.join("sample_without_graph.md").read }
32
+
33
+ it "generates code tag" do
34
+ html = markdown.render(content)
35
+ expect(html).to match /<code>.+<\/code>/m
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path("../lib/graphdown", File.dirname(__FILE__))
2
+ require "pathname"
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.order = "random"
7
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naoto Kaneko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-21 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.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ description:
70
+ email:
71
+ - naoty.k@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - examples/parser.rb
82
+ - examples/sample.html
83
+ - examples/sample.md
84
+ - examples/sample.png
85
+ - graphdown.gemspec
86
+ - lib/graphdown.rb
87
+ - lib/graphdown/renderable.rb
88
+ - spec/fixtures/sample.md
89
+ - spec/fixtures/sample_without_graph.md
90
+ - spec/graphdown/renderable_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/naoty/graphdown
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.14
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Markdown extension for embedding graphs.
116
+ test_files:
117
+ - spec/fixtures/sample.md
118
+ - spec/fixtures/sample_without_graph.md
119
+ - spec/graphdown/renderable_spec.rb
120
+ - spec/spec_helper.rb