mumuki-html-runner 1.3.1 → 1.4.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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test_hook.rb +20 -11
  3. data/lib/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a6e31df9afc15f0ad49852a5bab59a15c66381a355a31fcd749df891c91db12
4
- data.tar.gz: 03c5408ef996e8f040b3e7d9529d328e7f930596b8afc97085e61e061707e8fc
3
+ metadata.gz: 69334d46a08d472eab0c7f3c876deddb6b112d76c396963788d7d2e667464742
4
+ data.tar.gz: 676462124aca9486d5874f2100acd8eae6e7de3595622e79241aaa1d4370d52c
5
5
  SHA512:
6
- metadata.gz: 83c061ea8a7f3febf3f8f7c07c50b1af1c362bb67c28cc193c8e06acbab5a0d607edc8928442abaa234440835b97d23fff4e800e2defe7d054d546442052b765
7
- data.tar.gz: 240d048c86c734b2dfeb64c7eff424cd4ee4c00f9296df594ff06e08039431004354f89ccfb9568d1df82769efd23ef4329b75df4a4adf9fd3c2617203d9b77f
6
+ metadata.gz: d20a1a4a40b4688fec39cb16ee66273cca98cda64b62b056cee45deec23de6be3fbda41c9152272ab52a779550b7dc06bbc967bd2f01d6fe96d7d2c7087e9178
7
+ data.tar.gz: 7a124a4980f436e105b4c88b75f5b3e9abc34a4da00ce24b7181baea2de47e726bbebabc22c3b4fa8b7a41cf3ddce907486c7c47788fba08a6ea7cd881454688
data/lib/test_hook.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  require 'mumukit/hook'
2
2
 
3
- class String
4
- def visible_chars
5
- gsub(/\s+/, '').downcase
6
- end
7
- end
8
-
9
3
  class HtmlTestHook < Mumukit::Hook
10
4
  def compile(request)
11
5
  request
@@ -23,13 +17,18 @@ class HtmlTestHook < Mumukit::Hook
23
17
  end
24
18
 
25
19
  def contents_match?(expected, actual)
26
- hexp(expected) == hexp(actual)
20
+ hexp_without_blanks(expected) == hexp_without_blanks(actual)
27
21
  rescue
28
22
  expected == actual
29
23
  end
30
24
 
31
- def hexp(content)
32
- squeezed_content = ["\r", "\n", "\t"].reduce(content) { |c, it| c.gsub(it, ' ') }.squeeze(' ')
25
+ def hexp_without_blanks(content)
26
+ hexp ["\r", "\n", "\t"]
27
+ .reduce(content.strip) { |c, it| c.gsub(it, ' ') }
28
+ .squeeze(' ')
29
+ end
30
+
31
+ def hexp(squeezed_content)
33
32
  Hexp.parse("<html>#{squeezed_content}</html>")
34
33
  end
35
34
 
@@ -49,10 +48,20 @@ class HtmlTestHook < Mumukit::Hook
49
48
  html
50
49
  end
51
50
 
51
+ def page_title(dom)
52
+ title = dom.xpath('//title').first&.text
53
+ title.present? ? " data-title=\"#{title}\"" : ''
54
+ end
55
+
56
+ def page_favicon(dom)
57
+ dom.xpath("//link[@rel='icon' and @href]").first
58
+ .try { |tag| " data-favicon=\"#{tag['href']}\"" }
59
+ end
60
+
52
61
  def build_iframe(content)
62
+ dom = hexp(content).to_dom
53
63
  <<html
54
- <div class="mu-browser">
55
- <iframe srcdoc="#{content.gsub('"', '&quot;')}"></iframe>
64
+ <div class="mu-browser"#{page_title dom}#{page_favicon dom} data-srcdoc="#{content.gsub('"', '&quot;')}">
56
65
  </div>
57
66
  html
58
67
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HtmlVersionHook
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-html-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-25 00:00:00.000000000 Z
11
+ date: 2017-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit