-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Spec builders with PNG diagram as first PoC
(#9)
- Loading branch information
1 parent
491b334
commit 9f7ebd8
Showing
6 changed files
with
199 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lib/jekyll-theme-open-project-helpers/spec_builders/png_diagram.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{% comment %}Page stub.{% endcomment %} | ||
|
||
<div id="diagramContainer" style="height: {{ page.image_height }}px"></div> | ||
|
||
<style> | ||
.leaflet-container { | ||
background-color: transparent; | ||
} | ||
.documentation.with-expandable-toc > article { | ||
max-width: none; | ||
} | ||
</style> | ||
|
||
<script> | ||
(function () { | ||
var map = L.map('diagramContainer', { | ||
crs: L.CRS.Simple, | ||
attributionControl: false, | ||
scrollWheelZoom: false, | ||
zoomControl: false, | ||
minZoom: -10, | ||
}). | ||
setView([{{ page.image_height }}/2, {{ page.image_width }}/2]); | ||
|
||
map.addControl(L.control.zoom({ position: 'bottomleft' })); | ||
|
||
var bounds = [[0,0], [{{ page.image_height }}, {{ page.image_width }}]]; | ||
var image = L.imageOverlay('{{ page.image_path }}', bounds).addTo(map); | ||
map.fitBounds(bounds); | ||
}()); | ||
</script> |
66 changes: 66 additions & 0 deletions
66
lib/jekyll-theme-open-project-helpers/spec_builders/png_diagrams.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'fastimage' | ||
|
||
module Builder | ||
|
||
class PngDiagramPage < Jekyll::Page | ||
def initialize(site, base, dir, data) | ||
@site = site | ||
@base = base | ||
@dir = dir | ||
@name = 'index.html' | ||
|
||
self.process(@name) | ||
self.data ||= data | ||
|
||
self.data['extra_stylesheets'] = [{ | ||
"href" => "https://unpkg.com/[email protected]/dist/leaflet.css", | ||
"integrity" => "sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==", | ||
"crossorigin" => "", | ||
}] | ||
|
||
self.data['extra_scripts'] = [{ | ||
"src" => "https://unpkg.com/[email protected]/dist/leaflet.js", | ||
"integrity" => "sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==", | ||
"crossorigin" => "", | ||
}] | ||
|
||
self.data['layout'] = 'spec' | ||
end | ||
end | ||
|
||
def build_spec_pages(site, spec_info, source, destination, opts) | ||
images_path = source | ||
spec_root = destination | ||
stub_path = "#{File.dirname(__FILE__)}/png_diagram.html" | ||
pages = [] | ||
|
||
Dir.glob("#{images_path}/*.png") do |pngfile| | ||
png_name = File.basename(pngfile) | ||
png_name_noext = File.basename(png_name, File.extname(png_name)) | ||
|
||
nav_item = spec_info.data['navigation']['sections'].map { |section| | ||
section['items'] | ||
} .flatten.select { |item| item['path'] == png_name_noext} [0].clone | ||
|
||
png_dimensions = FastImage.size(pngfile) | ||
data = spec_info.data.clone | ||
data['image_path'] = "/#{spec_root}/images/#{png_name}" | ||
data['image_width'] = png_dimensions[0] | ||
data['image_height'] = png_dimensions[1] | ||
data = data.merge(nav_item) | ||
|
||
data['title'] = "#{spec_info['title']}: #{nav_item['title']}" | ||
|
||
page = PngDiagramPage.new( | ||
site, | ||
site.source, | ||
File.join(spec_root, png_name_noext), | ||
data) | ||
page.content = File.read(stub_path) | ||
pages << page | ||
end | ||
|
||
return pages | ||
end | ||
|
||
end |
33 changes: 33 additions & 0 deletions
33
lib/jekyll-theme-open-project-helpers/spec_builders/spec_builder.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'forwardable' | ||
|
||
module Jekyll | ||
module OpenProjectHelpers | ||
class SpecBuilder | ||
|
||
attr_reader :built_pages | ||
|
||
def initialize(site, spec_index_doc, spec_source_base, spec_out_base, engine, opts) | ||
require_relative engine | ||
extend Builder # adds the build_spec_pages method | ||
|
||
@site = site | ||
@spec_index_doc = spec_index_doc | ||
@spec_source_base = spec_source_base | ||
@spec_out_base = spec_out_base | ||
@opts = opts | ||
|
||
@built_pages = [] | ||
end | ||
|
||
def build() | ||
@built_pages = build_spec_pages( | ||
@site, | ||
@spec_index_doc, | ||
@spec_source_base, | ||
@spec_out_base, | ||
@opts) | ||
end | ||
|
||
end | ||
end | ||
end |