jekyll-cargodoc 0.0.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 (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jekyll/cargodoc.rb +127 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41170f909b267c7d9817db99f9d4f92aada714a4
4
+ data.tar.gz: b0f7a29a8773e788cec21fa9428b76380b00eded
5
+ SHA512:
6
+ metadata.gz: 7de536593c54bc193f6871cdda7b6c0700e0cc817fb46e3182cab7c0d10f81d531a0c62564f1d2b4e0d71d8ad91e73f68d5a25244d6d27d5ce8d84e4f4025ad8
7
+ data.tar.gz: d94698eb275cd6363ed1bdc62e765e9b05063680b2634c5d3ab85dd107f16a44bc9d28b40d65f9deebb738fd711905aa4d44935433c7657ac0fa8038bb0b1723
@@ -0,0 +1,127 @@
1
+ require 'jekyll'
2
+
3
+ module Jekyll
4
+ module Cargodoc
5
+ class Crate
6
+ attr_reader :name, :destination_root
7
+
8
+ def initialize(config)
9
+ @name = config['crate'] || ''
10
+ @version = config['version'] || '*'
11
+ @destination_root = config['destination_root'] || name
12
+ @git = config['git']
13
+ end
14
+
15
+ def dependency_section
16
+ section = "\n[dependencies"
17
+ section << ".#{name}" unless @git.nil?
18
+ section << "]\n"
19
+
20
+ section
21
+ end
22
+
23
+ def dependency_line
24
+ if !@git.nil?
25
+ "git = \"#{@git}\""
26
+ else
27
+ "#{@name} = \"#{@version}\"\n"
28
+ end
29
+ end
30
+
31
+ def doc_files_paths(root)
32
+ Dir.chdir("#{root}/#{name}") do
33
+ Dir.glob("**/*").reject { |path| Dir.exist?(path) }
34
+ end
35
+ end
36
+ end
37
+
38
+ class CargoRunner
39
+ DIR = '_cargo'
40
+ DOTFILE = ".jekyll-cargodoc"
41
+ DOC_TARGET = "#{DIR}/target/doc"
42
+
43
+ def initialize(crates)
44
+ @crates = crates
45
+ end
46
+
47
+ def run
48
+ abort_if_invalid
49
+ create_dir
50
+ add_dependencies
51
+ build_docs
52
+ end
53
+
54
+ private
55
+
56
+ def abort_if_invalid
57
+ if File.exist?(DIR) && !File.exist?("#{DIR}/#{DOTFILE}")
58
+ raise "#{DIR} isn't ours, stopping."
59
+ end
60
+ end
61
+
62
+ def create_dir
63
+ system("rm -r #{DIR}") if Dir.exist?(DIR)
64
+ system("cargo new #{DIR}")
65
+ system("touch #{DIR}/#{DOTFILE}")
66
+ end
67
+
68
+ def add_dependencies
69
+ File.open("#{DIR}/Cargo.toml", 'a') do |cargo_toml|
70
+
71
+ @crates.group_by(&:dependency_section).each do |section, crates|
72
+ cargo_toml.write(section)
73
+ crates.each { |crate| cargo_toml.write(crate.dependency_line) }
74
+ end
75
+
76
+ end
77
+ end
78
+
79
+ def build_docs
80
+ Dir.chdir("./#{DIR}") do |path|
81
+ @crates.each { |crate| system("cargo doc -p #{crate.name}") }
82
+ end
83
+ end
84
+ end
85
+
86
+ class RustDocFile < Jekyll::StaticFile
87
+ def initialize(site, base, dir, name, destination_root)
88
+ @destination_root = destination_root
89
+ super(site, base, dir, name)
90
+ end
91
+
92
+ def destination(dest)
93
+ [dest, @destination_root, destination_rel_dir, @name].join('/')
94
+ end
95
+ end
96
+
97
+ class Generator < Jekyll::Generator
98
+ def generate(site)
99
+ # if no crates are specified, there's nothing to do
100
+ return unless crate_configs = site.config['cargodoc']
101
+
102
+ crates = crate_configs.map do |crate_config|
103
+ Crate.new(crate_config)
104
+ end
105
+ CargoRunner.new(crates).run
106
+
107
+ files = crates.map { |crate| files_for_crate(site, crate) }.flatten
108
+ files.each { |page| site.static_files << page }
109
+ end
110
+
111
+ private
112
+
113
+ def files_for_crate(site, crate)
114
+ # paths = crate.doc_files_paths(CargoRunner::DOC_TARGET)
115
+ paths = Dir.chdir(CargoRunner::DOC_TARGET) do
116
+ Dir.glob('**/*').reject { |path| Dir.exist?(path) }
117
+ end
118
+ files = paths.map do |path|
119
+ components = path.split('/')
120
+ path = components.pop
121
+ dir = components.join('/')
122
+ RustDocFile.new(site, CargoRunner::DOC_TARGET, dir, path, crate.destination_root)
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-cargodoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Light
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: daniel.sj.light@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/jekyll/cargodoc.rb
20
+ homepage:
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.5
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A plugin to help generate rust docs for a crate into your jekyll site.
44
+ test_files: []