zenml-slide 1.0.2 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbd249bf130c4a84e1a05261112feb40a12a92c2f1a319a0c5129a82fafc9323
4
- data.tar.gz: 5c66c7a588bddd07243d68f7b68d44d7686dc03db0395b70809113fc67d448fb
3
+ metadata.gz: f62c999fa7c6c65551a0f86aeb2ef5ae23b937ab694241303cc7f0d58e06a0c1
4
+ data.tar.gz: 315cb39a7434912b14e7037eaf01e0b2b0f1fab15a3de72aa80f73843882d843
5
5
  SHA512:
6
- metadata.gz: a0d4d10cccd3f6bb34842a0d23719de911083dc4e2af7a7e956abd31137b2ab3298c824f11575cd4134f35f5ef630e2686b23da2a5eef0442f34553325f7ff9e
7
- data.tar.gz: 1473998ce07ced0ad0fbeb8f4122bfff04a9d04a981b86018f9368d71cb40dd27ac7a27ffd7760da7a26b52ba3e345fcc941b2c30cb0d1afd6fbf9acde323362
6
+ metadata.gz: 8f1f73aefd08ff49652df3b0aea59ff2b6f484289a9e535da8adc9fc75c6cfb622b26b94bc77ab58f149ba3c5e66f3658b561bd0065be0a9353ff29fb1449448
7
+ data.tar.gz: 25c339d308f0e732eca237eda687fb18f8cf6e2231b0ac6b85bbcc52b5a28ec3c6039b4d16cd74ff047dd5ec62f7a78cc104926566a109fef0dcaa0222fabdfd
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Zenithal::Slide
5
5
 
6
- VERSION = "1.0.2"
6
+ VERSION = "1.1.0"
7
7
  VERSION_ARRAY = VERSION.split(/\./).map(&:to_i)
8
8
 
9
9
  end
@@ -3,9 +3,14 @@
3
3
 
4
4
  class Zenithal::Slide::WholeSlideConverter
5
5
 
6
+ TEMPLATE = File.read(File.join(File.dirname(__FILE__), "resource/template.html"))
7
+ SCRIPT = File.read(File.join(File.dirname(__FILE__), "resource/script.js"))
8
+
6
9
  def initialize(args)
7
10
  @mode, @open = nil, false
8
11
  @dirs = {:output => "out", :document => "document", :template => "template"}
12
+ @asset_paths = {:style => ["style/style.css"]}
13
+ @title = "Slide"
9
14
  @image_size = [1920, 1080]
10
15
  options, rest_args = args.partition{|s| s =~ /^\-\w$/}
11
16
  if options.include?("-i")
@@ -59,8 +64,12 @@ class Zenithal::Slide::WholeSlideConverter
59
64
  @parser.update(File.read(path))
60
65
  document = @parser.run
61
66
  @converter.update(document)
62
- output = @converter.convert
67
+ header_string = ""
68
+ main_string = @converter.convert
63
69
  count = @converter.variables[:slide_count].to_i.to_s
70
+ header_string << "<script type=\"text/javascript\">#{SCRIPT}</script>\n"
71
+ header_string << @asset_paths[:style].map{|s| "<link rel=\"stylesheet\" type=\"text/css\" href=\"../#{s}\">\n"}.join
72
+ output = TEMPLATE.gsub(/#\{(.*?)\}/){instance_eval($1)}.gsub(/\r/, "")
64
73
  File.write(output_path, output)
65
74
  File.write(count_path, count)
66
75
  when "scss"
@@ -76,18 +85,22 @@ class Zenithal::Slide::WholeSlideConverter
76
85
  end
77
86
 
78
87
  def convert_image(path)
88
+ extension = File.extname(path).gsub(/^\./, "")
79
89
  page_path = path.gsub(@dirs[:document], @dirs[:output]).then(&method(:modify_extension))
80
90
  output_path = path.gsub(@dirs[:document], @dirs[:output]).gsub("slide", "image").gsub(".zml", "")
81
91
  count_path = path.gsub(@dirs[:document], @dirs[:output]).gsub("slide", "image").gsub(".zml", ".txt")
82
92
  output_dir = File.dirname(output_path)
83
- count = File.read(count_path).to_i
84
93
  FileUtils.mkdir_p(output_dir)
85
- @driver.navigate.to("file:///#{File.join(Dir.pwd, page_path)}")
86
- @driver.manage.window.resize_to(*@image_size)
87
- @driver.execute_script("document.body.classList.add('simple');")
88
- count.times do |index|
89
- @driver.execute_script("document.querySelectorAll('*[class$=\\'slide\\']')[#{index}].scrollIntoView();")
90
- @driver.save_screenshot("#{output_path}-#{index}.png")
94
+ case extension
95
+ when "zml"
96
+ count = File.read(count_path).to_i
97
+ @driver.navigate.to("file:///#{File.join(Dir.pwd, page_path)}")
98
+ @driver.manage.window.resize_to(*@image_size)
99
+ @driver.execute_script("document.body.classList.add('simple');")
100
+ count.times do |index|
101
+ @driver.execute_script("document.querySelectorAll('*[class$=\\'slide\\']')[#{index}].scrollIntoView();")
102
+ @driver.save_screenshot("#{output_path}-#{index}.png")
103
+ end
91
104
  end
92
105
  end
93
106
 
@@ -103,8 +116,9 @@ class Zenithal::Slide::WholeSlideConverter
103
116
  dirs << File.join(@dirs[:document], "slide")
104
117
  if @mode == :normal
105
118
  dirs << File.join(@dirs[:document], "asset")
106
- paths << File.join(@dirs[:document], "style", "style.scss")
107
- paths << File.join(@dirs[:document], "script", "script.js")
119
+ @asset_paths[:style].each do |style_path|
120
+ paths << File.join(@dirs[:document], style_path)
121
+ end
108
122
  end
109
123
  dirs.each do |dir|
110
124
  Dir.each_child(dir) do |entry|
@@ -182,6 +196,14 @@ class Zenithal::Slide::WholeSlideConverter
182
196
  @dirs[:template] = dir
183
197
  end
184
198
 
199
+ def script_paths=(paths)
200
+ @asset_paths[:script] = paths
201
+ end
202
+
203
+ def title=(title)
204
+ @title = title
205
+ end
206
+
185
207
  def image_size=(image_size)
186
208
  @image_size = image_size
187
209
  end
@@ -0,0 +1,28 @@
1
+ //
2
+
3
+
4
+ let index = 0;
5
+
6
+ function prepare() {
7
+ let size = document.querySelectorAll("*[class$='slide']").length;
8
+ document.addEventListener("keydown", (event) => {
9
+ if (event.key === "ArrowLeft" || event.key === "ArrowUp" || event.key === "Backspace") {
10
+ if (index > 0) {
11
+ index --;
12
+ }
13
+ scroll();
14
+ } else if (event.key === "ArrowRight" || event.key === "ArrowDown" || event.key === "Enter" || event.key === " ") {
15
+ if (index < size - 1) {
16
+ index ++;
17
+ }
18
+ scroll();
19
+ }
20
+ });
21
+ }
22
+
23
+ function scroll() {
24
+ document.querySelectorAll("*[class$='slide']")[index].scrollIntoView();
25
+ console.log("Page: " + index);
26
+ }
27
+
28
+ window.onload = prepare;
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ #{header_string.strip.indent(4)}
7
+ <title>#{@title}</title>
8
+ </head>
9
+ <body>
10
+
11
+ #{main_string.strip.indent(2)}
12
+
13
+ </body>
14
+ </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenml-slide
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziphil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-24 00:00:00.000000000 Z
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sassc
@@ -49,6 +49,8 @@ extra_rdoc_files: []
49
49
  files:
50
50
  - source/zenml/slide.rb
51
51
  - source/zenml/slide/converter.rb
52
+ - source/zenml/slide/resource/script.js
53
+ - source/zenml/slide/resource/template.html
52
54
  homepage: https://github.com/Ziphil/ZenithalSlide
53
55
  licenses:
54
56
  - MIT